diff options
author | Wataru Ishida <ishida.wataru@lab.ntt.co.jp> | 2016-09-22 09:36:43 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-10-02 06:20:07 -0700 |
commit | 64b0a7a467df3b13d25e7acecbbf7f1861b64ab8 (patch) | |
tree | 0c6b224e25428e83df5aac4d4f7fc88e2ef62d3d /packet | |
parent | 680ad99675a30191860295125c65c90dba06a396 (diff) |
packet/bgp: fix bug of CompareFlowSpecNLRI()
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 6 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 22 |
2 files changed, 24 insertions, 4 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index a3f137c4..d05e7c8d 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2397,7 +2397,6 @@ func flowSpecEtherTypeParser(rf RouteFamily, args []string) (FlowSpecComponentIn } return fmt.Errorf("ethernet type range exceeded") } - fmt.Println(args) return doFlowSpecNumericParser(0, args, validationFunc) } @@ -3301,10 +3300,9 @@ func CompareFlowSpecNLRI(n, m *FlowSpecNLRI) (int, error) { w := shorter[idx] if v.Type() < w.Type() { return invert, nil - } else if w.Type() > v.Type() { + } else if v.Type() > w.Type() { return invert * -1, nil - } - if v.Type() == FLOW_SPEC_TYPE_DST_PREFIX || v.Type() == FLOW_SPEC_TYPE_SRC_PREFIX { + } else if v.Type() == FLOW_SPEC_TYPE_DST_PREFIX || v.Type() == FLOW_SPEC_TYPE_SRC_PREFIX { // RFC5575 5.1 // // For IP prefix values (IP destination and source prefix) precedence is diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 0fcef12d..194dbf12 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -516,3 +516,25 @@ func Test_EVPNIPPrefixRoute(t *testing.T) { } } + +func Test_CompareFlowSpecNLRI(t *testing.T) { + assert := assert.New(t) + cmp, err := ParseFlowSpecComponents(RF_FS_IPv4_UC, "destination 10.0.0.2/32 source 10.0.0.1/32 destination-port =3128 protocol tcp") + assert.Nil(err) + n1 := &FlowSpecNLRI{Value: cmp, rf: RF_FS_IPv4_UC} + cmp, err = ParseFlowSpecComponents(RF_FS_IPv4_UC, "source 10.0.0.0/24 destination-port =3128 protocol tcp") + assert.Nil(err) + n2 := &FlowSpecNLRI{Value: cmp, rf: RF_FS_IPv4_UC} + cmp, err = ParseFlowSpecComponents(RF_FS_IPv4_UC, "source 10.0.0.9/32 port =80 =8080 destination-port >8080&<8080 =3128 source-port >1024 protocol udp tcp") + n3 := &FlowSpecNLRI{Value: cmp, rf: RF_FS_IPv4_UC} + assert.Nil(err) + cmp, err = ParseFlowSpecComponents(RF_FS_IPv4_UC, "destination 192.168.0.2/32") + n4 := &FlowSpecNLRI{Value: cmp, rf: RF_FS_IPv4_UC} + assert.Nil(err) + r, err := CompareFlowSpecNLRI(n1, n2) + assert.Nil(err) + assert.True(r > 0) + r, err = CompareFlowSpecNLRI(n3, n4) + assert.Nil(err) + assert.True(r < 0) +} |