def create_PIT_table(event): ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 96 ofmatch20_1.length = 16 #a new protocol,CCN,0x0011 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 112 ofmatch20_2.length = 16 #0x0001:Interest Packet,0x0002:Content Packet ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 144 ofmatch20_3.length = PIT_NAME_LEN * 8 #ContentName's length msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command = PIT_COMMAND #OFPTC_ADD msg.flowTable.tableType = PIT_TYPE #OF_MM_TABLE msg.flowTable.matchFieldNum = 3 #match num msg.flowTable.tableSize = Common.PIT_SIZE msg.flowTable.tableId = PIT_ID msg.flowTable.tableName = PIT_NAME msg.flowTable.keyLength = 32 + PIT_NAME_LEN * 8 #match field length event.connection.send(msg)
def add_first_table(connection): msg = of.ofp_table_mod() ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 96 ofmatch20_3.length = 16 msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 64 connection.send(msg)
def add_flow_table (tname): #global field_config msg = of.ofp_table_mod() t = g.table[tname] msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableName = tname msg.flowTable.tableId = t[0] msg.flowTable.tableType = t[1] msg.flowTable.tableSize = t[2] msg.flowTable.matchFieldNum = len(t[3]) key_len = 0 match_field = [] for i in t[3]: ofmatch20 = of.ofp_match20() ofmatch20.fieldId = i ofmatch20.offset = g.field_config[i][0] ofmatch20.length = g.field_config[i][1] match_field.append(ofmatch20) key_len += ofmatch20.length msg.flowTable.matchFieldList = match_field msg.flowTable.keyLength = key_len return msg
def add_classfier_table (tname): t = g.classfier_table[tname] msg = of.ofp_experimenter() msg.type = of.CLASSFIER_TABLE msg.ctab.type = of.SYNC_TABLE table = of.sync_flow_table() table.command = 0 #OFPTC_ADD table.tableName = tname table.tableId = t[0] table.tableType = t[1] table.tableSize = t[2] table.matchFieldNum = len(t[3]) key_len = 0 match_field = [] for i in t[3]: ofmatch20 = of.ofp_match20() ofmatch20.fieldId = i ofmatch20.offset = g.field_config[i][0] ofmatch20.length = g.field_config[i][1] match_field.append(ofmatch20) key_len += ofmatch20.length table.matchFieldList = match_field table.keyLength = key_len msg.ctab.table = table return msg
def add_match_field(tname): key_len = 0 match_field = [] field_name_list = g.table[tname][3] for i in field_name_list: field = g.field_config[i] ofmatch20 = of.ofp_match20() ofmatch20.fieldId = field[0] ofmatch20.offset = field[1] ofmatch20.length = field[2] match_field.append(ofmatch20) key_len += ofmatch20.length return match_field, key_len
def add_new_table(device_id, table): flow_table = of.ofp_flow_table() flow_table.tableId = table['table_id'] flow_table.tableName = table['table_name'] flow_table.tableSize = string.atoi(table['size'])# table size match_list = [] field_id_assigned = 0; for each_field in table['Table_entry']['match']: field_match20 = of.ofp_match20() field_match20.fieldId = field_id_assigned; field_match20.fieldname = each_field[0] field_match20.offset = each_field[2] field_match20.length = each_field[1] match_list.append(field_match20) field_id_assigned = field_id_assigned + 1 flow_table.matchFieldList = match_list core.PofManager.add_new_table(device_id, flow_table)
def send_table_mod(event): msg = of.ofp_table_mod() ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 48 ofmatch20_2.length = 48 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 96 ofmatch20_3.length = 16 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = 4 ofmatch20_4.offset = 112 ofmatch20_4.length = 64 ofmatch20_5 = of.ofp_match20() ofmatch20_5.fieldId = 5 ofmatch20_5.offset = 176 ofmatch20_5.length = 64 ofmatch20_6 = of.ofp_match20() ofmatch20_6.fieldId = 6 ofmatch20_6.offset = 240 ofmatch20_6.length = 16 msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command = of.OFPTC_ADD msg.flowTable.tableType = of.OF_MM_TABLE #test_port_mod(event) #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 64 event.connection.send(msg)
def test_OUTPUT(event): print "we are really doing\n" out_port = 1 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=46; ofmatch20_1.offset=0; ofmatch20_1.length=48; msg = of.ofp_table_mod() msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 msg.flowTable.matchFieldList.append(ofmatch20_1) #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=48 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=1 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=1 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=46 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("0000") # null tempmatchx.set_mask("0000") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() ''' action=of.ofp_action_setfield() action.fieldSetting.fieldId=46 action.fieldSetting.offset=0 action.fieldSetting.length=48 action.fieldSetting.set_value("0000000000ff") action.fieldSetting.set_mask("ffffffffffff") tempins.actionList.append(action) action=of.ofp_action_addfield() action.fieldId = 47 action.fieldPosition = 96 action.fieldLength = 16 tempins.actionList.append(action) action=of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 48 tempins.actionList.append(action) ''' action=of.ofp_action_output() action.portId=out_port action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 2 ############################################################################### msg=of.ofp_flow_mod() msg.command =3 msg.counterId=1 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=1 tempins=of.ofp_instruction_applyaction() action=of.ofp_action_setfield() action.fieldSetting.fieldId=46 action.fieldSetting.offset=0 action.fieldSetting.length=48 action.fieldSetting.set_value("0000000000ff") action.fieldSetting.set_mask("ffffffffffff") tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_MODIFY_FIELD(event): out_port = 2 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 48 ofmatch20_2.length = 48 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 48 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 1 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("00") # null tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_modifyfield() action.matchfield.fieldId = 2 action.matchfield.offset = 48 action.matchfield.length = 8 action.increment = 1 tempins.actionList.append(action) action = of.ofp_action_output() action.portId = out_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_CONNECT(event): ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.input_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 0 #input port ofmatch20_1.offset = 0 ofmatch20_1.length = 32 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 47 ofmatch20_2.offset = 96 ofmatch20_2.length = 16 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 12 #ip dest_ip ofmatch20_3.offset = 0 ofmatch20_3.length = 32 ########################################### # table 0 ########################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 16 event.connection.send(msg) ############################################################################## #flow_mod 0-0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0806") #arp tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_gototable() tempins.nextTableId = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0800") #ipv4 tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_to_CP() tempins.reasonType = 0 #0: immediate value; 1: from field tempins.apply_action_flag = 0 tempins.end_flag = 0 tempins.max_len = 0xff tempins.meta_pos = 0 tempins.meta_len = 0 tempins.reasonValue = 2 msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 2 msg.instruction.append(tempins) event.connection.send(msg) ########################################### # table 1 ########################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 1 msg.flowTable.tableName = "table1" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 1-0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 32 # even IP tempmatchx.set_value("00000001") tempmatchx.set_mask("0000000f") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 32 #odd IP tempmatchx.set_value("00000007") tempmatchx.set_mask("0000000f") msg.matchx.append(tempmatchx) #instructions tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 1 action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ################################################### # table 2 ################################################## msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 msg.flowTable.tableSize = 128 msg.flowTable.tableId = 2 msg.flowTable.tableName = "table2" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 2-0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 2 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 tempmatchx.set_value("00000001") # even ip last bit tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction ''' tempins = of.ofp_instruction_applyaction() action=of.ofp_action_setfield() action.fieldSetting.fieldId=49 # ip offset 32 action.fieldSetting.offset=32 action.fieldSetting.length=16 action.fieldSetting.set_value("ffaa") action.fieldSetting.set_mask("ffff") tempins.actionList.append(action) msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_modifyfield() action.matchfield.fieldId = 48 action.matchfield.offset = 26*8 action.matchfield.length = 32 action.increment = 1 tempins.actionList.append(action) msg.instruction.append(tempins) ''' tempins = of.ofp_instruction_applyaction() action = of.ofp_action_setfield() action.fieldSetting.fieldId = 47 # ip offset 32 action.fieldSetting.offset = 64 action.fieldSetting.length = 8 action.fieldSetting.set_value("3f") action.fieldSetting.set_mask("ff") tempins.actionList.append(action) action = of.ofp_action_setfield() action.fieldSetting.fieldId = 48 # ip offset 32 action.fieldSetting.offset = 80 action.fieldSetting.length = 16 action.fieldSetting.set_value("dace") action.fieldSetting.set_mask("ffff") tempins.actionList.append(action) msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 2-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 2 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 tempmatchx.set_value("00000000") # odd ip last bit tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_modifyfield() action.matchfield.fieldId = 48 action.matchfield.offset = 22 * 8 action.matchfield.length = 8 action.increment = -1 tempins.actionList.append(action) action = of.ofp_action_setfield() action.fieldSetting.fieldId = 49 # ip_checksum action.fieldSetting.offset = 192 action.fieldSetting.length = 16 action.fieldSetting.set_value("0000") action.fieldSetting.set_mask("ffff") tempins.actionList.append(action) action = of.ofp_action_calculatechecksum() action.checksumPosType = 0 action.calcPosType = 0 action.checksumPosition = 80 + 112 action.checksumLength = 16 action.calcStarPosition = 112 action.calcLength = 160 tempins.actionList.append(action) msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 1 msg.instruction.append(tempins) event.connection.send(msg)
def test_huawei_flow(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 48 ofmatch20_2.length = 48 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 96 ofmatch20_3.length = 16 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = 4 ofmatch20_4.offset = 184 ofmatch20_4.length = 8 ofmatch20_5 = of.ofp_match20() ofmatch20_5.fieldId = 5 ofmatch20_5.offset = 208 ofmatch20_5.length = 32 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.matchFieldList.append(ofmatch20_5) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 5 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 152 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### index_list = range(0, 10) name_list = [ "name0", "name1", "name2", "name3", "name4", "name5", "name6", "name7", "name8", "name9" ] for i in range(len(index_list)): msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = index_list[i] msg.index = index_list[i] tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 1 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("90b11c5a5299") #90:b1:1c:5a:52:99 tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 2 tempmatchx.offset = 48 tempmatchx.length = 48 tempmatchx.set_value("90b11c5a618d") #90:b1:1c:5a:61:8d tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) #need to new a ofp_matchx tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 3 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0800") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 4 tempmatchx.offset = 184 tempmatchx.length = 8 tempmatchx.set_value("01") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 5 tempmatchx.offset = 208 tempmatchx.length = 32 tempmatchx.set_value("c0a80103") tempmatchx.set_mask("ffffffff") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() ''' action=of.ofp_action_write() action.io_type =1 action.name_len=5 action.name=name_list[i] action.enable_flag=1 ''' action = of.ofp_action_packetin() action.reason = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_MOVE_PACKET_OFFSET(event): out_port = g.output_port ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[7] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 12 # IP dest_ip addr ofmatch20_1.offset = 0 ofmatch20_1.length = 32 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 # even IP tempmatchx.set_value("00000000") tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 tempmatchx.set_value("00000001") # 奇数IP tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_movepacketoffset() tempins.direction = 0 tempins.valueType = 0 tempins.move_value = 112 msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_setfield() action.fieldSetting.fieldId = 47 # ip offset 32 action.fieldSetting.offset = 64 action.fieldSetting.length = 8 action.fieldSetting.set_value("3f") action.fieldSetting.set_mask("ff") tempins.actionList.append(action) action = of.ofp_action_setfield() action.fieldSetting.fieldId = 48 # ip offset 32 action.fieldSetting.offset = 80 action.fieldSetting.length = 16 action.fieldSetting.set_value("dace") action.fieldSetting.set_mask("ffff") tempins.actionList.append(action) action = of.ofp_action_output() action.portId = out_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_DROP(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 2 ofmatch20_1.offset = 48 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = -1 ofmatch20_2.offset = 16 ofmatch20_2.length = 8 ########################################################## #table mode 1 ########################################################## msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 8 event.connection.send(msg) ############################################################################## #flow_mod 1-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 16 tempmatchx.length = 8 tempmatchx.set_value("02") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 4 action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1-2 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 16 tempmatchx.length = 8 tempmatchx.set_value("04") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_drop() action.reason = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_for_ipv6(event): ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 48 ofmatch20_2.length = 48 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 96 ofmatch20_3.length = 16 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = 4 ofmatch20_4.offset = 112 ofmatch20_4.length = 64 ofmatch20_5 = of.ofp_match20() ofmatch20_5.fieldId = 5 ofmatch20_5.offset = 176 ofmatch20_5.length = 64 ofmatch20_6 = of.ofp_match20() ofmatch20_6.fieldId = 6 ofmatch20_6.offset = 240 ofmatch20_6.length = 16 ############################################################################## #table_mod 0 ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 144 event.connection.send(msg) ############################################################################## #table_mod 1 ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 0 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 128 msg.flowTable.keyLength = 144 msg.flowTable.tableName = "CC" event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 0 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 1 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("000000000001") tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) #instruction writemetadatafrompacket 7 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 32 tempins.value = [1, 1, 1, 1, 1, 1] tempins.writeLength = 48 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 16 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 2 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 4 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_applyaction() action = of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 48 tempins.actionList.append(action) msg.instruction.append(tempins) #instruction writemetadata 2 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 0 tempins.writeLength = 0 tempins.value = [] #msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 0x10045 action.metadataOffset = 32 action.metadataLength = 48 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_for_single_vxlan(event): ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=0 ofmatch20_1.offset=0 ofmatch20_1.length=48 ofmatch20_2 =of.ofp_match20() ofmatch20_2.fieldId=-1 ofmatch20_2.offset=272 ofmatch20_2.length=32 ofmatch20_3 =of.ofp_match20() ofmatch20_3.fieldId= -1 ofmatch20_3.offset= 336 ofmatch20_3.length= 16 ofmatch20_4 =of.ofp_match20() ofmatch20_4.fieldId= -1 ofmatch20_4.offset= 160 ofmatch20_4.length= 16 ofmatch20_5 =of.ofp_match20() ofmatch20_5.fieldId= 2 ofmatch20_5.offset= 96 ofmatch20_5.length=16 ofmatch20_6 =of.ofp_match20() ofmatch20_6.fieldId=7 ofmatch20_6.offset=184 ofmatch20_6.length=8 ofmatch20_7 =of.ofp_match20() ofmatch20_7.fieldId= 12 ofmatch20_7.offset= 288 ofmatch20_7.length=16 ############################################################################## #table_mod 0 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) #msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=48 event.connection.send(msg) ############################################################################## #table_mod 16 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.tableId=0 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 128 msg.flowTable.keyLength= 0 msg.flowTable.tableName="VNI" event.connection.send(msg) ############################################################################## #table_mod 17 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.tableId=1 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 128 msg.flowTable.keyLength= 0 msg.flowTable.tableName="VxLanEncap" event.connection.send(msg) ############################################################################## #table_mod 8 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.tableId=0 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 1 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 32 msg.flowTable.tableName="FIB" event.connection.send(msg) ############################################################################## #table_mod 20 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.tableId=4 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 0 msg.flowTable.tableName="FIB_DT" event.connection.send(msg) ############################################################################## #table_mod 18 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.tableId=2 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 0 msg.flowTable.tableName="EPAT" event.connection.send(msg) ############################################################################## #table_mod 10 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_5) msg.flowTable.tableId=0 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 2 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 16 msg.flowTable.tableName="L2PA" event.connection.send(msg) ############################################################################## #table_mod 11 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_6) msg.flowTable.matchFieldList.append(ofmatch20_7) msg.flowTable.tableId=1 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 2 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 24 msg.flowTable.tableName="L3PA" event.connection.send(msg) ############################################################################## #table_mod 19 ############################################################################### msg =of.ofp_table_mod() msg.flowTable.tableId=3 msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength= 0 msg.flowTable.tableName="VxLanDecap" event.connection.send(msg) ############################################################################## #flow_mod 0-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 0 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 #matchx 1 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=0 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("000000000001") tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 16 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 #matchx 1 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=0 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("112233445566") tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins=of.ofp_instruction_gototable() tempins.nextTableId= 10 tempins.packetOffset=0 tempins.matchList.extend([ofmatch20_5]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 16-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 2 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=240 tempins.set_value('03030303') tempins.writeLength = 32 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=272 tempins.set_value('04040404') tempins.writeLength = 32 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset= 400 tempins.set_value('000001') tempins.writeLength = 24 msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 3 msg.cookie = 1 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=128 tempins.set_value('0800') tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=144 tempins.set_value('4500') tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=208 tempins.set_value('4011') tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=320 tempins.set_value('12b5') tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 4 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 1 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=368 tempins.set_value('80') tempins.writeLength = 8 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadatafrompacket() tempins.metadataOffset= 336 tempins.packetOffset = 128 tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_writemetadatafrompacket() tempins.metadataOffset= 160 tempins.packetOffset = 128 tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 2 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-2 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 5 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 2 tempins=of.ofp_instruction_calculatefiled() tempins.calcType = 0 tempins.src_valueType = 0 #0: use srcField_Value; 1: use srcField; tempins.des_field = ofmatch20_3 tempins.src_value = 30 #tempins.src_field = ofp_match20() msg.instruction.append(tempins) tempins=of.ofp_instruction_calculatefiled() tempins.calcType = 0 tempins.src_valueType = 0 #0: use srcField_Value; 1: use srcField; tempins.des_field = ofmatch20_4 tempins.src_value = 50 #tempins.src_field = ofp_match20() msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 3 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-3 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 3 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=304 tempins.set_value('04d2') tempins.writeLength = 16 msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 4 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-4 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 7 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 4 tempins=of.ofp_instruction_applyaction() action = of.ofp_action_calculatechecksum() action.checksumPosType = 1 action.calcPosType = 1 action.checksumPosition = 224 action.checksumLength = 16 action.calcStarPosition = 144 action.calcLength = 160 tempins.actionList.append(action) msg.instruction.append(tempins) tempins=of.ofp_instruction_gototable() tempins.nextTableId= 8 tempins.packetOffset=0 tempins.matchList.extend([ofmatch20_2]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 8-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 8 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 1 msg.priority = 0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId= -1 tempmatchx.offset= 272 tempmatchx.length= 32 tempmatchx.set_value("00000000") tempmatchx.set_mask("00000000") msg.matchx.append(tempmatchx) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 20 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 20-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 9 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 4 msg.tableType = 3 msg.priority = 0 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=32 tempins.set_value('112233445566') tempins.writeLength = 48 msg.instruction.append(tempins) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 18 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 18-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 10 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 2 msg.tableType = 3 msg.priority = 0 tempins=of.ofp_instruction_writemetadata() tempins.metaDataOffset=80 tempins.set_value('665544332211') tempins.writeLength = 48 msg.instruction.append(tempins) tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=0x10045 action.metadataOffset=32 action.metadataLength=400 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 10-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 2 msg.priority = 0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=2 tempmatchx.offset=96 tempmatchx.length=16 tempmatchx.set_value("0800") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins=of.ofp_instruction_gototable() tempins.nextTableId= 11 tempins.packetOffset=0 tempins.matchList.extend([ofmatch20_6,ofmatch20_7]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 11-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 2 msg.priority = 0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=7 tempmatchx.offset=184 tempmatchx.length=8 tempmatchx.set_value("11") tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) tempmatchx=of.ofp_matchx() tempmatchx.fieldId=12 tempmatchx.offset= 288 tempmatchx.length=16 tempmatchx.set_value("12b5") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 19 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 19-0 ############################################################################### msg=of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 3 msg.tableType = 3 msg.priority = 0 ''' tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=0x10047 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ''' tempins=of.ofp_instruction_applyaction() action=of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 128 tempins.actionList.append(action) tempins.actionList.append(action) tempins.actionList.append(action) action=of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 16 tempins.actionList.append(action) action=of.ofp_action_output() action.portId=0x10047 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_huawei_flow(event): ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=1; ofmatch20_1.offset=0; ofmatch20_1.length=48; ofmatch20_2 =of.ofp_match20() ofmatch20_2.fieldId=2; ofmatch20_2.offset=48; ofmatch20_2.length=48; ofmatch20_3 =of.ofp_match20() ofmatch20_3.fieldId=3; ofmatch20_3.offset=96; ofmatch20_3.length=16; ofmatch20_4 =of.ofp_match20() ofmatch20_4.fieldId=4; ofmatch20_4.offset=112; ofmatch20_4.length=64; ofmatch20_5 =of.ofp_match20() ofmatch20_5.fieldId=5; ofmatch20_5.offset=176; ofmatch20_5.length=64; ofmatch20_6 =of.ofp_match20() ofmatch20_6.fieldId=6; ofmatch20_6.offset=240; ofmatch20_6.length=16; msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 2 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=64 event.connection.send(msg) #sleep(1) ''' msg.flowTable.matchFieldList=[] msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.matchFieldList.append(ofmatch20_5) msg.flowTable.matchFieldList.append(ofmatch20_6) msg.flowTable.tableId=1 msg.flowTable.matchFieldNum = 3 msg.flowTable.keyLength=144 msg.flowTable.tableName="FP Parse Flow Table" event.connection.send(msg) #sleep(1) msg.flowTable.matchFieldList=[] msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.tableId=0 msg.flowTable.matchFieldNum = 1 msg.flowTable.keyLength= 64 msg.flowTable.tableName="FP Flow Table" msg.flowTable.tableType=1 #OF_LPM_TABLE event.connection.send(msg) #sleep(1) ''' ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=3 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=1 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=1 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("00") tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #need to new a ofp_matchx tempmatchx=of.ofp_matchx() tempmatchx.fieldId=3 tempmatchx.offset=96 tempmatchx.length=16 tempmatchx.set_value("0888") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_gototable() tempins.nextTableId=1 tempins.packetOffset=0 tempins.matchList.extend([ofmatch20_4,ofmatch20_5,ofmatch20_6]) msg.instruction.append(tempins) #print "Flow_mod 1" #print msg.pack().encode("hex") event.connection.send(msg) #log.info("Flow_Mod:succeed1") #sleep(1) '''
def test_COUNTER(event): ''' out_port = 2 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 47 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ############################################################################## # table mode 1 ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 48 event.connection.send(msg) ''' ############################################################################## #counter_mod 1 ############################################################################### msg =of.ofp_counter_mod() msg.counter.counterID=3 msg.counter.command=0 msg.counter.couterValue=0 msg.counter.byteValue=0 event.connection.send(msg) ''' ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 1 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("00") # null tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() ''' action=of.ofp_action_counter() action.counterId=1 tempins.actionList.append(action) ''' action = of.ofp_action_output() action.portId = 2 action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def cooper_test_ustc(event): ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 0 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = -1 ofmatch20_2.offset = 272 ofmatch20_2.length = 32 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = -1 ofmatch20_3.offset = 336 ofmatch20_3.length = 16 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = -1 ofmatch20_4.offset = 160 ofmatch20_4.length = 16 ofmatch20_5 = of.ofp_match20() ofmatch20_5.fieldId = 2 ofmatch20_5.offset = 96 ofmatch20_5.length = 16 ofmatch20_6 = of.ofp_match20() ofmatch20_6.fieldId = 7 ofmatch20_6.offset = 184 ofmatch20_6.length = 8 ofmatch20_7 = of.ofp_match20() ofmatch20_7.fieldId = 12 ofmatch20_7.offset = 288 ofmatch20_7.length = 16 ############################################################################## #table_mod 0 MM ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) #msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 48 event.connection.send(msg) ############################################################################## #table_mod 16 VNI ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 0 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 128 msg.flowTable.keyLength = 0 msg.flowTable.tableName = "VNI" event.connection.send(msg) ############################################################################## #table_mod 17 VxLanEncap ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 1 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 128 msg.flowTable.keyLength = 0 msg.flowTable.tableName = "VxLanEncap" event.connection.send(msg) ############################################################################## #table_mod 8 FIB ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.tableId = 0 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 1 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 32 msg.flowTable.tableName = "FIB" event.connection.send(msg) ############################################################################## #table_mod 20 FIB_DT ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 4 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 0 msg.flowTable.tableName = "FIB_DT" event.connection.send(msg) ############################################################################## #table_mod 18 EPAT ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 2 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 0 msg.flowTable.tableName = "EPAT" event.connection.send(msg) ############################################################################## #table_mod 10 L2PA ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_5) msg.flowTable.tableId = 0 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 2 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 16 msg.flowTable.tableName = "L2PA" event.connection.send(msg) ############################################################################## #table_mod 11 L3PA ############################################################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_6) msg.flowTable.matchFieldList.append(ofmatch20_7) msg.flowTable.tableId = 1 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 2 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 24 msg.flowTable.tableName = "L3PA" event.connection.send(msg) ############################################################################## #table_mod 19 VxLanDecap ############################################################################### msg = of.ofp_table_mod() msg.flowTable.tableId = 3 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 3 msg.flowTable.tableSize = 100 msg.flowTable.keyLength = 0 msg.flowTable.tableName = "VxLanDecap" event.connection.send(msg) ############################################################################## #flow_mod 0-0 MM ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 0 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("90e2ba2a22ca") #Network Center PC MAC tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 16 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-1 MM ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 0 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("6cf0498cd47b") #SXS PC MAC tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 16 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-2 MM ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 2 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("ffffffffffff") #for ARP request tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 10 tempins.packetOffset = 0 tempins.matchList.extend([ofmatch20_5]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-3 MM ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 3 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("643e8c394002") #USTC Switch MAC tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 10 tempins.packetOffset = 0 tempins.matchList.extend([ofmatch20_5]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 0-4 MM ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 4 #matchx 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 0 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("bc305ba4e124") #USTC PC MAC tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 18 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 16-0 VNI ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 2 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 240 tempins.set_value('72d6a6c1') #USTC Switch IP tempins.writeLength = 32 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 272 tempins.set_value('9FE23D4B') #Network Center Switch IP tempins.writeLength = 32 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 400 tempins.set_value('000001') #VNI tempins.writeLength = 24 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 16-1 VNI ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 2 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 3 msg.priority = 0 msg.index = 1 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 240 tempins.set_value('72d6a6c1') #USTC Switch IP tempins.writeLength = 32 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 272 tempins.set_value('D24BE144') #SXS Switch IP tempins.writeLength = 32 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 400 tempins.set_value('000001') #VNI tempins.writeLength = 24 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-0 VxLanEncap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 3 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 128 tempins.set_value('0800') #EthType tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 144 tempins.set_value('4500') #V_IHL_TOS tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 208 tempins.set_value('4011') #TTL & Protocol tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 320 tempins.set_value('12b5') #UDP Dport tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 1 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-1 VxLanEncap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 4 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 1 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 368 tempins.set_value('80') #VxLan Flag tempins.writeLength = 8 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadatafrompacket( ) #Total length to UDP_length tempins.metadataOffset = 336 tempins.packetOffset = 128 tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_writemetadatafrompacket( ) #Total length to Total length tempins.metadataOffset = 160 tempins.packetOffset = 128 tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 2 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-2 VxLanEncap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 5 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 2 tempins = of.ofp_instruction_calculatefiled() #UDP_length + 30 tempins.calcType = 0 tempins.src_valueType = 0 #0: use srcField_Value; 1: use srcField; tempins.des_field = ofmatch20_3 tempins.src_value = 30 #tempins.src_field = ofp_match20() msg.instruction.append(tempins) tempins = of.ofp_instruction_calculatefiled() #Total_length + 50 tempins.calcType = 0 tempins.src_valueType = 0 #0: use srcField_Value; 1: use srcField; tempins.des_field = ofmatch20_4 tempins.src_value = 50 #tempins.src_field = ofp_match20() msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 3 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-3 VxLanEncap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 3 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 304 tempins.set_value('04d2') #UDP Sport tempins.writeLength = 16 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 17 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 4 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 17-4 VxLanEncap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 7 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 3 msg.priority = 0 msg.index = 4 tempins = of.ofp_instruction_applyaction() action = of.ofp_action_calculatechecksum() action.checksumPosType = 1 action.calcPosType = 1 action.checksumPosition = 224 action.checksumLength = 16 action.calcStarPosition = 144 action.calcLength = 160 tempins.actionList.append(action) msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 8 tempins.packetOffset = 0 tempins.matchList.extend([ofmatch20_2]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 8-0 FIB ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 8 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 1 msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 272 tempmatchx.length = 32 tempmatchx.set_value("9FE23D4B") #Network Center switch IP tempmatchx.set_mask("ffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 20 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 8-1 FIB ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 8 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 1 msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 272 tempmatchx.length = 32 tempmatchx.set_value("D24BE144") #SXS switch IP tempmatchx.set_mask("ffffffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 20 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 20-0 FIB_DT ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 9 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 4 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 32 tempins.set_value('001244662000') #USTC GateWay MAC tempins.writeLength = 48 msg.instruction.append(tempins) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 18 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 18-0 EPAT ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 10 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 2 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 80 tempins.set_value('643e8c394002') #USTC switch MAC tempins.writeLength = 48 msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 0x10041 action.metadataOffset = 32 action.metadataLength = 400 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 18-1 EPAT ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 10 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 2 msg.tableType = 3 msg.priority = 0 msg.index = 1 tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 0x10043 action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 10-0 L2PA ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 2 msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 2 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0800") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 11 tempins.packetOffset = 0 tempins.matchList.extend([ofmatch20_6, ofmatch20_7]) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 10-1 L2PA ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 2 msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 2 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0806") #ARP type tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = 0x1003a #the console port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 11-0 L3PA ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 2 msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 7 tempmatchx.offset = 184 tempmatchx.length = 8 tempmatchx.set_value("11") tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 288 tempmatchx.length = 16 tempmatchx.set_value("12b5") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 19 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 19-0 VxLanDecap ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 6 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 3 msg.tableType = 3 msg.priority = 0 msg.index = 0 tempins = of.ofp_instruction_applyaction() action = of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 128 tempins.actionList.append(action) tempins.actionList.append(action) tempins.actionList.append(action) action = of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 16 tempins.actionList.append(action) msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 0 tempins.packetOffset = 0 tempins.matchList.extend([ofmatch20_1]) msg.instruction.append(tempins) event.connection.send(msg) '''
def test_WRITE_METADATA(event): out_port = 2 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = -1 ofmatch20_2.offset = 0 ofmatch20_2.length = 16 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = -1 ofmatch20_3.offset = 16 ofmatch20_3.length = 8 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = -1 ofmatch20_4.offset = 64 ofmatch20_4.length = 16 ############################################################################### # table_mode 1 ############################################################################### print " config flowTable 1" msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) print ofmatch20_2 msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 16 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 0 tempmatchx.length = 16 tempmatchx.set_value('003c') # null tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 64 tempins.set_value("a6a1") tempins.writeLength = 16 print "write metadata!" msg.instruction.append(tempins) tempins = of.ofp_instruction_gototable() tempins.nextTableId = 1 tempins.packetOffset = 0 tempins.matchFieldNum = 1 tempins.matchList.append(ofmatch20_3) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################### # table_mode 2 ############################################################################### print " config flowTable 2" msg = of.ofp_table_mod() #msg.flowTable.matchFieldList=[] print ofmatch20_4 msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 1 msg.flowTable.tableName = "Table 2" msg.flowTable.keyLength = 16 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 2 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 1 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = -1 tempmatchx.offset = 64 tempmatchx.length = 16 tempmatchx.set_value("a6a1") # null tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = out_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_CLASSFIER_TABLE (event): ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 23 #the last bit of dest IP ofmatch20_1.offset = 0 ofmatch20_1.length = 32 table = of.sync_flow_table() table.matchFieldList.append(ofmatch20_1) table.command = 0 #OFPTC_ADD table.tableType = of.OF_EM_TABLE #OF_MM_TABLE #table.matchFieldNum = 1 table.matchFieldNum = len(table.matchFieldList) table.tableSize = 128 table.tableId = 0xfd table.tableName = "Classfier_Table" table.keyLength = 16 msg = of.ofp_experimenter() msg.type = of.CLASSFIER_TABLE msg.ctab.type = of.SYNC_TABLE msg.ctab.table = table event.connection.send(msg) entry = of.sync_flow_entry() entry.command = 0 entry.counterId = 1 entry.cookie = 0 entry.cookieMask = 0 entry.tableId = 0xfd entry.tableType = of.OF_EM_TABLE #OF_MM_TABLE entry.priority = 0 entry.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = 12 *8 tempmatchx.length = 16 #odd IP tempmatchx.set_value("0806") tempmatchx.set_mask("ffff") entry.matchx.append(tempmatchx) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_addfield() action.fieldId = 48 action.fieldPosition = 96 action.fieldLength = 32 action.set_fieldValue("ffff0001") tempins.actionList.append(action) action = of.ofp_action_output() action.portId = 0xffe1 action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) entry.instruction.append(tempins) msg = of.ofp_experimenter() msg.type = of.CLASSFIER_TABLE msg.ctab.type = of.SYNC_ENTRY msg.ctab.entry = entry event.connection.send(msg)
def test_huawei_flow(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=1; ofmatch20_1.offset=0; ofmatch20_1.length=48; ofmatch20_2 =of.ofp_match20() ofmatch20_2.fieldId=2; ofmatch20_2.offset=48; ofmatch20_2.length=48; ofmatch20_3 =of.ofp_match20() ofmatch20_3.fieldId=3; ofmatch20_3.offset=96; ofmatch20_3.length=16; ofmatch20_4=of.ofp_match20() ofmatch20_4.fieldId=4 ofmatch20_4.offset=184 ofmatch20_4.length=8 ofmatch20_5 =of.ofp_match20() ofmatch20_5.fieldId=5; ofmatch20_5.offset=208; ofmatch20_5.length=32; msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.matchFieldList.append(ofmatch20_5) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 5 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=152 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=1 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=1 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("90b11c5a5299") #90:b1:1c:5a:52:99 tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempmatchx=of.ofp_matchx() tempmatchx.fieldId=2 tempmatchx.offset=48 tempmatchx.length=48 tempmatchx.set_value("90b11c5a618d") #90:b1:1c:5a:61:8d tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) #need to new a ofp_matchx tempmatchx=of.ofp_matchx() tempmatchx.fieldId=3 tempmatchx.offset=96 tempmatchx.length=16 tempmatchx.set_value("0800") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempmatchx=of.ofp_matchx() tempmatchx.fieldId=4 tempmatchx.offset=184 tempmatchx.length=8 tempmatchx.set_value("01") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempmatchx=of.ofp_matchx() tempmatchx.fieldId=5 tempmatchx.offset=208 tempmatchx.length=32 tempmatchx.set_value("c0a80103") tempmatchx.set_mask("ffffffff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_write() action.io_type =1 action.name_len=10 action.name="helloworld" action.enable_flag=1 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_DROP(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.input_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.output_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 47 ofmatch20_2.offset = g.arp_dest_ip_offset ofmatch20_2.length = g.arp_dest_ip_length ########################################################## #table mode 1 ########################################################## msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = g.arp_dest_ip_length event.connection.send(msg) ############################################################################## #flow_mod 1-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 1 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = g.arp_dest_ip_offset tempmatchx.length = g.arp_dest_ip_length tempmatchx.set_value("01") # null tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_writemetadatafrompacket() tempins.metadataOffset = 24 # get dest IP tempins.packetOffset = 38 * 8 tempins.writeLength = 4 * 8 msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_packetin() action.reason = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1-2 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = g.arp_dest_ip_offset tempmatchx.length = g.arp_dest_ip_length tempmatchx.set_value("00") # null tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_writemetadatafrompacket() tempins.metadataOffset = 24 # get dest IP tempins.packetOffset = 38 * 8 tempins.writeLength = 4 * 8 msg.instruction.append(tempins) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_huawei_flow(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] #make eth1 openflow_enable msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 1 ofmatch20_1.offset = 0 ofmatch20_1.length = 48 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 2 ofmatch20_2.offset = 96 ofmatch20_2.length = 16 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 3 ofmatch20_3.offset = 112 ofmatch20_3.length = 16 ofmatch20_4 = of.ofp_match20() ofmatch20_4.fieldId = 4 ofmatch20_4.offset = 144 ofmatch20_4.length = 40 #length of ContentName msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.matchFieldList.append(ofmatch20_4) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 4 #match num msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 120 #match field length event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 1 tempmatchx.offset = 0 tempmatchx.length = 48 tempmatchx.set_value("90b11c5a5299") #90:b1:1c:5a:52:99,192.168.1.2 tempmatchx.set_mask("ffffffffffff") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 2 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0011") tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #0011 means a new protocol tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 3 tempmatchx.offset = 112 tempmatchx.length = 16 tempmatchx.set_value("0001") tempmatchx.set_mask("ffff") #0001 means it is a Interest Packet msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 4 tempmatchx.offset = 144 tempmatchx.length = 40 name = 'name1' value = "" for i in range(0, len(name)): value += str(hex(ord(name[i]))[2:]) tempmatchx.set_value(value) tempmatchx.set_mask("ffffffffff") #6e 61 6d 65 31 means Name 'name1' msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_op_cache() action.io_type = 1 action.name_len = 10 action.name = "helloworld" action.enable_flag = 1 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_CALCULATE_FIELD(event): ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.input_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 12 #the last bit of dest IP ofmatch20_1.offset = 0 ofmatch20_1.length = 32 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 # even IP tempmatchx.set_value("00") tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_modifyfield() action.matchfield.fieldId = 47 action.matchfield.offset = 38 * 8 + 3 * 8 action.matchfield.length = 8 # action.increment = -1 + 2**32 action.increment = -1 tempins.actionList.append(action) action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 #odd IP tempmatchx.set_value("01") tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_modifyfield() action.matchfield.fieldId = 47 action.matchfield.offset = 38 * 8 + 3 * 8 action.matchfield.length = 8 # action.increment = -1 + 2**32 action.increment = -1 tempins.actionList.append(action) action = of.ofp_action_calculatechecksum() action.checksumPosType = 0 action.calcPosType = 1 action.checksumPosition = 80 + 112 action.checksumLength = 16 action.calcStarPosition = 112 action.calcLength = 160 tempins.actionList.append(action) action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_CHECKSUM(event): out_port = 2 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=1; ofmatch20_1.offset=0; ofmatch20_1.length=48; ofmatch20_2 =of.ofp_match20() ofmatch20_2.fieldId=-1; ofmatch20_2.offset=16; ofmatch20_2.length=8; ofmatch20_3 =of.ofp_match20() ofmatch20_3.fieldId=3; ofmatch20_3.offset=96; ofmatch20_3.length=16; ofmatch20_4 =of.ofp_match20() #TTL ofmatch20_4.fieldId=4; ofmatch20_4.offset=64; ofmatch20_4.length=8; ############################################################################### # table_mode 1 ############################################################################### print " config flowTable 1" msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_3) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=16 event.connection.send(msg) ############################################################################## #flow_mod 1-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=1 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=3 tempmatchx.offset=96 tempmatchx.length=16 tempmatchx.set_value("0800") # null tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_gotodirecttable() tempins.nextTableId = 16 tempins.indexType = 0 tempins.packetOffset= 112 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1-2 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=2 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=3 tempmatchx.offset=96 tempmatchx.length=16 tempmatchx.set_value("0806") # null tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_gototable() tempins.nextTableId=1 tempins.packetOffset=0 tempins.matchList.append(ofmatch20_2) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################### # table_mode 2 ############################################################################### print " config flowTable 2" msg =of.ofp_table_mod() msg.flowTable.matchFieldList=[] msg.flowTable.matchFieldList.append(ofmatch20_2) #input_port 8bit msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=1 msg.flowTable.tableName="Table 2" msg.flowTable.keyLength=8 event.connection.send(msg) ############################################################################## #flow_mod 2-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=3 msg.cookie=0 msg.cookieMask=0 msg.tableId=1 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=-1 tempmatchx.offset=16 tempmatchx.length=8 tempmatchx.set_value("02") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=4 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 2-2 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=4 msg.cookie=0 msg.cookieMask=0 msg.tableId=1 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=-1 tempmatchx.offset=16 tempmatchx.length=8 tempmatchx.set_value("04") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=2 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) #################################################################### #table mode 3 DT table #################################################################### msg =of.ofp_table_mod() msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=3 #OF_MM_TABLE msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="Table 3" msg.flowTable.keyLength= 0 event.connection.send(msg) ############################################################################## #flow_mod 3-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId= 5 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=3 #OF_LINER_TABLE msg.priority=0 msg.index=0 #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_modifyfield() #TTL action.matchfield.fieldId=4 action.matchfield.offset=64 action.matchfield.length=8 action.increment=1 tempins.actionList.append(action) action = of.ofp_action_calculatechecksum() action.checksumPosType = 0 action.calcPosType = 0 action.checksumPosition = 80 action.checksumLength = 16 action.calcStarPosition = 0 action.calcLength = 80 tempins.actionList.append(action) msg.instruction.append(tempins) tempins.actionList.append(action) msg.instruction.append(tempins) tempins=of.ofp_instruction_gototable() tempins.nextTableId=1 tempins.packetOffset=0 tempins.matchList.append(ofmatch20_1) msg.instruction.append(tempins) event.connection.send(msg)
def test_ADD_FIELD(event): ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.input_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 23 #the last bit of dest IP ofmatch20_1.offset = 0 ofmatch20_1.length = 32 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 23 tempmatchx.offset = 0 tempmatchx.length = 32 # even IP tempmatchx.set_value("00000000") tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 23 tempmatchx.offset = 0 tempmatchx.length = 32 #odd IP tempmatchx.set_value("00000001") tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_applyaction() action = of.ofp_action_addfield() action.fieldId = 47 action.fieldPosition = 96 action.fieldLength = 32 tempins.actionList.append(action) action = of.ofp_action_setfield() action.fieldSetting.fieldId = 47 # vlan action.fieldSetting.offset = 96 action.fieldSetting.length = 32 action.fieldSetting.set_value("8001000f") # vlan id: 15 action.fieldSetting.set_mask("ffffffff") tempins.actionList.append(action) action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_GOTO_TABLE(event): out_port = 2 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[3] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=1; ofmatch20_1.offset=0; ofmatch20_1.length=48; ofmatch20_2 =of.ofp_match20() ofmatch20_2.fieldId=-1; ofmatch20_2.offset=16; ofmatch20_2.length=8; ofmatch20_3 =of.ofp_match20() ofmatch20_3.fieldId=3; ofmatch20_3.offset=96; ofmatch20_3.length=16; ofmatch20_4 =of.ofp_match20() #TTL ofmatch20_4.fieldId=4; ofmatch20_4.offset=64; ofmatch20_4.length=8; ############################################################################### # table_mode 2 ############################################################################### print " config flowTable 2" msg =of.ofp_table_mod() msg.flowTable.matchFieldList=[] msg.flowTable.matchFieldList.append(ofmatch20_2) #input_port 8bit msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="Table 1" msg.flowTable.keyLength=8 event.connection.send(msg) ############################################################################## #flow_mod 2-1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=3 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=1 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=-1 tempmatchx.offset=16 tempmatchx.length=8 tempmatchx.set_value("02") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=4 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 2-2 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=4 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=1 msg.index=1 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=-1 tempmatchx.offset=16 tempmatchx.length=8 tempmatchx.set_value("04") # null tempmatchx.set_mask("ff") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=2 action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_GOTO_TABLE(event): out_port =4 num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ofmatch20_1 =of.ofp_match20() ofmatch20_1.fieldId=1; ofmatch20_1.offset=0; ofmatch20_1.length=48; ############################################################################### # table_mode 1 ############################################################################### print " config flowTable 1" msg =of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="FirstEntryTable" msg.flowTable.keyLength=48 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=1 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=1 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("00") # null tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_gototable() tempins.nextTableId=1 tempins.packetOffset=0 tempins.matchList.append(ofmatch20_1) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################### # table_mode 2 ############################################################################### print " config flowTable 2" msg =of.ofp_table_mod() msg.flowTable.matchFieldList=[] msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize=128 msg.flowTable.tableId=1 msg.flowTable.tableName="Table 2" msg.flowTable.keyLength=48 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=2 msg.cookie=0 msg.cookieMask=0 msg.tableId=1 msg.tableType=0 #OF_MM_TABLE msg.priority=0 msg.index=0 tempmatchx=of.ofp_matchx() tempmatchx.fieldId=1 tempmatchx.offset=0 tempmatchx.length=48 tempmatchx.set_value("00") # null tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #instruction tempins=of.ofp_instruction_applyaction() action=of.ofp_action_output() action.portId=out_port action.metadataOffset=0 action.metadataLength=0 action.packetOffset=0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_DELETE_FIELD(event): out_port = g.output_port ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[7] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 12 # dest_ip addr ofmatch20_1.offset = 0 ofmatch20_1.length = 32 msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_1) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 32 event.connection.send(msg) ############################################################################## #flow_mod 0 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 # even IP tempmatchx.set_value("00") tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_output() action.portId = g.output_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 0 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 12 tempmatchx.offset = 0 tempmatchx.length = 32 tempmatchx.set_value("01") # 奇数IP tempmatchx.set_mask("01") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_deletefield() action.tagPosition = 0 action.tagLengthValueType = 0 action.tagLengthValue = 48 tempins.actionList.append(action) action = of.ofp_action_output() action.portId = out_port action.metadataOffset = 0 action.metadataLength = 0 action.packetOffset = 0 tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_CONNECT(event): ''' num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[g.input_port - 1] msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 event.connection.send(msg) ''' ofmatch20_1 = of.ofp_match20() ofmatch20_1.fieldId = 0 #input port ofmatch20_1.offset = 0 ofmatch20_1.length = 32 ofmatch20_2 = of.ofp_match20() ofmatch20_2.fieldId = 47 ofmatch20_2.offset = 96 ofmatch20_2.length = 16 ofmatch20_3 = of.ofp_match20() ofmatch20_3.fieldId = 12 #ip dest_ip ofmatch20_3.offset = 0 ofmatch20_3.length = 32 ########################################### # table 0 ########################################### msg = of.ofp_table_mod() msg.flowTable.matchFieldList.append(ofmatch20_2) msg.flowTable.command = 0 #OFPTC_ADD msg.flowTable.tableType = 0 #OF_MM_TABLE msg.flowTable.matchFieldNum = 1 #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 16 event.connection.send(msg) ############################################################################## #flow_mod 0-1 ############################################################################### msg = of.ofp_flow_mod() msg.counterId = 1 msg.cookie = 0 msg.cookieMask = 0 msg.tableId = 0 msg.tableType = 0 #OF_MM_TABLE msg.priority = 0 msg.index = 1 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 47 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("0800") #ipv4 tempmatchx.set_mask("ffff") msg.matchx.append(tempmatchx) tempins = of.ofp_instruction_setpacketoffset() tempins.valueType = 0 tempins.set_value = 14 # bytes msg.instruction.append(tempins) event.connection.send(msg)