Esempio n. 1
0
    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)
Esempio n. 2
0
def add_lldp_flow(discovery,event):
   msg = of.ofp_flow_mod()
   msg.idle_timeout = 10
   msg.hard_timeout = 30
   
   #matchx :dst
   tempmatchx=of.ofp_matchx()
   tempmatchx.fieldId=1
   tempmatchx.offset=0
   tempmatchx.length=48                 
   tempmatchx.set_value("012320000001")        
   tempmatchx.set_mask("ff"*6)
   msg.matchx.append(tempmatchx)

   #matchx :type
   tempmatchx=of.ofp_matchx()
   tempmatchx.fieldId=3
   tempmatchx.offset=96
   tempmatchx.length=16
   tempmatchx.set_value("88cc")
   tempmatchx.set_mask("ffff")
   msg.matchx.append(tempmatchx) 
   
   #instruction
   tempins=of.ofp_instruction_applyaction()
   action=of.ofp_action_packetin()
   action.reason = 1
   tempins.actionList.append(action)  
   msg.instruction.append(tempins)                

   #msg.actions.append(of.ofp_action_output(port = port))
   msg.priority = discovery._flow_priority
   #msg.data = event.ofp 
   event.connection.send(msg)     
Esempio n. 3
0
def create_cache_table_flow(event, index, io_type, name, name_len, enable_flag,
                            counterId):

    msg = of.ofp_flow_mod()
    msg.counterId = counterId
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = CSIP_ID
    msg.tableType = CSIP_TYPE  #OF_MM_TABLE
    msg.priority = 0
    msg.index = index
    msg.hardTimeout = 10
    msg.idleTimeout = 10

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0011")
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)  #0011 means a new protocol

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 112
    tempmatchx.length = 16
    tempmatchx.set_value("0001")  #0001 means it is a Interest Packet
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 144
    tempmatchx.length = name_len * 8  #notice this must be bit length
    value = ""
    for i in range(0, len(name)):
        value += str(hex(ord(name[i]))[2:])
    mask = b'ff'
    tempmatchx.set_value(value)
    tempmatchx.set_mask(mask * name_len)
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_op_cache()
    action.io_type = io_type
    action.name_len = name_len
    action.name = name
    action.enable_flag = enable_flag
    '''
  action=of.ofp_action_output()
  action.portId = 4
  '''

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

    event.connection.send(msg)
Esempio n. 4
0
def ins_app_action(args): # [act1, act2, act3,..] ps: act = [act name, act args]
	tempins = of.ofp_instruction_applyaction()
	for i in args:
		tempact = insmap[i[0]](i[1])
		tempins.actionList.append(tempact)
	
	print ("add the apply instruction\n")
	return tempins
Esempio n. 5
0
def create_CSCP_flow(event, index, name, name_len, counterId):

    msg = of.ofp_flow_mod()
    msg.counterId = counterId
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = CSCP_ID
    msg.tableType = CSCP_TYPE  #OF_MM_TABLE
    msg.priority = 0
    msg.index = index
    msg.hardTimeout = 10
    msg.idleTimeout = 10

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0011")
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)  #0011 means a new protocol

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 112
    tempmatchx.length = 16
    tempmatchx.set_value("0002")  #0002 means it is a Content Packet
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 176
    tempmatchx.length = name_len * 8  #notice this must be bit length
    value = ""
    for i in range(0, len(name)):
        value += str(hex(ord(name[i]))[2:])
    mask = b'ff'
    tempmatchx.set_value(value)
    tempmatchx.set_mask(mask * name_len)
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action_drop = of.ofp_action_drop()
    action_drop.reason = 1  #have store matched Content Object

    tempins.actionList.append(action_drop)
    msg.instruction.append(tempins)
    event.connection.send(msg)
def instr_apply_action(apply_action_data):
    applyaction = of.ofp_instruction_applyaction()

    for each_action in apply_action_data.keys():
        
        if each_action == 'output':
            action = action_output(apply_action_data['output'])
            applyaction.actionList.append(action)

        elif each_action == 'set_field':
            action = action_set_field(apply_action_data['set_field'])
            applyaction.actionList.append(action)
            
        elif each_action == 'set_field_from_metadata':
            action = action_set_field_from_metadata(apply_action_data['set_field_from_metadata'])
            applyaction.actionList.append(action)
            
        elif each_action == 'modify_field':
            action = action_modify_field(apply_action_data['modify_field'])
            applyaction.actionList.append(action)
            
        elif each_action == 'add_field':
            action = action_add_field(apply_action_data['add_field'])
            applyaction.actionList.append(action)
            
        elif each_action == 'delete_field':
            action = action_delete_field(apply_action_data['delete_field'])
            applyaction.actionList.append(action)
            
        elif each_action == 'calculate_checksum':
            action = action_calculate_checksum(apply_action_data['calculate_checksum'])
            applyaction.actionList.append(action)
        
        elif each_action == 'group':
            action = action_group(apply_action_data['group'])
            applyaction.actionList.append(action)
            
        elif each_action == 'drop':
            action = action_drop(apply_action_data['drop'])
            applyaction.actionList.append(action)
            
        elif each_action == 'packet_in':
            action = action_packet_in(apply_action_data['packet_in'])
            applyaction.actionList.append(action)
            
        elif each_action == 'counter':
            action = action_counter(apply_action_data['counter'])
            applyaction.actionList.append(action)
    
    return applyaction
