def processevent(self, event): """Process authentication event """ if (event.host == None): return True if (isinstance(event, owevent.authenticated)): output.dbg( pu.array2hex_str(event.host) + " is authenticated", self.__class__.__name__) mcutil.set(host_auth.get_key(event.host), event.openid, MAX_AUTH_TIMEOUT) elif (isinstance(event, owevent.unauthenticated)): output.dbg( pu.array2hex_str(event.host) + " is unauthenticated", self.__class__.__name__) mcutil.delete(host_auth.get_key(event.host)) mcutil.delete(host_auth.get_auth_key(event.host)) elif (isinstance(event, owevent.going_to_auth)): output.dbg( pu.array2hex_str(event.host) + " is going to authenticate", self.__class__.__name__) mcutil.set(host_auth.get_auth_key(event.host), event.server(), AUTH_TIMEOUT) return True
def processevent(self, event): """Process OpenFlow message for switch status @param event OpenFlow message event to process @return True """ if isinstance(event, ofevents.features_reply): # Maintain list of datapath socket key = self.get_key(event.sock) dpidsl = mc.get(dp_features.DP_SOCK_LIST) if dpidsl == None: dpidsl = [] if key not in dpidsl: dpidsl.append(key) mc.set(dp_features.DP_SOCK_LIST, dpidsl) # Maintain dp features in memcache mc.set(key, event.features) elif isinstance(event, ofevents.port_status): # Port status if event.header.type == pyof.OFPT_PORT_STATUS: key = self.get_key(event.sock) sw = mc.get(key) if sw == None: output.warn("Port status from unknown datapath", self.__class__.__name__) else: output.dbg("Received port status:\n" + event.port.show("\t"), self.__class__.__name__) if event.port.reason == pyof.OFPPR_DELETE or event.port.reason == pyof.OFPPR_MODIFY: for p in sw.ports: if p.port_no == event.port.desc.port_no: sw.ports.remove(p) if event.port.reason == pyof.OFPPR_ADD or event.port.reason == pyof.OFPPR_MODIFY: sw.ports.append(event.port.desc) output.dbg("Updated switch features:\n" + sw.show("\t"), self.__class__.__name__) mc.set(key, sw) elif isinstance(event, comm.event): # Socket close if event.event == comm.event.SOCK_CLOSE: key = self.get_key(event.sock) sw = mc.get(key) if sw != None: output.info("Datapath %x leaves" % sw.datapath_id, self.__class__.__name__) # Maintain list of datapath socket dpidsl = mc.get(dp_features.DP_SOCK_LIST) if dpidsl != None: if key in dpidsl: dpidsl.remove(key) mc.set(dp_features.DP_SOCK_LIST, dpidsl) # Remove features mc.delete(key) return True
def processevent(self, event): """Process OpenFlow message for config reply @param event OpenFlow message event to process @return True """ if isinstance(event, ofevents.features_reply): # Get config getconfig = pyof.ofp_header() getconfig.type = pyof.OFPT_GET_CONFIG_REQUEST self.conn.send(event.sock, getconfig.pack()) elif isinstance(event, ofevents.config_reply): # Check if I should set config desired_flags = (event.config.flags | self.default_on_config_flags) & ~self.default_off_config_flags desired_miss_send_len = event.config.miss_send_len if self.default_miss_send_len != None: desired_miss_send_len = self.default_miss_send_len if (event.config.flags != desired_flags) or (desired_miss_send_len != event.config.miss_send_len): # Change config to desired output.dbg( "Set config to desired with flag %x " % desired_flags + "and miss_send_len " + str(desired_miss_send_len), self.__class__.__name__, ) setconfig = pyof.ofp_switch_config() setconfig.header.type = pyof.OFPT_SET_CONFIG setconfig.flags = desired_flags setconfig.miss_send_len = desired_miss_send_len self.conn.send(event.sock, setconfig.pack()) # Get config again after set getconfig = pyof.ofp_header() getconfig.type = pyof.OFPT_GET_CONFIG_REQUEST self.conn.send(event.sock, getconfig.pack()) else: # Remember config key = self.get_key(event.sock) mc.set(key, event.config) output.dbg("Updated config with key " + key, self.__class__.__name__) elif isinstance(event, comm.event): # Socket close, so remove config if event.event == comm.event.SOCK_CLOSE: key = self.get_key(event.sock) c = mc.get(key) if c != None: mc.delete(key) return True
def processevent(self, event): """Process authentication event """ if (event.host == None): return True if (isinstance(event, owevent.authenticated)): output.dbg(pu.array2hex_str(event.host)+" is authenticated", self.__class__.__name__) mcutil.set(host_auth.get_key(event.host), event.openid, MAX_AUTH_TIMEOUT) elif (isinstance(event, owevent.unauthenticated)): output.dbg(pu.array2hex_str(event.host)+" is unauthenticated", self.__class__.__name__) mcutil.delete(host_auth.get_key(event.host)) mcutil.delete(host_auth.get_auth_key(event.host)) elif (isinstance(event, owevent.going_to_auth)): output.dbg(pu.array2hex_str(event.host)+" is going to authenticate", self.__class__.__name__) mcutil.set(host_auth.get_auth_key(event.host), event.server(), AUTH_TIMEOUT) return True