diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-27 19:40:20 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-01 11:06:08 +0900 |
commit | e7cefb51f9cfd0012384239ee736375841af7a76 (patch) | |
tree | 82555f46303195712765f4c0e3c7b978b5ded253 | |
parent | 9b35be73826689b15839105ce0f386bbdaf56f06 (diff) |
table: simplify Path.getPathAttr()
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | packet/bgp.go | 4 | ||||
-rw-r--r-- | packet/validate.go | 6 | ||||
-rw-r--r-- | table/path.go | 21 |
3 files changed, 6 insertions, 25 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index e12d7cda..f5afc948 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1864,7 +1864,7 @@ type PathAttributeInterface interface { Serialize() ([]byte, error) Len() int getFlags() BGPAttrFlag - getType() BGPAttrType + GetType() BGPAttrType ToApiStruct() *api.PathAttr } @@ -1889,7 +1889,7 @@ func (p *PathAttribute) getFlags() BGPAttrFlag { return p.Flags } -func (p *PathAttribute) getType() BGPAttrType { +func (p *PathAttribute) GetType() BGPAttrType { return p.Type } diff --git a/packet/validate.go b/packet/validate.go index 3da96387..2afd53c4 100644 --- a/packet/validate.go +++ b/packet/validate.go @@ -23,10 +23,10 @@ func ValidateUpdateMsg(m *BGPUpdate, rfs map[RouteFamily]bool) (bool, error) { // check path attribute for _, a := range m.PathAttributes { // check duplication - if _, ok := seen[a.getType()]; !ok { - seen[a.getType()] = a + if _, ok := seen[a.GetType()]; !ok { + seen[a.GetType()] = a } else { - eMsg := "the path attribute apears twice. Type : " + strconv.Itoa(int(a.getType())) + eMsg := "the path attribute apears twice. Type : " + strconv.Itoa(int(a.GetType())) return false, NewMessageError(eCode, eSubCodeAttrList, nil, eMsg) } diff --git a/table/path.go b/table/path.go index 7ede28b8..0b8f732a 100644 --- a/table/path.go +++ b/table/path.go @@ -23,7 +23,6 @@ import ( "github.com/osrg/gobgp/packet" "math" "net" - "reflect" "time" ) @@ -261,26 +260,8 @@ func (path *Path) getPathAttrs() []bgp.PathAttributeInterface { } func (path *Path) getPathAttr(pattrType bgp.BGPAttrType) (int, bgp.PathAttributeInterface) { - attrMap := [bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR + 1]reflect.Type{} - attrMap[bgp.BGP_ATTR_TYPE_ORIGIN] = reflect.TypeOf(&bgp.PathAttributeOrigin{}) - attrMap[bgp.BGP_ATTR_TYPE_AS_PATH] = reflect.TypeOf(&bgp.PathAttributeAsPath{}) - attrMap[bgp.BGP_ATTR_TYPE_NEXT_HOP] = reflect.TypeOf(&bgp.PathAttributeNextHop{}) - attrMap[bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC] = reflect.TypeOf(&bgp.PathAttributeMultiExitDisc{}) - attrMap[bgp.BGP_ATTR_TYPE_LOCAL_PREF] = reflect.TypeOf(&bgp.PathAttributeLocalPref{}) - attrMap[bgp.BGP_ATTR_TYPE_ATOMIC_AGGREGATE] = reflect.TypeOf(&bgp.PathAttributeAtomicAggregate{}) - attrMap[bgp.BGP_ATTR_TYPE_AGGREGATOR] = reflect.TypeOf(&bgp.PathAttributeAggregator{}) - attrMap[bgp.BGP_ATTR_TYPE_COMMUNITIES] = reflect.TypeOf(&bgp.PathAttributeCommunities{}) - attrMap[bgp.BGP_ATTR_TYPE_ORIGINATOR_ID] = reflect.TypeOf(&bgp.PathAttributeOriginatorId{}) - attrMap[bgp.BGP_ATTR_TYPE_CLUSTER_LIST] = reflect.TypeOf(&bgp.PathAttributeClusterList{}) - attrMap[bgp.BGP_ATTR_TYPE_MP_REACH_NLRI] = reflect.TypeOf(&bgp.PathAttributeMpReachNLRI{}) - attrMap[bgp.BGP_ATTR_TYPE_MP_UNREACH_NLRI] = reflect.TypeOf(&bgp.PathAttributeMpUnreachNLRI{}) - attrMap[bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES] = reflect.TypeOf(&bgp.PathAttributeExtendedCommunities{}) - attrMap[bgp.BGP_ATTR_TYPE_AS4_PATH] = reflect.TypeOf(&bgp.PathAttributeAs4Path{}) - attrMap[bgp.BGP_ATTR_TYPE_AS4_AGGREGATOR] = reflect.TypeOf(&bgp.PathAttributeAs4Aggregator{}) - - t := attrMap[pattrType] for i, p := range path.pathAttrs { - if t == reflect.TypeOf(p) { + if p.GetType() == pattrType { return i, p } } |