Skip to content
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

[Do Not Review] tests: adding ospfv3 gr helper automation with scapy #9468

Closed
Closed
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
64 changes: 64 additions & 0 deletions tests/topotests/lib/common_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4591,3 +4591,67 @@ def verify_ip_nht(tgen, input_dict):

logger.debug("Exiting lib API: verify_ip_nht()")
return False




def scapy_send_raw_packet(
tgen, topo, senderRouter, intf, packet=None, interval=1, count=1
):
"""
Using scapy Raw() method to send BSR raw packet from one FRR
to other

Parameters:
-----------
* `tgen` : Topogen object
* `topo` : json file data
* `senderRouter` : Sender router
* `packet` : packet in raw format
* `interval` : Interval between the packets
* `count` : Number of packets to be sent

returns:
--------
errormsg or True
"""

global CD
result = ""
logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
sender_interface = intf
rnode = tgen.routers()[senderRouter]

for destLink, data in topo["routers"][senderRouter]["links"].items():
if "type" in data and data["type"] == "loopback":
continue

if not packet:
packet = topo["routers"][senderRouter]["pkt"]["test_packets"][packet][
"data"
]

if interval > 1 or count > 1:
cmd = (
"nohup /usr/bin/python {}/send_bsr_packet.py '{}' '{}' "
"--interval={} --count={} &".format(
CD, packet, sender_interface, interval, count
)
)
else:
cmd = (
"/usr/bin/python {}/send_bsr_packet.py '{}' '{}' "
"--interval={} --count={}".format(
CD, packet, sender_interface, interval, count
)
)

logger.info("Scapy cmd: \n %s", cmd)
result = rnode.run(cmd)

if result == "":
return result

logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True

63 changes: 63 additions & 0 deletions tests/topotests/lib/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2375,3 +2375,66 @@ def config_ospf6_interface(tgen, topo, input_dict=None, build=False, load_config
)
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return result


@retry(retry_timeout=20)
def verify_ospf6_gr_helper(tgen, topo, dut, input_dict=None):
"""
This API is used to vreify gr helper using command
show ip ospf graceful-restart helper

Parameters
----------
* `tgen` : Topogen object
* `topo` : topology descriptions
* 'dut' : router
* 'input_dict' - values to be verified

Usage:
-------
input_dict = {
"helperSupport":"Disabled",
"strictLsaCheck":"Enabled",
"restartSupoort":"Planned and Unplanned Restarts",
"supportedGracePeriod":1800
}
result = verify_ospf6_gr_helper(tgen, topo, dut, input_dict)

"""
logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
result = False

if 'ospf6' not in topo['routers'][dut]:
errormsg = "[DUT: {}] OSPF is not configured on the router.".format(
dut)
return errormsg

rnode = tgen.routers()[dut]
logger.info("Verifying OSPF GR details on router %s:", dut)
show_ospf_json = run_frr_cmd(rnode, "show ipv6 ospf graceful-restart helper json",
isjson=True)
# Verifying output dictionary show_ospf_json is empty or not
if not bool(show_ospf_json):
errormsg = "OSPF is not running"
raise ValueError (errormsg)
return errormsg

for ospf_gr, gr_data in input_dict.items():
try:
if input_dict[ospf_gr] == show_ospf_json[ospf_gr]:
logger.info("[DUT: FRR] OSPF GR Helper: %s is %s", ospf_gr,
show_ospf_json[ospf_gr])
result = True
else:
errormsg = ("[DUT: FRR] OSPF GR Helper: {} expected is {}, Found "
"is {}".format(ospf_gr, input_dict[ospf_gr], show_ospf_json[
ospf_gr]))
raise ValueError (errormsg)
return errormsg

except KeyError:
errormsg = ("[DUT: FRR] OSPF GR Helper: {}".format(ospf_gr))
return errormsg

logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return result
124 changes: 124 additions & 0 deletions tests/topotests/ospfv3_gr_helper_scapy/ospfv3_gr_helper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

{

"address_types": [
"ipv6"
],
"ipv6base": "fd00::",
"ipv6mask": 64,
"link_ip_start": {
"ipv6": "fd00::",
"v6mask": 64
},
"lo_prefix": {
"ipv6": "2001:db8:f::",
"v6mask": 128
},
"switches": {
"s1": {
"links": {
"r0": {
"ipv6": "fe80::250:56ff:feb7:4aa3/10",
"ospf6": {
"area": "0.0.0.0",
"hello_interval": 1,
"dead_interval": 40,
"priority": 98
}
},
"r1": {
"ipv6": "fe80::7270:8bff:fed0:51ef/10",
"ospf6": {
"area": "0.0.0.0",
"hello_interval": 1,
"dead_interval": 40,
"priority": 99
}
},
"r2": {
"ipv6": "fe80::2000:56ff:feb7:4aa3/10",
"ospf6": {
"area": "0.0.0.0",
"hello_interval": 1,
"dead_interval": 40,
"priority": 0
}
},
"r3": {
"ipv6": "fe80::3000:56ff:feb7:4aa3/10",
"ospf6": {
"area": "0.0.0.0",
"hello_interval": 1,
"dead_interval": 40,
"priority": 0
}
}
}
}
},
"routers": {
"r0": {
"links": {
"lo": {
"ipv6": "auto",
"type": "loopback"
}
},
"ospf6": {
"router_id": "100.1.1.0",
"neighbors": {
"r1": {},
"r2": {},
"r3": {}
}
}
},
"r1": {
"links": {
"lo": {
"ipv6": "auto",
"type": "loopback"
}
},
"ospf6": {
"router_id": "1.1.1.1",
"neighbors": {
"r0": {},
"r2": {},
"r3": {}
}
},
"opq_lsa_hex": "33330000000570708bd051ef86dd6c00000000385901fe8000000000000072708bfffed051efff0200000000000000000000000000050304003801010101000000002cf60000000000010001000b000000350101010180000001fc97002400010004000000780002000101000000"
},
"r2": {
"links": {
"lo": {
"ipv6": "auto",
"type": "loopback"
}
},
"ospf6": {
"router_id": "100.1.1.2",
"neighbors": {
"r1": {},
"r0": {}
}
}
},
"r3": {
"links": {
"lo": {
"ipv6": "auto",
"type": "loopback"
}
},
"ospf6": {
"router_id": "100.1.1.3",
"neighbors": {
"r0": {},
"r1": {}
}
}
}
}
}
Loading