def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0): logstr = "RequireUnicastRoutes %s" % str(wantroutes) vrfstr = "" if vrf != "": vrfstr = "vrf %s" % (vrf) if (afi != "ipv4") and (afi != "ipv6"): self.log("ERROR invalid afi") cmdstr = "show bgp %s %s unicast" % (vrfstr, afi) # non json form for humans cmd = 'vtysh -c "%s"' % cmdstr luCommand(target, cmd, ".", "None", "Get %s %s RIB (non-json)" % (vrfstr, afi)) cmd = 'vtysh -c "%s json"' % cmdstr ret = luCommand(target, cmd, ".*", "None", "Get %s %s RIB (json)" % (vrfstr, afi)) if re.search(r"^\s*$", ret): # degenerate case: empty json means no routes if len(wantroutes) > 0: luResult(target, False, title, logstr) return luResult(target, True, title, logstr) rib = json.loads(ret) try: table = rib["routes"] # KeyError: 'routes' probably means missing/bad VRF except KeyError as err: if vrf != "": errstr = "-script ERROR: check if wrong vrf (%s)" % (vrf) else: errstr = "-script ERROR: check if vrf missing" luResult(target, False, title + errstr, logstr) return # if debug: # self.log("table=%s" % table) for want in wantroutes: if debug: self.log("want=%s" % want) if not self.routes_include_wanted(table, want, debug): luResult(target, False, title, logstr) return luResult(target, True, title, logstr)
def RequireVpnRoutes(self, target, title, wantroutes, debug=0): import json logstr = "RequireVpnRoutes " + str(wantroutes) # non json form for humans luCommand( target, 'vtysh -c "show bgp ipv4 vpn"', ".", "None", "Get VPN RIB (non-json)", ) ret = luCommand( target, 'vtysh -c "show bgp ipv4 vpn json"', ".*", "None", "Get VPN RIB (json)", ) if re.search(r"^\s*$", ret): # degenerate case: empty json means no routes if len(wantroutes) > 0: luResult(target, False, title, logstr) return luResult(target, True, title, logstr) rib = json.loads(ret) rds = rib["routes"]["routeDistinguishers"] for want in wantroutes: found = 0 if debug: self.log("want rd %s" % want["rd"]) for rd in rds.keys(): if rd != want["rd"]: continue if debug: self.log("found rd %s" % rd) table = rds[rd] if self.routes_include_wanted(table, want, debug): found = 1 break if not found: luResult(target, False, title, logstr) return luResult(target, True, title, logstr)
{"p": "6.0.1.0/24", "n": "99.0.0.4"}, {"p": "6.0.2.0/24", "n": "99.0.0.4"}, {"p": "99.0.0.4/32", "n": "192.168.2.2"}, ] bgpribRequireUnicastRoutes( "r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf", want_r4_cust2_routes ) ######################################################################## # PE routers: core unicast routes are empty ######################################################################## luCommand( "r1", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass", "Core Unicast SAFI clean", ) luCommand( "r2", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass", "Core Unicast SAFI clean", ) luCommand( "r3", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass",
from lib.lutil import luCommand luCommand( "r1", '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r1-cust1" -c "no router bgp 5226"', ".", "none", "Cleared bgp instances", ) luCommand( "r2", '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5226"', ".", "none", "Cleared bgp instances", ) luCommand( "r3", '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r3-cust1" -c "no router bgp 5226"', ".", "none", "Cleared bgp instances", ) luCommand( "r4", '/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5228 vrf r4-cust2" -c "no router bgp 5227 vrf r4-cust1" -c "no router bgp 5226"', ".", "none", "Cleared bgp instances", )
from lib.lutil import luCommand, luLast from lib import topotest ret = luCommand( "r2", "ip -M route show", "\d*(?= via inet 10.0.2.4 dev r2-eth1)", "wait", "See mpls route to r4", ) found = luLast() if ret != False and found != None: label4r4 = found.group(0) luCommand("r2", "ip -M route show", ".", "pass", "See %s as label to r4" % label4r4) ret = luCommand( "r2", "ip -M route show", "\d*(?= via inet 10.0.1.1 dev r2-eth0)", "wait", "See mpls route to r1", ) found = luLast() if ret != False and found != None: label4r1 = found.group(0) luCommand("r2", "ip -M route show", ".", "pass", "See %s as label to r1" % label4r1) luCommand( "r1", "ip route show vrf r1-cust1",
from lib.lutil import luCommand from customize import l3mdev_accept l3mdev_rtrs = ["r1", "r3", "r4", "ce4"] for rtr in l3mdev_rtrs: luCommand(rtr, "sysctl net.ipv4.tcp_l3mdev_accept", " = \d*", "none", "") found = luLast() luCommand(rtr, "ss -naep", ":179", "pass", "IPv4:bgp, l3mdev{}".format(found.group(0))) luCommand(rtr, "ss -naep", ":.*:179", "pass", "IPv6:bgp") luCommand( rtr, "sysctl net.ipv4.tcp_l3mdev_accept", " = {}".format(l3mdev_accept), "pass", "l3mdev matches expected (real/expected{}/{})".format( found.group(0), l3mdev_accept), ) rtrs = ["r1", "r3", "r4"] for rtr in rtrs: luCommand( rtr, "ip link show type vrf {}-cust1".format(rtr), "cust1: .*UP", "pass", "VRF cust1 intf up", ) luCommand( rtr, "ip add show vrf {}-cust1".format(rtr),
from lib.lutil import luCommand rtrs = ["r1", "r3", "r4"] for rtr in rtrs: luCommand( rtr, "ip link show type vrf {}-cust1".format(rtr), "cust1: .*UP", "pass", "VRF cust1 intf up", ) luCommand( rtr, "ip add show vrf {}-cust1".format(rtr), "r..eth4.*UP", "pass", "VRF cust1 IP intf up", ) luCommand( rtr, "ip add show vrf {}-cust1".format(rtr), "192.168", "pass", "VRF cust1 IP config", ) luCommand( rtr, "ip route show vrf {}-cust1".format(rtr), "192.168...0/24 dev r.-eth", "pass", "VRF cust1 interface route",
{ "p": "99.0.0.4/32", "n": "192.168.2.2" }, ] bgpribRequireUnicastRoutes("r4", "ipv4", "r4-cust2", "Customer 2 routes in r4 vrf", want_r4_cust2_routes) ######################################################################## # PE routers: core unicast routes are empty ######################################################################## luCommand( "r1", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass", "Core Unicast SAFI clean", ) luCommand( "r2", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass", "Core Unicast SAFI clean", ) luCommand( "r3", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass",
from lib.lutil import luCommand holddownFactorSet = luCommand( "r1", 'vtysh -c "show running"', "rfp holddown-factor", "none", "Holddown factor set", ) luCommand("r1", 'vtysh -c "show vnc registrations"', ".", "none") luCommand("r3", 'vtysh -c "show vnc registrations"', ".", "none") luCommand("r4", 'vtysh -c "show vnc registrations"', ".", "none") if not holddownFactorSet: luCommand( "r1", 'vtysh -c "show vnc summary"', ".", "pass", "Holddown factor not set -- skipping test", ) else: # holddown time test luCommand( "r1", 'vtysh -c "debug rfapi-dev register vn 10.0.0.1 un 1.1.1.1 prefix 1.111.0.0/16 lifetime 10"', "", "none", "Prefix registered", ) luCommand( "r1",
from lib.lutil import luCommand holddownFactorSet = luCommand( "r1", 'vtysh -c "show running"', "rfp holddown-factor", "none", "Holddown factor set", ) if not holddownFactorSet: to = "-1" cost = "" else: to = "6" cost = "cost 50" luCommand( "r1", 'vtysh -c "debug rfapi-dev open vn 10.0.0.1 un 1.1.1.1"', "rfapi_set_response_cb: status 0", "pass", "Opened RFAPI", ) luCommand( "r1", 'vtysh -c "debug rfapi-dev query vn 10.0.0.1 un 1.1.1.1 target 11.11.11.11"', "rc=2", "pass", "Clean query", ) luCommand( "r1",
from lib.lutil import luCommand ret = luCommand( "ce1", 'vtysh -c "show ip route" | grep -c \\ 10\\.\\*/32', "(.*)", "pass", "Looking for sharp routes", ) found = luLast() if ret != False and found != None: num = int(found.group()) luCommand( "ce3", 'vtysh -c "show bgp sum"', ".", "pass", "See %s sharp routes" % num ) if num > 0: rtrs = ["ce1", "ce2", "ce3"] for rtr in rtrs: luCommand( rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display', ".", "none", "BGP routes pre remove", ) luCommand( rtr, "ip route show | cat -n | tail", ".", "none", "Linux routes pre remove",
from lib.lutil import luCommand luCommand("r1", 'vtysh -c "add vrf r1-cust1 prefix 99.0.0.1/32"', ".", "none", "IP Address") luCommand("r3", 'vtysh -c "add vrf r3-cust1 prefix 99.0.0.2/32"', ".", "none", "IP Address") luCommand("r4", 'vtysh -c "add vrf r4-cust1 prefix 99.0.0.3/32"', ".", "none", "IP Address") luCommand( "r1", 'vtysh -c "show vnc registrations local"', "99.0.0.1", "pass", "Local Registration", ) luCommand( "r3", 'vtysh -c "show vnc registrations local"', "99.0.0.2", "pass", "Local Registration", ) luCommand( "r4", 'vtysh -c "show vnc registrations local"', "99.0.0.3", "pass", "Local Registration", ) luCommand( "r1",
from lib.lutil import luCommand luCommand( "ce1", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 7", "wait", "Local and remote routes", ) luCommand( "ce2", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 9", "wait", "Local and remote routes", ) luCommand( "ce3", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 7", "wait", "Local and remote routes", ) luCommand("r1", 'vtysh -c "show bgp ipv4 uni"', "7 routes and 9", "pass", "Unicast SAFI") luCommand( "r2", 'vtysh -c "show bgp ipv4 uni"', "No BGP prefixes displayed", "pass", "Unicast SAFI",
from lib.lutil import luCommand luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") luCommand("r4", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") luCommand( "r1", 'vtysh -c "show vnc registrations"', "Locally: *Active: 1 .* Remotely: *Active: 3", "wait", "See all registrations", ) luCommand( "r3", 'vtysh -c "show vnc registrations"', "Locally: *Active: 1 .* Remotely: *Active: 3", "wait", "See all registrations", ) luCommand( "r4", 'vtysh -c "show vnc registrations"', "Locally: *Active: 2 .* Remotely: *Active: 2", "wait", "See all registrations", ) num = "4 routes and 4" luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay") luCommand("r3", 'vtysh -c "show bgp ipv4 vpn"', num, "pass", "VPN SAFI okay")
from lib.lutil import luCommand rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: ret = luCommand( rtr, 'vtysh -c "show bgp neigh"', "Notification received .([A-Za-z0-9/ ]*)", "none", "collect neighbor stats", ) found = luLast() if ret != False and found != None: val = found.group(1) ret = luCommand( rtr, 'vtysh -c "show bgp neigh"', "Notification received", "fail", "Notify RXed! {}".format(val), ) # done
from lib.lutil import luCommand luCommand( "r1", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" ) luCommand( "r3", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" ) luCommand( "r4", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" ) luCommand("r1", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") luCommand("r3", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") luCommand("r4", 'vtysh -c "show bgp ipv4 uni"', "i5.*i5", "wait", "See CE routes") luCommand("ce1", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") luCommand("r1", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") luCommand("ce2", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") luCommand("r3", 'vtysh -c "show bgp ipv4 uni 5.1.0.0/24"', "", "none", "See CE routes") luCommand("ce3", 'vtysh -c "show bgp ipv4 uni 5.1.2.0/24"', "", "none", "See CE routes") luCommand("r4", 'vtysh -c "show bgp ipv4 uni 5.1.2.0/24"', "", "none", "See CE routes") luCommand( "r1", 'vtysh -c "add vrf cust1 prefix 99.0.0.1/32"', ".", "none", "IP Address" ) luCommand( "r1", 'vtysh -c "show vnc registrations local"', "99.0.0.1", "wait", "Local Registration", )
from lib.lutil import luCommand luCommand( "r1", 'vtysh -c "clear vrf cust1 prefix 99.0.0.1/32"', ".", "none", "Cleared VRF route", ) luCommand( "r3", 'vtysh -c "clear vrf cust1 prefix 99.0.0.2/32"', ".", "none", "Cleared VRF route", ) luCommand( "r4", 'vtysh -c "clear vrf cust1 prefix 99.0.0.3/32"', ".", "none", "Cleared VRF route", ) luCommand( "r1", 'vtysh -c "show vnc registrations local"', "99.0.0.1", "fail", "Local Registration cleared", ) luCommand(
c = int(r / 256) if c > 0: d = r - c * 256 - 1 else: d = r wait = 2 * num / 1000 mem_z = {} mem_b = {} rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: mem_z[rtr] = {"value": 0, "units": "unknown"} mem_b[rtr] = {"value": 0, "units": "unknown"} ret = luCommand( rtr, 'vtysh -c "show memory"', "zebra: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics: Total heap allocated: *(\d*) ([A-Za-z]*)", "none", "collect bgpd memory stats", ) found = luLast() if ret != False and found != None: mem_z[rtr] = {"value": int(found.group(1)), "units": found.group(2)} mem_b[rtr] = {"value": int(found.group(3)), "units": found.group(4)} luCommand("ce1", 'vtysh -c "show mem"', "qmem sharpd", "none", "check if sharpd running") doSharp = False found = luLast() if ret != False and found != None: if len(found.group()): doSharp = True
from lib.lutil import luCommand luCommand("ce1", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") luCommand("ce2", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") luCommand("ce3", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") luCommand("ce1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) luCommand("ce2", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) luCommand("ce3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) luCommand( "r1", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 ) luCommand( "r3", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 ) luCommand( "r4", "ping 2.2.2.2 -c 1", " 0. packet loss", "wait", "PE->P2 (loopback) ping", 60 ) luCommand( "r2", 'vtysh -c "show bgp summary"', " 00:0.* 00:0.* 00:0", "wait", "Core adjacencies up", 180, ) luCommand( "r1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 ) luCommand( "r3", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Core adjacencies up", 180 )
from lib.lutil import luCommand luCommand( "r1", 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.1 un 1.1.1.1 prefix 11.11.11.0/24"', "", "none", "Prefix removed", ) luCommand( "r1", 'vtysh -c "show vnc registrations"', "Locally: *Active: 0 ", "wait", "Local registration removed", ) luCommand( "r1", 'vtysh -c "debug rfapi-dev close vn 10.0.0.1 un 1.1.1.1"', "status 0", "pass", "Closed RFAPI", ) luCommand( "r3", 'vtysh -c "debug rfapi-dev unregister vn 10.0.0.2 un 2.2.2.2 prefix 22.22.22.0/24"', "", "none", "Prefix removed", )