Esempio n. 7
0
def add_match_flow(l2, event, port, packet):
    #trying to install a flow entry
    msg = of.ofp_flow_mod()
    msg.idle_timeout = 10
    msg.hard_timeout = 30

    #matchx :dst
    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 0
    tempmatchx.length = 48
    temps = packet.dst.toStr()
    temps = "".join(temps.split(':'))
    tempmatchx.set_value(temps)
    tempmatchx.set_mask("ff" * 6)
    msg.matchx.append(tempmatchx)

    #need to new a ofp_matchx  do we need this???
    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0000")
    tempmatchx.set_mask("0000")
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_output()
    action.portId = port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0

    tempins.actionList.append(action)
    msg.instruction.append(tempins)
    #msg.match = of.ofp_match.from_packet(packet, event.port)

    #msg.actions.append(of.ofp_action_output(port = port))
    msg.data = event.ofp  # 6a
    #print "6a:install table entry"
    l2.connection.send(msg)
Esempio n. 8
0
def add_drop_flow(l2, event, duration, packet):
    msg = of.ofp_flow_mod()
    #msg.match = of.ofp_match.from_packet(packet)
    msg.idle_timeout = duration[0]
    msg.hard_timeout = duration[1]
    msg.bufferId = event.ofp.bufferId
    #matchx
    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 0
    tempmatchx.length = 48
    temps = packet.dst.toStr()
    temps = "".join(temps.split(':'))
    tempmatchx.set_value(temps)
    tempmatchx.set_mask("ff" * 6)
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 48
    tempmatchx.length = 48
    temps = packet.src.toStr()
    temps = "".join(temps.split(':'))
    tempmatchx.set_value(temps)
    tempmatchx.set_mask("ff" * 6)
    msg.matchx.append(tempmatchx)

    #need to new a ofp_matchx  do we need this???
    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("00")
    tempmatchx.set_mask("ff")
    msg.matchx.append(tempmatchx)

    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_drop()
    tempins.actionList.append(action)
    msg.instruction.append(tempins)
    l2.connection.send(msg)
Esempio n. 9
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)
Esempio n. 10
0
def test_huawei_flow(event):

    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[1]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

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

    ofmatch20_2 = of.ofp_match20()
    ofmatch20_2.fieldId = 2
    ofmatch20_2.offset = 48
    ofmatch20_2.length = 48

    ofmatch20_3 = of.ofp_match20()
    ofmatch20_3.fieldId = 3
    ofmatch20_3.offset = 96
    ofmatch20_3.length = 16

    ofmatch20_4 = of.ofp_match20()
    ofmatch20_4.fieldId = 4
    ofmatch20_4.offset = 184
    ofmatch20_4.length = 8

    ofmatch20_5 = of.ofp_match20()
    ofmatch20_5.fieldId = 5
    ofmatch20_5.offset = 208
    ofmatch20_5.length = 32

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)
    msg.flowTable.matchFieldList.append(ofmatch20_2)
    msg.flowTable.matchFieldList.append(ofmatch20_3)
    msg.flowTable.matchFieldList.append(ofmatch20_4)
    msg.flowTable.matchFieldList.append(ofmatch20_5)

    msg.flowTable.command = 0  #OFPTC_ADD

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

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

    ##############################################################################
    #flow_mod 1
    ###############################################################################
    index_list = range(0, 10)
    name_list = [
        "name0", "name1", "name2", "name3", "name4", "name5", "name6", "name7",
        "name8", "name9"
    ]
    for i in range(len(index_list)):
        msg = of.ofp_flow_mod()
        msg.counterId = 1
        msg.cookie = 0
        msg.cookieMask = 0
        msg.tableId = 0
        msg.tableType = 0  #OF_MM_TABLE
        msg.priority = index_list[i]
        msg.index = index_list[i]

        tempmatchx = of.ofp_matchx()
        tempmatchx.fieldId = 1
        tempmatchx.offset = 0
        tempmatchx.length = 48
        tempmatchx.set_value("90b11c5a5299")  #90:b1:1c:5a:52:99
        tempmatchx.set_mask("ffffffffffff")
        msg.matchx.append(tempmatchx)

        tempmatchx = of.ofp_matchx()
        tempmatchx.fieldId = 2
        tempmatchx.offset = 48
        tempmatchx.length = 48
        tempmatchx.set_value("90b11c5a618d")  #90:b1:1c:5a:61:8d
        tempmatchx.set_mask("ffffffffffff")
        msg.matchx.append(tempmatchx)

        #need to new a ofp_matchx
        tempmatchx = of.ofp_matchx()
        tempmatchx.fieldId = 3
        tempmatchx.offset = 96
        tempmatchx.length = 16
        tempmatchx.set_value("0800")
        tempmatchx.set_mask("ffff")
        msg.matchx.append(tempmatchx)

        tempmatchx = of.ofp_matchx()
        tempmatchx.fieldId = 4
        tempmatchx.offset = 184
        tempmatchx.length = 8
        tempmatchx.set_value("01")
        tempmatchx.set_mask("ffff")
        msg.matchx.append(tempmatchx)

        tempmatchx = of.ofp_matchx()
        tempmatchx.fieldId = 5
        tempmatchx.offset = 208
        tempmatchx.length = 32
        tempmatchx.set_value("c0a80103")
        tempmatchx.set_mask("ffffffff")
        msg.matchx.append(tempmatchx)

        #instruction
        tempins = of.ofp_instruction_applyaction()
        '''
                            action=of.ofp_action_write()
                            action.io_type =1
                            action.name_len=5
                            action.name=name_list[i]
                            action.enable_flag=1
                            '''

        action = of.ofp_action_packetin()
        action.reason = 0

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

        event.connection.send(msg)
