1 """Utilities for setting up quagga peering"""
6 import functest.utils.functest_logger as ft_logger
7 import functest.utils.functest_utils as ft_utils
8 import sdnvpn.lib.config as config
9 from sdnvpn.lib.utils import run_odl_cmd, exec_cmd
11 logger = ft_logger.Logger("sdnvpn-quagga").getLogger()
13 COMMON_CONFIG = config.CommonConfig()
16 def odl_add_neighbor(neighbor_ip, controller):
17 command = 'configure-bgp -op add-neighbor --as-num 200'
18 command += ' --ip %s --use-source-ip %s' % (neighbor_ip, controller.ip)
19 success = run_odl_cmd(controller, command)
23 def bootstrap_quagga(fip_addr, controller_ip):
24 script = gen_quagga_setup_script(
27 cmd = "sshpass -popnfv ssh opnfv@%s << EOF %s EOF" % (fip_addr, script)
28 rc = ft_utils.execute_command(cmd)
32 def gen_quagga_setup_script(controller_ip,
35 with open(COMMON_CONFIG.quagga_setup_script_path) as f:
37 script = template % (controller_ip,
43 def check_for_peering(controller):
44 cmd = 'show-bgp --cmd "ip bgp neighbors"'
47 bgp_state_regex = re.compile("(BGP state =.*)")
48 opens_regex = re.compile("Opens:(.*)")
50 if neighbors and 'Established' in neighbors:
52 neighbors = run_odl_cmd(controller, cmd)
53 logger.info("Output of %s: %s", cmd, neighbors)
55 opens = opens_regex.search(neighbors)
57 logger.info("Opens sent/received: %s", opens.group(1))
58 state = bgp_state_regex.search(neighbors)
60 logger.info("Peering state: %s", state.group(1))
64 if not neighbors or 'Established' not in neighbors:
65 logger.error("Quagga failed to peer with OpenDaylight")
66 logger.error("OpenDaylight status: %s", neighbors)
69 logger.info("Quagga peered with OpenDaylight")
73 def check_for_route_exchange(ip):
74 """Check that Quagga has learned the route to an IP"""
75 logger.debug("Checking that '%s' is in the Zebra routing table", ip)
76 routes, success = exec_cmd("vtysh -c 'show ip route'", verbose=True)
79 logger.debug("Zebra routing table: %s", routes)