From e0031c61a0f6e6d5a90be5b4cb69fa994e85ac8e Mon Sep 17 00:00:00 2001 From: Patrick Seeburger Date: Fri, 22 Feb 2019 10:44:13 +0100 Subject: [PATCH] Change extended communities fomat Change format for extended BGP communities from (string,int,int) to (string,string,string) in order to support communities like (generic, 0x43000000, 0x1) --- bird/parser.go | 4 ++-- bird/parser_test.go | 32 +++++++++++++++++--------------- test/routes_bird1_ipv4.sample | 4 ++-- test/routes_bird2_ipv4.sample | 4 ++-- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/bird/parser.go b/bird/parser.go index 074e808..92ed1d9 100644 --- a/bird/parser.go +++ b/bird/parser.go @@ -79,7 +79,7 @@ func init() { regex.routes.bgp = regexp.MustCompile(`^\s+BGP.(\w+):\s+(.+)\s*$`) regex.routes.community = regexp.MustCompile(`^\((\d+),\s*(\d+)\)`) regex.routes.largeCommunity = regexp.MustCompile(`^\((\d+),\s*(\d+),\s*(\d+)\)`) - regex.routes.extendedCommunity = regexp.MustCompile(`^\(([^,]+),\s*(\d+),\s*(\d+)\)`) + regex.routes.extendedCommunity = regexp.MustCompile(`^\(([^,]+),\s*([^,]+),\s*([^,]+)\)`) regex.routes.origin = regexp.MustCompile(`\([^\(]*\)\s*`) regex.routes.prefixBird2 = regexp.MustCompile(`^([0-9a-f\.\:\/]+)?\s+unicast\s+\[([\w\.:]+)\s+([0-9\-\:\s]+)(?:\s+from\s+([0-9a-f\.\:\/]+))?\]\s+(?:(\*)\s+)?\((\d+)(?:\/\d+)?(?:\/[^\)]*)?\).*$`) regex.routes.gatewayBird2 = regexp.MustCompile(`^\s+via\s+([0-9a-f\.\:]+)\s+on\s+([\w\.]+)\s*$`) @@ -503,7 +503,7 @@ func parseRoutesExtendedCommunities(groups []string, res Parsed) { for _, community := range regex.routes.origin.FindAllString(groups[2], -1) { if regex.routes.extendedCommunity.MatchString(community) { communityGroups := regex.routes.extendedCommunity.FindStringSubmatch(community) - communities = append(communities, []interface{}{communityGroups[1], parseInt(communityGroups[2]), parseInt(communityGroups[3])}) + communities = append(communities, []interface{}{communityGroups[1], communityGroups[2], communityGroups[3]}) } } diff --git a/bird/parser_test.go b/bird/parser_test.go index a4a81f8..82da052 100644 --- a/bird/parser_test.go +++ b/bird/parser_test.go @@ -169,7 +169,8 @@ func runTestForIpv4WithFile(file string, t *testing.T) { {9033, 65666, 9}, }, extendedCommunities: []interface{}{ - []interface{}{"rt", int64(48858), int64(50)}, + []interface{}{"rt", "42", "1234"}, + []interface{}{"generic", "0x43000000", "0x1"}, }, metric: 100, localPref: "100", @@ -190,9 +191,9 @@ func runTestForIpv4WithFile(file string, t *testing.T) { {9033, 65666, 9}, }, extendedCommunities: []interface{}{ - []interface{}{"ro", int64(21414), int64(52001)}, - []interface{}{"ro", int64(21414), int64(52004)}, - []interface{}{"ro", int64(21414), int64(64515)}, + []interface{}{"ro", "21414", "52001"}, + []interface{}{"ro", "21414", "52004"}, + []interface{}{"ro", "21414", "64515"}, }, metric: 100, localPref: "100", @@ -213,9 +214,9 @@ func runTestForIpv4WithFile(file string, t *testing.T) { {9033, 65666, 9}, }, extendedCommunities: []interface{}{ - []interface{}{"ro", int64(21414), int64(52001)}, - []interface{}{"ro", int64(21414), int64(52004)}, - []interface{}{"ro", int64(21414), int64(64515)}, + []interface{}{"ro", "21414", "52001"}, + []interface{}{"ro", "21414", "52004"}, + []interface{}{"ro", "21414", "64515"}, }, metric: 100, localPref: "100", @@ -236,7 +237,8 @@ func runTestForIpv4WithFile(file string, t *testing.T) { {9033, 65666, 9}, }, extendedCommunities: []interface{}{ - []interface{}{"rt", int64(48858), int64(50)}, + []interface{}{"rt", "42", "1234"}, + []interface{}{"generic", "0x43000000", "0x1"}, }, metric: 100, localPref: "100", @@ -332,9 +334,9 @@ func runTestForIpv6WithFile(file string, t *testing.T) { {48821, 0, 2100}, }, extendedCommunities: []interface{}{ - []interface{}{"ro", int64(21414), int64(52001)}, - []interface{}{"ro", int64(21414), int64(52004)}, - []interface{}{"ro", int64(21414), int64(64515)}, + []interface{}{"ro", "21414", "52001"}, + []interface{}{"ro", "21414", "52004"}, + []interface{}{"ro", "21414", "64515"}, }, metric: 100, localPref: "500", @@ -355,9 +357,9 @@ func runTestForIpv6WithFile(file string, t *testing.T) { {48821, 0, 3100}, }, extendedCommunities: []interface{}{ - []interface{}{"ro", int64(21414), int64(52001)}, - []interface{}{"ro", int64(21414), int64(52004)}, - []interface{}{"ro", int64(21414), int64(64515)}, + []interface{}{"ro", "21414", "52001"}, + []interface{}{"ro", "21414", "52004"}, + []interface{}{"ro", "21414", "64515"}, }, localPref: "100", metric: 100, @@ -378,7 +380,7 @@ func runTestForIpv6WithFile(file string, t *testing.T) { {48821, 0, 2100}, }, extendedCommunities: []interface{}{ - []interface{}{"unknown 0x4300", int64(0), int64(1)}, + []interface{}{"unknown 0x4300", "0", "1"}, }, metric: 100, localPref: "5000", diff --git a/test/routes_bird1_ipv4.sample b/test/routes_bird1_ipv4.sample index e56318c..814ea82 100644 --- a/test/routes_bird1_ipv4.sample +++ b/test/routes_bird1_ipv4.sample @@ -8,7 +8,7 @@ BIRD 1.6.3 ready. BGP.community: (0,5464) (0,8339) (0,8741) (0,8823) (0,12387) (0,13101) (0,16097) (0,16316) (0,20546) (0,20686) (0,20723) (0,21083) (0,21385) (0,24940) (0,25504) (0,28876) (0,29545) (0,30058) (0,31103) (0,31400) (0,39090) (0,39392) (0,39912) (0,42473) (0,43957) (0,44453) (0,47297) (0,47692) (0,48200) (0,50629) (0,51191) (0,51839) (0,51852) (0,54113) (0,56719) (0,57957) (0,60517) (0,60574) (0,61303) (0,62297) (0,62336) (0,62359) (33891,33892) (33891,50673) (48793,48793) (50673,500) (65101,11077) (65102,11000) (65103,724) (65104,150) BGP.large_community: (9033, 65666, 12) (9033, 65666, 9) - BGP.ext_community: (rt, 48858, 50) + BGP.ext_community: (rt, 42, 1234) (generic, 0x43000000, 0x1) 200.0.0.0/24 via 1.2.3.15 on eno7 [ID8497_AS1339 2017-06-21 08:17:31] * (100) [AS1339i] Type: BGP unicast univ BGP.origin: IGP @@ -35,4 +35,4 @@ BIRD 1.6.3 ready. BGP.local_pref: 100 BGP.community: (65011,3) (9033,3251) BGP.large_community: (9033, 65666, 12) (9033, 65666, 9) - BGP.ext_community: (rt, 48858, 50) + BGP.ext_community: (rt, 42, 1234) (generic, 0x43000000, 0x1) diff --git a/test/routes_bird2_ipv4.sample b/test/routes_bird2_ipv4.sample index a566130..4bd1f5c 100644 --- a/test/routes_bird2_ipv4.sample +++ b/test/routes_bird2_ipv4.sample @@ -9,7 +9,7 @@ BIRD 1.6.3 ready. BGP.community: (0,5464) (0,8339) (0,8741) (0,8823) (0,12387) (0,13101) (0,16097) (0,16316) (0,20546) (0,20686) (0,20723) (0,21083) (0,21385) (0,24940) (0,25504) (0,28876) (0,29545) (0,30058) (0,31103) (0,31400) (0,39090) (0,39392) (0,39912) (0,42473) (0,43957) (0,44453) (0,47297) (0,47692) (0,48200) (0,50629) (0,51191) (0,51839) (0,51852) (0,54113) (0,56719) (0,57957) (0,60517) (0,60574) (0,61303) (0,62297) (0,62336) (0,62359) (33891,33892) (33891,50673) (48793,48793) (50673,500) (65101,11077) (65102,11000) (65103,724) (65104,150) BGP.large_community: (9033, 65666, 12) (9033, 65666, 9) - BGP.ext_community: (rt, 48858, 50) + BGP.ext_community: (rt, 42, 1234) (generic, 0x43000000, 0x1) 200.0.0.0/24 unicast [ID8497_AS1339 2017-06-21 08:17:31] * (100) [AS1339i] via 1.2.3.15 on eno7 Type: BGP univ @@ -39,4 +39,4 @@ BIRD 1.6.3 ready. BGP.local_pref: 100 BGP.community: (65011,3) (9033,3251) BGP.large_community: (9033, 65666, 12) (9033, 65666, 9) - BGP.ext_community: (rt, 48858, 50) + BGP.ext_community: (rt, 42, 1234) (generic, 0x43000000, 0x1)