def test_METER(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 ############################################################### #table mode ################################################################# 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) ########################################################################## #meter mode ########################################################################## msg = of.ofp_meter_mod() msg.command = 0 #add #msg.reverse=20 msg.rate = 200 # msg.meterID = 1 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_meter() tempins.meterID = 1 msg.instruction.append(tempins) 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_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_to_CP(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 = 23 # 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 = 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_toCP() 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 tempmatchx.set_value("00000001") # 奇数IP tempmatchx.set_mask("00000001") msg.matchx.append(tempmatchx) #instruction tempins = of.ofp_instruction_applyaction() action = of.ofp_action_setfield() action.fieldSetting.fieldId = 24 # src_mac action.fieldSetting.offset = 0 action.fieldSetting.length = 48 action.fieldSetting.set_value("ffaaffaaffaa") action.fieldSetting.set_mask("ffffffffffff") 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_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 = 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 = 1 msg.flowTable.tableName = "SecondEntryTable" 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 = 1 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_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_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)
def test_huawei_flow(event): num = len(event.connection.phyports) msg = of.ofp_port_mod() portmessage = event.connection.phyports[1] print portmessage.desc.portId print "test for two pc" msg.setByPortState(portmessage) msg.desc.openflowEnable = 1 print msg.desc.portId event.connection.send(msg) ''' msg = of.ofp_port_mod() msg.desc.portId=2 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 = 208 ofmatch20_4.length = 32 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_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 #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList) msg.flowTable.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 144 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("90b11c5a5298") #90:b1:1c:5a:52:98 #tempmatchx.set_mask("ffffffffffff") tempmatchx.set_mask("0") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 2 tempmatchx.offset = 48 tempmatchx.length = 48 tempmatchx.set_value("70f96d594742") #70:f9:6d:59:47:42 tempmatchx.set_mask("0") #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") tempmatchx.set_mask("0") msg.matchx.append(tempmatchx) tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 4 tempmatchx.offset = 208 tempmatchx.length = 32 tempmatchx.set_value("da6afe68") #tempmatchx.set_mask("ffffffff") tempmatchx.set_mask("0") 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 ''' action=of.ofp_action_write() action.io_type=1 ''' tempins.actionList.append(action) msg.instruction.append(tempins) event.connection.send(msg)
def test_GOTO_DIRECT_TABLE(event): out_port = 4 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; ############################################################################### # 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_gotodirecttable() tempins.nextTableId =16 tempins.indexType = 0 tempins.packetOffset= 0 tempins.indexValue = 0 msg.instruction.append(tempins) event.connection.send(msg) ############################################################################### # table_mode 2 ############################################################################### print " config flowTable 2" msg =of.ofp_table_mod() msg.flowTable.command=0 #OFPTC_ADD msg.flowTable.tableType=3 #OF_LINER_TABLE msg.flowTable.tableSize=128 msg.flowTable.tableId=0 msg.flowTable.tableName="Table 3" msg.flowTable.keyLength= 0 event.connection.send(msg) ############################################################################## #flow_mod 1 ############################################################################### msg=of.ofp_flow_mod() msg.counterId=2 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_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.counterId=3 msg.cookie=0 msg.cookieMask=0 msg.tableId=0 msg.tableType=3 #OF_LINER_TABLE msg.priority=0 msg.index=1 #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)
def test_all_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 ############################################################################## #table_mod ############################################################################### 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.tableSize = 128 msg.flowTable.tableId = 0 msg.flowTable.tableName = "FirstEntryTable" msg.flowTable.keyLength = 64 event.connection.send(msg) #print ('Table_mod') #print (msg) #sleep(10) ############################################################################## #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 #matchx 1 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) #matchx 2 tempmatchx = of.ofp_matchx() tempmatchx.fieldId = 3 tempmatchx.offset = 96 tempmatchx.length = 16 tempmatchx.set_value("00") tempmatchx.set_mask("00") msg.matchx.append(tempmatchx) #instruction gototable 1 tempins = of.ofp_instruction_gototable() tempins.nextTableId = 0 tempins.packetOffset = 0 #msg.instruction.append(tempins) #instruction gotodirecttable 8 tempins = of.ofp_instruction_gotodirecttable() tempins.nextTableId = 0 tempins.indexType = 0 tempins.packetOffset = 0 tempins.indexValue = 0 #msg.instruction.append(tempins) #instruction meter 6 tempins = of.ofp_instruction_meter() tempins.meterId = 0 #msg.instruction.append(tempins) #instruction writemetadata 2 tempins = of.ofp_instruction_writemetadata() tempins.metaDataOffset = 0 tempins.writeLength = 0 tempins.value = [] #msg.instruction.append(tempins) #instruction writemetadatafrompacket 7 tempins = of.ofp_instruction_writemetadatafrompacket() tempins.metadataOffset = 0 tempins.packetOffset = 0 tempins.writeLength = 48 msg.instruction.append(tempins) #instruction conditionaljmp 9 tempins = of.ofp_instruction_conditionaljmp() #msg.instruction.append(tempins) event.connection.send(msg) #sleep(10) #print ('Flow_mod_1') #print (msg) '''