def _handle_PacketIn(self, event):
        '''
        Table_mod msg
        '''
        packet = event.parsed

        if packet.effective_ethertype == 0x0908:

            print 'Dmac:', packet.dst
            print 'eth type: %x' % packet.effective_ethertype

            path = [(1, 1, 5), (4, 1, 3)]  #(sw_id, in_port, out_port)
            table_id = 1
            entry_id = 0

            for each_sw in path:

                flow_mod_msg = of.ofp_flow_mod(tableId = table_id, index = entry_id,\
                                               priority = 0, idleTimeout = 1000)

                dmac = of.ofp_matchx(fieldId=1, offset=0, length=48)
                print packet.dst.toStr()
                dmac.set_value("0708090a0b0c")
                dmac.set_mask("ffffffffffff")
                flow_mod_msg.matchx.append(dmac)
                '''        
                smac = of.ofp_matchx()
                smac.fieldId = 2
                smac.offset = 48
                smac.length = 48
                flow_mod_msg.matchx.append(smac)
                
                type1 = of.ofp_matchx()
                type1.fieldId = 3
                type1.offset = 96
                type1.length = 16
                flow_mod_msg.matchx.append(type1)
                '''
                if each_sw[0] == 4:
                    instruction1 = of.ofp_instruction_applyaction()
                    version = of.ofp_matchx(fieldId=4, offset=100, length=4)
                    version.set_mask('f')
                    version.set_value('4')

                    action1 = of.ofp_action_setfield()
                    action1.fieldSetting = version
                    instruction1.actionList.append(action1)
                    flow_mod_msg.instruction.append(instruction1)

                action2 = of.ofp_action_output()
                action2.portId = each_sw[2]  # out port
                instruction2 = of.ofp_instruction_applyaction()
                instruction2.actionList.append(action2)

                flow_mod_msg.instruction.append(instruction2)

                core.PofManager.add_flow_entry(sw_id2device_id[each_sw[0]],
                                               table_id, flow_mod_msg)
示例#2
0
def act_set_field (args): # [field_id, value, mask]
	action = of.ofp_action_setfield()
	action.fieldSetting.fieldId = args[0]
	f = g.field_config[args[0]]
	action.fieldSetting.offset = f[0]
	action.fieldSetting.length = f[1]
	action.fieldSetting.set_value(args[1]) 
	action.fieldSetting.set_mask(args[2])
	
	print ("add set_field action\n")
	return action
示例#3
0
def test_group_mod(event):
    msg=of.ofp_group_mod()
    msg.command = 0
    msg.groupType = 0
    #msg.actionNum = 4
    msg.padding = 0
    msg.groupId = 1
    msg.counterId = 4
    msg.padding = 0    
    msg.actions = []
    
    action_1 = of.ofp_action_setfield()
    action_1.ofActionType = 1
    action_1.length = 44
    action_1.fieldSetting = of.ofp_matchx()
    action_1.fieldSetting.fieldId = 0
    action_1.fieldSetting.offset = 0
    action_1.fieldSetting.length = 0
    action_1.fieldSetting.padding = 0
    action_1.fieldSetting.set_value("00")
    action_1.fieldSetting.set_mask("00")
    msg.actions.append(action_1)
    
    
    
    
    
    action_2 = of.ofp_action_addfield()
    action_2.length = 20
    action_2.fieldId = 0
    action_2.fieldPosition = 0
    action_2.fieldLength = 0
    action_2.set_fieldValue("00")
    msg.actions.append(action_2)
    
    action_3 = of.ofp_action_group()
    action_3.length = 12
    action_3.groupId = 0
    msg.actions.append(action_3)
    
    action_4 = of.ofp_action_drop()
    action_4.length = 12
    action_4.reason = 0
    msg.actions.append(action_4)
    
    event.connection.send(msg)
def action_set_field(action_set_field_data):
    set_field = of.ofp_action_setfield()
    fieldsetting = of.ofp_matchx()
    fieldname_temp = action_set_field_data[0]['name']
    fieldname = string.split(fieldname_temp, ';')[0]
    #value = string.atoi(action_set_field_data[0]['value'])
    #mask = string.atoi(action_set_field_data[0]['mask'])
    
    fieldsetting_of20 = core.PofManager.get_field_by_name(fieldname)
    fieldsetting.fieldId = fieldsetting_of20.fieldId
    fieldsetting.offset = fieldsetting_of20.offset
    fieldsetting.length = fieldsetting_of20.length
    fieldsetting.set_value(action_set_field_data[0]['value'])
    fieldsetting.set_mask(action_set_field_data[0]['mask'])
    
    set_field.fieldSetting = fieldsetting
    
    return set_field