Esempio n. 11
0
def test_DROP(event):
    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[1]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[3]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 2
    ofmatch20_1.offset = 48
    ofmatch20_1.length = 48

    ofmatch20_2 = of.ofp_match20()
    ofmatch20_2.fieldId = -1
    ofmatch20_2.offset = 16
    ofmatch20_2.length = 8

    ##########################################################
    #table mode 1
    ##########################################################
    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_2)

    msg.flowTable.command = 0  #OFPTC_ADD

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

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

    ##############################################################################
    #flow_mod 1-1
    ###############################################################################

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

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = -1
    tempmatchx.offset = 16
    tempmatchx.length = 8
    tempmatchx.set_value("02")  #  null
    tempmatchx.set_mask("ff")
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

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

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

    event.connection.send(msg)

    ##############################################################################
    #flow_mod 1-2
    ###############################################################################

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

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = -1
    tempmatchx.offset = 16
    tempmatchx.length = 8
    tempmatchx.set_value("04")  #  null
    tempmatchx.set_mask("ff")
    msg.matchx.append(tempmatchx)

    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_drop()
    action.reason = 0
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)
Esempio n. 12
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)
Esempio n. 13
0
def test_for_ipv6(event):
    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 1
    ofmatch20_1.offset = 0
    ofmatch20_1.length = 48

    ofmatch20_2 = of.ofp_match20()
    ofmatch20_2.fieldId = 2
    ofmatch20_2.offset = 48
    ofmatch20_2.length = 48

    ofmatch20_3 = of.ofp_match20()
    ofmatch20_3.fieldId = 3
    ofmatch20_3.offset = 96
    ofmatch20_3.length = 16

    ofmatch20_4 = of.ofp_match20()
    ofmatch20_4.fieldId = 4
    ofmatch20_4.offset = 112
    ofmatch20_4.length = 64

    ofmatch20_5 = of.ofp_match20()
    ofmatch20_5.fieldId = 5
    ofmatch20_5.offset = 176
    ofmatch20_5.length = 64

    ofmatch20_6 = of.ofp_match20()
    ofmatch20_6.fieldId = 6
    ofmatch20_6.offset = 240
    ofmatch20_6.length = 16

    ##############################################################################
    #table_mod 0
    ###############################################################################

    msg = of.ofp_table_mod()
    msg.flowTable.matchFieldList.append(ofmatch20_1)
    msg.flowTable.command = 0  #OFPTC_ADD
    msg.flowTable.tableType = 0  #OF_MM_TABLE
    msg.flowTable.matchFieldNum = 1
    msg.flowTable.tableSize = 128
    msg.flowTable.tableId = 0
    msg.flowTable.tableName = "FirstEntryTable"
    msg.flowTable.keyLength = 144
    event.connection.send(msg)

    ##############################################################################
    #table_mod 1
    ###############################################################################
    msg = of.ofp_table_mod()
    msg.flowTable.tableId = 0
    msg.flowTable.command = 0  #OFPTC_ADD
    msg.flowTable.tableType = 3
    msg.flowTable.tableSize = 128
    msg.flowTable.keyLength = 144
    msg.flowTable.tableName = "CC"
    event.connection.send(msg)

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

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

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

    #instruction writemetadatafrompacket 7
    tempins = of.ofp_instruction_writemetadata()
    tempins.metaDataOffset = 32
    tempins.value = [1, 1, 1, 1, 1, 1]
    tempins.writeLength = 48
    msg.instruction.append(tempins)

    tempins = of.ofp_instruction_gotodirecttable()
    tempins.nextTableId = 16
    tempins.indexType = 0
    tempins.packetOffset = 0
    tempins.indexValue = 0
    msg.instruction.append(tempins)

    event.connection.send(msg)

    ##############################################################################
    #flow_mod 2
    ###############################################################################
    msg = of.ofp_flow_mod()
    msg.counterId = 4
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = 0
    msg.tableType = 3
    msg.priority = 0
    msg.index = 0

    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_deletefield()
    action.tagPosition = 0
    action.tagLengthValueType = 0
    action.tagLengthValue = 48
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    #instruction writemetadata 2
    tempins = of.ofp_instruction_writemetadata()
    tempins.metaDataOffset = 0
    tempins.writeLength = 0
    tempins.value = []
    #msg.instruction.append(tempins)

    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_output()
    action.portId = 0x10045
    action.metadataOffset = 32
    action.metadataLength = 48
    action.packetOffset = 0
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)
Esempio n. 14
0
def test_COUNTER(event):
    '''
  out_port = 2
  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[3]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  '''

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

    ##############################################################################
    # table mode 1
    ###############################################################################

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)

    msg.flowTable.command = 0  #OFPTC_ADD

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

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

    event.connection.send(msg)
    '''
  ##############################################################################
  #counter_mod 1
  ###############################################################################
  msg =of.ofp_counter_mod()
  msg.counter.counterID=3
  msg.counter.command=0
  msg.counter.couterValue=0
  msg.counter.byteValue=0
  event.connection.send(msg)
  '''
    ##############################################################################
    #flow_mod 1
    ###############################################################################

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

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

    #instruction
    tempins = of.ofp_instruction_applyaction()
    '''
  action=of.ofp_action_counter()
  action.counterId=1
  tempins.actionList.append(action)
  '''
    action = of.ofp_action_output()
    action.portId = 2
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0
    tempins.actionList.append(action)

    msg.instruction.append(tempins)

    event.connection.send(msg)
Esempio n. 15
0
def create_PIT_table_flow(event, index, name, name_len, operation_type,
                          counterId):

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

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0011")
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)  #0011 means a new protocol

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 112
    tempmatchx.length = 16
    tempmatchx.set_value("0001")  #0001 means it is a Interest Packet
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 144
    tempmatchx.length = name_len * 8  #notice this must be bit length
    value = ""
    for i in range(0, len(name)):
        value += str(hex(ord(name[i]))[2:])
    mask = b'ff'
    tempmatchx.set_value(value)
    tempmatchx.set_mask(mask * name_len)
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_modify()
    action.current_table_id = PIT_ID
    action.current_table_type = PIT_TYPE
    action.current_index = index

    action.related_table_id = 2
    action.related_table_type = 0
    action.related_index = index
    action.operation_type = operation_type
    '''
  action=of.ofp_action_output()
  action.portId = 4
  '''

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

    event.connection.send(msg)
