diff --git a/src/Constants.py b/src/Constants.py index 62ec457212d9254c945f689e9b3bbbdfe7af7ad0..fee596b01cf9181bfa58333ac5d216b742a1b07c 100644 --- a/src/Constants.py +++ b/src/Constants.py @@ -17,7 +17,7 @@ import logging, os, json # Default logging level -DEFAULT_LOGGING_LEVEL = logging.DEBUG +DEFAULT_LOGGING_LEVEL = logging.INFO # Default port for NSC deployment NSC_PORT = 8081 @@ -47,9 +47,11 @@ PCE_EXTERNAL = False # Controller Flags # If True, config is not sent to controllers -DUMMY_MODE = True +DUMMY_MODE = False # Teraflow IP TFS_IP = ips.get('TFS_IP') +UPLOAD_TYPE = "NBI" # "WEBUI" or "NBI" +NBI_L2_PATH = "restconf/data/ietf-l2vpn-svc:l2vpn-svc/vpn-services" # Flag to determine if additional L2VPN configuration support is required for deploying L2VPNs with path selection TFS_L2VPN_SUPPORT = False # IXIA NEII IP diff --git a/src/helpers.py b/src/helpers.py index 080238e324f2fced66a0bf21a26cb5e1f38bb0c5..0e150791ac742c02c03aaa755c04a980481b4336 100644 --- a/src/helpers.py +++ b/src/helpers.py @@ -26,7 +26,7 @@ logging.basicConfig( #Teraflow class tfs_connector(): - def simple_post(self, tfs_ip, service): + def webui_post(self, tfs_ip, service): user="admin" password="admin" token="" @@ -46,6 +46,22 @@ class tfs_connector(): logging.debug("Http response: %s",response.text) return response + def nbi_post(self, tfs_ip, service, path): + token="" + user="admin" + password="admin" + token="" + session = requests.Session() + session.auth = (user, password) + url = f'http://{tfs_ip}/{path}' + headers = {'Content-Type': 'application/json'} + data = json.dumps(service) + logging.debug("Posting to TFS NBI: %s",data) + token={'csrf_token':token} + response = session.post(url,headers=headers,data=data,timeout=60) + logging.debug("Http response: %s",response.text) + return response + #CISCO class cisco_connector(): def __init__(self, address, configs=None): diff --git a/src/network_slice_controller.py b/src/network_slice_controller.py index fd7dfcc01f19c330820323e7d2b95213ef194880..55a338962c6f8165775ee8585bc823b2c216e264 100644 --- a/src/network_slice_controller.py +++ b/src/network_slice_controller.py @@ -17,7 +17,7 @@ import json, time, os, logging, uuid, traceback, sys from datetime import datetime from src.helpers import tfs_connector, cisco_connector -from src.Constants import DEFAULT_LOGGING_LEVEL, TFS_IP, TFS_L2VPN_SUPPORT, IXIA_IP, SRC_PATH, TEMPLATES_PATH, DUMMY_MODE, DUMP_TEMPLATES, PLANNER_ENABLED, NRP_ENABLED +from src.Constants import DEFAULT_LOGGING_LEVEL, TFS_IP, TFS_L2VPN_SUPPORT, IXIA_IP, SRC_PATH, TEMPLATES_PATH, DUMMY_MODE, DUMP_TEMPLATES, PLANNER_ENABLED, NRP_ENABLED, UPLOAD_TYPE, NBI_L2_PATH from src.realizers.ixia.NEII_V4 import NEII_controller from src.planner.planner import Planner @@ -42,7 +42,7 @@ class NSController: - Slice Realization: Convert intents to specific network configurations (L2VPN, L3VPN) """ - def __init__(self, controller_type = "TFS", tfs_ip=TFS_IP, ixia_ip =IXIA_IP, need_l2vpn_support=TFS_L2VPN_SUPPORT): + def __init__(self, controller_type = "TFS", tfs_ip=TFS_IP, ixia_ip =IXIA_IP, need_l2vpn_support=TFS_L2VPN_SUPPORT, path=NBI_L2_PATH): """ Initialize the Network Slice Controller. @@ -61,6 +61,7 @@ class NSController: """ self.controller_type = controller_type self.tfs_ip = tfs_ip + self.path = path self.answer = {} self.cool_answer = {} self.start_time = 0 @@ -298,7 +299,10 @@ class NSController: # Optional: Upload template to Teraflow if not DUMMY_MODE: if self.controller_type == "TFS": - response = tfs_connector().simple_post(self.tfs_ip, requests) + if UPLOAD_TYPE == "WEBUI": + response = tfs_connector().webui_post(self.tfs_ip, requests) + elif UPLOAD_TYPE == "NBI": + response = tfs_connector().nbi_post(self.tfs_ip, requests, self.path) if not response.ok: return self.__send_response(False, code=response.status_code, message=f"Teraflow upload failed. Response: {response.text}") diff --git a/src/templates/ietfL2VPN_template.json b/src/templates/ietfL2VPN_template.json index 79037c2f7e423ce44b34bd90f35ca8fe74071f18..6430e40b261fc21578038d8a0b18d5eb2fef3088 100644 --- a/src/templates/ietfL2VPN_template.json +++ b/src/templates/ietfL2VPN_template.json @@ -1,38 +1,34 @@ { - "l2vpn": { - "vpn-services": { - "vpn-service": [ - { - "vpn-id": 100, - "name": "VPN_L2_Example", - "vpn-type": "point-to-point", - "site": [ - { - "site-id": 1, - "site-role": "hub", - "site-location": "R4", - "site-network-access": { - "interface": { - "ip-address": "4.4.4.4", - "encapsulation": "ethernet" - } - } - }, - { - "site-id": 2, - "site-role": "spoke", - "site-location": "R5", - "site-network-access": { - "interface": { - "ip-address": "5.5.5.5", - "encapsulation": "ethernet" - } - } - } - ] + "ietf-l2vpn-svc:vpn-service": [ + { + "vpn-id": "11327140-7361-41b3-aa45-e84a7fb40be9", + "customer-name": "osm", + "vpn-svc-type": "vpws", + "svc-topo": "any-to-any", + "site": [ + { + "site-id": "1.1.1.1", + "site-role": "hub", + "site-location": "CU-N2", + "site-network-access": { + "interface": { + "ip-address": "10.60.11.3", + "encapsulation": "ethernet" + } } - ] - } + }, + { + "site-id": "3.3.3.3", + "site-role": "spoke", + "site-location": "AMF-N2", + "site-network-access": { + "interface": { + "ip-address": "10.60.60.105", + "encapsulation": "ethernet" + } + } + } + ] } - } - \ No newline at end of file + ] +}