def run1(filename): Sim.scheduler.reset() net = Network(filename) # setup routes a = net.get_node('a') b = net.get_node('b') c = net.get_node('c') a.add_forwarding_entry(c.get_address('b'), a.links[0]) b.add_forwarding_entry(c.get_address('b'), b.links[1]) # setup app PH = PacketHandler() net.nodes['c'].add_protocol(protocol="delay", handler=PH) amount_data = 8 * 1000000 packet_size = 8 * 1000 packet2send = amount_data / packet_size delay_amount = packet_size / a.links[0].bandwidth count = 0 for i in range(int(packet2send)): count += 1 p = Packet(destination_address=c.get_address('b'), protocol='delay', ident=i + 1, length=1000) Sim.scheduler.add(delay=(i * delay_amount), event=p, handler=a.send_packet) Sim.scheduler.run()
def generic_3node(file_name, time_to_send_packet): # parameters Sim.scheduler.reset() # setup network net = Network(file_name) # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n3 = net.get_node('n3') n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0]) n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0]) n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0]) n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[1]) n3.add_forwarding_entry(address=n2.get_address('n3'), link=n2.links[0]) # setup app d = DelayHandler() net.nodes['n3'].add_protocol(protocol="delay", handler=d) # send 10,000 packets for i in range(1, 10001): p = Packet(destination_address=n3.get_address('n2'), ident=i, protocol='delay', length=1000) calc_delay = (i - 1) * time_to_send_packet Sim.scheduler.add(delay=calc_delay, event=p, handler=n1.send_packet) # run the simulation Sim.scheduler.run()
def main(): # parameters Sim.scheduler.reset() # setup network net = Network('../networks/five-nodes.txt') # get nodes n1 = net.get_node('n1') n2 = net.get_node('n2') n3 = net.get_node('n3') n4 = net.get_node('n4') n5 = net.get_node('n5') # setup broadcast application b1 = BroadcastApp(n1) n1.add_protocol(protocol="broadcast", handler=b1) b2 = BroadcastApp(n2) n2.add_protocol(protocol="broadcast", handler=b2) b3 = BroadcastApp(n3) n3.add_protocol(protocol="broadcast", handler=b3) b4 = BroadcastApp(n4) n4.add_protocol(protocol="broadcast", handler=b4) b5 = BroadcastApp(n5) n5.add_protocol(protocol="broadcast", handler=b5) # send a broadcast packet from 1 with TTL 2, so everyone should get it p = Packet(source_address=n1.get_address('n2'), destination_address=BROADCAST_IP_ADDRESS, ident=1, ttl=2, protocol='broadcast', length=100) Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet) # send a broadcast packet from 1 with TTL 1, so just nodes 2 and 3 # should get it p = Packet(source_address=n1.get_address('n2'), destination_address=BROADCAST_IP_ADDRESS, ident=2, ttl=1, protocol='broadcast', length=100) Sim.scheduler.add(delay=1, event=p, handler=n1.send_packet) # send a broadcast packet from 3 with TTL 1, so just nodes 1, 4, and 5 # should get it p = Packet(source_address=n3.get_address('n1'), destination_address=BROADCAST_IP_ADDRESS, ident=3, ttl=1, protocol='broadcast', length=100) Sim.scheduler.add(delay=2, event=p, handler=n3.send_packet) # run the simulation Sim.scheduler.run()
def run(self): # parameters Sim.scheduler.reset() logging.getLogger('app').setLevel(logging.INFO) logging.getLogger('bene.link.queue').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG) if self.debug: logging.getLogger('bene.tcp').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG) # setup network net = Network('networks/one-hop.txt') net.loss(self.loss) # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(n2.get_address('n1'), n1.links[0]) n2.add_forwarding_entry(n1.get_address('n2'), n2.links[0]) # setup transport t1 = Transport(n1) t2 = Transport(n2) # setup application a = AppHandler(self.filename) window = 1000 # setup connection drop = self.packets2lose c1 = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a, window=window, drop=drop, reno=self.reno) c2 = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a, window=window) # send a file with open(self.filename, 'rb') as f: while True: data = f.read(1000) if not data: break Sim.scheduler.add(delay=0, event=data, handler=c1.send) # run the simulation Sim.scheduler.run()
def main(): # parameters Sim.scheduler.reset() # setup network net = Network('../networks/one-hop.txt') # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0]) n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0]) # setup app d = DelayHandler() net.nodes['n2'].add_protocol(protocol="delay", handler=d) # setup packet generator destination = n2.get_address('n1') max_rate = 1000000 // (1000 * 8) load = 0.8 * max_rate g = Generator(node=n1, destination=destination, load=load, duration=10) Sim.scheduler.add(delay=0, event='generate', handler=g.handle) # run the simulation Sim.scheduler.run()
def run1(filename, packetsize, p, file): Sim.scheduler.reset() net = Network(filename) a = net.get_node('a') b = net.get_node('b') c = net.get_node('c') a.add_forwarding_entry(c.get_address('b'), a.links[0]) b.add_forwarding_entry(c.get_address('b'), b.links[1]) d = DelayHandler(file) net.nodes['c'].add_protocol(protocol="delay", handler=d) bandwidth = a.links[0].bandwidth service_rate = bandwidth / (packetsize * 8) arrival_rate = p * service_rate destination = c.get_address('b') g = Generator(node=a, destination=destination, load=arrival_rate, duration=600) Sim.scheduler.add(delay=0, event='generate', handler=g.handle) Sim.scheduler.run()
def generic_3node(p, csv_file_name): # parameters Sim.scheduler.reset() # setup network net = Network('../lab1b/networks/fast-fast.txt') # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n3 = net.get_node('n3') n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0]) n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0]) n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0]) n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[1]) n3.add_forwarding_entry(address=n2.get_address('n3'), link=n2.links[0]) # setup app d = DelayHandler(csv_file_name) net.nodes['n3'].add_protocol(protocol="delay", handler=d) # setup packet gen erator destination = n3.get_address('n2') max_rate = 1000000 // (1000 * 8) load = p * max_rate g = Generator(node=n1, destination=destination, load=load, duration=600) Sim.scheduler.add(delay=0, event='generate', handler=g.handle) # run the simulation Sim.scheduler.run() #write out results d.write_out()
def main(): # parameters Sim.scheduler.reset() # setup network net = Network('../networks/one-hop.txt') # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0]) n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0]) # setup app d = DelayHandler() net.nodes['n2'].add_protocol(protocol="delay", handler=d) # send one packet p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000) Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet) # take the link down Sim.scheduler.add(delay=1, event=None, handler=n1.get_link('n2').down) # send one packet (it won't go through) p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000) Sim.scheduler.add(delay=1.1, event=p, handler=n1.send_packet) # bring the link up Sim.scheduler.add(delay=2, event=None, handler=n1.get_link('n2').up) # send one packet (and now it goes through) p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000) Sim.scheduler.add(delay=2.1, event=p, handler=n1.send_packet) # run the simulation Sim.scheduler.run()
def generic_1packet(file_name): # parameters Sim.scheduler.reset() # setup network net = Network(file_name) # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0]) n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0]) # setup app d = DelayHandler() net.nodes['n2'].add_protocol(protocol="delay", handler=d) # send one packet p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000) Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet) # run the simulation Sim.scheduler.run()
def run(self, size): # parameters Sim.scheduler.reset() logging.getLogger('app').setLevel(logging.INFO) logging.getLogger('bene.link.queue').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG) if self.debug: logging.getLogger('bene.tcp').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG) # setup network net = Network('networks/one-hop-q10.txt') net.loss(self.loss) # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(n2.get_address('n1'), n1.links[0]) n2.add_forwarding_entry(n1.get_address('n2'), n2.links[0]) # setup transport t1 = Transport(n1) t2 = Transport(n2) # setup application a = AppHandler(self.filename) window = size # setup connection drop = [] filen = ("data/queue-%i.csv" % size) fd = open(filen, "w") fd.write("Time_stamp,qDelay\n") c1 = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a, window=window, drop=drop, retran=self.retran) c2 = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a, window=window, fd=fd) # send a file time_before = Sim.scheduler.current_time() count = 0 with open(self.filename, 'rb') as f: while True: data = f.read(1000) count += len(data) # print("0",count) if not data: break Sim.scheduler.add(delay=0, event=data, handler=c1.send) Sim.scheduler.run() time_after = Sim.scheduler.current_time() Sim.scheduler.reset() fd.close() return (time_after - time_before), count
def run(self): # parameters Sim.scheduler.reset() logging.getLogger('app').setLevel(logging.INFO) logging.getLogger('bene.link.queue').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG) if self.debug: logging.getLogger('bene.tcp').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG) logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG) # setup network net = Network('networks/one-hop-q10.txt') net.loss(self.loss) # setup routes n1 = net.get_node('n1') n2 = net.get_node('n2') n1.add_forwarding_entry(n2.get_address('n1'), n1.links[0]) n2.add_forwarding_entry(n1.get_address('n2'), n2.links[0]) # setup transport t1 = Transport(n1) t2 = Transport(n2) # setup application a = AppHandler(self.filename) window = self.wsize # setup connection drop = [] c1 = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a, window=window, drop=drop, retran=self.retran) c2 = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a, window=window) # send a file strin = "" times = [] for i in range(5): with open(self.filename, 'rb') as f: while True: data = f.read(1000) if not data: break Sim.scheduler.add(delay=0, event=data, handler=c1.send) # break Sim.scheduler.run() times.append(Sim.scheduler.current_time()) Sim.scheduler.reset() times.append(sum(times) / len(times)) with open("report/w10000_TESTING.txt", 'w') as f2: f2.writelines(["%s\n" % item for item in times])