Commit 20d2c4df authored by Leandro Campos's avatar Leandro Campos
Browse files

L2NMEmulated Functionality

parent ee95258b
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,8 @@ from service.service.service_handler_api.SettingsHandler import SettingsHandler
from service.service.task_scheduler.TaskExecutor import TaskExecutor
from service.service.task_scheduler.TaskExecutor import TaskExecutor
from .ConfigRules import setup_config_rules, teardown_config_rules
from .ConfigRules import setup_config_rules, teardown_config_rules


import requests

LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)


METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'l2nm_emulated'})
METRICS_POOL = MetricsPool('Service', 'Handler', labels={'handler': 'l2nm_emulated'})
@@ -47,6 +49,7 @@ class L2NMEmulatedServiceHandler(_ServiceHandler):
        settings = self.__settings_handler.get('/settings')
        settings = self.__settings_handler.get('/settings')


        results = []
        results = []
        dynamic_nodes = []
        for endpoint in endpoints:
        for endpoint in endpoints:
            try:
            try:
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)
                device_uuid, endpoint_uuid = get_device_endpoint_uuids(endpoint)
@@ -79,6 +82,13 @@ class L2NMEmulatedServiceHandler(_ServiceHandler):
                    str(device_uuid), str(device_name), str(endpoint_uuid), str(endpoint_name), str_endpoint_settings
                    str(device_uuid), str(device_name), str(endpoint_uuid), str(endpoint_name), str_endpoint_settings
                ))
                ))


                
                try:
                    dynamic_nodes.append(f"{device_name}")
                except Exception as e:
                    LOGGER.error(f"Error extracting endpoint info: {e}")


                json_config_rules = setup_config_rules(
                json_config_rules = setup_config_rules(
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    service_uuid, connection_uuid, device_uuid, endpoint_uuid, endpoint_name,
                    settings, endpoint_settings, endpoint_acls)
                    settings, endpoint_settings, endpoint_acls)
@@ -100,6 +110,42 @@ class L2NMEmulatedServiceHandler(_ServiceHandler):
                LOGGER.exception('Unable to SetEndpoint({:s})'.format(str(endpoint)))
                LOGGER.exception('Unable to SetEndpoint({:s})'.format(str(endpoint)))
                results.append(e)
                results.append(e)



        try:
            STATIC_BW = 2000000
            STATIC_BW_AVAILABLE = '0x1.e84p+20'

            src = dynamic_nodes[0]   # R1
            dst = dynamic_nodes[-1]  # R4
            path = [src, "R2", dst]

            for i in range(len(path) - 1):
                link_id = f"{path[i]}=={path[i+1]}"
                LOGGER.info(f"[EMULATED] Setting BW {STATIC_BW} ({STATIC_BW_AVAILABLE}) on link {link_id}")
                

            URL = "http://192.168.165.44:8080/set_path_bw"
            payload = {
                "bandwidth": STATIC_BW,
                "segment-list": [
                    {"node-uuid": "R1"},
                    {"node-uuid": "R2"},
                    {"node-uuid": "R4"}
                ]
            }

            resp = requests.post(URL, json=payload)
            LOGGER.info(f"Status: {resp.status_code}")
            try:
                LOGGER.info(f"Response: {resp.json()}")
            except Exception:
                LOGGER.info(f"Response text: {resp.text}")

        except Exception as e:
            LOGGER.error(f"Error updating emulated BW: {e}")



        return results
        return results


    @metered_subclass_method(METRICS_POOL)
    @metered_subclass_method(METRICS_POOL)