summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp/bgp_test.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-28 11:39:42 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-28 15:23:04 +0900
commit76c289ea3624502f12d03ee9a5a34340d571df88 (patch)
tree15120098ecd56f831b119edfb87503cd8b69c1bf /packet/bgp/bgp_test.go
parent5440f32fcd85264b659d126573f447a80eb3db31 (diff)
packet/bgp: Use fixed len types in FlowSpec components
Currently, the "FlowSpecComponentItem" uses int type for the "Op" and "Value" fields, but Golang int type has 4 bytes length on the 32-bit env and 8 bytes length on the 64-bit env. For example, to support the SNAP (Type 20) rule, which has 5 bytes value field, int type has not enough length on 32-bit env. This patch fixes to use the fixed length integer types for the FlowSpec components and avoid overflows of value range. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp/bgp_test.go')
-rw-r--r--packet/bgp/bgp_test.go46
1 files changed, 17 insertions, 29 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index d3e2719f..ba3cabbd 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -367,16 +367,11 @@ func Test_FlowSpecNlri(t *testing.T) {
cmp := make([]FlowSpecComponentInterface, 0)
cmp = append(cmp, NewFlowSpecDestinationPrefix(NewIPAddrPrefix(24, "10.0.0.0")))
cmp = append(cmp, NewFlowSpecSourcePrefix(NewIPAddrPrefix(24, "10.0.0.0")))
- eq := 0x1
- gt := 0x2
- lt := 0x4
- and := 0x40
- not := 0x2
- item1 := NewFlowSpecComponentItem(eq, TCP)
+ item1 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, TCP)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_IP_PROTO, []*FlowSpecComponentItem{item1}))
- item2 := NewFlowSpecComponentItem(gt|eq, 20)
- item3 := NewFlowSpecComponentItem(and|lt|eq, 30)
- item4 := NewFlowSpecComponentItem(eq, 10)
+ item2 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 20)
+ item3 := NewFlowSpecComponentItem(DEC_NUM_OP_AND|DEC_NUM_OP_LT_EQ, 30)
+ item4 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 10)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DST_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_SRC_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
@@ -384,14 +379,13 @@ func Test_FlowSpecNlri(t *testing.T) {
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ICMP_CODE, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PKT_LEN, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DSCP, []*FlowSpecComponentItem{item2, item3, item4}))
- isFlagment := 0x02
- lastFlagment := 0x08
- match := 0x1
- item5 := NewFlowSpecComponentItem(match, isFlagment)
- item6 := NewFlowSpecComponentItem(and, lastFlagment)
+ isFragment := uint64(0x02)
+ lastFragment := uint64(0x08)
+ item5 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_MATCH, isFragment)
+ item6 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND, lastFragment)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_FRAGMENT, []*FlowSpecComponentItem{item5, item6}))
item7 := NewFlowSpecComponentItem(0, TCP_FLAG_ACK)
- item8 := NewFlowSpecComponentItem(and|not, TCP_FLAG_URGENT)
+ item8 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND|BITMASK_FLAG_OP_NOT, TCP_FLAG_URGENT)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, []*FlowSpecComponentItem{item7, item8}))
n1 := NewFlowSpecIPv4Unicast(cmp)
buf1, err := n1.Serialize()
@@ -461,16 +455,11 @@ func Test_FlowSpecNlriv6(t *testing.T) {
cmp := make([]FlowSpecComponentInterface, 0)
cmp = append(cmp, NewFlowSpecDestinationPrefix6(NewIPv6AddrPrefix(64, "2001::"), 12))
cmp = append(cmp, NewFlowSpecSourcePrefix6(NewIPv6AddrPrefix(64, "2001::"), 12))
- eq := 0x1
- gt := 0x2
- lt := 0x4
- and := 0x40
- not := 0x2
- item1 := NewFlowSpecComponentItem(eq, TCP)
+ item1 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, TCP)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_IP_PROTO, []*FlowSpecComponentItem{item1}))
- item2 := NewFlowSpecComponentItem(gt|eq, 20)
- item3 := NewFlowSpecComponentItem(and|lt|eq, 30)
- item4 := NewFlowSpecComponentItem(eq, 10)
+ item2 := NewFlowSpecComponentItem(DEC_NUM_OP_GT_EQ, 20)
+ item3 := NewFlowSpecComponentItem(DEC_NUM_OP_AND|DEC_NUM_OP_LT_EQ, 30)
+ item4 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, 10)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DST_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_SRC_PORT, []*FlowSpecComponentItem{item2, item3, item4}))
@@ -479,11 +468,11 @@ func Test_FlowSpecNlriv6(t *testing.T) {
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_PKT_LEN, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_DSCP, []*FlowSpecComponentItem{item2, item3, item4}))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_LABEL, []*FlowSpecComponentItem{item2, item3, item4}))
- isFlagment := 0x02
- item5 := NewFlowSpecComponentItem(isFlagment, 0)
+ isFragment := uint64(0x02)
+ item5 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_MATCH, isFragment)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_FRAGMENT, []*FlowSpecComponentItem{item5}))
item6 := NewFlowSpecComponentItem(0, TCP_FLAG_ACK)
- item7 := NewFlowSpecComponentItem(and|not, TCP_FLAG_URGENT)
+ item7 := NewFlowSpecComponentItem(BITMASK_FLAG_OP_AND|BITMASK_FLAG_OP_NOT, TCP_FLAG_URGENT)
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_TCP_FLAG, []*FlowSpecComponentItem{item6, item7}))
n1 := NewFlowSpecIPv6Unicast(cmp)
buf1, err := n1.Serialize()
@@ -529,8 +518,7 @@ func Test_FlowSpecNlriL2(t *testing.T) {
cmp := make([]FlowSpecComponentInterface, 0)
cmp = append(cmp, NewFlowSpecDestinationMac(mac))
cmp = append(cmp, NewFlowSpecSourceMac(mac))
- eq := 0x1
- item1 := NewFlowSpecComponentItem(eq, int(IPv4))
+ item1 := NewFlowSpecComponentItem(DEC_NUM_OP_EQ, uint64(IPv4))
cmp = append(cmp, NewFlowSpecComponent(FLOW_SPEC_TYPE_ETHERNET_TYPE, []*FlowSpecComponentItem{item1}))
rd, _ := ParseRouteDistinguisher("100:100")
n1 := NewFlowSpecL2VPN(rd, cmp)