X-Git-Url: https://git.josue.xyz/?p=vsorcdistro%2F.git;a=blobdiff_plain;f=precompiler.py;h=86bd4d4eee3ce8b5e5898b86d863900cb42c345f;hp=2e2cf569ca861f7e87d003194fea3f506ca74e22;hb=9f435e1824145d4834563f0b92e3e53b61306b4b;hpb=023012b025db1c4a62fc799e7c8dfe9bdae362d3 diff --git a/precompiler.py b/precompiler.py old mode 100644 new mode 100755 index 2e2cf56..86bd4d4 --- a/precompiler.py +++ b/precompiler.py @@ -1,26 +1,64 @@ -#!/usr/bin/env python3 +#!/usr/bin/python import sys import os import time -cmd = './cleaner.sh '+sys.argv[1] -os.system(cmd) +from mininet.topo import Topo +from mininet.log import setLogLevel, info + +""" +Este precompilador transforma el lenguaje VSORC a la API de topologias de +Mininet +""" +links = [] +devices = [] +hosts = [] +switches = [] +#Lists + +#cmd = './cleaner.sh '+sys.argv[1] +cmd2 = './cleaner.sh data' +os.system(cmd2) time.sleep(.300) -document = open(sys.argv[1] + "_clean" ,"r+") +#document = open(sys.argv[1] + "_clean" ,"r+") +document = open("data" + "_clean" ,"r+") links = document.readlines() document.close + #clean the \n in the colected data a = 0 for linkline in links: links[a] = linkline.rstrip() a+=1 + # get a list of non repeating devices -devices = [] for value in links: value_split = value.split(':') devices.append(value_split[0]) devices.append(value_split[1]) devices = list(dict.fromkeys(devices)) -print devices -print links + + +class TopoFromCompiler(Topo): +#This class is for create the custom topology from the data collected. +#Here we also process the data to make the topo + def build(self): + for device in devices: + if device.startswith("h"): + host = device + host = self.addHost(host) #Create a host with the data collected from the list + hosts.append(host) + + elif device.startswith("s"): + switch = device + switch = self.addSwitch(switch) #Create a switch + switches.append(switch) + + print ("Devices: " + str(devices) + "\n" + "Links: " + str(links) + "\n" + "Hosts: " + str(hosts) + "\n" + "Switches: " + str(switches) + "\n") + + #Create links + for pair in links: + split = pair.split(":") + self.addLink(split[0],split[1]) +