Commit edcd5ba5 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Refactor IPoWDM service handling and update data structures in proto definitions

parent 168b56ca
Loading
Loading
Loading
Loading
+37 −17
Original line number Diff line number Diff line
// Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";
package ipowdm;

@@ -20,8 +6,41 @@ message RuleEndpoint {
    string ip_address = 2;
    string ip_mask = 3;
    int32 vlan_id = 4;
    float power = 5;
    float frequency = 6;
}

message DigitalSubCarrierId {
    int32 sub_carrier_id = 1;
    bool active = 2;
}

message DigitalSubCarriersGroup {
    int32 digital_sub_carriers_group_id = 1;
    int32 number_of_digital_subcarriers = 2;
    int32 digital_sub_carrier_group_size = 3;
    repeated DigitalSubCarrierId digital_sub_carrier_id = 4;
}

message OpticalChannelConfig {
    float frequency = 1;
    float target_output_power = 2;
    int32 operational_mode = 3;
    string line_port = 4;
    int32 total_number_of_digital_sub_carriers = 5;
    int32 digital_sub_carrier_spacing = 6;
    repeated DigitalSubCarriersGroup digital_sub_carriers_group = 7;
}

message OpticalChannel {
    OpticalChannelConfig config = 1;
}

message Component {
    string name = 1;
    OpticalChannel optical_channel = 2;
}

message Transceiver {
    repeated Component components = 1;
}

message IpowdmRuleSet {
@@ -29,4 +48,5 @@ message IpowdmRuleSet {
    repeated RuleEndpoint dst = 2;
    int32 bw = 3;
    string uuid = 4;
    Transceiver transceiver = 5;
}
+4 −3
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ def compute_rules_to_add_delete(
        elif config_rule_kind == 'ipowdm':
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            endpoint_uuid = config_rule.ipowdm.endpoint_id.endpoint_uuid.uuid
            ipowdm_ruleset_name = config_rule.ipowdm.rule_set.name
            ipowdm_ruleset_name = config_rule.ipowdm.rule_set.uuid
            IPOWDM_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/ipowdm_ruleset[{:s}]'
            key_or_path = IPOWDM_KEY_TEMPLATE.format(device_uuid, endpoint_uuid, ipowdm_ruleset_name)
            context_config_rules[key_or_path] = grpc_message_to_json(config_rule.ipowdm)
@@ -348,8 +348,9 @@ def compute_rules_to_add_delete(
        elif config_rule_kind == 'ipowdm':  # resource management of "ipowdm" rule
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            endpoint_uuid = config_rule.ipowdm.endpoint_id.endpoint_uuid.uuid
            IPOWDM_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/ipowdm_ruleset'
            key_or_path = IPOWDM_KEY_TEMPLATE.format(device_uuid, endpoint_uuid)
            ipowdm_name = config_rule.ipowdm.rule_set.uuid
            IPOWDM_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/ipowdm_ruleset[{:s}]'
            key_or_path = IPOWDM_KEY_TEMPLATE.format(device_uuid, endpoint_uuid,ipowdm_name)
            request_config_rules.append((
                config_rule.action, key_or_path, grpc_message_to_json(config_rule.ipowdm)
            ))
+4 −59
Original line number Diff line number Diff line
@@ -40,70 +40,15 @@ def create_request(resource_value):
    """

    LOGGER.info("Creating request for resource_value: %s", resource_value)
    try:
        BaseDir = os.path.dirname(os.path.abspath(__file__))
        json_path = os.path.join(BaseDir, 'ipowdm.json')
        with open(json_path, 'r', encoding='utf-8') as f:
            template = json.load(f)

        # rule_set = resource_value[1]['rule_set']
    data = resource_value[1]['rule_set']['transceiver']

        # service = template["services"][0]
    LOGGER.info("Sending POST DSTINATION request with payload: %s", json.dumps(data, indent=2))

        # # 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()
    response = FakeResponse()

    return response

    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):
+2 −11
Original line number Diff line number Diff line
@@ -30,19 +30,10 @@ class E2EInfoDelete(Resource):
        LOGGER.info("Received DELETE request for allocationId: %s", allocationId)

        service_type = None
        if 'tapi_lsp' in allocationId: service_type = 'TAPI_LSP'
        elif 'ipowdm' in allocationId: service_type = 'IPoWDM'

        if 'ipowdm' in allocationId: service_type = 'IPoWDM'
        LOGGER.info("Service type identified as: %s", service_type)

        if service_type == 'TAPI_LSP':
            delete_media_channel_id = allocationId.split(':')[-1]
            allocationId = allocationId.split('=')[1].split(':')[0]
            url = f'http://11.1.1.101:4900/{allocationId}/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/connectivity-service={delete_media_channel_id}'
            LOGGER.info("DELETE URL: %s", url)
            response = requests.delete(url, timeout=10)
            LOGGER.info(f"RESPUESTA : {response}")
        elif service_type == 'IPoWDM':
        if service_type == 'IPoWDM':
            LOGGER.info("Deleting IPoWDM service with allocationId: %s", allocationId)
            data = allocationId.split(':')[-1]
            allocationId = allocationId.split('=')[1].split(':')[0]