Example #1
0
 def flood(self, frame):
     each(self.other_ports).send(frame)
     self.host.report(
         '{} -> {}',
         self.index,
         ','.join(map(str, each(self.other_ports).index)),
     )
Example #2
0
 def populate(self, models):
     self.devices = []
     self.links = []
     self.items = []
     tip2device = {}
     for model in models:
         item = create(model)
         if item:
             log.debug('adding {}'.format(model))
             self.items.append(item)
             if isinstance(item, Device):
                 log.debug('update {}\'s tips'.format(model))
                 tip2device.update({tip: item for tip in model.tips})
                 self.devices.append(item)
             elif isinstance(item, Link):
                 item.setZValue(-1)
                 self.links.append(item)
     log.debug('adding finished: {}'.format(
         map(str, each(self.items).model)))
     self.load_ok = True
     for link in self.links:
         peers = each(link.model.tips).peer
         try:
             link.devices = tuple(tip2device[tip] for tip in peers)
         except KeyError:
             log.error('{}\'s endpoint is not added to scene'.format(
                 link.model))
             self.ok = False
     if self.load_ok:
         for item in self.items:
             self.addItem(item)
             self.addItem(item.console)
Example #3
0
 def flood(self, frame):
     each(self.other_ports).send(frame)
     self.host.report(
         '{} -> {}',
         self.index,
         ','.join(map(str,
                      each(self.other_ports).index)),
     )
Example #4
0
 def __init__(self, n_interfaces=3):
     super(Switch, self).__init__(n_interfaces)
     self.mac2port = CacheTable(entry_duration=1000)
     self.ports = [
         Port(
             host=self,
             nic=nic,
             mac2port=self.mac2port,
             index=i,
         ) for i, nic in enumerate(self.nics)
     ]
     each(self.ports).calc_other_ports(self.ports)
Example #5
0
 def __init__(self, n_interfaces=3):
     super(Switch, self).__init__(n_interfaces)
     self.mac2port = CacheTable(entry_duration=1000)
     self.ports = [
         Port(
             host=self,
             nic=nic,
             mac2port=self.mac2port,
             index=i,
         ) for i, nic in enumerate(self.nics)
     ]
     each(self.ports).calc_other_ports(self.ports)
Example #6
0
 def __init__(self, n_tips=3):
     super(Switch, self).__init__(n_tips)
     self.nics = [NIC(tip) for tip in self.tips]
     mac2port = CacheTable(entry_duration=1000)
     self.ports = [
         Port(
             host=self,
             nic=nic,
             mac2port=mac2port,
             index=i,
         ) for i, nic in enumerate(self.nics)
     ]
     each(self.ports).calc_other_ports(self.ports)
     mint.worker(self.run, priority=simulation.SWITCH_PRIORITY)
Example #7
0
 def __init__(self, n_tips=3):
     super(Switch, self).__init__(n_tips)
     self.nics = [NIC(tip) for tip in self.tips]
     mac2port = CacheTable(entry_duration=1000)
     self.ports = [
         Port(
             host=self,
             nic=nic,
             mac2port=mac2port,
             index=i,
         ) for i, nic in enumerate(self.nics)
     ]
     each(self.ports).calc_other_ports(self.ports)
     mint.worker(self.run, priority=simulation.SWITCH_PRIORITY)
Example #8
0
 def __init__(self, a, b, latency=0):
     super(Link, self).__init__(n_interfaces=2)
     a.peer_with(self.tips[0], by=self)
     self.tips[1].peer_with(b, by=self)
     self.latency = latency
     self.pipes = [deque([0] * self.latency) for _ in xrange(2)]
     self.endpoint_names = map(str, each(self.tips).peer.host)
Example #9
0
 def __init__(self, a, b, latency=0):
     super(Link, self).__init__(n_tips=2)
     a.peer_with(self.tips[0]); self.tips[1].peer_with(b)
     self.latency = latency
     self.pipes = [deque([0] * self.latency) for _ in xrange(2)]
     self.endpoint_names = map(str, each(self.tips).peer.host)
     mint.worker(self.run, priority=simulation.LINK_PRIORITY)