Esempio n. 16
0
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)
Esempio n. 17
0
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)
Esempio n. 18
0
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)
Esempio n. 20
0
def test_CLASSFIER_TABLE (event):
	ofmatch20_1 = of.ofp_match20()
	ofmatch20_1.fieldId = 23
	#the last bit of dest IP
	ofmatch20_1.offset = 0
	ofmatch20_1.length = 32


	table = of.sync_flow_table()
	
	table.matchFieldList.append(ofmatch20_1)
	table.command = 0    #OFPTC_ADD
	table.tableType = of.OF_EM_TABLE  #OF_MM_TABLE
	#table.matchFieldNum = 1

	table.matchFieldNum = len(table.matchFieldList)
	table.tableSize = 128
	table.tableId = 0xfd 
	table.tableName = "Classfier_Table"
	table.keyLength = 16
	

	msg = of.ofp_experimenter()
	msg.type = of.CLASSFIER_TABLE
	msg.ctab.type = of.SYNC_TABLE
	msg.ctab.table = table

	event.connection.send(msg)
	entry = of.sync_flow_entry()
	entry.command = 0
	entry.counterId = 1
	entry.cookie = 0
	entry.cookieMask = 0
	entry.tableId = 0xfd
	entry.tableType = of.OF_EM_TABLE #OF_MM_TABLE
	entry.priority = 0
	entry.index = 1

	tempmatchx = of.ofp_matchx()
	tempmatchx.fieldId = 47
	tempmatchx.offset = 12 *8
	tempmatchx.length = 16
	#odd IP
	tempmatchx.set_value("0806")
	tempmatchx.set_mask("ffff")

	entry.matchx.append(tempmatchx)

	tempins = of.ofp_instruction_applyaction()

	action = of.ofp_action_addfield()
	action.fieldId = 48
	action.fieldPosition = 96
	action.fieldLength = 32
	action.set_fieldValue("ffff0001")
	tempins.actionList.append(action)
	
	action = of.ofp_action_output()
	action.portId = 0xffe1
	action.metadataOffset = 0
	action.metadataLength = 0
	action.packetOffset = 0
	tempins.actionList.append(action)
	entry.instruction.append(tempins)

	msg = of.ofp_experimenter()
	msg.type = of.CLASSFIER_TABLE
	msg.ctab.type = of.SYNC_ENTRY
   	msg.ctab.entry = entry

	event.connection.send(msg)
Esempio n. 21
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)
Esempio n. 22
0
def test_MODIFY_FIELD(event):
    out_port = 2
    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[3]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

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

    ofmatch20_2 = of.ofp_match20()
    ofmatch20_2.fieldId = 2
    ofmatch20_2.offset = 48
    ofmatch20_2.length = 48

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)

    msg.flowTable.command = 0  #OFPTC_ADD

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

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

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

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

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

    #instruction
    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_modifyfield()
    action.matchfield.fieldId = 2
    action.matchfield.offset = 48
    action.matchfield.length = 8
    action.increment = 1
    tempins.actionList.append(action)

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

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

    event.connection.send(msg)
Esempio n. 23
0
def modify_ContentInterest_table_flow(event, name, name_len, operation_type,
                                      index, table_id, table_type,
                                      related_index, related_table_id,
                                      related_type, port_id, port_list,
                                      counterId):
    msg = of.ofp_flow_mod()
    msg.counterId = counterId
    msg.command = 1
    msg.cookie = 0
    msg.cookieMask = 0
    msg.tableId = table_id
    msg.tableType = table_type  #OF_MM_TABLE
    msg.priority = 0
    msg.index = index

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0011")
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)  #0011 means a new protocol

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 112
    tempmatchx.length = 16
    tempmatchx.set_value("0002")  #0002 means it is a Content Packet
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 176
    tempmatchx.length = name_len * 8  #notice this must be bit length
    value = ""
    for i in range(0, len(name)):
        value += str(hex(ord(name[i]))[2:])
    mask = b'ff'
    tempmatchx.set_value(value)
    tempmatchx.set_mask(mask * name_len)
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action_output = of.ofp_action_output()
    action_output.portId = port_id
    tempins.actionList.append(action_output)

    for i in range(len(port_list)):
        action_output_other = of.ofp_action_output()
        action_output_other.portId = port_list[i]
        tempins.actionList.append(action_output_other)

    action_delete_related = of.ofp_action_modify()
    action_delete_related.current_table_id = table_id
    action_delete_related.current_table_type = table_type
    action_delete_related.current_index = index
    action_delete_related.related_table_id = related_table_id
    action_delete_related.related_table_type = related_type
    action_delete_related.related_index = related_index
    action_delete_related.operation_type = operation_type

    action_delete_self = of.ofp_action_modify()
    action_delete_self.current_table_id = table_id
    action_delete_self.current_table_type = table_type
    action_delete_self.current_index = index
    action_delete_self.related_table_id = table_id
    action_delete_self.related_table_type = table_type
    action_delete_self.related_index = index
    action_delete_self.operation_type = operation_type

    tempins.actionList.append(action_delete_related)
    tempins.actionList.append(action_delete_self)
    msg.instruction.append(tempins)

    event.connection.send(msg)
