Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/bgpmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var protocolNameRe = regexp.MustCompile(`\[(.*?) .*\]`)
var routeSplitRe = regexp.MustCompile("(unicast|blackhole|unreachable|prohibited)")

var routeViaRe = regexp.MustCompile(`(?m)^\t(via .*?)$`)
var routeASPathRe = regexp.MustCompile(`(?m)^\tBGP\.as_path: (.*?)$`)
var routeASPathRe = regexp.MustCompile(`(?mi)^\tBGP(?:\.as)?_path: (.*?)$`)

func makeEdgeAttrs(preferred bool) RouteAttrs {
result := RouteAttrs{
Expand Down
4 changes: 4 additions & 0 deletions frontend/bgpmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func TestBirdRouteToGraph(t *testing.T) {
if result.GetEdge("4242423914", "target") == nil {
t.Error("Result doesn't contain edge from 4242423914 to target")
}
// This route is written in bird3 notation
if result.GetEdge("4242423391", "4242420604") == nil {
t.Error("Result doesn't contain edge from 4242423391 to 4242420604 (bird3)")
}
}

func TestBirdRouteToGraphviz(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func smartFormatter(s string) template.HTML {
s = template.HTMLEscapeString(s)
for _, line := range strings.Split(s, "\n") {
var lineFormatted string
if strings.HasPrefix(strings.TrimSpace(line), "BGP.as_path:") || strings.HasPrefix(strings.TrimSpace(line), "Neighbor AS:") || strings.HasPrefix(strings.TrimSpace(line), "Local AS:") {
if strings.HasPrefix(strings.TrimSpace(line), "BGP.as_path:") || strings.HasPrefix(strings.TrimSpace(line), "bgp_path:") || strings.HasPrefix(strings.TrimSpace(line), "Neighbor AS:") || strings.HasPrefix(strings.TrimSpace(line), "Local AS:") {
lineFormatted = regexp.MustCompile(`(\d+)`).ReplaceAllString(line, `<a href="/whois/AS${1}" class="whois">${1}</a>`)
} else {
lineFormatted = regexp.MustCompile(`([a-zA-Z0-9\-]*\.([a-zA-Z]{2,3}){1,2})(\s|$)`).ReplaceAllString(line, `<a href="/whois/${1}" class="whois">${1}</a>${3}`)
Expand Down
2 changes: 1 addition & 1 deletion frontend/telegram_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
} else if telegramIsCommand(request.Message.Text, "path") {
commandResult = telegramBatchRequestFormat(servers, "bird", "show route for "+target+" all primary", func(result string) string {
for _, s := range strings.Split(result, "\n") {
if strings.Contains(s, "BGP.as_path: ") {
if strings.Contains(s, "BGP.as_path: ") || strings.Contains(s, "bgp_path: ") {
return strings.TrimSpace(strings.Split(s, ":")[1])
}
}
Expand Down
22 changes: 13 additions & 9 deletions frontend/test_data/bgpmap_case1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ Table master4:
BGP.community: (64511,3) (64511,24) (64511,34)
BGP.large_community: (4242421080, 101, 42) (4242421080, 103, 123) (4242421080, 104, 2)
unicast [cola_3391 18:41:16.608 from fe80::3391] (100) [AS4242423914i]
via 172.22.96.65 on dn42-cola
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 4242423391 4242420604 4242423914
BGP.next_hop: 172.22.96.65
BGP.med: 50
BGP.local_pref: 100
BGP.community: (64511,4) (64511,34) (64511,24)
BGP.large_community: (4242420604, 2, 50) (4242420604, 501, 4242423914) (4242420604, 502, 44) (4242420604, 504, 4) (4242421080, 104, 1) (4242421080, 101, 44) (4242421080, 103, 126)
via 172.22.96.65 on dn42-bird3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, it might be better to move the Bird3 test case into a separate file (maybe with 2-3 routes in total?)

This would make it more clear where the output is coming from, as I don't think you would ever see mixed Bird 2 / 3 output formats in one command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but that would require either duplicating all appropriate tests or rework them to work with multiple inputs.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my POV : The code is straightforward, the test coverage is adequate, and the changes are minimal and focused.
That said, if the codebase doesn't already have a pattern for this, the current approach is pragmatic

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is fine, since bird-lg-go doesn't require an additional flag to switch mode between bird2/bird3, so it should simultaneously work with both of them.

preference: 100
igp_metric: 0
from: 172.22.96.65
source: BGP
bgp_origin: IGP
bgp_path: 4242423391 4242420604 4242423914
bgp_next_hop: 172.22.96.65
bgp_med: 50
bgp_local_pref: 100
bgp_community: (64511,4) (64511,34) (64511,24)
bgp_large_community: (4242420604, 2, 50) (4242420604, 501, 4242423914) (4242420604, 502, 44) (4242420604, 504, 4) (4242421080, 104, 1) (4242421080, 101, 44) (4242421080, 103, 126)
Internal route handling values: 0L 13G 0S id 3743
Loading