class RealIo(object): def __init__(self, iface_map): self.port_to_iface_name = iface_map self.iface_name_to_port = dict((n, p) for p, n in iface_map.items()) self.frame_io = FrameIOManager() self.ponsim = None self.io_ports = dict() @inlineCallbacks def start(self): log.debug('starting') yield self.frame_io.start() for port, iface_name in self.port_to_iface_name.items(): io_port = self.frame_io.open_port(iface_name, self.ingress) self.io_ports[port] = io_port log.info('started') returnValue(self) @inlineCallbacks def stop(self): log.debug('stopping') try: for port in self.io_ports.values(): yield self.frame_io.del_interface(port.iface_name) yield self.frame_io.stop() log.info('stopped') except Exception, e: log.exception('exception', e=e)
class RealIo(object): def __init__(self, iface_map): self.port_to_iface_name = iface_map self.iface_name_to_port = dict((n, p) for p, n in iface_map.items()) self.frame_io = FrameIOManager() self.ponsim = None self.io_ports = dict() @inlineCallbacks def start(self): log.debug('starting') yield self.frame_io.start() for port, iface_name in self.port_to_iface_name.items(): io_port = self.frame_io.open_port(iface_name, self.ingress) self.io_ports[port] = io_port log.info('started') returnValue(self) @inlineCallbacks def stop(self): log.debug('stopping') try: for port in self.io_ports.values(): yield self.frame_io.del_interface(port.iface_name) yield self.frame_io.stop() log.info('stopped') except Exception, e: log.exception('exception', e=e)
class RealIo(object): def __init__(self, iface_map): self.port_to_iface_name = iface_map self.iface_name_to_port = dict((n, p) for p, n in iface_map.items()) self.frame_io = FrameIOManager() self.ponsim = None self.io_ports = dict() @inlineCallbacks def start(self): log.debug('starting') yield self.frame_io.start() for port, iface_name in self.port_to_iface_name.items(): io_port = self.frame_io.open_port(iface_name, self.ingress) self.io_ports[port] = io_port log.info('started') returnValue(self) def stop(self): log.debug('stopping') for port in self.io_ports.values(): self.frame_io.del_interface(port.iface_name) self.frame_io.stop() log.info('stopped') def register_ponsim(self, ponsim): self.ponsim = ponsim def ingress(self, io_port, frame): port = self.iface_name_to_port.get(io_port.iface_name) log.debug('ingress', port=port, iface_name=io_port.iface_name, frame=hexify(frame)) decoded_frame = Ether(frame) if self.ponsim is not None: self.ponsim.ingress(port, decoded_frame) def egress(self, port, frame): if isinstance(frame, Packet): frame = str(frame) io_port = self.io_ports[port] log.debug('sending', port=port, frame=hexify(frame)) io_port.send(frame)