Commit d7042277 authored by Javier Velázquez's avatar Javier Velázquez Committed by Samuel Santos
Browse files

L3VPN

Add routing protocols and vlan match
Network access: change custommer address, site role and access type
L2VPN
Change initial structure
parent b3be306d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -31,14 +31,14 @@ def apply_metric_constraint(service, qos_class, constraint, vpn_id, layer_type):
                        "direction": "input-bw",
                        "vpn-id": vpn_id,
                        "cir": bandwidth,
                        "cbs": bandwidth*0.05
                        "cbs": int(bandwidth*0.05)
                    },
                    {
                        "type": "bw-per-svc",
                        "direction": "output-bw",
                        "vpn-id": vpn_id,
                        "cir": bandwidth,
                        "cbs": bandwidth*0.05
                        "cbs": int(bandwidth*0.05)
                    },
                ]
            }
+32 −8
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ import logging
from src.utils.safe_get import safe_get


def configure_match_criteria(network_access, sdp, layer_type):
def configure_match_criteria(network_access, site, sdp, layer_type):
    """Configura los criterios de coincidencia en el acceso a la red."""
    MATCH_TYPE_MAPPING = {
        "dscp": "dscp"
@@ -26,6 +26,7 @@ def configure_match_criteria(network_access, sdp, layer_type):
    if layer_type == "l3":
        MATCH_TYPE_MAPPING["source-ip-prefix"] = "ipv4-src-prefix"
        MATCH_TYPE_MAPPING["destination-ip-prefix"] = "ipv4-dst-prefix"
        MATCH_TYPE_MAPPING["vlan"] = "vlan" # Need to check if applies with l2 too
        
    match_criteria = sdp.get("match_criteria")
    if not match_criteria:
@@ -41,6 +42,11 @@ def configure_match_criteria(network_access, sdp, layer_type):
        logging.warning(f"Unknown match type: {match_type}")
        return
    
    provider_address = safe_get(sdp, ["sdp", "attachment-circuits", "attachment-circuit", 0, "ac-ipv4-address"])
    prefix_length = safe_get(sdp, ["sdp", "attachment-circuits", "attachment-circuit", 0, "ac-ipv4-prefix-length"])
    lan = f"{provider_address}/{prefix_length}" if provider_address and prefix_length else None

    if match_type != "vlan":
        rule = {
            "id": f"match-{match_type}-{index}",
            "match-flow": {
@@ -49,3 +55,21 @@ def configure_match_criteria(network_access, sdp, layer_type):
        }
        
        network_access["service"]["qos"]["qos-classification-policy"]["rule"].append(rule)
    else:
        # Handle VLAN match criteria
        routing_protocol = {
            "type": "static",
            "static":{
                "cascaded-lan-prefixes": {
                    "ipv4-lan-prefixes":[
                        {
                            "lan": lan,
                            "lan-tag": value,
                            "next-hop": provider_address # This is not correct, should be the management ip of the provider router, but we don't have that info in the SDP. Need to check how to handle this.
                        }
                    ]
                }
            }
        }

        site["routing-protocols"]["routing-protocol"].append(routing_protocol)
+18 −7
Original line number Diff line number Diff line
@@ -33,19 +33,27 @@ def create_network_access(sdp, ietf_intent, connectivity_type, router_id, router
                "address-allocation-type": "static-address",
                "addresses": {
                    "provider-address": safe_get(sdp, ["sdp", "attachment-circuits", "attachment-circuit", 0, "ac-ipv4-address"]),
                    # "customer-address": "",
                    "customer-address": safe_get(sdp, ["sdp", "attachment-circuits", "attachment-circuit", 0, "ac-ipv4-address"]), # We set the same address for provider and customer because we don't have the customer address in the SDP. This is not correct and should be fixed in the future when we have that info.
                    "prefix-length": safe_get(sdp, ["sdp", "attachment-circuits", "attachment-circuit", 0, "ac-ipv4-prefix-length"])
                }
            }
        }

    if sdp['type'] == "sender":
        site_role = "hub-role"
    elif sdp['type'] == "receiver":
        site_role = "spoke-role"
    else:
        site_role = "any-to-any-role"

    network_access = {
        access_id: router_if,
        access_type: f"{connectivity_type}",
        # access_type: f"{connectivity_type}",
        access_type: "multipoint", # We set to multipoint to avoid errors in Teraflow
        "device-reference": router_id,
        "vpn-attachment": {
            "vpn-id": ietf_intent["id"],
            # "site-role": f"{sdp['type']}" # Revisar esto!!!!
            "site-role": site_role # This will be changed in the future. Hub and spoke roles are only for multipoint connectivity constructs, there is no defined roles por point to point constructs
        },
        "service": {
            "qos": {
@@ -63,9 +71,12 @@ def create_network_access(sdp, ietf_intent, connectivity_type, router_id, router
    }
    if layer_type == "l3":
        network_access["ip-connection"] = ip_connection
    
    # Configurar match criteria y SLOs
    configure_match_criteria(network_access, sdp, layer_type)
    configure_slos(network_access, ietf_intent, layer_type)
    elif layer_type == "l2": # This should not be needed, but we add it because TFS requires it
        network_access["connection"] = {
            "oam": {
                "md-name": "test",
                "md-level": 0
            }
        }
    
    return network_access
+12 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
import logging
from src.utils.safe_get import safe_get
from .create_network_access import create_network_access
from .configure_match_criteria import configure_match_criteria
from .configure_slos import configure_slos

def create_site_from_sdp(sdp, ietf_intent, connectivity_type, layer_type):
    """
@@ -39,6 +41,8 @@ def create_site_from_sdp(sdp, ietf_intent, connectivity_type, layer_type):
    
    logging.debug(f"Configured site for SDP {safe_get(sdp, ['sdp', 'id'])} with location: {location}, router_id: {router_id}, router_if: {router_if}")
    
    network_access = create_network_access(sdp, ietf_intent, connectivity_type, router_id, router_if, layer_type)

    # Crear estructura del site
    site = {
        "site-id": safe_get(sdp, ["sdp", "id"]),
@@ -55,8 +59,15 @@ def create_site_from_sdp(sdp, ietf_intent, connectivity_type, layer_type):
            "type": "provider-managed"
        },
        "site-network-accesses": {
            "site-network-access": [create_network_access(sdp, ietf_intent, connectivity_type, router_id, router_if, layer_type)]
            "site-network-access": [network_access]
        }
    }

    if layer_type == "l3":
        site["routing-protocols"] = {"routing-protocol": []}

    # Configure match criteria and SLOs
    configure_match_criteria(network_access, site, sdp, layer_type)
    configure_slos(network_access, ietf_intent, layer_type)
    
    return site
+3 −4
Original line number Diff line number Diff line
@@ -29,10 +29,9 @@ def initialize_structure(vpn_id, connectivity_type, layer_type):
            }
        }
    if layer_type == "l2":
        structure[f"ietf-{layer_type}vpn-svc:{layer_type}vpn-svc"]["vpn-services"]["vpn-service"] = {
        structure[f"ietf-{layer_type}vpn-svc:{layer_type}vpn-svc"]["vpn-services"]["vpn-service"][0] = {
            "vpn-id": vpn_id,
            "customer-name": "osm",
            "vpn-svc-type": "vpws", # Lo dejamos en vpws porque es el unico que encaja
            "svc-topo": connectivity_type,
            "ce-vlan-preservation": False,
            "ce-vlan-cos-preservation": False
        }
    return structure
 No newline at end of file