summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2017-05-05 12:30:32 -0400
committerWataru Ishida <ishida.wataru@lab.ntt.co.jp>2017-05-10 08:15:00 +0000
commit9b9a65d410bbf35730f4970932c7688203e096b1 (patch)
tree5a539d40d6190c20341ae7e5c4827e2c0bd532e2 /table
parent1f053c25c423c79471fbe1d5fb6c618bb67409df (diff)
*: support replace-peer-as (aka as-override)
we use the term replace-peer-as instead of as-override since openconfig is using it. cli ``` $ gobgp n add <neighbor-addr> as <asn> replace-peer-as ``` config ``` neighbor: config: peer-as: <asn> neighbor-address: <neighbor-addr> as-path-options: config: replace-peer-as: true ``` Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/path.go26
-rw-r--r--table/path_test.go14
2 files changed, 40 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go
index 3b0fc40d..0453139a 100644
--- a/table/path.go
+++ b/table/path.go
@@ -713,6 +713,32 @@ func (path *Path) RemovePrivateAS(localAS uint32, option config.RemovePrivateAsO
return
}
+func (path *Path) ReplaceAS(localAS, peerAS uint32) *Path {
+ original := path.GetAsPath()
+ if original == nil {
+ return path
+ }
+ newASParams := make([]bgp.AsPathParamInterface, 0, len(original.Value))
+ changed := false
+ for _, param := range original.Value {
+ asParam := param.(*bgp.As4PathParam)
+ newASParam := make([]uint32, 0, len(asParam.AS))
+ for _, as := range asParam.AS {
+ if as == peerAS {
+ as = localAS
+ changed = true
+ }
+ newASParam = append(newASParam, as)
+ }
+ newASParams = append(newASParams, bgp.NewAs4PathParam(asParam.Type, newASParam))
+ }
+ if changed {
+ path = path.Clone(path.IsWithdraw)
+ path.setPathAttr(bgp.NewPathAttributeAsPath(newASParams))
+ }
+ return path
+}
+
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 29a296ac..ea4e23d5 100644
--- a/table/path_test.go
+++ b/table/path_test.go
@@ -353,3 +353,17 @@ func TestRemovePrivateAS(t *testing.T) {
assert.Equal(t, list[2], uint32(1))
assert.Equal(t, list[3], uint32(2))
}
+
+func TestReplaceAS(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 = path.ReplaceAS(10, 1)
+ list := path.GetAsList()
+ assert.Equal(t, len(list), 4)
+ assert.Equal(t, list[0], uint32(64512))
+ assert.Equal(t, list[1], uint32(64513))
+ assert.Equal(t, list[2], uint32(10))
+ assert.Equal(t, list[3], uint32(2))
+}