summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-09-30 18:42:40 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-01 11:23:39 +0900
commit4081c33b46a72a1a61651a9d0463a2ed85a82bbe (patch)
tree7646f65fe2fee1341a4caac1565664a5a5a830d1
parent38d80240654acf7e6b41077b00ef4c8288d93e46 (diff)
path: distinguish aspath set from aspath seq
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--policy/policy_test.go16
-rw-r--r--table/path.go17
2 files changed, 17 insertions, 16 deletions
diff --git a/policy/policy_test.go b/policy/policy_test.go
index b36dae6c..246c77b3 100644
--- a/policy/policy_test.go
+++ b/policy/policy_test.go
@@ -554,8 +554,7 @@ func TestAsPathConditionEvaluate(t *testing.T) {
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam1 := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65005}),
- bgp.NewAsPathParam(1, []uint16{65001, 65010, 65004, 65005}),
+ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65010, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam1)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
@@ -567,7 +566,7 @@ func TestAsPathConditionEvaluate(t *testing.T) {
path1 := table.ProcessMessage(updateMsg1, peer)[0]
aspathParam2 := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(1, []uint16{65010}),
+ bgp.NewAsPathParam(2, []uint16{65010}),
}
aspath2 := bgp.NewPathAttributeAsPath(aspathParam2)
pathAttributes = []bgp.PathAttributeInterface{origin, aspath2, nexthop, med}
@@ -662,7 +661,6 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) {
origin := bgp.NewPathAttributeOrigin(0)
aspathParam1 := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 54000, 65004, 65005}),
- bgp.NewAsPathParam(1, []uint16{65001, 65010, 54000, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam1)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
@@ -705,7 +703,7 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) {
asPathSet5 := config.AsPathSet{
AsPathSetName: "asset5",
AsPathList: []config.AsPath{
- config.AsPath{AsPath: "^65001 65000 54000 65004 65005 65001,65010,54000,65004,65005$"},
+ config.AsPath{AsPath: "^65001 65000 54000 65004 65005$"},
},
}
@@ -726,7 +724,7 @@ func TestMultipleAsPathConditionEvaluate(t *testing.T) {
asPathSet8 := config.AsPathSet{
AsPathSetName: "asset8",
AsPathList: []config.AsPath{
- config.AsPath{AsPath: "6[0-9]+_6[0-9]+_6[0-9]+"},
+ config.AsPath{AsPath: "6[0-9]+_6[0-9]+_5[0-9]+"},
},
}
@@ -844,8 +842,8 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) {
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
+ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
@@ -1041,8 +1039,8 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
+ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
@@ -1501,8 +1499,8 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.2.1.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
- bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
+ bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
nexthop := bgp.NewPathAttributeNextHop("10.2.1.1")
diff --git a/table/path.go b/table/path.go
index 08e037ae..8997af67 100644
--- a/table/path.go
+++ b/table/path.go
@@ -330,31 +330,34 @@ func (path *Path) GetAsPathLen() int {
}
func (path *Path) GetAsString() string {
- r := ""
+ s := bytes.NewBuffer(make([]byte, 0, 64))
if _, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); attr != nil {
aspath := attr.(*bgp.PathAttributeAsPath)
for i, paramIf := range aspath.Value {
segment := paramIf.(*bgp.As4PathParam)
if i != 0 {
- r += " "
+ s.WriteString(" ")
}
sep := " "
switch segment.Type {
case bgp.BGP_ASPATH_ATTR_TYPE_SET, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET:
+ s.WriteString("{")
sep = ","
- case bgp.BGP_ASPATH_ATTR_TYPE_SEQ, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
- sep = " "
}
for j, as := range segment.AS {
- r += fmt.Sprintf("%d", as)
+ s.WriteString(fmt.Sprintf("%d", as))
if j != len(segment.AS)-1 {
- r += sep
+ s.WriteString(sep)
}
}
+ switch segment.Type {
+ case bgp.BGP_ASPATH_ATTR_TYPE_SET, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET:
+ s.WriteString("}")
+ }
}
}
- return r
+ return s.String()
}
func (path *Path) GetAsList() []uint32 {