From d6943c92f042f4cdbc1811ff9f69fa128fbb1913 Mon Sep 17 00:00:00 2001 From: tomsou Date: Tue, 27 Jun 2017 11:48:31 +0000 Subject: Route exchange test with testcase3 This review brings up quagga VM installed with 6WIND quagga, configures with external ip prefix and making sure that it gets exchanged with ODL peer. Change-Id: I9ba677e74f24258f7cc59db70b013fbdbbec917a Signed-off-by: Periyasamy Palanisamy --- sdnvpn/lib/quagga.py | 6 ++++-- sdnvpn/lib/utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'sdnvpn/lib') diff --git a/sdnvpn/lib/quagga.py b/sdnvpn/lib/quagga.py index e072f1c..0ea206e 100644 --- a/sdnvpn/lib/quagga.py +++ b/sdnvpn/lib/quagga.py @@ -44,12 +44,14 @@ def bootstrap_quagga(fip_addr, controller_ip): def gen_quagga_setup_script(controller_ip, fake_floating_ip, - ext_net_mask): + ext_net_mask, + ip_prefix, rd, irt, ert): with open(COMMON_CONFIG.quagga_setup_script_path) as f: template = f.read() script = template % (controller_ip, fake_floating_ip, - ext_net_mask) + ext_net_mask, + ip_prefix, rd, irt, ert) return script diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index 33ff594..e43750c 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -7,6 +7,7 @@ # # http://www.apache.org/licenses/LICENSE-2.0 # +import json import logging import os import time @@ -14,6 +15,7 @@ import requests import re import subprocess from concurrent.futures import ThreadPoolExecutor +from requests.auth import HTTPBasicAuth from opnfv.deployment.factory import Factory as DeploymentFactory @@ -942,3 +944,41 @@ def get_odl_bgp_entity_owner(controllers): if re.search(odl_bgp_owner, line): return controller return None + + +def add_quagga_external_gre_end_point(controllers, remote_tep_ip): + json_body = {'input': + {'destination-ip': remote_tep_ip, + 'tunnel-type': "odl-interface:tunnel-type-mpls-over-gre"} + } + url = ('http://{ip}:8081/restconf/operations/' + 'itm-rpc:add-external-tunnel-endpoint'.format(ip=controllers[0].ip)) + headers = {'Content-type': 'application/yang.data+json', + 'Accept': 'application/yang.data+json'} + try: + requests.post(url, data=json.dumps(json_body), + headers=headers, + auth=HTTPBasicAuth('admin', 'admin')) + except Exception as e: + logger.error("Failed to create external tunnel endpoint on" + " ODL for external tep ip %s with error %s" + % (remote_tep_ip, e)) + return None + + +def is_fib_entry_present_on_odl(controllers, ip_prefix, vrf_id): + url = ('http://admin:admin@{ip}:8081/restconf/config/odl-fib:fibEntries/' + 'vrfTables/{vrf}/'.format(ip=controllers[0].ip, vrf=vrf_id)) + logger.error("url is %s" % url) + try: + vrf_table = requests.get(url).json() + is_ipprefix_exists = False + for vrf_entry in vrf_table['vrfTables'][0]['vrfEntry']: + if vrf_entry['destPrefix'] == ip_prefix: + is_ipprefix_exists = True + break + return is_ipprefix_exists + except Exception as e: + logger.error('Failed to find ip prefix %s with error %s' + % (ip_prefix, e)) + return False -- cgit 1.2.3-korg