summaryrefslogtreecommitdiffstats
path: root/sdnvpn/lib/quagga.py
diff options
context:
space:
mode:
authorRomanos Skiadas <rski@intracom-telecom.com>2016-09-08 16:23:40 +0300
committerRomanos Skiadas <rski@intracom-telecom.com>2017-03-02 15:54:33 +0200
commitbe5cd25ed85bb42f4115b49aec13ddfec20c1b97 (patch)
tree656520216279d026ad7c1bd3c8eb013deb810648 /sdnvpn/lib/quagga.py
parent71273a2b8d51725be2743010fb65fb46229dd10c (diff)
Implement quagga peering
- Create an openstack instance - Assign it a floating IP - Execute a quagga bootstrap script using cloud init - Tell ODL to peer with the instance - Start an instance in a VPN - make sure the route was exchanged between the peered quagga and ODL Change-Id: I73bcaec5425df2b953c2bceaca7d4f09ff28f3d0 Signed-off-by: Romanos Skiadas <rski@intracom-telecom.com>
Diffstat (limited to 'sdnvpn/lib/quagga.py')
-rw-r--r--sdnvpn/lib/quagga.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/sdnvpn/lib/quagga.py b/sdnvpn/lib/quagga.py
new file mode 100644
index 0000000..e2885c2
--- /dev/null
+++ b/sdnvpn/lib/quagga.py
@@ -0,0 +1,76 @@
+"""Utilities for setting up quagga peering"""
+
+import re
+import time
+
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
+import sdnvpn.lib.config as config
+from sdnvpn.lib.utils import run_odl_cmd, exec_cmd
+
+logger = ft_logger.Logger("sdnvpn-quagga").getLogger()
+
+COMMON_CONFIG = config.CommonConfig()
+
+
+def odl_add_neighbor(neighbor_ip, controller):
+ command = 'configure-bgp -op add-neighbor --as-num 200'
+ command += ' --ip %s --use-source-ip %s' % (neighbor_ip, controller.ip)
+ success = run_odl_cmd(controller, command)
+ return success
+
+
+def bootstrap_quagga(fip_addr, controller_ip):
+ script = gen_quagga_setup_script(
+ controller_ip,
+ fip_addr)
+ cmd = "sshpass -popnfv ssh opnfv@%s << EOF %s EOF" % (fip_addr, script)
+ rc = ft_utils.execute_command(cmd)
+ return rc == 0
+
+
+def gen_quagga_setup_script(controller_ip, instance_floating_ip):
+ with open(COMMON_CONFIG.quagga_setup_script_path) as f:
+ template = f.read()
+ script = template % (controller_ip, instance_floating_ip)
+ return script
+
+
+def check_for_peering(controller):
+ cmd = 'show-bgp --cmd "ip bgp neighbors"'
+ tries = 20
+ neighbors = None
+ bgp_state_regex = re.compile("(BGP state =.*)")
+ opens_regex = re.compile("Opens:(.*)")
+ while tries > 0:
+ if neighbors and 'Established' in neighbors:
+ break
+ neighbors = run_odl_cmd(controller, cmd)
+ logger.info("Output of %s: %s", cmd, neighbors)
+ if neighbors:
+ opens = opens_regex.search(neighbors)
+ if opens:
+ logger.info("Opens sent/received: %s", opens.group(1))
+ state = bgp_state_regex.search(neighbors)
+ if state:
+ logger.info("Peering state: %s", state.group(1))
+ tries -= 1
+ time.sleep(1)
+
+ if not neighbors or 'Established' not in neighbors:
+ logger.error("Quagga failed to peer with OpenDaylight")
+ logger.error("OpenDaylight status: %s", neighbors)
+ return False
+
+ logger.info("Quagga peered with OpenDaylight")
+ return True
+
+
+def check_for_route_exchange(ip):
+ """Check that Quagga has learned the route to an IP"""
+ logger.debug("Checking that '%s' is in the Zebra routing table", ip)
+ routes, success = exec_cmd("vtysh -c 'show ip route'", verbose=True)
+ if not success:
+ return False
+ logger.debug("Zebra routing table: %s", routes)
+ return ip in routes