From de58be441150daf8943a5a66ced6703b8201303e Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Sun, 26 Jun 2016 23:18:23 +0900 Subject: support AGGREGATOR and AS4_AGGREGATOR conversion Signed-off-by: FUJITA Tomonori --- table/message.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'table') diff --git a/table/message.go b/table/message.go index 5cf9b5b6..68801e73 100644 --- a/table/message.go +++ b/table/message.go @@ -20,6 +20,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet/bgp" "hash/fnv" + "reflect" ) func UpdatePathAttrs2ByteAs(msg *bgp.BGPUpdate) error { @@ -198,6 +199,58 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error { return nil } +func UpdatePathAggregator2ByteAs(msg *bgp.BGPUpdate) { + as := uint32(0) + var addr string + for _, attr := range msg.PathAttributes { + switch attr.(type) { + case *bgp.PathAttributeAggregator: + agg := attr.(*bgp.PathAttributeAggregator) + agg.Value.Askind = reflect.Uint16 + if agg.Value.AS > (1<<16)-1 { + as = agg.Value.AS + addr = agg.Value.Address.String() + agg.Value.AS = bgp.AS_TRANS + } + } + } + if as != 0 { + msg.PathAttributes = append(msg.PathAttributes, bgp.NewPathAttributeAs4Aggregator(as, addr)) + } +} + +func UpdatePathAggregator4ByteAs(msg *bgp.BGPUpdate) error { + var aggAttr *bgp.PathAttributeAggregator + var agg4Attr *bgp.PathAttributeAs4Aggregator + agg4AttrPos := 0 + for i, attr := range msg.PathAttributes { + switch attr.(type) { + case *bgp.PathAttributeAggregator: + attr := attr.(*bgp.PathAttributeAggregator) + if attr.Value.Askind == reflect.Uint16 { + aggAttr = attr + aggAttr.Value.Askind = reflect.Uint32 + } + case *bgp.PathAttributeAs4Aggregator: + agg4Attr = attr.(*bgp.PathAttributeAs4Aggregator) + agg4AttrPos = i + } + } + if aggAttr == nil && agg4Attr == nil { + return nil + } + + if aggAttr == nil && agg4Attr != nil { + return bgp.NewMessageError(bgp.BGP_ERROR_UPDATE_MESSAGE_ERROR, bgp.BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "AS4 AGGREGATOR attribute exists, but AGGREGATOR doesn't") + } + + if agg4Attr != nil { + msg.PathAttributes = append(msg.PathAttributes[:agg4AttrPos], msg.PathAttributes[agg4AttrPos+1:]...) + aggAttr.Value.AS = agg4Attr.Value.AS + } + return nil +} + func createUpdateMsgFromPath(path *Path, msg *bgp.BGPMessage) *bgp.BGPMessage { rf := path.GetRouteFamily() -- cgit v1.2.3