diff options
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 20 | ||||
-rw-r--r-- | packet/bgp_test.go | 39 |
2 files changed, 57 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 533b0288..6f541037 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1997,7 +1997,15 @@ func (a *AsPathParam) Len() int { } func (a *AsPathParam) ASLen() int { - return len(a.AS) + switch a.Type { + case BGP_ASPATH_ATTR_TYPE_SEQ: + return len(a.AS) + case BGP_ASPATH_ATTR_TYPE_SET: + return 1 + case BGP_ASPATH_ATTR_TYPE_CONFED_SET,BGP_ASPATH_ATTR_TYPE_CONFED_SEQ: + return 0 + } + return 0 } func NewAsPathParam(segType uint8, as []uint16) *AsPathParam { @@ -2048,7 +2056,15 @@ func (a *As4PathParam) Len() int { } func (a *As4PathParam) ASLen() int { - return len(a.AS) + switch a.Type { + case BGP_ASPATH_ATTR_TYPE_SEQ: + return len(a.AS) + case BGP_ASPATH_ATTR_TYPE_SET: + return 1 + case BGP_ASPATH_ATTR_TYPE_CONFED_SET,BGP_ASPATH_ATTR_TYPE_CONFED_SEQ: + return 0 + } + return 0 } func NewAs4PathParam(segType uint8, as []uint32) *As4PathParam { diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 3b5d7b4c..8afa7363 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -323,3 +323,42 @@ func Test_RFC5512(t *testing.T) { assert.Equal(nil, err) assert.Equal("2001::1", n2.String()) } + +func Test_ASLen(t *testing.T) { + assert := assert.New(t) + + aspath := AsPathParam{ + Num: 2, + AS: []uint16{65000, 65001}, + } + aspath.Type = BGP_ASPATH_ATTR_TYPE_SEQ + assert.Equal(2, aspath.ASLen()) + + aspath.Type = BGP_ASPATH_ATTR_TYPE_SET + assert.Equal(1, aspath.ASLen()) + + aspath.Type = BGP_ASPATH_ATTR_TYPE_CONFED_SEQ + assert.Equal(0, aspath.ASLen()) + + aspath.Type = BGP_ASPATH_ATTR_TYPE_CONFED_SET + assert.Equal(0, aspath.ASLen()) + + + as4path := As4PathParam{ + Num: 2, + AS: []uint32{65000, 65001}, + } + as4path.Type = BGP_ASPATH_ATTR_TYPE_SEQ + assert.Equal(2, as4path.ASLen()) + + as4path.Type = BGP_ASPATH_ATTR_TYPE_SET + assert.Equal(1, as4path.ASLen()) + + as4path.Type = BGP_ASPATH_ATTR_TYPE_CONFED_SEQ + assert.Equal(0, as4path.ASLen()) + + as4path.Type = BGP_ASPATH_ATTR_TYPE_CONFED_SET + assert.Equal(0, as4path.ASLen()) + +} + |