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, instance_floating_ip):
33 with open(COMMON_CONFIG.quagga_setup_script_path) as f:
35 script = template % (controller_ip, instance_floating_ip)
39 def check_for_peering(controller):
40 cmd = 'show-bgp --cmd "ip bgp neighbors"'
43 bgp_state_regex = re.compile("(BGP state =.*)")
44 opens_regex = re.compile("Opens:(.*)")
46 if neighbors and 'Established' in neighbors:
48 neighbors = run_odl_cmd(controller, cmd)
49 logger.info("Output of %s: %s", cmd, neighbors)
51 opens = opens_regex.search(neighbors)
53 logger.info("Opens sent/received: %s", opens.group(1))
54 state = bgp_state_regex.search(neighbors)
56 logger.info("Peering state: %s", state.group(1))
60 if not neighbors or 'Established' not in neighbors:
61 logger.error("Quagga failed to peer with OpenDaylight")
62 logger.error("OpenDaylight status: %s", neighbors)
65 logger.info("Quagga peered with OpenDaylight")
69 def check_for_route_exchange(ip):
70 """Check that Quagga has learned the route to an IP"""
71 logger.debug("Checking that '%s' is in the Zebra routing table", ip)
72 routes, success = exec_cmd("vtysh -c 'show ip route'", verbose=True)
75 logger.debug("Zebra routing table: %s", routes)