def callback(): if label.get() == "host": device = self.canvas.create_oval(event.x - 10, event.y - 10, event.x + 10, event.y + 10, fill="blue") device_id.append([device, 0]) devices.append(Host(ip=self.set_ip)) text_id = self.canvas.create_text(event.x, event.y, text=self.set_ip, fill="white") self.set_ip += 1 master.destroy() elif label.get() == "router": device = self.canvas.create_oval(event.x - 10, event.y - 10, event.x + 10, event.y + 10, fill="green") device_id.append([device, 1]) devices.append(Router(ip=self.set_ip)) text_id = self.canvas.create_text(event.x, event.y, text=self.set_ip, fill="white") self.set_ip += 1 master.destroy()
def __init__(self): jsonObject = self.readData() # initialize the hosts,flows,routers,links self.queue = EventQueue(0) self.routers = {} for r in jsonObject['routers']: self.routers[r['id']] = Router(r['id']) self.hosts = {} for h in jsonObject['hosts']: self.hosts[h['id']] = Host(h['id']) self.links = {} for l in jsonObject['links']: self.links[l['id']] = Link(l) self.links[l['id']].scheduler = self.queue if (l['endpoints'][0][0] == 'H' or l['endpoints'][0][0] == 'S' or l['endpoints'][0][0] == 'T'): self.links[l['id']].pointA = self.hosts[l['endpoints'][0]] self.hosts[l['endpoints'][0]].link = self.links[l['id']] else: self.links[l['id']].pointA = self.routers[l['endpoints'][0]] self.routers[l['endpoints'][0]].links.append( self.links[l['id']]) if (l['endpoints'][1][0] == 'H' or l['endpoints'][1][0] == 'S' or l['endpoints'][1][0] == 'T'): self.links[l['id']].pointB = self.hosts[l['endpoints'][1]] self.hosts[l['endpoints'][1]].link = self.links[l['id']] else: self.links[l['id']].pointB = self.routers[l['endpoints'][1]] self.routers[l['endpoints'][1]].links.append( self.links[l['id']]) self.flows = {} for f in jsonObject['flows']: self.flows[f['id']] = Flow(f) self.flows[f['id']].event_queue = self.queue self.flows[f['id']].controller.event_scheduler = self.queue self.flows[f['id']].source = self.hosts[f['source']] self.hosts[f['source']].flow[f['id']] = self.flows[f['id']] self.flows[f['id']].destination = self.hosts[f['destination']] self.hosts[f['destination']].flow[f['id']] = self.flows[f['id']] self.queue.blind(self.routers)
from device import Router from link import Link from utils import flow from utils import dynamic_routing from utils import graph_live env = simpy.Environment() # routing table maps to link object, not the idx in list devices = [ Host(ip=0), Host(ip=1), Host(ip=2), Host(ip=3), Host(ip=4), Host(ip=5), Router(ip=6), Router(ip=7), Router(ip=8), Router(ip=9), ] links = [ Link(l_id=0, link_rate=(1562500), link_delay=10, max_buffer_size=128000, env=env), Link(l_id=1, link_rate=(1.25 * 10**6), link_delay=10, max_buffer_size=128000,
from device import Host from device import Router from link import Link env = simpy.Environment() # Simulates Host - Router - Host data1 = 1024 * 4000 links = [Link(link_rate=(2.578 * 10 ** 11), link_delay=10, max_buffer_size=64000, env=env), Link(link_rate=(2.578 * 10 ** 11), link_delay=10, max_buffer_size=64000, env=env)] devices = [Host(ip=0), Host(ip=1)] routing_table = {} routing_table[0] = links[0] routing_table[1] = links[1] devices.append(Router(ip=2,routing_table=routing_table)) devices[0].add_link(links[0]) # Host 1 devices[1].add_link(links[1]) # Host 2 devices[2].add_link(links[0]) # Router devices[2].add_link(links[1]) links[0].add_device(devices[0]) links[0].add_device(devices[2]) links[1].add_device(devices[2]) links[1].add_device(devices[1]) def flow(data, start, source, destination, sim_env): yield sim_env.timeout(start) sim_env.process(devices[source].start_flow(data=data, destination=destination, env=sim_env))
import simpy from device import Host from device import Router from link import Link from utils import flow from utils import dynamic_routing from utils import graph_live env = simpy.Environment() # data1 = 20 * 10 ** 6 data1 = 1024 * 2000 devices = [ Host(ip=0), Host(ip=1), Router(ip=2), Router(ip=3), Router(ip=4), Router(ip=5) ] links = [ Link(l_id=0, link_rate=(1562500), link_delay=10, max_buffer_size=64000, env=env), Link(l_id=1, link_rate=(1.25 * 10**6), link_delay=10, max_buffer_size=64000, env=env),
def client_data(self): print("client data start") while True: try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((HOST, PORT2DATA)) s.listen() except Exception as e: print(str(e)) break else: print("else block") conn, addr = s.accept() with conn: print('2 Connected by', addr) while True: data = conn.recv(config["socket"]["buffer_size"]) e_data = data.split(b" ") e_data[-1] = e_data[-1].strip(b"\r\n") print(b"controller data" + data) r_data = e_data[-1].split(b":") print(str(r_data)) #print("controller r_data" + str(r_data)) #Check AddDeviceResponse if r_data[0] == b"addDeviceResponse": data_info = r_data[1].split(b';') print("data_info" + str(data_info)) if data_info[1] == b"OK": eui = data_info[0].decode('utf-8') print(eui) print( str(self.device_dict.get(eui).deviceState)) self.device_dict.get( eui).deviceState = DeviceState.ADDED print( str(self.device_dict.get(eui).deviceState)) print("OK") else: self.device_dict.pop(data_info[0]) print("ERROR addDeviceResponse") #Check for deviceSetupInfo and deviceData elif r_data[0] == b'deviceSetupInfo': data_info = r_data[1].split(b';') print("data_info" + str(data_info)) if data_info[1] == b'BRIGHTNESS': eui = data_info[0].decode('utf-8') brightness = BrightnessSensor(eui) brightness.deviceState = DeviceState.ADDED self.device_dict[eui] = brightness self.device_dict.get( eui).deviceState = DeviceState.INITIALIZED print( str(self.device_dict.get(eui).deviceState)) elif data_info[1] == b"ROUTER": eui = data_info[0].decode('utf-8') router = Router(eui) router.deviceState = DeviceState.ADDED self.device_dict[eui] = router self.device_dict.get( eui).deviceState = DeviceState.INITIALIZED print( str(self.device_dict.get(eui).deviceState)) else: print("error") elif r_data[0] == b"deviceData": data_info = r_data[1].split(b';') eui = data_info[0].decode('utf-8') new_lux = data_info[1].decode('utf-8') self.device_dict.get(eui).lux = new_lux print(str(self.device_dict.get(eui).lux))
- - r3 - r1 - - - - -r2 ''' data1 = 1024 * 1000 links = [Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \ Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \ Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env), \ Link(link_rate=(2.578 * 10 ** 11), link_delay=1, max_buffer_size=64000, env=env)] devices = [Router(ip=0), Router(ip=1), Router(ip=2), Router(ip=3)] devices[0].add_link(links[0]) devices[0].add_link(links[3]) devices[1].add_link(links[0]) devices[1].add_link(links[1]) devices[2].add_link(links[1]) devices[2].add_link(links[2]) devices[3].add_link(links[3]) devices[3].add_link(links[2]) links[0].add_device(devices[0]) links[0].add_device(devices[1]) links[1].add_device(devices[1]) links[1].add_device(devices[2]) links[2].add_device(devices[2])