Commit 3019db36 authored by Javier Velázquez's avatar Javier Velázquez
Browse files

Delete old files

parent 6950b1f8
Loading
Loading
Loading
Loading

src/old/intent_generator.py

deleted100644 → 0
+0 −136
Original line number Diff line number Diff line
#!/usr/bin/env python3
import json
import os
#import requests
import socket
import random

# Obtain the current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

# Create the path to the templates directory
parent_dir = os.path.dirname(current_dir)
file_path = os.path.join(parent_dir, "templates")

class IntentCreator:

    def __init__(self, plt, lnodes):
        self.plantilla = ''
        with open(plt, 'r') as source:
            self.plantilla = source.read()
        self.nodes = ''
        with open(lnodes, 'r') as source:
            self.nodes = source.read()
            self.nodes = json.loads(str(self.nodes))


    def __create_ep(self,node_name, node_ip, vlan_id):
        ep_tansport_key = f"EpTransport {node_name}"
        ep_transport = {
            ep_tansport_key:{
                "IpAddress":str(node_ip.rsplit('.', 1)[0] + '.1'),
                "logicalInterfaceInfo":{
                    "logicalInterfaceType":"VLAN",
                    "logicalInterfaceId":vlan_id
                },
                "NextHopInfo": str(node_ip.rsplit('.', 1)[0] + '.254'),
                "qosProfile":"A",
                "EpApplicationRef":[f"EP_F1U {node_name}"] 
            }
        }

        ep_rp_key = f"EP_F1U {node_name}"
        ep_rp = {
            ep_rp_key:{
                "localAddress":node_ip,
                "remoteAddress":"",
                "epTransportRef":[ep_tansport_key] 
            }
        }
        return ep_transport,ep_rp

    def create_intent(self):
        '''
        In this function we are going to create intents randomly and return them as a json.
        Parameters to modify:
         - Origin IP, Destination IP, Interfaces, Match type
         - SDP id and Node id
         - Required value
        '''

        request = json.loads(str(self.plantilla))

        # Subnet list in the slicing environment
        subnets = [["TopSliceSubnet1","TopSliceSubnetProfile"],["CNSliceSubnet1","CNSliceSubnetProfile"], ["RANSliceSubnet1","RANSliceSubnetProfile"], ["MidhaulSliceSubnet1","RANSliceSubnetProfile"], ["BackhaulSliceSubnet1","RANSliceSubnetProfile"]]

        # Possible values for throughput and latency
        throughput = [100, 200, 500, 1000]
        latency = [5, 10, 15, 20]

        # Assign random values to the QoS parameters
        top_slice_qos = [random.choice(throughput), 0, random.choice(latency)]
        top_slice_qos[1] = int(2*top_slice_qos[0])
        cn_slice_qos = [int(val) for val in [top_slice_qos[0]/2,top_slice_qos[1]/2, top_slice_qos[2]*0.4]]
        ran_slice_qos = [int(val) for val in [top_slice_qos[0]/2,top_slice_qos[1]/2, top_slice_qos[2]*0.6]]
        midhaul_slice_qos = [int(val) for val in [ran_slice_qos[0]*0.6,ran_slice_qos[1]*0.6, ran_slice_qos[2]/3]]
        backhaul_slice_qos = [int(val) for val in [ran_slice_qos[0]*0.4,ran_slice_qos[1]*0.4, ran_slice_qos[2]*2/3]]

        qos = [top_slice_qos, cn_slice_qos, ran_slice_qos, midhaul_slice_qos, backhaul_slice_qos]

        for index, subnet in enumerate(subnets):
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["dLThptPerSliceSubnet"]["GuaThpt"] = qos[index][0]
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["dLThptPerSliceSubnet"]["MaxThpt"] = qos[index][1]
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["uLThptPerSliceSubnet"]["GuaThpt"] = qos[index][0]
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["uLThptPerSliceSubnet"]["MaxThpt"] = qos[index][1]
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["dLLatency"] = qos[index][2]
            request[subnet[0]]["SliceProfileList"][0][subnet[1]]["uLLatency"] = qos[index][2]
        
        #dus = self.nodes["public-prefixes"]
        #cus = self.nodes["public-prefixes"]
        dus = self.nodes["DU"]
        cus = self.nodes["CU"]

        if random.randint(0, 1) == 0:
            src = random.choice(dus)
            dst = random.choice(cus)
        else:
            src = random.choice(cus)
            dst = random.choice(dus)

        # Delete all the EpTransport objects from the request
        pop_keys = []

        for key in request:
            # Verify if the key is an EpTransport object
            if key.startswith("EpTransport") or key.startswith("EP_F1U"):
                # Aggregate the key to the list of keys to be removed
                pop_keys.append(key)

        for key in pop_keys:
            request.pop(key)

        # Randomly select a VLAN ID
        l_iid = ["100","200","300", "400"]
        vlan_id = random.choice(l_iid)

        # Create the EPs for the source and destination nodes
        ep_transport_src, ep_rp_src = self.__create_ep(src["node-name"], src["prefix"], vlan_id)
        request.update(ep_transport_src)
        request.update(ep_rp_src)
        ep_transport_dst, ep_rp_dst = self.__create_ep(dst["node-name"], dst["prefix"], vlan_id)
        request.update(ep_transport_dst)
        request.update(ep_rp_dst)

        ep_transport_src_name = list(ep_transport_src.keys())[0]
        ep_transport_dst_name = list(ep_transport_dst.keys())[0]

        request["MidhaulSliceSubnet1"]["EpTransport"] = [ep_transport_src_name, ep_transport_dst_name]

        request[ep_transport_src[ep_transport_src_name]["EpApplicationRef"][0]]["remoteAddress"] = request[ep_transport_dst[ep_transport_dst_name]["EpApplicationRef"][0]]["localAddress"]
        request[ep_transport_dst[ep_transport_dst_name]["EpApplicationRef"][0]]["remoteAddress"] = request[ep_transport_src[ep_transport_src_name]["EpApplicationRef"][0]]["localAddress"]

        return (str(request).replace('\t', '').replace('\n', '').replace("'", '"').replace("None", '"None"'))
        
if __name__ == '__main__':
    creador = IntentCreator(os.path.join(file_path, "3gpp_template_empty.json"), os.path.join(file_path, "ips.json"))
    print(creador.create_intent())

src/old/send_request.py

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
import sys, os
import requests
import time
import json
from intent_generator import IntentCreator

# Obtain the current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

# Create the path to the templates directory
parent_dir = os.path.dirname(current_dir)
file_path = os.path.join(parent_dir, "templates")

def send_request(port):
    if len(sys.argv) == 2:
        resp = IntentCreator(os.path.join(file_path, "3gpp_template_empty.json"), os.path.join(file_path, "ips.json")).create_intent()
        requests.post(f'http://localhost:{port}/intent', headers={'Content-Type': 'application/json'}, data=resp)
    else:
        intent = sys.argv[2]
        with open(intent, 'r') as source:
            resp = source.read()
            resp = str(resp).replace('\t', '').replace('\n', '').replace("'", '"').replace("None", '"None"')
        requests.post(f'http://localhost:{port}/intent', headers={'Content-Type': 'application/json'}, data=resp)

while True:
    # Use: python3 send_request.py <port> <intent_file>
    send_request(sys.argv[1])
    time.sleep(3)