def run_example_alt(): e = simpynet.Environment() e.add_network(network_alt) e.run( ) received_frames = e.collectors_values['received_frames'] sent_frames = e.collectors_values['sent_frames'] time_spent = 0 for k in received_frames: time_spent += (received_frames[k][-1]-sent_frames[k][-1])*TIME_INCREMENT time_spent = time_spent/NUMBER_OF_PACKETS print "Each packet sent has spent an average time of " + str(time_spent) + " inside the switch."
def run_example(): e = simpynet.Environment() e.add_network(network) e.run( ) time_spent = (numpy.sum(e.collectors_values['data'][0][-1]['Switch0PointToPoint1']) - numpy.sum(e.collectors_values['data'][0][0]['PointToPoint0Switch0']) + numpy.sum(e.collectors_values['data'][0][-1]['Switch0PointToPoint0']) - numpy.sum(e.collectors_values['data'][0][0]['PointToPoint1Switch0']))/NUMBER_OF_PACKETS print "Each packet sent has spent an average time of " + str(time_spent) + " inside the switch."
spn.physical.plug(r0, l4) spn.physical.plug(l4, r0) def tcp_handler(segment): print 'attivato tcp' def h_receiver(name, data, trm_delay): # receiver' s handler def _new_handler(name, data, trm_delay): yield env.timeout(trm_delay) return env.process(_new_handler(name, data, trm_delay)) f_send = host_c.add_transport_handler(tcp_handler) host_b.add_handler('rcv', h_receiver) def rcv_r(): pass host_c.default_gateway = spn.Mac('88:B2:2F:54:1A:0F') def sender(): yield env.timeout(0) f_send('ciao da host 1', spn.IP('222.222.222.220')) env.process(sender()) e = spn.Environment() e.add_network(example2) e.run()
def example2(env): """" example figure 5.17 p. 492 (Computer Networking, 6th edition, Kurose-Ross). c----l1-----| | b----l2--- |so|---l4---ro | a----l3-----| """ env = spn.Environment() host_c = spn.Host(env, spn.Mac('1A:23:F9:CD:06:9B'), spn.IP('222.222.222.220')) host_b = spn.Host(env, spn.Mac('5C:66:AB:90:75:B1'), spn.IP('222.222.222.221')) host_a = spn.Host(env, spn.Mac('49:BD:D2:C7:56:2A'), spn.IP('222.222.222.222')) l1 = spn.Link(env, trm_delay=lambda name, data: 1, prg_delay=lambda s, r, l: 1) l2 = spn.Link(env, trm_delay=lambda name, data: 1, prg_delay=lambda s, r, l: 1) l3 = spn.Link(env, trm_delay=lambda name, data: 1, prg_delay=lambda s, r, l: 1) l4 = spn.Link(env, trm_delay=lambda name, data: 1, prg_delay=lambda s, r, l: 1) s0 = spn.Switch(env) def frw(datagram, mac): print mac if mac == spn.Mac('88:B2:2F:54:1A:0F'): print 'forwanding' return spn.Mac('5C:66:AB:90:75:B1') else: print 'no fornarding' r0 = spn.Router(env, spn.Mac('88:B2:2F:54:1A:0F'), frw) spn.physical.plug(host_c, l1) spn.physical.plug(l1, s0) spn.physical.plug(host_b, l2) spn.physical.plug(l2, s0) spn.physical.plug(host_a, l3) spn.physical.plug(l3, s0) spn.physical.plug(r0, l4) spn.physical.plug(l4, r0) def tcp_handler(segment): print 'attivato tcp' def h_receiver(name, data, trm_delay): # receiver' s handler def _new_handler(name, data, trm_delay): yield env.timeout(trm_delay) return env.process(_new_handler(name, data, trm_delay)) f_send = host_c.add_transport_handler(tcp_handler) host_b.add_handler('rcv', h_receiver) def rcv_r(): pass host_c.default_gateway = spn.Mac('88:B2:2F:54:1A:0F') def sender(): yield env.timeout(0) f_send('ciao da host 1', spn.IP('222.222.222.220')) env.process(sender())
def run_example(): e = simpynet.Environment() e.add_network(network) e.run()