1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Changed the data structure for the extended communities to be a single

slice of {string, int64, int64} instead of a parsed record.
This commit is contained in:
Patrick Seeburger 2018-10-04 21:09:50 +02:00 committed by Benedikt Rudolph
parent 95cf1a71af
commit 980fcff9c2
2 changed files with 27 additions and 28 deletions

View file

@ -441,12 +441,11 @@ func parseRoutesLargeCommunities(groups []string, res Parsed) {
}
func parseRoutesExtendedCommunities(groups []string, res Parsed) {
communities := []Parsed{}
communities := []interface{}{}
for _, community := range regex.routes.origin.FindAllString(groups[2], -1) {
if regex.routes.extendedCommunity.MatchString(community) {
communityGroups := regex.routes.extendedCommunity.FindStringSubmatch(community)
c := Parsed{communityGroups[1]: []int64{parseInt(communityGroups[2]), parseInt(communityGroups[3])}}
communities = append(communities, c)
communities = append(communities, []interface{}{communityGroups[1], parseInt(communityGroups[2]), parseInt(communityGroups[3])})
}
}

View file

@ -100,8 +100,8 @@ func runTestForIpv4WithFile(file string, t *testing.T) {
{9033, 65666, 12},
{9033, 65666, 9},
},
extendedCommunities: []Parsed{
{"rt": []int64{48858, 50}},
extendedCommunities: []interface{}{
[]interface{}{"rt", int64(48858), int64(50)},
},
metric: 100,
localPref: "100",
@ -121,10 +121,10 @@ func runTestForIpv4WithFile(file string, t *testing.T) {
{9033, 65666, 12},
{9033, 65666, 9},
},
extendedCommunities: []Parsed{
{"ro": []int64{21414, 52001}},
{"ro": []int64{21414, 52004}},
{"ro": []int64{21414, 64515}},
extendedCommunities: []interface{}{
[]interface{}{"ro", int64(21414), int64(52001)},
[]interface{}{"ro", int64(21414), int64(52004)},
[]interface{}{"ro", int64(21414), int64(64515)},
},
metric: 100,
localPref: "100",
@ -144,10 +144,10 @@ func runTestForIpv4WithFile(file string, t *testing.T) {
{9033, 65666, 12},
{9033, 65666, 9},
},
extendedCommunities: []Parsed{
{"ro": []int64{21414, 52001}},
{"ro": []int64{21414, 52004}},
{"ro": []int64{21414, 64515}},
extendedCommunities: []interface{}{
[]interface{}{"ro", int64(21414), int64(52001)},
[]interface{}{"ro", int64(21414), int64(52004)},
[]interface{}{"ro", int64(21414), int64(64515)},
},
metric: 100,
localPref: "100",
@ -167,8 +167,8 @@ func runTestForIpv4WithFile(file string, t *testing.T) {
{9033, 65666, 12},
{9033, 65666, 9},
},
extendedCommunities: []Parsed{
{"rt": []int64{48858, 50}},
extendedCommunities: []interface{}{
[]interface{}{"rt", int64(48858), int64(50)},
},
metric: 100,
localPref: "100",
@ -215,10 +215,10 @@ func runTestForIpv6WithFile(file string, t *testing.T) {
{48821, 0, 2000},
{48821, 0, 2100},
},
extendedCommunities: []Parsed{
{"ro": []int64{21414, 52001}},
{"ro": []int64{21414, 52004}},
{"ro": []int64{21414, 64515}},
extendedCommunities: []interface{}{
[]interface{}{"ro", int64(21414), int64(52001)},
[]interface{}{"ro", int64(21414), int64(52004)},
[]interface{}{"ro", int64(21414), int64(64515)},
},
metric: 100,
localPref: "500",
@ -238,10 +238,10 @@ func runTestForIpv6WithFile(file string, t *testing.T) {
{48821, 0, 3000},
{48821, 0, 3100},
},
extendedCommunities: []Parsed{
{"ro": []int64{21414, 52001}},
{"ro": []int64{21414, 52004}},
{"ro": []int64{21414, 64515}},
extendedCommunities: []interface{}{
[]interface{}{"ro", int64(21414), int64(52001)},
[]interface{}{"ro", int64(21414), int64(52004)},
[]interface{}{"ro", int64(21414), int64(64515)},
},
localPref: "100",
metric: 100,
@ -261,8 +261,8 @@ func runTestForIpv6WithFile(file string, t *testing.T) {
{48821, 0, 2000},
{48821, 0, 2100},
},
extendedCommunities: []Parsed{
{"unknown 0x4300": []int64{0, 1}},
extendedCommunities: []interface{}{
[]interface{}{"unknown 0x4300", int64(0), int64(1)},
},
metric: 100,
localPref: "5000",
@ -310,8 +310,8 @@ func assertRouteIsEqual(expected expectedRoute, actual Parsed, name string, t *t
t.Fatal(name, ": Expected large_community to be:", expected.largeCommunities, "not", largeCommunity)
}
if _, ok := bgp["ext_communities"]; ok {
if extendedCommunity := value(bgp, "ext_communities", name, t).([]Parsed); !reflect.DeepEqual(extendedCommunity, expected.extendedCommunities) {
if extendedCommunity, ok := bgp["ext_communities"]; ok {
if !reflect.DeepEqual(extendedCommunity.([]interface{}), expected.extendedCommunities) {
t.Fatal(name, ": Expected ext_community to be:", expected.extendedCommunities, "not", extendedCommunity)
}
}
@ -332,7 +332,7 @@ type expectedRoute struct {
asPath []string
community [][]int64
largeCommunities [][]int64
extendedCommunities []Parsed
extendedCommunities []interface{}
metric int64
protocol string
primary bool