-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathinterest_test.go
71 lines (58 loc) · 2.09 KB
/
interest_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
62
63
64
65
66
67
68
69
70
71
package ndn_test
import (
"testing"
"time"
"github.com/usnistgov/ndn-dpdk/ndn"
"github.com/usnistgov/ndn-dpdk/ndn/tlv"
)
func TestInterestEncode(t *testing.T) {
assert, _ := makeAR(t)
var interest ndn.Interest
interest.Name = ndn.ParseName("/A")
wire, e := tlv.EncodeFrom(interest)
assert.NoError(e)
assert.Len(wire, 13)
assert.Equal(bytesFromHex("050B 0703080141 0A04"), wire[:9])
assert.Equal("/8=A", interest.String())
interest = ndn.MakeInterest("/B", ndn.CanBePrefixFlag, ndn.MustBeFreshFlag,
ndn.ForwardingHint{ndn.ParseName("/FH")}, ndn.NonceFromUint(0x85AC8579),
8198*time.Millisecond, ndn.HopLimit(5),
)
wire, e = tlv.EncodeFrom(interest)
assert.NoError(e)
assert.Equal(bytesFromHex("051E name=0703080142 cbp=2100 mbf=1200 "+
"fh=1E06070408024648 nonce=0A0485AC8579 lifetime=0C022006 hoplimit=220105"), wire)
assert.Equal("/8=B[P][F]", interest.String())
}
func TestInterestLpEncode(t *testing.T) {
assert, _ := makeAR(t)
var lph ndn.LpL3
lph.PitToken = bytesFromHex("B0B1B2")
interest := ndn.MakeInterest("/A", lph)
interest.Nonce = ndn.NonceFromUint(0xC0C1C2C3)
wire, e := tlv.EncodeFrom(interest.ToPacket())
assert.NoError(e)
assert.Equal(bytesFromHex("6414 pittoken=6203B0B1B2 payload=500D "+
"interest=050B 0703080141 0A04C0C1C2C3"), wire)
}
func TestInterestDecode(t *testing.T) {
assert, _ := makeAR(t)
var pkt ndn.Packet
assert.NoError(tlv.Decode(bytesFromHex("0505 0703080141"), &pkt))
interest := pkt.Interest
assert.NotNil(interest)
nameEqual(assert, "/A", interest)
assert.False(interest.CanBePrefix)
assert.False(interest.MustBeFresh)
assert.NoError(tlv.Decode(bytesFromHex("051E name=0703080141 cbp=2100 mbf=1200 "+
"fh=1E06070408024648 nonce=0A04A0A1A2A3 lifetime=0C0276A1 hoplimit=2201DC"), &pkt))
interest = pkt.Interest
assert.NotNil(interest)
nameEqual(assert, "/A", interest)
assert.True(interest.CanBePrefix)
assert.True(interest.MustBeFresh)
assert.Len(interest.ForwardingHint, 1)
assert.Equal(ndn.Nonce{0xA0, 0xA1, 0xA2, 0xA3}, interest.Nonce)
assert.Equal(30369*time.Millisecond, interest.Lifetime)
assert.EqualValues(220, interest.HopLimit)
}