Commit 6c033acf authored by Pablo Armingol's avatar Pablo Armingol
Browse files

update ietf l3vpn driver templates, tools

parent 76856f00
Loading
Loading
Loading
Loading
+10 −10
Changes for src/device/service/drivers/ietf_l3vpn/templates/hub.json: 10 added lines, 10 removed lines.
Original line number Diff line number Diff line
{
  "initial": {
    "name": "channel-5",
    "name": "channel-7",
    "frequency": "194000000",
    "target_output_power": "0.0",
    "operation": "merge",
@@ -10,19 +10,19 @@
        "digital-subcarrier-id": [
          {
            "subcarrier-id": 1,
            "active": false
            "active": true
          },
          {
            "subcarrier-id": 2,
            "active": false
            "active": true
          },
          {
            "subcarrier-id": 3,
            "active": false
            "active": true
          },
          {
            "subcarrier-id": 4,
            "active": false
            "active": true
          }
        ]
      },
@@ -31,19 +31,19 @@
        "digital-subcarrier-id": [
          {
            "subcarrier-id": 5,
            "active": true
            "active": false
          },
          {
            "subcarrier-id": 6,
            "active": true
            "active": false
          },
          {
            "subcarrier-id": 7,
            "active": true
            "active": false
          },
          {
            "subcarrier-id": 8,
            "active": true
            "active": false
          }
        ]
      },
@@ -92,7 +92,7 @@
    ]
  },
  "second": {
    "name": "channel-5",
    "name": "channel-7",
    "frequency": "194000000",
    "target_output_power": "0.0",
    "operation": "merge",
+32 −35
Changes for src/device/service/drivers/ietf_l3vpn/templates/tools.py: 32 added lines, 35 removed lines.
Original line number Diff line number Diff line
@@ -108,15 +108,16 @@ def create_request(resource_value):
    dests_uuids = [dst['uuid'] for dst in dsts]
    src_uuid = src[0]['uuid']
    vpn_id = src_uuid + "-" + "-".join(dests_uuids)
    LOGGER.info(f"VPN ID: {vpn_id}")

    resource_key = resource_value[0]
    is_initial = "T1.1" in resource_key

    try:
        components = val['rule_set']['transceiver']['components']
        components = val['rule_set']['transceiver']['components'][:2]
        LOGGER.info(f"components : {components}")
        for i, device in enumerate(components):
            name = sites_input[i]['uuid']
            LOGGER.info(f"NODE DATA: \n {json.dumps(device, indent=2)}")
            is_hub = (name == src_uuid)
            
            if is_hub:
@@ -145,32 +146,35 @@ def create_request(resource_value):
                    url = f"http://192.168.202.254:80/restconf/data/device=R2/openconfig-platform:components/component=1/optical-channel/config"

                send_request("DELETE", url, headers=HEADERS, auth=AUTH)
                time.sleep(2)
                time.sleep(5)
                LOGGER.info(f"Device {dev_uuid} deleted successfully")
                LOGGER.info(f"Device {dev_uuid} payload: \n{json.dumps(payload, indent=2)}")
                # send_request("POST", url, headers=HEADERS, auth=AUTH, data=payload)
                time.sleep(2)
                # LOGGER.info(f"Device {dev_uuid} payload: \n{json.dumps(payload, indent=2)}")
                send_request("POST", url, headers=HEADERS, auth=AUTH, data=payload)
                LOGGER.info(f"Device {dev_uuid} posted successfully")

            except Exception as e:
                LOGGER.error(f"Error patching device {dev_uuid}: {e}")
                return False
            LOGGER.info(f"Device {dev_uuid} config done.")
            LOGGER.info("Waiting 10 seconds for device to stabilize...")
            time.sleep(10)

                
    except Exception as e:
        LOGGER.error(f"Error parsing components: {e}")
        return

    components = resource_value[1]['rule_set']['transceiver']['components']
    for i, device in enumerate(components):
        name = sites_input[i]['uuid']

        if name == "T2.1":device["frequency"]= 195000000
        if name == "T1.1":device["frequency"]= 195006250
        if name == "T1.2":device["frequency"]= 195018750
        if name == "T1.3":device["frequency"]= 195031250

        LOGGER.debug(f"NODE TO CONFIGURE: \n{name}: {json.dumps(device, indent=2)}")
    LOGGER.info("CONFIGURACION DE L3VPN")
    previous_tunnel = val['rule_set']['previous_tunnel_id']
    if previous_tunnel: 
        LOGGER.info(f"Previous tunnel: {previous_tunnel}")
        data = previous_tunnel.split("_")
        vpn = f"L3VPN_{data[0]}_{data[2]}"
        url = f"http://192.168.202.254:80/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services"
        send_request("DELETE", url = url + f"/vpn-service={vpn}", headers=HEADERS, auth=AUTH)
        LOGGER.info(f"L3VPN service {vpn} deleted (if existed) successfully")
        time.sleep(1)
    else: LOGGER.info("No previous tunnel found")
    templates = []
    LOGGER.info(f"dsts: {dsts}")
    for dst in dsts:
        LOGGER.info(f"dst: {dst}")
        vpn = "L3VPN_"+src[0]['uuid']+"_"+dst['uuid']
@@ -185,7 +189,7 @@ def create_request(resource_value):
            # Delete first if it already exists
            send_request("DELETE", url = url + f"/vpn-service={vpn_id_val}", headers=HEADERS, auth=AUTH)
            LOGGER.info(f"L3VPN service {vpn_id_val} deleted (if existed) successfully")
            time.sleep(1)
            time.sleep(3)
            # Post the template to create it
            LOGGER.info(f"L3VPN service {vpn_id_val} data: \n{json.dumps(template, indent=2)}")
            send_request("POST", url, headers=HEADERS, auth=AUTH, data=template)
@@ -197,34 +201,27 @@ def create_request(resource_value):


def send_request(method, url, headers=None, auth=("admin", "admin"), data=None):
    print(f"\n[+] {method} -> {url}")
    LOGGER.info(f"[+] {method} -> {url}")
    if data:
        print("Payload:")
        print(json.dumps(data, indent=2))
        LOGGER.info(f"Payload: {json.dumps(data, indent=2)}")
    
    try:
        if method == "POST":
            response = requests.post(url, headers=headers, auth=auth, json=data, timeout=10)
            response = requests.post(url, headers=headers, auth=auth, json=data, timeout=30)
        elif method == "PUT":
            response = requests.put(url, headers=headers, auth=auth, json=data, timeout=10)
            response = requests.put(url, headers=headers, auth=auth, json=data, timeout=30)
        elif method == "GET":
            response = requests.get(url, headers=headers, auth=auth, timeout=10)
            response = requests.get(url, headers=headers, auth=auth, timeout=30)
        elif method == "DELETE":
            response = requests.delete(url, headers=headers, auth=auth, timeout=10)
            response = requests.delete(url, headers=headers, auth=auth, timeout=30)
        else:
            print(f"[-] Unsupported method: {method}")
            LOGGER.error(f"[-] Unsupported method: {method}")
            return None

        print(f"Response Status Code: {response.status_code}")
        try:
            resp_json = response.json()
            print("Response Payload:")
            print(json.dumps(resp_json, indent=2))
        except ValueError:
            print(f"Response Text (raw): {response.text}")
        LOGGER.info(f"Response Status Code: {response.status_code}")
        return response
    except Exception as e:
        print(f"[-] Error during request: {e}")
        LOGGER.error(f"[-] Error during request: {e}")
        return None