def add_flow_table(self, switch_id, table_name, table_type, table_size, match_field_list = []): # Have been tested if (switch_id not in self.switches) or (table_name == None) or (len(table_name) == 0): return FLOWTABLEID_INVALID if (table_size == 0) or (table_type < 0) or (table_type >= of.OF_MAX_TABLE_TYPE): return FLOWTABLEID_INVALID if (table_type == of.OF_LINEAR_TABLE) and (len(match_field_list) != 0): return FLOWTABLEID_INVALID if (table_type != of.OF_LINEAR_TABLE) and (len(match_field_list) == 0): return FLOWTABLEID_INVALID field_num = len(match_field_list) key_length = 0 for field in match_field_list: key_length += field.length global_table_id = self.database.add_flow_table(switch_id, table_name, table_type, key_length, table_size, field_num, match_field_list) if global_table_id == FLOWTABLEID_INVALID: return FLOWTABLEID_INVALID flow_table = self.database.get_flow_table(switch_id, global_table_id) msg = of.ofp_table_mod() msg.flow_table = flow_table self.write_of(switch_id, msg) #self.add_sended_msg(switch_id, msg) return global_table_id
def add_flow_table(self, switch_id, table_name, table_type, table_size, match_field_list = []): # Have been tested if (switch_id not in self.switches) or (table_name == None) or (len(table_name) == 0): log.error("no such switch_id or wrong table name") return FLOWTABLEID_INVALID if (table_size == 0) or (table_type < 0) or (table_type >= of.OF_MAX_TABLE_TYPE): log.error("wrong table size or wrong table type") return FLOWTABLEID_INVALID if (table_type == of.OF_LINEAR_TABLE) and (len(match_field_list) != 0): log.error("wrong match_field_list") return FLOWTABLEID_INVALID if (table_type != of.OF_LINEAR_TABLE) and (len(match_field_list) == 0): log.error("wrong match_field_list") return FLOWTABLEID_INVALID field_num = len(match_field_list) # calculate the field_num key_length = 0 for field in match_field_list: # calculate the key_length key_length += field.length global_table_id = self.database.add_flow_table(switch_id, table_name, table_type, key_length, table_size, field_num, match_field_list) if global_table_id == FLOWTABLEID_INVALID: log.error("ERROR when add flow table in PMDatabase") return FLOWTABLEID_INVALID flow_table = self.database.get_flow_table(switch_id, global_table_id) msg = of.ofp_table_mod() msg.flow_table = flow_table self.write_of(switch_id, msg) msg_info = '' msg_info += ('ADD <table[' + str(flow_table.table_type) + '][' + str(flow_table.table_id) + ']> ') msg_info += ('[G_TID] ' + str(global_table_id) + ' [T_NAME] ' + flow_table.table_name) #log.info('ADD <table[' + str(flow_table.table_type) + '][' + str(flow_table.table_id) + ']> ' + flow_table.table_name) log.info(msg_info) #self.add_sended_msg(switch_id, msg) return global_table_id
def _handle_ConnectionUp(self, event): msg = pof.ofp_table_mod() match = pof.ofp_match20(field_id=1, offset=0, length=48) #match.field_id = 1 #match.offset = 0 #match.length = 48 msg.flow_table.match_field_list.append(match) msg.flow_table.match_field_num = 1 msg.flow_table.table_size = 128 msg.flow_table.key_length = 48 msg.flow_table.table_name = 'FirstEntryTable' print 'send TABLE_MOD message:\n', msg event.connection.send(msg) """
def del_empty_flow_table(self, switch_id, global_table_id): # Have been tested flow_entry_map = self.database.get_flow_entries_map(switch_id, global_table_id) if len(flow_entry_map) != 0: log.error("table is not empty") return False flow_table = self.get_flow_table(switch_id, global_table_id) if flow_table is None: log.error("table doesn't exist, no need to delete") return True self.database.delete_flow_table(switch_id, flow_table.table_type, global_table_id) flow_table.command = of.OFPTC_DELETE table_mod = of.ofp_table_mod() table_mod.flow_table = flow_table self.write_of(switch_id, table_mod) # send to switch return True
def _handle_ConnectionUp(self, event): msg = pof.ofp_table_mod() match = pof.ofp_match20(field_id = 1, offset = 0, length = 48) #match.field_id = 1 #match.offset = 0 #match.length = 48 msg.flow_table.match_field_list.append(match) msg.flow_table.match_field_num = 1 msg.flow_table.table_size = 128 msg.flow_table.key_length = 48 msg.flow_table.table_name = 'FirstEntryTable' print 'send TABLE_MOD message:\n', msg event.connection.send(msg) """
def _handle_ConnectionUp(self, event): msg = pof.ofp_table_mod() match = pof.ofp_match20() match.field_id = 1 match.offset = 0 match.length = 48 msg.flow_table.match_field_list.append(match) msg.flow_table.match_field_num = 1 msg.flow_table.table_size = 128 msg.flow_table.key_length = 48 msg.flow_table.table_name = 'FirstEntryTable' print 'send TABLE_MOD message:\n', msg event.connection.send(msg) msg = pof.ofp_flow_mod() msg.priority = 0 msg.table_id=0 matchx = pof.ofp_matchx() matchx.field_id = 1 matchx.offset = 0 matchx.length = 48 matchx.value="010203040506" matchx.mask="000000000000" msg.match_list.append(matchx) msg.match_field_num = 1 instruction = pof.ofp_instruction_goto_table() instruction.next_table_id=1 #instruction.type = 6 #instruction.length = 16 msg.instruction_list.append(instruction) msg.instruction_num = 1 print 'send FLOW_MOD message:\n', msg event.connection.send(msg)
def _handle_ConnectionUp(self, event): msg = pof.ofp_table_mod() match = pof.ofp_match20() match.field_id = 1 match.offset = 0 match.length = 48 msg.flow_table.match_field_list.append(match) msg.flow_table.match_field_num = 1 msg.flow_table.table_size = 128 msg.flow_table.key_length = 48 msg.flow_table.table_name = 'FirstEntryTable' print 'send TABLE_MOD message:\n', msg event.connection.send(msg) msg = pof.ofp_flow_mod() msg.priority = 0 msg.table_id = 0 matchx = pof.ofp_matchx() matchx.field_id = 1 matchx.offset = 0 matchx.length = 48 matchx.value = "010203040506" matchx.mask = "000000000000" msg.match_list.append(matchx) msg.match_field_num = 1 instruction = pof.ofp_instruction_goto_table() instruction.next_table_id = 1 #instruction.type = 6 #instruction.length = 16 msg.instruction_list.append(instruction) msg.instruction_num = 1 print 'send FLOW_MOD message:\n', msg event.connection.send(msg)
def add_flow_table(self, switch_id, table_name, table_type, table_size, match_field_list=[]): # Have been tested if (switch_id not in self.switches) or (table_name == None) or (len(table_name) == 0): return FLOWTABLEID_INVALID if (table_size == 0) or (table_type < 0) or (table_type >= of.OF_MAX_TABLE_TYPE): return FLOWTABLEID_INVALID if (table_type == of.OF_LINEAR_TABLE) and (len(match_field_list) != 0): return FLOWTABLEID_INVALID if (table_type != of.OF_LINEAR_TABLE) and (len(match_field_list) == 0): return FLOWTABLEID_INVALID field_num = len(match_field_list) key_length = 0 for field in match_field_list: key_length += field.length global_table_id = self.database.add_flow_table(switch_id, table_name, table_type, key_length, table_size, field_num, match_field_list) if global_table_id == FLOWTABLEID_INVALID: return FLOWTABLEID_INVALID flow_table = self.database.get_flow_table(switch_id, global_table_id) msg = of.ofp_table_mod() msg.flow_table = flow_table self.write_of(switch_id, msg) #self.add_sended_msg(switch_id, msg) return global_table_id