Example #10
0
 def __init__(self, a, b, latency=0):
     super(Link, self).__init__(n_interfaces=2)
     a.peer_with(self.tips[0], by=self)
     self.tips[1].peer_with(b, by=self)
     self.latency = latency
     self.pipes = [deque([0] * self.latency) for _ in xrange(2)]
     self.endpoint_names = map(str, each(self.tips).peer.host)
Example #11
0
 def track_device(self):
     old_line = self.line()
     new_line = QLineF(*each(self.devices).scenePos())
     old_mid_pt = old_line.pointAt(0.5)
     new_mid_pt = new_line.pointAt(0.5)
     offset = new_mid_pt - old_mid_pt
     self.console.moveBy(offset.x(), offset.y())
     self.setLine(new_line)
Example #12
0
 def __init__(self, a, b, latency=0):
     super(Link, self).__init__(n_tips=2)
     a.peer_with(self.tips[0], by=self)
     self.tips[1].peer_with(b, by=self)
     self.latency = latency
     self.pipes = [deque([0] * self.latency) for _ in xrange(2)]
     self.endpoint_names = map(str, each(self.tips).peer.host)
     mint.worker(self.run, priority=simulation.LINK_PRIORITY)
Example #13
0
 def track_device(self):
     old_line = self.line()
     new_line = QLineF(*each(self.devices).scenePos())
     old_mid_pt = old_line.pointAt(0.5)
     new_mid_pt = new_line.pointAt(0.5)
     offset = new_mid_pt - old_mid_pt
     self.console.moveBy(offset.x(), offset.y())
     self.setLine(new_line)
Example #14
0
 def run(self):
     if hasattr(self, 'timer'):
         self.stop()
     elif not self.sim.finished:
         each(self.scene().devices).highlighted = False
         self.timer = QTimer()
         self.timer.timeout.connect(self.step_and_refresh)
         self.timer.start(self.ms_per_step)
     else:
         QMessageBox.warning(self, 'Error',
                             'Simulation finished.\n' + 'Please restart.')
Example #15
0
 def run(self):
     if hasattr(self, 'timer'):
         self.stop()
     elif not self.sim.finished:
         each(self.scene().devices).highlighted = False
         self.timer = QTimer()
         self.timer.timeout.connect(self.step_and_refresh)
         self.timer.start(self.ms_per_step)
     else:
         QMessageBox.warning(self, 'Error',
                             'Simulation finished.\n' +
                             'Please restart.')
Example #16
0
 def keyPressEvent(self, ev):
     ch = ev.text()
     if ch == config.key['Step']:
         self.step()
     elif ch == config.key['Run']:
         self.run()
     elif ch == config.key['Toggle console']:
         self.toggle_console()
     elif ch == config.key['Toggle console frame']:
         self.scene().toggle('console frame')
     elif ch == config.key['Toggle mode']:
         self.toggle_mode()
     elif ch == config.key['Next mode']:
         self.next_mode()
     elif ch == config.key['Clear']:
         each(self.scene().devices).highlighted = False
         self.refresh()
     elif ch == '?':
         self.help()
Example #17
0
 def keyPressEvent(self, ev):
     ch = ev.text()
     if ch == config.key['Step']:
         self.step()
     elif ch == config.key['Run']:
         self.run()
     elif ch == config.key['Toggle console']:
         self.toggle_console()
     elif ch == config.key['Toggle console frame']:
         self.scene().toggle('console frame')
     elif ch == config.key['Toggle mode']:
         self.toggle_mode()
     elif ch == config.key['Next mode']:
         self.next_mode()
     elif ch == config.key['Clear']:
         each(self.scene().devices).highlighted = False
         self.refresh()
     elif ch == '?':
         self.help()
Example #18
0
 def step(self):
     sim = self.sim
     each(self.scene().devices).highlighted = False
     if sim.finished and self.mode == self.MODE_EVENT:
         self.mode = self.MODE_TIK_TOK
     if self.mode == self.MODE_EVENT:
         # stop
         if self.thread and not self.thread.isFinished:
             self.thread.stopped = True
             self.thread.wait()
         # start
         else:
             self.thread = StepUntilSthHappend(sim)
             self.thread.finished.connect(self.refresh)
             self.thread.start()
     elif self.mode == self.MODE_TIK_TOK:
         sim.step()
     elif self.mode == self.MODE_PHASE:
         sim.step(by=sim.Phase)
     else:
         log.error('{} mode not recognized'.format(self.mode))
     self.refresh()
