summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-06-26 23:18:23 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-06-26 23:18:23 +0900
commitde58be441150daf8943a5a66ced6703b8201303e (patch)
tree9ac3d65049a648e17158bafa7956e047fa5fdad4 /table
parent38230504ac1fb85409d382556d3e16e08149e399 (diff)
support AGGREGATOR and AS4_AGGREGATOR conversion
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/message.go53
1 files changed, 53 insertions, 0 deletions
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()