示例#5
0
def test_OUTPUT(event):
  print "we are really doing\n" 
  out_port = 1 
  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[1]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  
   
  ofmatch20_1 =of.ofp_match20()
  ofmatch20_1.fieldId=46;
  ofmatch20_1.offset=0;
  ofmatch20_1.length=48;
  
 
  msg = of.ofp_table_mod()  
  msg.flowTable.command=0 #OFPTC_ADD
  
  msg.flowTable.tableType=0  #OF_MM_TABLE
  msg.flowTable.matchFieldNum = 1
  
  msg.flowTable.matchFieldList.append(ofmatch20_1)
  #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList)
  msg.flowTable.tableSize=128
  msg.flowTable.tableId=0
  msg.flowTable.tableName="FirstEntryTable"
  msg.flowTable.keyLength=48
  event.connection.send(msg)
    
  ##############################################################################
  #flow_mod 1
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId=1
  msg.cookie=0
  msg.cookieMask=0
  msg.tableId=0
  msg.tableType=0 #OF_MM_TABLE
  msg.priority=0
  msg.index=1
 
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=46
  tempmatchx.offset=0
  tempmatchx.length=48
  tempmatchx.set_value("0000") #  null 
  tempmatchx.set_mask("0000")
  msg.matchx.append(tempmatchx)
  
  #instruction
  tempins=of.ofp_instruction_applyaction()
  '''
  action=of.ofp_action_setfield()
  action.fieldSetting.fieldId=46
  action.fieldSetting.offset=0
  action.fieldSetting.length=48
  action.fieldSetting.set_value("0000000000ff")
  action.fieldSetting.set_mask("ffffffffffff")
  tempins.actionList.append(action)

  action=of.ofp_action_addfield()
  action.fieldId = 47
  action.fieldPosition = 96
  action.fieldLength = 16
  tempins.actionList.append(action)
  
  action=of.ofp_action_deletefield()
  action.tagPosition = 0
  action.tagLengthValueType = 0
  action.tagLengthValue = 48
  tempins.actionList.append(action)
  '''
  action=of.ofp_action_output()
  action.portId=out_port
  action.metadataOffset=0
  action.metadataLength=0
  action.packetOffset=0
  tempins.actionList.append(action)
  
  msg.instruction.append(tempins)
  
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 2 
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.command =3 
  msg.counterId=1
  msg.cookie=0
  msg.cookieMask=0
  msg.tableId=0
  msg.tableType=0 #OF_MM_TABLE
  msg.priority=0
  msg.index=1
  
  tempins=of.ofp_instruction_applyaction()
  
  action=of.ofp_action_setfield()
  action.fieldSetting.fieldId=46
  action.fieldSetting.offset=0
  action.fieldSetting.length=48
  action.fieldSetting.set_value("0000000000ff")
  action.fieldSetting.set_mask("ffffffffffff")
  tempins.actionList.append(action)
  
  msg.instruction.append(tempins)
  
 
  event.connection.send(msg)
示例#6
0
def test_MOVE_PACKET_OFFSET(event):
    out_port = g.output_port
    '''
  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[7]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  '''

    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 12
    # IP dest_ip addr
    ofmatch20_1.offset = 0
    ofmatch20_1.length = 32

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)

    msg.flowTable.command = 0  #OFPTC_ADD

    msg.flowTable.tableType = 0  #OF_MM_TABLE
    msg.flowTable.matchFieldNum = 1

    #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList)
    msg.flowTable.tableSize = 128
    msg.flowTable.tableId = 0
    msg.flowTable.tableName = "FirstEntryTable"
    msg.flowTable.keyLength = 32
    event.connection.send(msg)

    ##############################################################################
    #flow_mod 0
    ###############################################################################

    msg = of.ofp_flow_mod()
    msg.counterId = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 0  #OF_MM_TABLE
    msg.priority = 0
    msg.index = 0

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 12
    tempmatchx.offset = 0
    tempmatchx.length = 32
    # even IP
    tempmatchx.set_value("00000000")
    tempmatchx.set_mask("00000001")

    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_output()
    action.portId = g.output_port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)

    ##############################################################################
    #flow_mod 1
    ###############################################################################

    msg = of.ofp_flow_mod()
    msg.counterId = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 0  #OF_MM_TABLE
    msg.priority = 0
    msg.index = 1

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 12
    tempmatchx.offset = 0
    tempmatchx.length = 32
    tempmatchx.set_value("00000001")  #  奇数IP
    tempmatchx.set_mask("00000001")
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_movepacketoffset()
    tempins.direction = 0
    tempins.valueType = 0
    tempins.move_value = 112
    msg.instruction.append(tempins)

    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_setfield()
    action.fieldSetting.fieldId = 47  # ip offset 32
    action.fieldSetting.offset = 64
    action.fieldSetting.length = 8
    action.fieldSetting.set_value("3f")
    action.fieldSetting.set_mask("ff")
    tempins.actionList.append(action)

    action = of.ofp_action_setfield()
    action.fieldSetting.fieldId = 48  # ip offset 32
    action.fieldSetting.offset = 80
    action.fieldSetting.length = 16
    action.fieldSetting.set_value("dace")
    action.fieldSetting.set_mask("ffff")
    tempins.actionList.append(action)

    action = of.ofp_action_output()
    action.portId = out_port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0

    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)
