forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
topotato: test_bgp_route_map_match_source_protocol.py #123
Open
Chromico
wants to merge
2
commits into
opensourcerouting:topotato-base
Choose a base branch
from
tecknologg:bgp-route-map-match-source-protocol
base: topotato-base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# Copyright (C) 2023 Nathan Mangar | ||
|
||
""" | ||
Test if r1 can announce only static routes to r2, and only connected | ||
routes to r3 using `match source-protocol` with route-maps. | ||
""" | ||
|
||
|
||
__topotests_file__ = ( | ||
"bgp_route_map_match_source_protocol/test_bgp_route_map_match_source_protocol.py" | ||
) | ||
__topotests_gitrev__ = "9c3ffc80db2ef0445ab6d8dabf6b5f696cbd0470" | ||
|
||
# pylint: disable=invalid-name, missing-class-docstring, missing-function-docstring, line-too-long, consider-using-f-string, wildcard-import, unused-wildcard-import, f-string-without-interpolation, too-few-public-methods | ||
|
||
from topotato import * | ||
|
||
|
||
@topology_fixture() | ||
def topology(topo): | ||
""" | ||
[ r1 ]--{ s2 } | ||
| | | ||
{ s1 }--[ r3 ] | ||
| | ||
[ r2 ] | ||
""" | ||
|
||
topo.router("r1").lo_ip4.append("172.16.255.1/32") | ||
topo.router("r1").iface_to("s1").ip4.append("192.168.1.1/24") | ||
topo.router("r2").iface_to("s1").ip4.append("192.168.1.2/24") | ||
topo.router("r1").iface_to("s2").ip4.append("192.168.2.1/24") | ||
topo.router("r3").iface_to("s1").ip4.append("192.168.2.2/24") | ||
|
||
|
||
class Configs(FRRConfigs): | ||
routers = ["r1", "r2", "r3"] | ||
|
||
zebra = """ | ||
#% extends "boilerplate.conf" | ||
#% block main | ||
#% for iface in router.ifaces | ||
interface {{ iface.ifname }} | ||
ip address {{ iface.ip4[0] }} | ||
! | ||
#% endfor | ||
#% endblock | ||
""" | ||
|
||
# this bit does not seem to work. It's required so that bgp_check_advertised_routes_r2 can pass | ||
staticd = """ | ||
#% extends "boilerplate.conf" | ||
#% block main | ||
#% if router.name == 'r1' | ||
ip route 10.10.10.10/32 192.168.2.2 | ||
#% endif | ||
#% endblock | ||
""" | ||
|
||
bgpd = """ | ||
#% extends "boilerplate.conf" | ||
#% block main | ||
#% if router.name == 'r1' | ||
router bgp 65001 | ||
no bgp ebgp-requires-policy | ||
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as external | ||
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 1 3 | ||
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers connect 1 | ||
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} remote-as external | ||
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers 1 3 | ||
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers connect 1 | ||
address-family ipv4 | ||
redistribute connected | ||
redistribute static | ||
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} route-map r2 out | ||
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} route-map r3 out | ||
exit-address-family | ||
! | ||
route-map r2 permit 10 | ||
match source-protocol static | ||
route-map r3 permit 10 | ||
match source-protocol connected | ||
! | ||
#% elif router.name == 'r2' | ||
router bgp 65002 | ||
no bgp ebgp-requires-policy | ||
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as external | ||
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 1 3 | ||
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers connect 1 | ||
! | ||
#% elif router.name == 'r3' | ||
router bgp 65003 | ||
no bgp ebgp-requires-policy | ||
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} remote-as external | ||
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers 1 3 | ||
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers connect 1 | ||
! | ||
#% endif | ||
#% endblock | ||
""" | ||
|
||
|
||
class BGPRouteMapMatchSourceProtocol( | ||
TestBase, AutoFixture, topo=topology, configs=Configs | ||
): | ||
@topotatofunc | ||
def bgp_check_advertised_routes_r2(self, _, r1, r3): | ||
expected = { | ||
"advertisedRoutes": { | ||
"10.10.10.10/32": { | ||
"valid": True, | ||
} | ||
}, | ||
"totalPrefixCounter": 1, | ||
} | ||
|
||
yield from AssertVtysh.make( | ||
r1, | ||
"bgpd", | ||
f"show bgp ipv4 unicast neighbors {r3.iface_to('s1').ip4[0].ip} advertised-routes json", | ||
maxwait=5.0, | ||
compare=expected, | ||
) | ||
|
||
@topotatofunc | ||
def bgp_check_advertised_routes_r3(self, _, r1): | ||
expected = { | ||
"advertisedRoutes": { | ||
"192.168.1.0/24": { | ||
"valid": True, | ||
}, | ||
"192.168.2.0/24": { | ||
"valid": True, | ||
}, | ||
"172.16.255.1/32": { | ||
"valid": True, | ||
}, | ||
}, | ||
"totalPrefixCounter": 3, | ||
} | ||
yield from AssertVtysh.make( | ||
r1, | ||
"bgpd", | ||
f"show bgp ipv4 unicast neighbors 192.168.2.2 advertised-routes json", | ||
maxwait=5.0, | ||
compare=expected, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r2
notr3
:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed :)