Commit 168b56ca authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Enhance service definitions and API integration for IPoWDM and TAPI LSP

- Added RuleEndpoint message to ipowdm.proto for better endpoint management.
- Updated IpowdmRuleSet to use repeated RuleEndpoint for source and destination.
- Enhanced tapi_lsp.proto with additional fields for tenant_uuid and link_uuid_path.
- Modified ipowdm.json to include detailed service configurations and endpoints.
- Improved tools.py for IPoWDM to handle requests with new structure and added error handling.
- Updated lsp.json to include new media channel specifications and endpoint configurations.
- Created Resources.py and Tools.py for E2E service management, including DELETE operations.
- Registered new E2E API in app.py for handling service deletions.
- Updated ServiceHandlerFactory.py and Tapi_LSPServiceHandler.py for better logging and context management.
- Modified home.html to reflect the End-to-End service context in the UI.
parent 3812e8c4
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -15,10 +15,18 @@
syntax = "proto3";
package ipowdm;

message RuleEndpoint {
    string uuid = 1;
    string ip_address = 2;
    string ip_mask = 3;
    int32 vlan_id = 4;
    float power = 5;
    float frequency = 6;
}

message IpowdmRuleSet {
  string  src  = 1;
  string  dst  = 2;
  string  uuid = 3;
  string  bw   = 4;
  string  unit = 5;
    repeated RuleEndpoint src = 1;
    repeated RuleEndpoint dst = 2;
    int32 bw = 3;
    string uuid = 4;
}
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -20,9 +20,13 @@ message TapiLspRuleSet {
  string  dst  = 2;
  string  uuid = 3;
  string  bw   = 4;
  string  direction = 5;
  string  tenant_uuid = 5;
  string  layer_protocol_name = 6;
  string  layer_protocol_qualifier = 7;
  string  lower_frequency_mhz = 8;
  string  upper_frequency_mhz = 9;
  repeated string link_uuid_path = 10;
  string  granularity    = 11;
  string  grid_type      = 12;
  string  direction      = 13;
}
 No newline at end of file
+73 −30
Original line number Diff line number Diff line
@@ -2,42 +2,85 @@
    "services": [
        {
            "service_id": {
                "context_id": {"context_uuid": {"uuid": "admin"}},
                "service_uuid": {"uuid": "IP-Link2"}
                "context_id": {
                    "context_uuid": {
                        "uuid": "admin"
                    }
                },
                "service_uuid": {
                    "uuid": "8078f62d-91f4-55fa-81dd-de369e414be8"
                }
            },
            "service_type": 12,
            "service_status": {
                "service_status": 1
            },
            "service_type": 8,
            "service_status": {"service_status": 1},
            "service_endpoint_ids": [
                {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}},
                {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}}
                {
                    "device_id": {
                        "device_uuid": {
                            "uuid": "IP1"
                        }
                    },
                    "endpoint_uuid": {
                        "uuid": "PORT-xe4"
                    }
                },
                {
                    "device_id": {
                        "device_uuid": {
                            "uuid": "IP2"
                        }
                    },
                    "endpoint_uuid": {
                        "uuid": "PORT-xe4"
                    }
                }
            ],
            "service_constraints": [],

            "service_config": {"config_rules": [
                {"action": 1, "ip_link": {
            "service_config": {
                "config_rules": [
                    {
                        "action": 1,
                        "ipowdm": {
                            "endpoint_id": {
                        "device_id": {"device_uuid": {"uuid": ""}},
                        "endpoint_uuid": {"uuid": ""}
                                "device_id": {
                                    "device_uuid": {
                                        "uuid": "IP1"
                                    }
                                },
                    "rule_set": {
                        "ip"  : "",
                        "mask": "",
                        "vlan": ""
                                "endpoint_uuid": {
                                    "uuid": "PORT-xe4"
                                }
                }},
                {"action": 1, "ip_link": {
                    "endpoint_id": {
                        "device_id": {"device_uuid": {"uuid": ""}},
                        "endpoint_uuid": {"uuid": ""}
                            },
                            "rule_set": {
                        "ip"  : "",
                        "mask": "",
                        "vlan": ""
                                "src": [
                                    {
                                        "uuid": "Phoenix-1",
                                        "ip_address": "10.10.1.1",
                                        "ip_mask": "/24",
                                        "vlan_id": 100,
                                        "power": 0,
                                        "frequency": 194700
                                    }
                                ],
                                "dst": [
                                    {
                                        "uuid": "Phoenix-2",
                                        "ip_address": "10.10.2.1",
                                        "ip_mask": "/24",
                                        "vlan_id": 100,
                                        "power": 0,
                                        "frequency": 194700
                                    }
                                ],
                                "bw": 100,
                                "uuid": "95876830-8396-5241-9bbd-7bfa248232e7"
                            }
                        }
                    }
                ]
            }
                }}

            ]}
        }
    ]
}
 No newline at end of file
