Skip to content

Commit 9ca0ca1

Browse files
committed
test: Add test case to verify RA adv
Added test cases with interface down/up/shutdown to verify RA state of an interface Signed-off-by: Soumya Roy <[email protected]>
1 parent 1634d0b commit 9ca0ca1

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/topotests/high_ecmp/test_high_ecmp_unnumbered.py

+97
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,103 @@ def teardown_module(_mod):
105105
tgen.stop_topology()
106106

107107

108+
def test_v6_rtadv_():
109+
failures = 0
110+
tgen = get_topogen()
111+
print("Shutdown r1-eth200")
112+
tgen.gears["r1"].vtysh_cmd(
113+
"""
114+
configure terminal
115+
interface r1-eth200
116+
shutdown
117+
"""
118+
)
119+
120+
# Take two snap shots for RA status, it should not change
121+
# Give enough time, RA adv timer to expire
122+
sleep(2)
123+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
124+
sleep(2)
125+
rtadv_output2 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
126+
if rtadv_output1 != rtadv_output2:
127+
sys.stderr.write(
128+
f"RA state should not have changed: got {rtadv_output1}, expected {rtadv_output2}\n"
129+
)
130+
failures += 1
131+
132+
logger.info("Do no shutdown for r1-eth200")
133+
tgen.gears["r1"].vtysh_cmd(
134+
"""
135+
configure terminal
136+
interface r1-eth200
137+
no shutdown
138+
"""
139+
)
140+
141+
sleep(2)
142+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
143+
sleep(2)
144+
rtadv_output2 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
145+
if rtadv_output1 == rtadv_output2:
146+
sys.stderr.write(
147+
f"RA state didn't change: got {rtadv_output1}, previous {rtadv_output2}\n"
148+
)
149+
failures += 1
150+
151+
logger.info("Remove r1-eth200")
152+
existing_config = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200")
153+
tgen.gears["r1"].cmd(
154+
"""
155+
sudo ip link set dev r1-eth200 down
156+
"""
157+
)
158+
159+
sleep(2)
160+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
161+
pattern1 = '"administrativeStatus":"down"'
162+
163+
if pattern1 not in rtadv_output1:
164+
sys.stderr.write(f"Interface state not down yet:: got {rtadv_output1}\n")
165+
failures += 1
166+
167+
# Parse the JSON string into a Python dictionary
168+
rtadv_output1 = json.loads(rtadv_output1)
169+
sent_count1 = rtadv_output1.get("r1-eth200", {}).get("ndRouterAdvertisementsSent")
170+
171+
if sent_count1 is not None:
172+
# Wait 2 seconds
173+
sleep(2)
174+
175+
# Get second output
176+
rtadv_output2 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
177+
178+
rtadv_output2 = json.loads(rtadv_output2)
179+
sent_count2 = rtadv_output2.get("r1-eth200", {}).get(
180+
"ndRouterAdvertisementsSent"
181+
)
182+
183+
# Verify counts are the same
184+
if sent_count1 is not None and sent_count2 is not None:
185+
if sent_count1 != sent_count2:
186+
sys.stderr.write(
187+
f"RA count changed from {sent_count1} to {sent_count2} within 2 seconds\n"
188+
)
189+
failures += 1
190+
191+
tgen.gears["r1"].cmd(
192+
"""
193+
sudo ip link set dev r1-eth200 up
194+
"""
195+
)
196+
197+
pattern1 = '"administrativeStatus":"up"'
198+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
199+
if pattern1 not in rtadv_output1:
200+
sys.stderr.write(f"Interface state not up yet:: got {rtadv_output1}\n")
201+
failures += 1
202+
assert failures == 0, f"Test failed with {failures} failures"
203+
204+
108205
def test_bgp_route_cleanup():
109206
failures = 0
110207
net = get_topogen().net

0 commit comments

Comments
 (0)