-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnack_test.go
61 lines (49 loc) · 2.07 KB
/
nack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ndn_test
import (
"testing"
"github.com/usnistgov/ndn-dpdk/ndn"
"github.com/usnistgov/ndn-dpdk/ndn/an"
"github.com/usnistgov/ndn-dpdk/ndn/tlv"
)
func TestNackLpEncode(t *testing.T) {
assert, _ := makeAR(t)
var lph ndn.LpL3
lph.PitToken = bytesFromHex("B0B1B2")
interest := ndn.MakeInterest("/A", lph, ndn.NonceFromUint(0xC0C1C2C3))
nackNoReason := ndn.MakeNack(interest)
wire, e := tlv.EncodeFrom(nackNoReason.ToPacket())
assert.NoError(e)
assert.Equal(bytesFromHex("6418 pittoken=6203B0B1B2 nack=FD032000 payload=500D "+
"interest=050B 0703080141 0A04C0C1C2C3"), wire)
nackNoRoute := ndn.MakeNack(interest)
nackNoRoute.Reason = an.NackNoRoute
wire, e = tlv.EncodeFrom(nackNoRoute.ToPacket())
assert.NoError(e)
assert.Equal(bytesFromHex("641D pittoken=6203B0B1B2 nack=FD032005FD03210196 payload=500D "+
"interest=050B 0703080141 0A04C0C1C2C3"), wire)
nackDuplicate := ndn.MakeNack(&interest, an.NackDuplicate)
wire, e = tlv.EncodeFrom(nackDuplicate.ToPacket())
assert.NoError(e)
assert.Equal(bytesFromHex("641D pittoken=6203B0B1B2 nack=FD032005FD03210164 payload=500D "+
"interest=050B 0703080141 0A04C0C1C2C3"), wire)
}
func TestNackDecode(t *testing.T) {
assert, _ := makeAR(t)
var pkt ndn.Packet
assert.NoError(tlv.Decode(bytesFromHex("6418 pittoken=6203B0B1B2 nack=FD032000 payload=500D "+
"interest=050B 0703080141 0A04A0A1A2A3"), &pkt))
nackNoReason := pkt.Nack
assert.NotNil(nackNoReason)
assert.EqualValues(an.NackUnspecified, nackNoReason.Reason)
nameEqual(assert, "/A", nackNoReason)
assert.Equal(ndn.Nonce{0xA0, 0xA1, 0xA2, 0xA3}, nackNoReason.Interest.Nonce)
assert.Equal("/8=A~unspecified", nackNoReason.String())
assert.NoError(tlv.Decode(bytesFromHex("641D pittoken=6203B0B1B2 nack=FD032005FD03210196 payload=500D "+
"interest=050B 0703080141 0A04A0A1A2A3"), &pkt))
nackNoRoute := pkt.Nack
assert.NotNil(nackNoRoute)
assert.EqualValues(an.NackNoRoute, nackNoRoute.Reason)
nameEqual(assert, "/A", nackNoRoute)
assert.Equal(ndn.Nonce{0xA0, 0xA1, 0xA2, 0xA3}, nackNoRoute.Interest.Nonce)
assert.Equal("/8=A~no-route", nackNoRoute.String())
}