def _handle_PacketIn(self, event): packet = event.parsed if packet.effective_ethertype == 0x0908: table_id = 0 entry_id = 1 flow_mod_msg0 = of.ofp_flow_mod(tableId = table_id, index = entry_id, priority = 1) dmac = of.ofp_matchx(fieldId = 1, offset = 0, length = 48) dmac.set_value("010203040506") dmac.set_mask("000000000000") dl_type = of.ofp_matchx(fieldId = 3, offset = 96, length = 16) dl_type.set_value('0908') dl_type.set_mask("0000") flow_mod_msg0.matchx.append(dmac) flow_mod_msg0.matchx.append(dl_type) ins = of.ofp_instruction_gototable() ins.nextTableId = 1 flow_mod_msg0.instruction.append(ins) event.connection.send(flow_mod_msg0)
def instr_goto_table(goto_table_data): goto_table = of.ofp_instruction_gototable() nextid = string.split(goto_table_data[0]['table_id'],':')[0] if goto_table_data[0]['offset'] == '': offset = 0 else: offset = string.atoi(goto_table_data[0]['offset']) goto_table.nextTableId = string.atoi(nextid) goto_table.packetOffset = offset return goto_table
def _handle_ConnectionUp(self, event): sw_list = core.PofManager.get_all_switches() print 'switch number:', len(sw_list) ''' Set port to openflow enable. ''' for sw in sw_list: if isinstance(sw, of.ofp_features_reply): #print sw.show() ports_list = core.PofManager.get_all_ports(sw.deviceId) for port in ports_list: phy_port = port.desc if phy_port.openflowEnable == 1 and phy_port.name == 'eth0': core.PofManager.set_port_pof_enable( event.dpid, phy_port.portId, 0) #print core.PofManager.get_port(event.dpid, 7).show() ''' Send second table mod ''' flow_table = of.ofp_flow_table(tableName = 'Mac flow table',\ tableId = 1, tableSize = 128) protocol = core.PofManager.get_protocol_by_name('ethernet+ipv4') flow_table.matchFieldList = protocol.to_match('dmac') core.PofManager.add_new_table(event.dpid, flow_table) ''' Install first entry in the first table ''' #print 'get field', 'smac' #print core.PofManager.get_field_by_name('smac') flow_mod_msg1 = of.ofp_flow_mod(tableId=0, index=0, priority=1) dmac = of.ofp_matchx(fieldId=1, offset=0, length=48) dmac.set_value("010203040506") #dmac.value = [0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c] dmac.set_mask("000000000000") dl_type = of.ofp_matchx(fieldId=2, offset=96, length=16) dl_type.set_value('0908') dl_type.set_mask("0000") flow_mod_msg1.matchx.append(dmac) flow_mod_msg1.matchx.append(dl_type) ins = of.ofp_instruction_gototable() ins.nextTableId = 1 flow_mod_msg1.instruction.append(ins) core.PofManager.add_flow_entry(event.dpid, 0, flow_mod_msg1)
def ins_goto_table(args): # [next_table_id] tempins=of.ofp_instruction_gototable() tempins.nextTableId = args[0] print ("add the instruction go to table\n") return tempins
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_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_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 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_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_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_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) '''