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 __init__(self, sock, msg): """Initialize @param sock reference to socket @param msg message """ ofcomm.message.__init__(self, sock, msg) ##Switch config struct self.config = None if (self.header.type == pyof.OFPT_GET_CONFIG_REPLY): self.config = pyof.ofp_switch_config() r = self.config.unpack(msg) if (len(r) > 0): output.warn("Config reply is of irregular length with "+\ str(len(r))+" bytes remaining.", self.__class__.__name__) output.dbg("Received switch config:\n"+\ self.config.show("\t"), self.__class__.__name__)