Esempio n. 24
0
def test_for_single_vxlan(event):    
  ofmatch20_1 =of.ofp_match20()
  ofmatch20_1.fieldId=0
  ofmatch20_1.offset=0
  ofmatch20_1.length=48
  
  ofmatch20_2 =of.ofp_match20()
  ofmatch20_2.fieldId=-1
  ofmatch20_2.offset=272
  ofmatch20_2.length=32
  
  ofmatch20_3 =of.ofp_match20()
  ofmatch20_3.fieldId= -1
  ofmatch20_3.offset= 336
  ofmatch20_3.length= 16
  
  ofmatch20_4 =of.ofp_match20()
  ofmatch20_4.fieldId= -1
  ofmatch20_4.offset= 160
  ofmatch20_4.length= 16
  
  ofmatch20_5 =of.ofp_match20()
  ofmatch20_5.fieldId= 2
  ofmatch20_5.offset= 96
  ofmatch20_5.length=16
  
  ofmatch20_6 =of.ofp_match20()
  ofmatch20_6.fieldId=7
  ofmatch20_6.offset=184
  ofmatch20_6.length=8
  
  ofmatch20_7 =of.ofp_match20()
  ofmatch20_7.fieldId= 12
  ofmatch20_7.offset= 288
  ofmatch20_7.length=16
  
  ##############################################################################
  #table_mod 0
  ###############################################################################
  
  msg =of.ofp_table_mod()
  msg.flowTable.matchFieldList.append(ofmatch20_1)
  #msg.flowTable.matchFieldList.append(ofmatch20_3)
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType=0  #OF_MM_TABLE
  msg.flowTable.matchFieldNum = 1
  msg.flowTable.tableSize=128
  msg.flowTable.tableId=0
  msg.flowTable.tableName="FirstEntryTable"
  msg.flowTable.keyLength=48
  event.connection.send(msg)

  ##############################################################################
  #table_mod 16
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.tableId=0
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 3
  msg.flowTable.tableSize = 128
  msg.flowTable.keyLength= 0
  msg.flowTable.tableName="VNI"
  event.connection.send(msg)
  
  ##############################################################################
  #table_mod 17
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.tableId=1
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 3
  msg.flowTable.tableSize = 128
  msg.flowTable.keyLength= 0
  msg.flowTable.tableName="VxLanEncap"
  event.connection.send(msg)
  
   ##############################################################################
  #table_mod 8
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.matchFieldList.append(ofmatch20_2)
  msg.flowTable.tableId=0
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 1
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 32
  msg.flowTable.tableName="FIB"
  event.connection.send(msg)
  
   ##############################################################################
  #table_mod 20
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.tableId=4
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 3
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 0
  msg.flowTable.tableName="FIB_DT"
  event.connection.send(msg)
  
   ##############################################################################
  #table_mod 18
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.tableId=2
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 3
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 0
  msg.flowTable.tableName="EPAT"
  event.connection.send(msg)
  
  ##############################################################################
  #table_mod 10
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.matchFieldList.append(ofmatch20_5)
  msg.flowTable.tableId=0
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 2
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 16
  msg.flowTable.tableName="L2PA"
  event.connection.send(msg)
  
  
   ##############################################################################
  #table_mod 11
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.matchFieldList.append(ofmatch20_6)
  msg.flowTable.matchFieldList.append(ofmatch20_7)
  msg.flowTable.tableId=1
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 2
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 24
  msg.flowTable.tableName="L3PA"
  event.connection.send(msg)
  
   ##############################################################################
  #table_mod 19
  ###############################################################################
  msg =of.ofp_table_mod()
  msg.flowTable.tableId=3
  msg.flowTable.command=0 #OFPTC_ADD
  msg.flowTable.tableType = 3
  msg.flowTable.tableSize = 100
  msg.flowTable.keyLength= 0
  msg.flowTable.tableName="VxLanDecap"
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 0-0
  ###############################################################################
 
  msg=of.ofp_flow_mod()
  msg.counterId = 0
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 0
  msg.tableType = 0 #OF_MM_TABLE
  msg.priority = 0
  msg.index = 0
  
  #matchx 1
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=0
  tempmatchx.offset=0
  tempmatchx.length=48
  tempmatchx.set_value("000000000001")
  tempmatchx.set_mask("ffffffffffff")
  msg.matchx.append(tempmatchx)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 16
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 0
  msg.instruction.append(tempins)

  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 0-1
  ###############################################################################
 
  msg=of.ofp_flow_mod()
  msg.counterId = 1
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 0  
  msg.tableType = 0 #OF_MM_TABLE
  msg.priority = 0
  msg.index = 1
  
  #matchx 1
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=0
  tempmatchx.offset=0
  tempmatchx.length=48
  tempmatchx.set_value("112233445566")
  tempmatchx.set_mask("ffffffffffff")
  msg.matchx.append(tempmatchx)

  tempins=of.ofp_instruction_gototable()
  tempins.nextTableId= 10
  tempins.packetOffset=0
  tempins.matchList.extend([ofmatch20_5])
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 16-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 2
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 0
  msg.tableType = 3
  msg.priority = 0
  msg.index = 0
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=240
  tempins.set_value('03030303')
  tempins.writeLength = 32
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=272
  tempins.set_value('04040404')
  tempins.writeLength = 32
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset= 400
  tempins.set_value('000001')
  tempins.writeLength = 24
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 17
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 0
  msg.instruction.append(tempins)
  
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 17-0
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId = 3
  msg.cookie = 1
  msg.cookieMask = 0
  msg.tableId = 0
  msg.tableType = 3
  msg.priority = 0
  msg.index = 0
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=128
  tempins.set_value('0800')
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=144
  tempins.set_value('4500')
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=208
  tempins.set_value('4011')
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=320
  tempins.set_value('12b5')
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 17
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 1
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 17-1
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId = 4
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 1
  msg.tableType = 3
  msg.priority = 0
  msg.index = 1
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=368
  tempins.set_value('80')
  tempins.writeLength = 8
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadatafrompacket()
  tempins.metadataOffset= 336
  tempins.packetOffset = 128
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_writemetadatafrompacket()
  tempins.metadataOffset= 160
  tempins.packetOffset = 128
  tempins.writeLength = 16
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 17
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 2
  msg.instruction.append(tempins)
  event.connection.send(msg)

  ##############################################################################
  #flow_mod 17-2
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId = 5
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 1
  msg.tableType = 3
  msg.priority = 0
  msg.index = 2
  
  tempins=of.ofp_instruction_calculatefiled()
  tempins.calcType = 0
  tempins.src_valueType = 0    #0: use srcField_Value; 1: use srcField;
  tempins.des_field = ofmatch20_3
  tempins.src_value = 30
  #tempins.src_field = ofp_match20()
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_calculatefiled()
  tempins.calcType = 0
  tempins.src_valueType = 0    #0: use srcField_Value; 1: use srcField;
  tempins.des_field = ofmatch20_4
  tempins.src_value = 50
  #tempins.src_field = ofp_match20()
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 17
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 3
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 17-3
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId = 6
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 1
  msg.tableType = 3
  msg.priority = 0
  msg.index = 3
  
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=304
  tempins.set_value('04d2')
  tempins.writeLength = 16
  msg.instruction.append(tempins)
    
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 17
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 4
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 17-4
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId = 7
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 1
  msg.tableType = 3
  msg.priority = 0
  msg.index = 4
  
  tempins=of.ofp_instruction_applyaction()
  action = of.ofp_action_calculatechecksum()
  action.checksumPosType = 1
  action.calcPosType = 1
  action.checksumPosition = 224
  action.checksumLength = 16
  action.calcStarPosition = 144
  action.calcLength = 160
  tempins.actionList.append(action) 
  msg.instruction.append(tempins)
    
  tempins=of.ofp_instruction_gototable()
  tempins.nextTableId= 8
  tempins.packetOffset=0
  tempins.matchList.extend([ofmatch20_2])
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  
  ##############################################################################
  #flow_mod 8-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 8
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 0
  msg.tableType = 1
  msg.priority = 0
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId= -1
  tempmatchx.offset= 272
  tempmatchx.length= 32
  tempmatchx.set_value("00000000")
  tempmatchx.set_mask("00000000")
  msg.matchx.append(tempmatchx)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 20
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 0
  msg.instruction.append(tempins)

  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 20-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 9
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 4
  msg.tableType = 3
  msg.priority = 0
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=32
  tempins.set_value('112233445566')
  tempins.writeLength = 48
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 18
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 0
  msg.instruction.append(tempins)

  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 18-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 10
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 2
  msg.tableType = 3
  msg.priority = 0
  
  tempins=of.ofp_instruction_writemetadata()
  tempins.metaDataOffset=80
  tempins.set_value('665544332211')
  tempins.writeLength = 48
  msg.instruction.append(tempins)
  
  tempins=of.ofp_instruction_applyaction()
  action=of.ofp_action_output()
  action.portId=0x10045
  action.metadataOffset=32
  action.metadataLength=400
  action.packetOffset=0
  tempins.actionList.append(action) 
  msg.instruction.append(tempins)
  
  event.connection.send(msg)
  
  
  ##############################################################################
  #flow_mod 10-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 6
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 0
  msg.tableType = 2
  msg.priority = 0
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=2
  tempmatchx.offset=96
  tempmatchx.length=16
  tempmatchx.set_value("0800")
  tempmatchx.set_mask("ffff")
  msg.matchx.append(tempmatchx)
  
  tempins=of.ofp_instruction_gototable()
  tempins.nextTableId= 11
  tempins.packetOffset=0
  tempins.matchList.extend([ofmatch20_6,ofmatch20_7])
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  
  ##############################################################################
  #flow_mod 11-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 6
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 1
  msg.tableType = 2
  msg.priority = 0
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=7
  tempmatchx.offset=184
  tempmatchx.length=8
  tempmatchx.set_value("11")
  tempmatchx.set_mask("ff")
  msg.matchx.append(tempmatchx)
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=12
  tempmatchx.offset= 288
  tempmatchx.length=16
  tempmatchx.set_value("12b5")
  tempmatchx.set_mask("ffff")
  msg.matchx.append(tempmatchx)
  
  tempins=of.ofp_instruction_gotodirecttable()
  tempins.nextTableId = 19
  tempins.indexType = 0
  tempins.packetOffset= 0
  tempins.indexValue = 0
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 19-0
  ###############################################################################
  msg=of.ofp_flow_mod()
  msg.counterId = 6
  msg.cookie = 0
  msg.cookieMask = 0
  msg.tableId = 3
  msg.tableType = 3
  msg.priority = 0
  
  ''' 
  tempins=of.ofp_instruction_applyaction()
  action=of.ofp_action_output()
  action.portId=0x10047
  action.metadataOffset=0
  action.metadataLength=0
  action.packetOffset=0
  tempins.actionList.append(action) 
  msg.instruction.append(tempins)
  event.connection.send(msg)
  
  '''
  tempins=of.ofp_instruction_applyaction()
  action=of.ofp_action_deletefield()
  action.tagPosition = 0
  action.tagLengthValueType = 0
  action.tagLengthValue = 128
  tempins.actionList.append(action)
  tempins.actionList.append(action)
  tempins.actionList.append(action)
  
  action=of.ofp_action_deletefield()
  action.tagPosition = 0
  action.tagLengthValueType = 0
  action.tagLengthValue = 16
  tempins.actionList.append(action)
  
  action=of.ofp_action_output()
  action.portId=0x10047
  action.metadataOffset=0
  action.metadataLength=0
  action.packetOffset=0
  tempins.actionList.append(action) 
  msg.instruction.append(tempins)
  event.connection.send(msg)
