def run(latency): @mint.proc() def sender(): a.framer.send('\x12\x34\x56\x78') yield mint.end @mint.proc() def receiver(): data = yield b.framer.recv() print 'bytes recv by {}: {}'.format(b, fmt(data, 'hex')) data = yield b.framer.recv() print 'bytes recv by {}: {}'.format(b, fmt(data, 'hex')) print 'bits ever received at {}: {}'.format( b.port, fmt(utils.unbitify(b.port.bits_received), 'bin')) print 'bits ever received at {} (shifted): {}'.format( b.port, fmt(utils.unbitify(b.port.bits_received[3:]), 'hex')) raise mint.Stop yield mint.end a = PC('a') b = PC('b') link = Link(a, b) link.latency = latency
def run(sep, latency): @mint.proc() def sender(): a.port.put('\xff') yield mint.env.timeout(sep) a.port.put('\xff') yield mint.end @mint.proc() def receiver(): data = yield b.recv(4) print 'Received at {}: {}'.format(mint.env.now, fmt(data, 'hex')) print ' {}'.format(fmt(data, 'bin')) raise mint.Stop yield mint.end a = PC('a') b = PC('b') link = Link(a, b) link.latency = latency
Interestingly, if we increse the latency of b-hub link, the message c received will change accordingly. Try increese the latency to, say, 95 - see what happens? Why? ''' from mint import * from devices import PC @proc def _(): a.send('hello world') b.send('who are you') put(a, repr(a.recv(11)), now()) @proc def _(): put(b, repr(b.recv(11)), now()) @proc def _(): d = c.port.recv(3 + 8 + 11 * 8) d = utils.unbitify(d[3 + 8:]) put(c, repr(d), now()) a, b, c = PC('a'), PC('b'), PC('c') hub = Hub() link(a, hub.ports[0]) link(b, hub.ports[1], latency=0) link(c, hub.ports[2]) run()
''' a sends 'hi', b lost it (1st) a resends 'hi', b lost it (2nd) a resends 'hi', b lost it (3rd) a resends 'hi', b got it b acknowledges, a lost it (1st) a resends 'hi', b got it b acknowledges, a got it a sends 'how are you?', b got it ''' from mint import * from devices import PC @actor def _(): a.send('hi') a.send('how are you?') @actor def _(): put(b, 'recved', repr(b.recv())) put(b, 'recved', repr(b.recv())) a, b = PC(), PC() a.nic.drop(1) b.nic.drop(1,2,3) l = link(a, b) run()
print 'Now is {}'.format(net.env.now) print '{:1} -> {:<28} {:>2} >-> {:<2} {:>28} -> {:1}'.format( pc1.name, ''.join(list(reversed(pc1.port.obuffer))), ''.join(list(reversed(link.ports[0].ibuffer))), ''.join(list(reversed(link.ports[1].obuffer))), ''.join(list(reversed(pc2.port.ibuffer))), pc2.name) print '{:1} <- {:<28} {:>2} <-< {:<2} {:>28} <- {:1}'.format( pc1.name, pc1.port.ibuffer, link.ports[0].obuffer, link.ports[1].ibuffer, pc2.port.obuffer, pc2.name) raw_input() #import code #code.interact(local=globals()) @mint.proc() def sender(): pc1.port.put('\x01\x02') yield mint.end @mint.proc() def receiver(): #print 'Received:', pc2.recv(2) yield mint.end pc1 = PC('a') pc2 = PC('b') link = Link(pc1, pc2) mint.run(monitor=monitor)
''' pc1 send 11111 to pc2 pc2 send 11 to pc1 1 second later the dot is configured as noise bit ''' from devices import PC import mint from mint import Link pc1 = PC('fans656') pc2 = PC('twiispa') link = Link(pc1, pc2) def monitor(net): print 'Now is {}'.format(net.env.now) print '{:7} -> {:<11} {:>11} >-> {:<11} {:>11} -> {:7}'.format( pc1.name, ''.join(list(reversed(pc1.port.obuffer))), ''.join(list(reversed(link.ports[0].ibuffer))), ''.join(list(reversed(link.ports[1].obuffer))), ''.join(list(reversed(pc2.port.ibuffer))), pc2.name) print '{:7} <- {:<11} {:>11} <-< {:<11} {:>11} <- {:7}'.format( pc1.name, pc1.port.ibuffer, link.ports[0].obuffer, link.ports[1].ibuffer, pc2.port.obuffer, pc2.name) raw_input() #import time #time.sleep(0.8) #@mint.proc def sender():