Commit fdce401e authored by Waleed Akbar's avatar Waleed Akbar
Browse files

feat: Implement SIMAP network configuration (V1) for E2E, Aggregation, and...

feat: Implement SIMAP network configuration (V1) for E2E, Aggregation, and Transport Packet networks.
parent 4a6829ac
Loading
Loading
Loading
Loading
+128 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI 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.


import logging
from .SimapClient import SimapClient


LOGGER = logging.getLogger(__name__)

# NOTE: for e2e --> network_data = [
# ('ONT1', {'termination_points': ['200', '500']}),
# ('POP2', {'termination_points': ['200', '201', '500']})
# ]

def set_simap_network(simap_client: SimapClient, network_id: str,
                      network_data: list[dict]
                      ) -> None:
    """
    Configure a SIMAP network with preset configurations.
    
    Args:
        simap_client: SimapClient instance
        network_id: Network identifier ('e2e', 'agg', or 'trans-pkt')
        supp_net_ids: Tuple of supporting network IDs
        term_point_ids: List of termination point IDs
    """

    if network_id == 'e2e':
        # E2E Network Configuration
        simap = simap_client.network('e2e')
        simap.update(supporting_network_ids=['admin', 'agg'])

        # Configure nodes
        node_names = ['sdp1', 'sdp2']
        endpoints  = []

        for i, (admin_node_id, node_config) in enumerate(network_data):
            node = simap.node(node_names[i])
            node.update(supporting_node_ids=[('admin', admin_node_id)])
            for tp in node_config['termination_points']:
                node.termination_point(tp).update(supporting_termination_point_ids=[('admin', admin_node_id, tp)])
                endpoints.append(tp)

        if len(endpoints) != 2:
            MSG = 'Invalid number of endpoints for E2E network configuration. Expected 2, got {:d}.'
            LOGGER.error(MSG.format(len(endpoints)))
            return  
        
        link = simap.link('E2E-L1')
        link.update(
            'sdp1', endpoints[0], 'sdp2', endpoints[1],
            supporting_link_ids=[
                ('admin', 'L1'), ('admin', 'L3'), ('agg', 'AggNet-L1')
            ]
        )
        
    elif network_id == 'agg':
        # Aggregation Network Configuration
        simap = simap_client.network('agg')
        simap.update(supporting_network_ids=['admin', 'trans-pkt'])

        # Configure nodes
        node_names = ['sdp1', 'sdp2']
        endpoints  = []
        for i, (admin_node_id, node_config) in enumerate(network_data):
            node = simap.node(node_names[i])
            node.update(supporting_node_ids=[('admin', admin_node_id)])
            for tp in node_config['termination_points']:
                node.termination_point(tp).update(supporting_termination_point_ids=[('admin', admin_node_id, tp)])
                endpoints.append(tp)
        if len(endpoints) != 2:
            MSG = 'Invalid number of endpoints for Aggregation network configuration. Expected 2, got {:d}.'
            LOGGER.error(MSG.format(len(endpoints)))
            return
        
        link = simap.link('AggNet-L1')
        link.update(
            'sdp1', endpoints[0], 'sdp2', endpoints[1],
            supporting_link_ids=[
                ('trans-pkt', 'Trans-L1'), ('admin', 'L13')
            ]
        )
        
    elif network_id == 'trans-pkt':
        # Transport Packet Network Configuration
        simap = simap_client.network('trans-pkt')
        simap.update(supporting_network_ids=['admin'])

        # Configure nodes
        node_names = ['site1', 'site2']
        endpoints  = []
        for i, (admin_node_id, node_config) in enumerate(network_data):
            node = simap.node(node_names[i])
            node.update(supporting_node_ids=[('admin', admin_node_id)])
            for tp in node_config['termination_points']:
                node.termination_point(tp).update(supporting_termination_point_ids=[('admin', admin_node_id, tp)])
                endpoints.append(tp)
        if len(endpoints) != 2:
            MSG = 'Invalid number of endpoints for Transport Packet network configuration. Expected 2, got {:d}.'
            LOGGER.error(MSG.format(len(endpoints)))
            return

        link = simap.link('Trans-L1')
        link.update(
            'site1', endpoints[0], 'site2', endpoints[1],
            supporting_link_ids=[
                ('admin', 'L5'), ('admin', 'L9')
            ]
        )
        
    else:
        MSG = 'Unsupported network_id({:s}) to set SIMAP'
        LOGGER.warning(MSG.format(str(network_id)))
        return
    
    LOGGER.info(f'Successfully configured SIMAP network: {network_id}')