Commit 0ed05f66 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Refactor IPoWDM proto definitions and update Tools.py for rule set handling;...

Refactor IPoWDM proto definitions and update Tools.py for rule set handling; streamline Resources.py service type identification
parents 6ef97daa edcd5ba5
Loading
Loading
Loading
Loading
+37 −17
Original line number Original line 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";
syntax = "proto3";
package ipowdm;
package ipowdm;


@@ -20,8 +6,41 @@ message RuleEndpoint {
    string ip_address = 2;
    string ip_address = 2;
    string ip_mask = 3;
    string ip_mask = 3;
    int32 vlan_id = 4;
    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 {
message IpowdmRuleSet {
@@ -29,4 +48,5 @@ message IpowdmRuleSet {
    repeated RuleEndpoint dst = 2;
    repeated RuleEndpoint dst = 2;
    int32 bw = 3;
    int32 bw = 3;
    string uuid = 4;
    string uuid = 4;
    Transceiver transceiver = 5;
}
}
+4 −3
Original line number Original line Diff line number Diff line
@@ -315,7 +315,7 @@ def compute_rules_to_add_delete(
        elif config_rule_kind == 'ipowdm':
        elif config_rule_kind == 'ipowdm':
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            endpoint_uuid = config_rule.ipowdm.endpoint_id.endpoint_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}]'
            IPOWDM_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/ipowdm_ruleset[{:s}]'
            key_or_path = IPOWDM_KEY_TEMPLATE.format(device_uuid, endpoint_uuid, ipowdm_ruleset_name)
            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)
            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
        elif config_rule_kind == 'ipowdm':  # resource management of "ipowdm" rule
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            device_uuid = config_rule.ipowdm.endpoint_id.device_id.device_uuid.uuid
            endpoint_uuid = config_rule.ipowdm.endpoint_id.endpoint_uuid.uuid
            endpoint_uuid = config_rule.ipowdm.endpoint_id.endpoint_uuid.uuid
            IPOWDM_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/ipowdm_ruleset'
            ipowdm_name = config_rule.ipowdm.rule_set.uuid
            key_or_path = IPOWDM_KEY_TEMPLATE.format(device_uuid, endpoint_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((
            request_config_rules.append((
                config_rule.action, key_or_path, grpc_message_to_json(config_rule.ipowdm)
                config_rule.action, key_or_path, grpc_message_to_json(config_rule.ipowdm)
            ))
            ))
+4 −55
Original line number Original line Diff line number Diff line
@@ -40,66 +40,15 @@ def create_request(resource_value):
    """
    """


    LOGGER.info("Creating request for resource_value: %s", 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_uuid = rule_set["uuid"]
    LOGGER.info("Sending POST DSTINATION request with payload: %s", json.dumps(data, indent=2))
        bandwidth    = rule_set["bw"]


        src_router_id  = rule_set["src"][0]["uuid"]
    response = FakeResponse()
        src_ip_address = rule_set["src"][0]["ip_address"]
        src_ip_mask    = rule_set["src"][0]["ip_mask"]
        src_vlan_id    = rule_set["src"][0]["vlan_id"]
        src_frequency  = rule_set["src"][0]["frequency"]
        src_power      = rule_set["src"][0]["power"]

        dst_router_id  = rule_set["dst"][0]["uuid"]
        dst_ip_address = rule_set["dst"][0]["ip_address"]
        dst_ip_mask    = rule_set["dst"][0]["ip_mask"]
        dst_vlan_id    = rule_set["dst"][0]["vlan_id"]
        dst_frequency  = rule_set["dst"][0]["frequency"]
        dst_power      = rule_set["dst"][0]["power"]


        template["services"][0]["service_id"]["service_uuid"]["uuid"] = service_uuid
        config_rules = template["services"][0]["service_config"]["config_rules"][0]
        src = config_rules["ipowdm"]["rule_set"]["src"]
        src.append({
            'uuid': src_router_id,
            'ip_address': src_ip_address,
            'ip_mask': src_ip_mask,
            'vlan_id': src_vlan_id,
            'power': src_power,
            'frequency': src_frequency
        })

        dst = config_rules["ipowdm"]["rule_set"]["dst"]
        dst.append({
            'uuid': dst_router_id,
            'ip_address': dst_ip_address,
            'ip_mask': dst_ip_mask,
            'vlan_id': dst_vlan_id,
            'power': dst_power,
            'frequency': dst_frequency
        })

        config_rules["ipowdm"]["rule_set"]["bw"]        = bandwidth
        config_rules["ipowdm"]["rule_set"]["uuid"]      = service_uuid


        response = tfs_post(template)


    return response
    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:
class FakeResponse:
    """_Fake response object for testing purposes."""
    """_Fake response object for testing purposes."""
    def __init__(self):
    def __init__(self):
+1 −3
Original line number Original line Diff line number Diff line
@@ -30,9 +30,7 @@ class E2EInfoDelete(Resource):
        LOGGER.info("Received DELETE request for allocationId: %s", allocationId)
        LOGGER.info("Received DELETE request for allocationId: %s", allocationId)


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

        LOGGER.info("Service type identified as: %s", service_type)
        LOGGER.info("Service type identified as: %s", service_type)


        if service_type == 'TAPI_LSP':
        if service_type == 'TAPI_LSP':