def _wait_for_sync(self): if not self._synchronized: yield (ModuleNotification.createMatcher(self.getServiceName(), 'synchronized'), )
def _wait_for_sync(self): if not self._synchronized: yield (ModuleNotification.createMatcher(self.getServiceName(), 'synchronized'),)
def _manage_ports(self): try: self.apiroutine.subroutine(self._get_existing_ports()) conn_update = ModuleNotification.createMatcher('openflowmanager', 'update') port_status = OpenflowAsyncMessageEvent.createMatcher(of13.OFPT_PORT_STATUS, None, 0) while True: yield (conn_update, port_status) if self.apiroutine.matcher is port_status: e = self.apiroutine.event m = e.message c = e.connection if (c.protocol.vhost, c.openflow_datapathid) in self.managed_ports: if m.reason == c.openflowdef.OFPPR_ADD: # A new port is added self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)][m.desc.port_no] = m.desc self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', datapathid = c.openflow_datapathid, connection = c, vhost = c.protocol.vhost, add = [m.desc], remove = [], reason = 'add')) elif m.reason == c.openflowdef.OFPPR_DELETE: try: del self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)][m.desc.port_no] self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', datapathid = c.openflow_datapathid, connection = c, vhost = c.protocol.vhost, add = [], remove = [m.desc], reason = 'delete')) except KeyError: pass elif m.reason == c.openflowdef.OFPPR_MODIFY: try: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'modified', datapathid = c.openflow_datapathid, connection = c, vhost = c.protocol.vhost, old = self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)][m.desc.port_no], new = m.desc, reason = 'modified')) except KeyError: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', datapathid = c.openflow_datapathid, connection = c, vhost = c.protocol.vhost, add = [m.desc], remove = [], reason = 'add')) self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)][m.desc.port_no] = m.desc else: e = self.apiroutine.event for c in e.remove: if c.openflow_auxiliaryid == 0 and (c.protocol.vhost, c.openflow_datapathid) in self.managed_ports: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', datapathid = c.openflow_datapathid, connection = c, vhost = c.protocol.vhost, add = [], remove = list(self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)].values()), reason = 'disconnected')) del self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)] for c in e.add: if c.openflow_auxiliaryid == 0: self.apiroutine.subroutine(self._get_ports(c, c.protocol, True, True)) finally: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'unsynchronized'))
def _manage_ports(self): try: self.apiroutine.subroutine(self._get_existing_ports()) conn_update = ModuleNotification.createMatcher( 'openflowmanager', 'update') port_status = OpenflowAsyncMessageEvent.createMatcher( of13.OFPT_PORT_STATUS, None, 0) while True: yield (conn_update, port_status) if self.apiroutine.matcher is port_status: e = self.apiroutine.event m = e.message c = e.connection if (c.protocol.vhost, c.openflow_datapathid) in self.managed_ports: if m.reason == c.openflowdef.OFPPR_ADD: # A new port is added self.managed_ports[(c.protocol.vhost, c.openflow_datapathid )][m.desc.port_no] = m.desc self.scheduler.emergesend( ModuleNotification( self.getServiceName(), 'update', datapathid=c.openflow_datapathid, connection=c, vhost=c.protocol.vhost, add=[m.desc], remove=[], reason='add')) elif m.reason == c.openflowdef.OFPPR_DELETE: try: del self.managed_ports[( c.protocol.vhost, c.openflow_datapathid)][m.desc.port_no] self.scheduler.emergesend( ModuleNotification( self.getServiceName(), 'update', datapathid=c.openflow_datapathid, connection=c, vhost=c.protocol.vhost, add=[], remove=[m.desc], reason='delete')) except KeyError: pass elif m.reason == c.openflowdef.OFPPR_MODIFY: try: self.scheduler.emergesend( ModuleNotification( self.getServiceName(), 'modified', datapathid=c.openflow_datapathid, connection=c, vhost=c.protocol.vhost, old=self.managed_ports[( c.protocol.vhost, c.openflow_datapathid )][m.desc.port_no], new=m.desc, reason='modified')) except KeyError: self.scheduler.emergesend( ModuleNotification( self.getServiceName(), 'update', datapathid=c.openflow_datapathid, connection=c, vhost=c.protocol.vhost, add=[m.desc], remove=[], reason='add')) self.managed_ports[(c.protocol.vhost, c.openflow_datapathid )][m.desc.port_no] = m.desc else: e = self.apiroutine.event for c in e.remove: if c.openflow_auxiliaryid == 0 and ( c.protocol.vhost, c.openflow_datapathid) in self.managed_ports: self.scheduler.emergesend( ModuleNotification( self.getServiceName(), 'update', datapathid=c.openflow_datapathid, connection=c, vhost=c.protocol.vhost, add=[], remove=list(self.managed_ports[( c.protocol.vhost, c.openflow_datapathid)].values()), reason='disconnected')) del self.managed_ports[(c.protocol.vhost, c.openflow_datapathid)] for c in e.add: if c.openflow_auxiliaryid == 0: self.apiroutine.subroutine( self._get_ports(c, c.protocol, True, True)) finally: self.scheduler.emergesend( ModuleNotification(self.getServiceName(), 'unsynchronized'))