+115 −37
Original line number Diff line number Diff line
@@ -16,9 +16,29 @@ import os
import json
import logging

import requests

LOGGER = logging.getLogger(__name__)

def create_request(resource_value):
    """ Create and send HTTP request based on a JSON template and provided resource value.
        The JSON template is expected to be in the same directory as this script, named 'ipowdm.json'.
        Example resource_value:
            {"rule_set": {
                "uuid": "unique-service-uuid",
                "bw": 100,
                "src": [{"uuid": "src-device-uuid", "ip_address": "192.168.1.1", "ip_mask": "24", "vlan_id": 100, "power": 10, "frequency": 193100}],
                "dst": [{"uuid": "dst-device-uuid", "ip_address": "192.168.3.3", "ip_mask": "24", "vlan_id": 100, "power": 10, "frequency": 193100}]
            }}
        The src and dst fields are lists to accommodate future extensions for multi-endpoint scenarios.
        The request is sent to a predefined URL with appropriate headers.
        Returns a response-like object with status_code and text attributes.
        In case of error, returns a SimpleNamespace with status_code 500 and the error message in text.

        Note: The actual HTTP request sending is currently mocked for testing purposes.
        The URL and headers are hardcoded for demonstration and should be adapted as needed.
    """

    LOGGER.info("Creating request for resource_value: %s", resource_value)
    try:
        BaseDir = os.path.dirname(os.path.abspath(__file__))
@@ -26,44 +46,102 @@ def create_request(resource_value):
        with open(json_path, 'r', encoding='utf-8') as f:
            template = json.load(f)

        rule_set = resource_value[1]['rule_set']

        # Completar los campos en el template cargado desde ipowdm.json
        service = template["services"][0]

        # service_id
        service["service_id"]["service_uuid"]["uuid"] = rule_set["uuid"]

        # endpoints
        service_endpoints = service["service_endpoint_ids"]
        service_endpoints[0]["device_id"]["device_uuid"]["uuid"] = rule_set["src"]
        service_endpoints[0]["endpoint_uuid"]["uuid"] = rule_set

        service_endpoints[1]["device_id"]["device_uuid"]["uuid"] = rule_set["dst"]
        service_endpoints[1]["endpoint_uuid"]["uuid"] = rule_set["dst"]
        # config rules
        config_rules = service["service_config"]["config_rules"]

        # regla 1 - endpoint origen
        config_rules[0]["action"] = 1
        config_rules[0]["ip_link"]["endpoint_id"]["device_id"]["device_uuid"]["uuid"] = rule_set["src"]
        config_rules[0]["ip_link"]["endpoint_id"]["endpoint_uuid"]["uuid"] = rule_set["src"]
        config_rules[0]["ip_link"]["rule_set"]["ip"] = rule_set["bw"]
        config_rules[0]["ip_link"]["rule_set"]["mask"] = rule_set["bw"]
        config_rules[0]["ip_link"]["rule_set"]["vlan"] = rule_set["bw"]

        # regla 2 - endpoint destino
        config_rules[1]["action"] = 1
        config_rules[1]["ip_link"]["endpoint_id"]["device_id"]["device_uuid"]["uuid"] = rule_set["dst"]
        config_rules[1]["ip_link"]["endpoint_id"]["endpoint_uuid"]["uuid"] = rule_set["dst"]
        config_rules[1]["ip_link"]["rule_set"]["ip"] = rule_set["bw"]
        config_rules[1]["ip_link"]["rule_set"]["mask"] = rule_set["bw"]
        config_rules[1]["ip_link"]["rule_set"]["vlan"] = rule_set["bw"]

        LOGGER.info("Sending POST request with payload: %s", json.dumps(template))
        response = requests.post(url, headers=headers, json=template, timeout=10)
        # rule_set = resource_value[1]['rule_set']

        # service = template["services"][0]

        # # service_id
        # service["service_id"]["service_uuid"]["uuid"] = rule_set["uuid"]

        # # endpoints
        # service_endpoints = service["service_endpoint_ids"]

        # src = rule_set["src"][0]
        # service_endpoints[0]["device_id"]["device_uuid"]["uuid"] = src["uuid"]
        # service_endpoints[0]["endpoint_uuid"]["uuid"] = "mgmt"

        # dst = rule_set["dst"][0]
        # service_endpoints[1]["device_id"]["device_uuid"]["uuid"] = dst["uuid"]
        # service_endpoints[1]["endpoint_uuid"]["uuid"] = "mgmt"

        # config_rules = service["service_config"]["config_rules"]

        # # rule 1 - source
        # config_rules[0]["action"] = 1
        # config_rules[0]["activate_transceiver"]["endpoint_id"]["device_id"]["device_uuid"]["uuid"] = src["uuid"]
        # config_rules[0]["activate_transceiver"]["endpoint_id"]["endpoint_uuid"]["uuid"] = "mgmt"

        # config_rules[0]["activate_transceiver"]["rule_set"]["ip"]    = src["ip_address"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["mask"]  = src["ip_mask"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["vlan"]  = src["vlan_id"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["bw"]    = rule_set["bw"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["power"] = src.get("power", 0)
        # config_rules[0]["activate_transceiver"]["rule_set"]["uuid"]  = rule_set["uuid"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["frequency"] = src.get("frequency", 0)

        # LOGGER.info("Sending POST SOURCE request with payload: %s", json.dumps(template, indent=2))

        # # rule 2 - destination
        # config_rules[0]["action"] = 1
        # config_rules[0]["activate_transceiver"]["endpoint_id"]["device_id"]["device_uuid"]["uuid"] = dst["uuid"]
        # config_rules[0]["activate_transceiver"]["endpoint_id"]["endpoint_uuid"]["uuid"] = "mgmt"

        # config_rules[0]["activate_transceiver"]["rule_set"]["ip"]    = dst["ip_address"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["mask"]  = dst["ip_mask"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["vlan"]  = dst["vlan_id"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["bw"]    = rule_set["bw"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["power"] = dst.get("power", 0)
        # config_rules[0]["activate_transceiver"]["rule_set"]["uuid"]  = rule_set["uuid"]
        # config_rules[0]["activate_transceiver"]["rule_set"]["frequency"] = dst.get("frequency", 0)

        LOGGER.info("Sending POST DSTINATION request with payload: %s", json.dumps(template, indent=2))
        response = tfs_post(template)
        # response = FakeResponse()

        return response

    except (OSError, json.JSONDecodeError, Exception) as e:
    except (OSError, json.JSONDecodeError, KeyError, TypeError) as e:
        LOGGER.error("Error creating request: %s", str(e))
        return SimpleNamespace(status_code=500, text=str(e))

