Commit 219f8173 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Merge branch...

Merge branch 'feat/314-tid-new-service-for-ipowdm-configuration-fron-orchestrator-to-ipowdm-controller' of https://labs.etsi.org/rep/tfs/controller into feat/314-tid-new-service-for-ipowdm-configuration-fron-orchestrator-to-ipowdm-controller
parents e403d0b2 859ea356
Loading
Loading
Loading
Loading
+185 −29
Original line number Diff line number Diff line
@@ -60,36 +60,179 @@ site_template = {
    }
}

def generate_p2mp_l3vpn_service(sites_data):
    sites = []
    for idx, site in enumerate(sites_data):
        site_entry = json.loads(json.dumps(site_template))
        site_entry["site-id"] = site["uuid"]
        site_entry["devices"]["device"][0]["device-id"] = site["ip_address"]
        site_entry["devices"]["device"][0]["location"] = site.get("location", f"site-{idx+1}")
        site_entry["site-network-accesses"]["site-network-access"][0]["site-network-access-id"] = f"access-{site['uuid']}"
        site_entry["site-network-accesses"]["site-network-access"][0]["device-reference"] = site["ip_address"]
        site_entry["site-network-accesses"]["site-network-access"][0]["ip-connection"]["ipv4"]["addresses"]["provider-address"] = site["ip_address"]
        site_entry["site-network-accesses"]["site-network-access"][0]["ip-connection"]["ipv4"]["addresses"]["customer-address"] = site["ip_address"]
        site_entry["site-network-accesses"]["site-network-access"][0]["ip-connection"]["ipv4"]["addresses"]["prefix-length"] = site["ip_mask"]
        sites.append(site_entry)

    service = {
def generate_l3vpn_template_pair(src, dst, vpn_id):

    return {
        "ietf-l3vpn-svc:l3vpn-svc": {
            "vpn-services": {
                "vpn-service": [{"vpn-id": vpn_id}]
            },
            "sites": {
                "site": sites
                "site": [
                    {
                        "site-id": src["uuid"],
                        "management": {"type": "ietf-l3vpn-svc:provider-managed"},
                        "locations": {"location": [{"location-id": f"location-{src['uuid']}"}]},
                        "devices": {"device": [{
                            "device-id": "10.0.30.1",
                            "location": f"location-{src['uuid']}"
                        }]},
                        "routing-protocols": {"routing-protocol": [{
                            "type": "ietf-l3vpn-svc:static",
                            "static": {
                                "cascaded-lan-prefixes": {
                                    "ipv4-lan-prefixes": [
                                        {
                                        "lan": "128.32.10.1/24",
                                        "lan-tag": f"vlan{src['vlan_id']}",
                                        "next-hop": "10.0.30.10"
                                        }
                                    ]
                                }
                            }
                        }]},
                        "site-network-accesses": {
                            "site-network-access": [{
                                "site-network-access-id": f"{src['vlan_id']}",
                                "site-network-access-type": "ietf-l3vpn-svc:multipoint",
                                "device-reference": "10.0.30.1",
                                "vpn-attachment": {
                                    "vpn-id": vpn_id, "site-role": "ietf-l3vpn-svc:spoke-role"
                                },
                                "ip-connection": {
                                    "ipv4": {
                                        "address-allocation-type": "ietf-l3vpn-svc:static-address",
                                        "addresses": {
                                            "provider-address": "10.0.30.254",
                                            "customer-address": "10.0.30.10",
                                            "prefix-length": 24
                                        }
                                    }
                                },
                                "routing-protocols": {"routing-protocol": [{
                                    "type": "ietf-l3vpn-svc:static",
                                    "static": {
                                        "cascaded-lan-prefixes": {
                                            "ipv4-lan-prefixes": [
                                                {
                                                "lan": "172.1.101.1/24",
                                                "lan-tag": "vlan100",
                                                "next-hop": "10.0.30.254"
                                                }
                                            ]
                                        }
                                    }
                                }]},
                                "service": {
                                    "svc-mtu": 1500,
                                    "svc-input-bandwidth": 1000000000,
                                    "svc-output-bandwidth": 1000000000,
                                    "qos": {
                                        "qos-profile": {
                                        "classes": {
                                            "class": [
                                            {
                                                "class-id": "qos-realtime",
                                                "direction": "ietf-l3vpn-svc:both",
                                                "latency": {
                                                "latency-boundary": 10
                                                },
                                                "bandwidth": {
                                                "guaranteed-bw-percent": 100
                                                }
                                            }
                                            ]
                                        }
                                        }
                                    }
                                }
                            }]
                        }
                    },
            "vpn-services": {
                "vpn-service": [
                    {
                        "vpn-id": "vpn-p2mp",
                        "vpn-service-topology": "ietf-l3vpn-svc:multipoint"
                        "site-id": dst["uuid"],
                        "management": {"type": "ietf-l3vpn-svc:provider-managed"},
                        "locations": {"location": [{"location-id": f"location-{dst['uuid']}"}]},
                        "devices": {"device": [{
                            "device-id": "10.0.20.1",
                            "location": f"location-{dst['uuid']}"
                        }]},
                        "routing-protocols": {"routing-protocol": [{
                            "type": "ietf-l3vpn-svc:static",
                            "static": {
                                "cascaded-lan-prefixes": {
                                    "ipv4-lan-prefixes": [
                                        {
                                        "lan": "172.1.101.1/24",
                                        "lan-tag": "vlan200",
                                        "next-hop": "172.10.33.2"
                                        }
                                    ]
                                }
                            }
                        }]},
                        "site-network-accesses": {
                            "site-network-access": [{
                                "site-network-access-id": f"{dst['vlan_id']}",
                                "site-network-access-type": "ietf-l3vpn-svc:multipoint",
                                "device-reference": "10.0.20.1",
                                "vpn-attachment": {
                                    "vpn-id": vpn_id, "site-role": "ietf-l3vpn-svc:hub-role"
                                },
                                "ip-connection": {
                                    "ipv4": {
                                        "address-allocation-type": "ietf-l3vpn-svc:static-address",
                                        "addresses": {
                                            "provider-address": "172.10.33.254",
                                            "customer-address": "172.10.33.2",
                                            "prefix-length": 24
                                        }
                                    }
                                },
                                "routing-protocols": {"routing-protocol": [{
                                    "type": "ietf-l3vpn-svc:static",
                                    "static": {
                                        "cascaded-lan-prefixes": {
                                            "ipv4-lan-prefixes": [
                                                {
                                                "lan": "128.32.10.1/24",
                                                "lan-tag": "vlan200",
                                                "next-hop": "172.10.33.254"
                                                }
                                            ]
                                        }
                                    }
                                }]},
                                "service": {
                                    "svc-mtu": 1500,
                                    "svc-input-bandwidth": 1000000000,
                                    "svc-output-bandwidth": 1000000000,
                                    "qos": {
                                        "qos-profile": {
                                        "classes": {
                                            "class": [
                                            {
                                                "class-id": "qos-realtime",
                                                "direction": "ietf-l3vpn-svc:both",
                                                "latency": {
                                                "latency-boundary": 10
                                                },
                                                "bandwidth": {
                                                "guaranteed-bw-percent": 100
                                                }
                                            }
                                            ]
                                        }
                                        }
                                    }
                                }
                            }]
                        }
                    }
                ]
            }
        }
    }
    return json.dumps(service, indent=2)

def create_request(resource_value):
    """ Create and send HTTP request based on a JSON template and provided resource value.
@@ -120,16 +263,16 @@ def create_request(resource_value):
        'vlan_id': node_src["vlan_id"]
    }]
    dst_list = resource_value[1]['rule_set']['dst']
    dst = []
    dsts = []
    for node in dst_list:
        dst.append({
        dsts.append({
            'uuid': node["uuid"],
            'ip_address': node["ip_address"],
            'ip_mask': node["ip_mask"],
            'vlan_id': node["vlan_id"]
        })

    sites_input = src + dst
    sites_input = src + dsts

    components = resource_value[1]['rule_set']['transceiver']['components']
    for i, device in enumerate(components):
@@ -140,13 +283,26 @@ def create_request(resource_value):
        if name == "T1.2":device["frequency"]= 195018750
        if name == "T1.3":device["frequency"]= 195031250

        LOGGER.debug(f"NODE DATA: \n{name}: {json.dumps(device, indent=2)}")
        LOGGER.debug(f"NODE TO CONFIGURE: \n{name}: {json.dumps(device, indent=2)}")
        response = patch_optical_channel_frequency(device, name)
        LOGGER.debug(f"RESPONSE :\n {response}")
    templates = []
    for dst in dsts:
        vpn = "L3VPN_"+src[0]['uuid']+"_"+dst['uuid']
        templates.append(generate_l3vpn_template_pair(src[0], dst,vpn))

    p2mp_json = generate_p2mp_l3vpn_service(sites_input)
    LOGGER.debug(f"Generated L3VPN P2MP service JSON:\n{p2mp_json}")
    return response
    url = "http://192.168.202.254:80/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services"
    headers = {
        'accept': 'application/json',
        'Content-Type': 'application/json'
    }

    for template in templates:
        LOGGER.info("Generated L3VPN P2MP service JSON:\n%s", json.dumps(template, indent=2))

        response = requests.post(url = url, headers= headers, json=template)
        LOGGER.debug(response)
    return None

def patch_optical_channel_frequency(data, DEVICE_ID):
    encoded_path = f"http://192.168.202.254:80/restconf/data/device={DEVICE_ID}/openconfig-platform:components/component=channel-1/optical-channel/config"
+9 −1
Original line number Diff line number Diff line
@@ -52,6 +52,14 @@ class E2EInfoDelete(Resource):
            data       = json.loads(data_str)
            components = data.get("components", [])

            src = nodes[0]
            dst_list = nodes[1:]
            services = [f"L3VPN_{src}_{dst}" for dst in dst_list]
            for service in services:
                url = f"http://192.168.202.254:80/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service={service}"
                response = requests.delete(url=url)
                LOGGER.debug(f"RESPONSE :\n {response}")

            for i, device in enumerate(components):
                if i >= len(nodes):
                    LOGGER.warning(f"Index {i} exceeds nodes list length {len(nodes)}")
@@ -62,7 +70,7 @@ class E2EInfoDelete(Resource):
                if name == "T1.2":device["frequency"]= 195018750
                if name == "T1.3":device["frequency"]= 195031250

                LOGGER.debug(f"NODE DATA: \n{name}:{device}")
                LOGGER.debug(f"NODE TO DELETE: \n{name}:{device}")
                response = test_patch_optical_channel_frequency(device, name)
                LOGGER.debug(f"RESPONSE :\n {response}")
        elif 'tapi_lsp' in allocationId: