diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-02-27 09:49:35 +0900 |
---|---|---|
committer | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-04-03 09:16:41 +0900 |
commit | 264bd0ca126bf721687764332a01315d56e5b671 (patch) | |
tree | 05a0eb911e99fcba2a621fde34f6fc749f130d1d /table/destination.go | |
parent | a25522edddf05653bef26c5ff220f34f7354791f (diff) |
packet/bgp: Getter functions for AS segment
This patch adds getter functions for the segment type and AS list of
each segment without using type assertion.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/table/destination.go b/table/destination.go index f9ed3509..fd32371d 100644 --- a/table/destination.go +++ b/table/destination.go @@ -861,17 +861,18 @@ func compareByMED(path1, path2 *Path) *Path { isSameAS := func() bool { firstAS := func(path *Path) uint32 { - if aspath := path.GetAsPath(); aspath != nil { - asPathParam := aspath.Value - for i := 0; i < len(asPathParam); i++ { - asPath := asPathParam[i].(*bgp.As4PathParam) - if asPath.Num == 0 { + if asPath := path.GetAsPath(); asPath != nil { + for _, v := range asPath.Value { + segType := v.GetType() + asList := v.GetAS() + if len(asList) == 0 { continue } - if asPath.Type == bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET || asPath.Type == bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ { + switch segType { + case bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ: continue } - return asPath.AS[0] + return asList[0] } } return 0 |