def test_huawei_flow(event):

    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[1]  #make eth1 openflow_enable
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)

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

    ofmatch20_2 = of.ofp_match20()
    ofmatch20_2.fieldId = 2
    ofmatch20_2.offset = 96
    ofmatch20_2.length = 16

    ofmatch20_3 = of.ofp_match20()
    ofmatch20_3.fieldId = 3
    ofmatch20_3.offset = 112
    ofmatch20_3.length = 16

    ofmatch20_4 = of.ofp_match20()
    ofmatch20_4.fieldId = 4
    ofmatch20_4.offset = 144
    ofmatch20_4.length = 40
    #length of ContentName

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)
    msg.flowTable.matchFieldList.append(ofmatch20_2)
    msg.flowTable.matchFieldList.append(ofmatch20_3)
    msg.flowTable.matchFieldList.append(ofmatch20_4)

    msg.flowTable.command = 0  #OFPTC_ADD

    msg.flowTable.tableType = 0  #OF_MM_TABLE
    msg.flowTable.matchFieldNum = 4  #match num

    msg.flowTable.tableSize = 128
    msg.flowTable.tableId = 0
    msg.flowTable.tableName = "FirstEntryTable"
    msg.flowTable.keyLength = 120  #match field length
    event.connection.send(msg)

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

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

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 1
    tempmatchx.offset = 0
    tempmatchx.length = 48
    tempmatchx.set_value("90b11c5a5299")  #90:b1:1c:5a:52:99,192.168.1.2
    tempmatchx.set_mask("ffffffffffff")
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 2
    tempmatchx.offset = 96
    tempmatchx.length = 16
    tempmatchx.set_value("0011")
    tempmatchx.set_mask("ffff")
    msg.matchx.append(tempmatchx)  #0011 means a new protocol

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 3
    tempmatchx.offset = 112
    tempmatchx.length = 16
    tempmatchx.set_value("0001")
    tempmatchx.set_mask("ffff")  #0001 means it is a Interest Packet
    msg.matchx.append(tempmatchx)

    tempmatchx = of.ofp_matchx()
    tempmatchx.fieldId = 4
    tempmatchx.offset = 144
    tempmatchx.length = 40
    name = 'name1'
    value = ""
    for i in range(0, len(name)):
        value += str(hex(ord(name[i]))[2:])
    tempmatchx.set_value(value)
    tempmatchx.set_mask("ffffffffff")  #6e 61 6d 65 31 means Name 'name1'
    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_op_cache()
    action.io_type = 1
    action.name_len = 10
    action.name = "helloworld"
    action.enable_flag = 1

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

    event.connection.send(msg)
