Skip to content

Commit dbed339

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 dbed339

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/topotests/high_ecmp/test_high_ecmp_unnumbered.py

+119
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,125 @@ 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+
else:
132+
print("RA state verified successfully for interface shut")
133+
134+
print("Do no shutdown for r1-eth200")
135+
tgen.gears["r1"].vtysh_cmd(
136+
"""
137+
configure terminal
138+
interface r1-eth200
139+
no shutdown
140+
"""
141+
)
142+
143+
sleep(2)
144+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
145+
sleep(2)
146+
rtadv_output2 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
147+
if rtadv_output1 == rtadv_output2:
148+
sys.stderr.write(
149+
f"RA state didn't change: got {rtadv_output1}, previous {rtadv_output2}\n"
150+
)
151+
failures += 1
152+
else:
153+
print("RA state verified successfully for interface unshut")
154+
155+
print("Remove r1-eth200")
156+
existing_config = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200")
157+
tgen.gears["r1"].cmd(
158+
"""
159+
sudo ip link set dev r1-eth200 down
160+
"""
161+
)
162+
sleep(2)
163+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
164+
pattern1 = '"administrativeStatus":"down"'
165+
166+
if pattern1 in rtadv_output1:
167+
print("Interface is down verified successfully")
168+
else:
169+
sys.stderr.write(f"Interface state not down yet:: got {rtadv_output1}\n")
170+
failures += 1
171+
172+
# Parse the JSON string into a Python dictionary
173+
try:
174+
rtadv_output1 = json.loads(rtadv_output1)
175+
sent_count1 = rtadv_output1.get("r1-eth200", {}).get(
176+
"ndRouterAdvertisementsSent"
177+
)
178+
except json.JSONDecodeError:
179+
sys.stderr.write(f"Error parsing JSON: {rtadv_output1}\n")
180+
failures += 1
181+
sent_count1 = None
182+
183+
if sent_count1 is not None:
184+
# Wait 2 seconds
185+
sleep(2)
186+
187+
# Get second output
188+
rtadv_output2 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
189+
190+
try:
191+
rtadv_output2 = json.loads(rtadv_output2)
192+
sent_count2 = rtadv_output2.get("r1-eth200", {}).get(
193+
"ndRouterAdvertisementsSent"
194+
)
195+
except json.JSONDecodeError:
196+
sys.stderr.write(f"Error parsing JSON: {rtadv_output2}\n")
197+
failures += 1
198+
sent_count2 = None
199+
200+
# Verify counts are the same
201+
if sent_count1 is not None and sent_count2 is not None:
202+
if sent_count1 != sent_count2:
203+
sys.stderr.write(
204+
f"RA count changed from {sent_count1} to {sent_count2} within 2 seconds\n"
205+
)
206+
failures += 1
207+
else:
208+
print(
209+
f"RA count verified successfully: {sent_count1} (unchanged after 2 seconds)"
210+
)
211+
212+
tgen.gears["r1"].cmd(
213+
"""
214+
sudo ip link set dev r1-eth200 up
215+
"""
216+
)
217+
pattern1 = '"administrativeStatus":"up"'
218+
rtadv_output1 = tgen.gears["r1"].vtysh_cmd("show interface r1-eth200 json")
219+
if pattern1 in rtadv_output1:
220+
print("Interface is up verified successfully")
221+
else:
222+
sys.stderr.write(f"Interface state not up yet:: got {rtadv_output1}\n")
223+
failures += 1
224+
assert failures == 0, f"Test failed with {failures} failures"
225+
226+
108227
def test_bgp_route_cleanup():
109228
failures = 0
110229
net = get_topogen().net

0 commit comments

Comments
 (0)