summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2017-05-05 11:19:40 -0400
committerWataru Ishida <ishida.wataru@lab.ntt.co.jp>2017-05-10 08:05:47 +0000
commit1f053c25c423c79471fbe1d5fb6c618bb67409df (patch)
treeba3c43da6df3e1163a754ff742f25a64d819d6e2 /table
parent540d77319c6eaa1eefd7b52df2a4771c7ee565ac (diff)
*: support remove private as
cli ``` $ gobgp n add <neighbor-addr> as <asn> remove-private-as (all|replace) ``` config ``` neighbor: config: peer-as: <asn> neighbor-address: <neighbor-addr> remove-private-as: all ``` Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/path.go36
-rw-r--r--table/path_test.go22
2 files changed, 58 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go
index ef63d720..3b0fc40d 100644
--- a/table/path.go
+++ b/table/path.go
@@ -188,6 +188,9 @@ func UpdatePathAttrs(global *config.Global, peer *config.Neighbor, info *PeerInf
path.SetNexthop(localAddress)
}
+ // remove-private-as handling
+ path.RemovePrivateAS(peer.Config.LocalAs, peer.State.RemovePrivateAs)
+
// AS_PATH handling
path.PrependAsn(peer.Config.LocalAs, 1)
@@ -677,6 +680,39 @@ func (path *Path) PrependAsn(asn uint32, repeat uint8) {
path.setPathAttr(asPath)
}
+func isPrivateAS(as uint32) bool {
+ return (64512 <= as && as <= 65534) || (4200000000 <= as && as <= 4294967294)
+}
+
+func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsOption) {
+ original := path.GetAsPath()
+ if original == nil {
+ return
+ }
+ switch option {
+ case config.REMOVE_PRIVATE_AS_OPTION_ALL, config.REMOVE_PRIVATE_AS_OPTION_REPLACE:
+ newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value))
+ for _, param := range original.Value {
+ asParam := param.(*bgp.As4PathParam)
+ newASParam := make([]uint32, 0, len(asParam.AS))
+ for _, as := range asParam.AS {
+ if isPrivateAS(as) {
+ if option == config.REMOVE_PRIVATE_AS_OPTION_REPLACE {
+ newASParam = append(newASParam, localAS)
+ }
+ } else {
+ newASParam = append(newASParam, as)
+ }
+ }
+ if len(newASParam) > 0 {
+ newASParams = append(newASParams, bgp.NewAs4PathParam(asParam.Type, newASParam))
+ }
+ }
+ path.setPathAttr(bgp.NewPathAttributeAsPath(newASParams))
+ }
+ return
+}
+
func (path *Path) GetCommunities() []uint32 {
communityList := []uint32{}
if attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_COMMUNITIES); attr != nil {
diff --git a/table/path_test.go b/table/path_test.go
index 6e7a3534..29a296ac 100644
--- a/table/path_test.go
+++ b/table/path_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"time"
+ "github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"github.com/stretchr/testify/assert"
)
@@ -331,3 +332,24 @@ func updateMsgP3() *bgp.BGPMessage {
withdrawnRoutes := []*bgp.IPAddrPrefix{w1}
return bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
}
+
+func TestRemovePrivateAS(t *testing.T) {
+ aspathParam := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(2, []uint32{64512, 64513, 1, 2})}
+ aspath := bgp.NewPathAttributeAsPath(aspathParam)
+ nlri := bgp.NewIPAddrPrefix(24, "30.30.30.0")
+ path := NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false)
+ path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_ALL)
+ list := path.GetAsList()
+ assert.Equal(t, len(list), 2)
+ assert.Equal(t, list[0], uint32(1))
+ assert.Equal(t, list[1], uint32(2))
+
+ path = NewPath(nil, nlri, false, []bgp.PathAttributeInterface{aspath}, time.Now(), false)
+ path.RemovePrivateAS(10, config.REMOVE_PRIVATE_AS_OPTION_REPLACE)
+ list = path.GetAsList()
+ assert.Equal(t, len(list), 4)
+ assert.Equal(t, list[0], uint32(10))
+ assert.Equal(t, list[1], uint32(10))
+ assert.Equal(t, list[2], uint32(1))
+ assert.Equal(t, list[3], uint32(2))
+}