Esempio n. 26
0
def test_huawei_flow(event): 

  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[1]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  
   
  ofmatch20_1 =of.ofp_match20()
  ofmatch20_1.fieldId=1;
  ofmatch20_1.offset=0;
  ofmatch20_1.length=48;
  
  
  ofmatch20_2 =of.ofp_match20()
  ofmatch20_2.fieldId=2;
  ofmatch20_2.offset=48;
  ofmatch20_2.length=48;
  
  ofmatch20_3 =of.ofp_match20()
  ofmatch20_3.fieldId=3;
  ofmatch20_3.offset=96;
  ofmatch20_3.length=16;
  
  ofmatch20_4=of.ofp_match20()
  ofmatch20_4.fieldId=4
  ofmatch20_4.offset=184
  ofmatch20_4.length=8
  
  ofmatch20_5 =of.ofp_match20()
  ofmatch20_5.fieldId=5;
  ofmatch20_5.offset=208;
  ofmatch20_5.length=32;
  
    
  msg =of.ofp_table_mod()
  
  msg.flowTable.matchFieldList.append(ofmatch20_1)
  msg.flowTable.matchFieldList.append(ofmatch20_2)
  msg.flowTable.matchFieldList.append(ofmatch20_3)
  msg.flowTable.matchFieldList.append(ofmatch20_4)
  msg.flowTable.matchFieldList.append(ofmatch20_5)
  
  msg.flowTable.command=0  #OFPTC_ADD
  
  msg.flowTable.tableType=0  #OF_MM_TABLE
  msg.flowTable.matchFieldNum = 5
  
  #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList)
  msg.flowTable.tableSize=128
  msg.flowTable.tableId=0
  msg.flowTable.tableName="FirstEntryTable"
  msg.flowTable.keyLength=152
  event.connection.send(msg)
  
  ##############################################################################
  #flow_mod 1
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId=1
  msg.cookie=0
  msg.cookieMask=0
  msg.tableId=0
  msg.tableType=0 #OF_MM_TABLE
  msg.priority=0
  msg.index=0
 
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=1
  tempmatchx.offset=0
  tempmatchx.length=48
  tempmatchx.set_value("90b11c5a5299") #90:b1:1c:5a:52:99
  tempmatchx.set_mask("ffffffffffff")
  msg.matchx.append(tempmatchx)
  
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=2
  tempmatchx.offset=48
  tempmatchx.length=48
  tempmatchx.set_value("90b11c5a618d")  #90:b1:1c:5a:61:8d 
  tempmatchx.set_mask("ffffffffffff")
  msg.matchx.append(tempmatchx)
  
  
  
  #need to new a ofp_matchx
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=3
  tempmatchx.offset=96
  tempmatchx.length=16
  tempmatchx.set_value("0800")
  tempmatchx.set_mask("ffff")
  msg.matchx.append(tempmatchx) 
  
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=4
  tempmatchx.offset=184
  tempmatchx.length=8
  tempmatchx.set_value("01")
  tempmatchx.set_mask("ffff")
  msg.matchx.append(tempmatchx) 
  
  
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=5
  tempmatchx.offset=208
  tempmatchx.length=32
  tempmatchx.set_value("c0a80103")
  tempmatchx.set_mask("ffffffff")
  msg.matchx.append(tempmatchx) 
  
  
  #instruction
  tempins=of.ofp_instruction_applyaction()
     
  action=of.ofp_action_write()
  action.io_type =1
  action.name_len=10
  action.name="helloworld"
  action.enable_flag=1
  
  tempins.actionList.append(action)
  msg.instruction.append(tempins)
  
  event.connection.send(msg)