示例#7
0
def test_SET_FIELD(event):
    out_port = 2
    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[3]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 1
    ofmatch20_1.offset = 0
    ofmatch20_1.length = 48

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)

    msg.flowTable.command = 0  #OFPTC_ADD

    msg.flowTable.tableType = 0  #OF_MM_TABLE
    msg.flowTable.matchFieldNum = 1

    #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList)
    msg.flowTable.tableSize = 128
    msg.flowTable.tableId = 0
    msg.flowTable.tableName = "FirstEntryTable"
    msg.flowTable.keyLength = 48
    event.connection.send(msg)

    ##############################################################################
    #flow_mod 1
    ###############################################################################

    msg = of.ofp_flow_mod()
    msg.counterId = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 0  #OF_MM_TABLE
    msg.priority = 0
    msg.index = 0

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 0
    tempmatchx.length = 48
    tempmatchx.set_value("00")  #  null
    tempmatchx.set_mask("00")
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_setfield()
    action.fieldSetting.fieldId = 1
    action.fieldSetting.offset = 0
    action.fieldSetting.length = 48
    action.fieldSetting.set_value("0000000000ff")
    action.fieldSetting.set_mask("ffffffffffff")
    tempins.actionList.append(action)

    action = of.ofp_action_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)
示例#8
0
def test_ADD_FIELD(event):
    '''
    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[g.input_port - 1]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)
    '''
    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 23
    #the last bit of dest IP
    ofmatch20_1.offset = 0
    ofmatch20_1.length = 32

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)
    msg.flowTable.command = 0  #OFPTC_ADD
    msg.flowTable.tableType = 0  #OF_MM_TABLE
    msg.flowTable.matchFieldNum = 1

    #msg.flowTable.matchFieldNum = len(msg.flowTable.matchFieldList)
    msg.flowTable.tableSize = 128
    msg.flowTable.tableId = 0
    msg.flowTable.tableName = "FirstEntryTable"
    msg.flowTable.keyLength = 32
    event.connection.send(msg)

    ##############################################################################
    #flow_mod 0
    ###############################################################################

    msg = of.ofp_flow_mod()
    msg.counterId = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 0  #OF_MM_TABLE
    msg.priority = 0
    msg.index = 0

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 23
    tempmatchx.offset = 0
    tempmatchx.length = 32
    # even IP
    tempmatchx.set_value("00000000")
    tempmatchx.set_mask("00000001")

    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_output()
    action.portId = g.output_port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)

    ##############################################################################
    #flow_mod 1
    ###############################################################################

    msg = of.ofp_flow_mod()
    msg.counterId = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 0  #OF_MM_TABLE
    msg.priority = 0
    msg.index = 1

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 23
    tempmatchx.offset = 0
    tempmatchx.length = 32
    #odd IP
    tempmatchx.set_value("00000001")
    tempmatchx.set_mask("00000001")

    msg.matchx.append(tempmatchx)

    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_addfield()
    action.fieldId = 47
    action.fieldPosition = 96
    action.fieldLength = 32
    tempins.actionList.append(action)

    action = of.ofp_action_setfield()
    action.fieldSetting.fieldId = 47  # vlan
    action.fieldSetting.offset = 96
    action.fieldSetting.length = 32
    action.fieldSetting.set_value("8001000f")  # vlan id: 15
    action.fieldSetting.set_mask("ffffffff")
    tempins.actionList.append(action)

    action = of.ofp_action_output()
    action.portId = g.output_port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)
示例#9
0
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)