class FakeResponse:
    """_Fake response object for testing purposes."""
    def __init__(self):
        self.ok = True
        self.status_code = 200
        self.text = '{"message": "OK"}'

    def json(self):
        """Return a sample JSON response."""
        return {"message": "OK"}
def tfs_post(request):
        """
        Send a POST request to the TeraFlow Service Orchestrator.

        Args:
            ip (str): IP address of the TeraFlow Service Orchestrator.
            request (dict): The request payload to be sent.

        Returns:
            dict: The response from the TeraFlow Service Orchestrator.
        """
        user="admin"
        password="admin"
        token=""
        session = requests.Session()
        session.auth = (user, password)
        url=f'http://10.95.86.62/webui'
        response=session.get(url=url)
        for item in response.iter_lines():
            if"csrf_token" in str(item):
                string=str(item).split('<input id="csrf_token" name="csrf_token" type="hidden" value=')[1]
                token=string.split(">")[0].strip('"')
        logging.debug("csrf token %s",token)

        files = {'descriptors': ("data.json", json.dumps(request).encode(
                                                                "utf-8"), "application/json")}
        token={'csrf_token':token}
        response = session.post(url,files=files,data=token,timeout=60)
        logging.debug("Http response: %s",response.text)

        return response
 No newline at end of file
+17 −2
Original line number Diff line number Diff line
@@ -4,16 +4,29 @@
         "connectivity-direction" : "",
         "end-point" : [
            {
               "direction:" : "",
               "direction" : "",
               "layer-protocol-name" : "",
               "layer-protocol-qualifier" : "",
               "local-id" : "",
               "service-interface-point" : {
                  "service-interface-point-uuid" : ""
               },

               "tapi-photonic-media:media-channel-connectivity-service-end-point-spec":{
                  "mc-config":{
                     "spectrum":{
                        "lower-frequency": "",
                        "upper-frequency": "",
                        "frequency-constraint":{
                           "adjustment-granularity" : "",
                           "grid-type": ""
                        }
                     }
                  }
               }
            },
            {
               "direction:" : "",
               "direction" : "",
               "layer-protocol-name" : "",
               "layer-protocol-qualifier" : "",
               "local-id" : "",
@@ -30,6 +43,8 @@
               "value" : ""
            }
         },
         "include-link":[
         ],
         "route-objective-function" : "10000",
         "uuid" : ""
      }
Loading