Example #19
0
 def step(self):
     sim = self.sim
     each(self.scene().devices).highlighted = False
     if sim.finished and self.mode == self.MODE_EVENT:
         self.mode = self.MODE_TIK_TOK
     if self.mode == self.MODE_EVENT:
         # stop
         if self.thread and not self.thread.isFinished:
             self.thread.stopped = True
             self.thread.wait()
         # start
         else:
             self.thread = StepUntilSthHappend(sim)
             self.thread.finished.connect(self.refresh)
             self.thread.start()
     elif self.mode == self.MODE_TIK_TOK:
         sim.step()
     elif self.mode == self.MODE_PHASE:
         sim.step(by=sim.Phase)
     else:
         log.error('{} mode not recognized'.format(self.mode))
     self.refresh()
Example #20
0
 def devices(self, val):
     self._devices = val
     each(self._devices).links.append(self)
     self.track_device()
Example #21
0
 def flood(self, frame):
     each(self.other_ports).send(frame)
Example #22
0
 def flood(self, frame):
     each(self.other_ports).send(frame)
Example #23
0
 def run(self):
     while True:
         each(self.ports).forward()
         mint.elapse(1)
Example #24
0
 def itemChange(self, change, val):
     if change == self.ItemPositionHasChanged:
         each(self.links).track_device()
     return super(Device, self).itemChange(change, val)
Example #25
0
 def __repr__(self):
     return '\n'.join(map(repr, each(self.layers).container))
Example #26
0
 def devices(self, val):
     self._devices = val
     each(self._devices).links.append(self)
     self.track_device()
Example #27
0
 def refresh(self):
     each(self.views).refresh()
Example #28
0
 def gen_name(self):
     roles = [m.role for m in each(self.items).model]
     name = ' '.join('{}{}'.format(len(tuple(g)), role.lower())
                     for role, g in itertools.groupby(sorted(roles)))
     return name + '.topo'
Example #29
0
 def toggle(self, what):
     each(self.items).toggle(what)
Example #30
0
 def update_status(self):
     each(self.items).refresh()
Example #31
0
 def run(self):
     while True:
         isum = sum(each(self.tips).isymbol)
Example #32
0
 def refresh(self):
     each(self.views).refresh()
Example #33
0
 def run(self):
     while True:
         each(self.interfaces).do_send()
         each(self.interfaces).do_recv()
         mint.elapse(1)
Example #34
0
 def itemChange(self, change, val):
     if change == self.ItemPositionHasChanged:
         each(self.links).track_device()
     return super(Device, self).itemChange(change, val)
Example #35
0
 def __init__(self, n_interfaces=3):
     super(Router, self).__init__(n_interfaces)
     self.interfaces = [Interface(self, nic) for nic in self.nics]
     each(self.interfaces).report.connect(self.report)
     each(self.interfaces).on_ipv4.connect(self.on_ipv4)
     self.routes = RouteTable()
Example #36
0
 def run(self):
     while True:
         each(self.ports).forward()
         mint.elapse(1)
Example #37
0
 def run(self):
     while True:
         each(self.interfaces).do_send()
         each(self.interfaces).do_recv()
         mint.elapse(1)
Example #38
0
 def __init__(self, n_interfaces=3):
     super(Router, self).__init__(n_interfaces)
     self.interfaces = [Interface(self, nic) for nic in self.nics]
     each(self.interfaces).report.connect(self.report)
     each(self.interfaces).on_ipv4.connect(self.on_ipv4)
     self.routes = RouteTable()
Example #39
0
 def gen_name(self):
     roles = [m.role for m in each(self.items).model]
     name = ' '.join('{}{}'.format(len(tuple(g)), role.lower())
                     for role, g in itertools.groupby(sorted(roles)))
     return name + '.topo'
Example #40
0
 def __repr__(self):
     return repr(list(each(self.a).e))
Example #41
0
 def __repr__(self):
     return repr(list(each(self.a).e))