Esempio n. 27
0
def test_GOTO_TABLE(event): 
  out_port = 2
  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[3]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[1]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)

  ofmatch20_1 =of.ofp_match20()
  ofmatch20_1.fieldId=1;
  ofmatch20_1.offset=0;
  ofmatch20_1.length=48;
  
  ofmatch20_2 =of.ofp_match20()
  ofmatch20_2.fieldId=-1;
  ofmatch20_2.offset=16;
  ofmatch20_2.length=8;

  ofmatch20_3 =of.ofp_match20()
  ofmatch20_3.fieldId=3;
  ofmatch20_3.offset=96;
  ofmatch20_3.length=16;

  ofmatch20_4 =of.ofp_match20() #TTL
  ofmatch20_4.fieldId=4;
  ofmatch20_4.offset=64;
  ofmatch20_4.length=8;

  
  ###############################################################################
  # table_mode 2
  ###############################################################################
  print " config flowTable 2"
  msg =of.ofp_table_mod()

  msg.flowTable.matchFieldList=[]
  msg.flowTable.matchFieldList.append(ofmatch20_2) #input_port 8bit

  msg.flowTable.command=0  #OFPTC_ADD
  msg.flowTable.tableType=0  #OF_MM_TABLE
  msg.flowTable.matchFieldNum = 1
  
  #msg.flowTable.matchFieldNum=len(msg.flowTable.matchFieldList)
  msg.flowTable.tableSize=128
  msg.flowTable.tableId=0
  msg.flowTable.tableName="Table 1"
  msg.flowTable.keyLength=8
  event.connection.send(msg)
  
 ##############################################################################
  #flow_mod 2-1
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId=3
  msg.cookie=0
  msg.cookieMask=0
  msg.tableId=0
  msg.tableType=0 #OF_MM_TABLE
  msg.priority=1
  msg.index=0
 
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=-1
  tempmatchx.offset=16
  tempmatchx.length=8
  tempmatchx.set_value("02") #  null 
  tempmatchx.set_mask("ff")
  msg.matchx.append(tempmatchx)
  
  #instruction
  tempins=of.ofp_instruction_applyaction()
  
  action=of.ofp_action_output()
  action.portId=4
  action.metadataOffset=0
  action.metadataLength=0
  action.packetOffset=0
  
  tempins.actionList.append(action)
  msg.instruction.append(tempins)

  event.connection.send(msg)
 ##############################################################################
  #flow_mod 2-2
  ###############################################################################
  
  msg=of.ofp_flow_mod()
  msg.counterId=4
  msg.cookie=0
  msg.cookieMask=0
  msg.tableId=0
  msg.tableType=0 #OF_MM_TABLE
  msg.priority=1
  msg.index=1
 
  tempmatchx=of.ofp_matchx()
  tempmatchx.fieldId=-1
  tempmatchx.offset=16
  tempmatchx.length=8
  tempmatchx.set_value("04") #  null 
  tempmatchx.set_mask("ff")
  msg.matchx.append(tempmatchx)
  
  #instruction
  tempins=of.ofp_instruction_applyaction()
  
  action=of.ofp_action_output()
  action.portId=2
  action.metadataOffset=0
  action.metadataLength=0
  action.packetOffset=0
  
  tempins.actionList.append(action)
  msg.instruction.append(tempins)

  event.connection.send(msg)
Esempio n. 28
0
def test_CALCULATE_FIELD(event): 
    '''
    num = len(event.connection.phyports)
    msg = of.ofp_port_mod()
    portmessage = event.connection.phyports[g.input_port - 1]
    msg.setByPortState(portmessage)
    msg.desc.openflowEnable = 1
    event.connection.send(msg)
    '''
    ofmatch20_1 = of.ofp_match20()
    ofmatch20_1.fieldId = 12
    #the last bit of dest IP
    ofmatch20_1.offset = 0
    ofmatch20_1.length = 32

    msg = of.ofp_table_mod()

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

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

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

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

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

    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

    action = of.ofp_action_modifyfield()
    action.matchfield.fieldId = 47
    action.matchfield.offset = 38 * 8 + 3 * 8
    action.matchfield.length = 8
    #  action.increment = -1 + 2**32
    action.increment = -1
    tempins.actionList.append(action)
  
    action = of.ofp_action_output()
    action.portId = g.output_port
    action.metadataOffset = 0
    action.metadataLength = 0
    action.packetOffset = 0    
    tempins.actionList.append(action)
    msg.instruction.append(tempins)

    event.connection.send(msg)

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

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

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

    msg.matchx.append(tempmatchx)

    tempins = of.ofp_instruction_applyaction()
    
    action = of.ofp_action_modifyfield()
    action.matchfield.fieldId = 47
    action.matchfield.offset = 38 * 8 + 3 * 8
    action.matchfield.length = 8
    #  action.increment = -1 + 2**32
    action.increment = -1
    tempins.actionList.append(action)

    action = of.ofp_action_calculatechecksum()
    action.checksumPosType = 0
    action.calcPosType = 1
    action.checksumPosition = 80 + 112
    action.checksumLength = 16
    action.calcStarPosition = 112
    action.calcLength = 160
    tempins.actionList.append(action) 

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

    event.connection.send(msg)
Esempio n. 29
0
def test_DELETE_FIELD(event):
    out_port = g.output_port
    '''
  num =  len(event.connection.phyports)
  msg = of.ofp_port_mod()
  portmessage = event.connection.phyports[7]
  msg.setByPortState(portmessage)
  msg.desc.openflowEnable = 1 
  event.connection.send(msg)
  '''

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

    msg = of.ofp_table_mod()

    msg.flowTable.matchFieldList.append(ofmatch20_1)

    msg.flowTable.command = 0  #OFPTC_ADD

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

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

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

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

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

    msg.matchx.append(tempmatchx)

    #instruction
    tempins = of.ofp_instruction_applyaction()

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

    event.connection.send(msg)

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

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

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

    #instruction
    tempins = of.ofp_instruction_applyaction()
    action = of.ofp_action_deletefield()
    action.tagPosition = 0
    action.tagLengthValueType = 0
    action.tagLengthValue = 48
    tempins.actionList.append(action)

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

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

    event.connection.send(msg)
Esempio n. 30
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)