forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrib-command.go
80 lines (66 loc) · 2.09 KB
/
rib-command.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
72
73
74
75
76
77
78
79
80
package nfdmgmt
import (
"github.com/usnistgov/ndn-dpdk/core/nnduration"
"github.com/usnistgov/ndn-dpdk/ndn"
"github.com/usnistgov/ndn-dpdk/ndn/tlv"
)
var (
verbRibRegister = ndn.ParseName("/rib/register")
verbRibUnregister = ndn.ParseName("/rib/unregister")
)
func encodeRibCommonParameters(name ndn.Name, faceID int, origin int) (a []tlv.Fielder) {
a = append(a, name)
if faceID != 0 {
a = append(a, tlv.TLVNNI(TtFaceID, faceID))
}
a = append(a, tlv.TLVNNI(TtOrigin, origin))
return a
}
// RibRegisterCommand is a NFD command to register a route.
type RibRegisterCommand struct {
Name ndn.Name `json:"name"`
FaceID int `json:"faceID,omitempty"`
Origin int `json:"origin"`
Cost int `json:"cost"`
NoInherit bool `json:"noInherit"`
Capture bool `json:"capture"`
Expires nnduration.Milliseconds `json:"expires,omitempty"`
}
var _ ControlCommand = RibRegisterCommand{}
// Verb returns "rib/register".
func (RibRegisterCommand) Verb() []ndn.NameComponent {
return verbRibRegister
}
// Parameters encodes ControlParameters.
func (cmd RibRegisterCommand) Parameters() (a []tlv.Fielder) {
a = encodeRibCommonParameters(cmd.Name, cmd.FaceID, cmd.Origin)
a = append(a, tlv.TLVNNI(TtCost, cmd.Cost))
flags := 0
if !cmd.NoInherit {
flags |= 1
}
if cmd.Capture {
flags |= 2
}
a = append(a, tlv.TLVNNI(TtFlags, flags))
if cmd.Expires > 0 {
a = append(a, tlv.TLVNNI(TtExpirationPeriod, cmd.Expires))
}
return a
}
// RibUnregisterCommand is a NFD command to unregister a route.
type RibUnregisterCommand struct {
Name ndn.Name `json:"name"`
FaceID int `json:"faceID,omitempty"`
Origin int `json:"origin"`
}
var _ ControlCommand = RibUnregisterCommand{}
// Verb returns "rib/unregister".
func (RibUnregisterCommand) Verb() []ndn.NameComponent {
return verbRibUnregister
}
// Parameters encodes ControlParameters.
func (cmd RibUnregisterCommand) Parameters() (a []tlv.Fielder) {
a = encodeRibCommonParameters(cmd.Name, cmd.FaceID, cmd.Origin)
return a
}