Ejemplo n.º 1
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)
Ejemplo n.º 2
0
        def drop(duration=None):
            """
      Drops this packet and optionally installs a flow to continue
      dropping similar ones for a while
      """
            if duration is not None:
                if not isinstance(duration, tuple):
                    duration = (duration, duration)
                add_drop_flow(self, event, duration, packet)

            elif event.ofp.bufferId is not None:
                #print ('-----------------------')
                msg = of.ofp_packet_out()
                msg.bufferId = event.ofp.bufferId
                msg.inPort = event.port
                msg.actions.append(of.ofp_action_drop())  #need to add?
                self.connection.send(msg)
Ejemplo n.º 3
0
def test_group_mod(event):
    msg=of.ofp_group_mod()
    msg.command = 0
    msg.groupType = 0
    #msg.actionNum = 4
    msg.padding = 0
    msg.groupId = 1
    msg.counterId = 4
    msg.padding = 0    
    msg.actions = []
    
    action_1 = of.ofp_action_setfield()
    action_1.ofActionType = 1
    action_1.length = 44
    action_1.fieldSetting = of.ofp_matchx()
    action_1.fieldSetting.fieldId = 0
    action_1.fieldSetting.offset = 0
    action_1.fieldSetting.length = 0
    action_1.fieldSetting.padding = 0
    action_1.fieldSetting.set_value("00")
    action_1.fieldSetting.set_mask("00")
    msg.actions.append(action_1)
    
    
    
    
    
    action_2 = of.ofp_action_addfield()
    action_2.length = 20
    action_2.fieldId = 0
    action_2.fieldPosition = 0
    action_2.fieldLength = 0
    action_2.set_fieldValue("00")
    msg.actions.append(action_2)
    
    action_3 = of.ofp_action_group()
    action_3.length = 12
    action_3.groupId = 0
    msg.actions.append(action_3)
    
    action_4 = of.ofp_action_drop()
    action_4.length = 12
    action_4.reason = 0
    msg.actions.append(action_4)
    
    event.connection.send(msg)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def act_drop(args):# [reason]
	action=of.ofp_action_drop()
	action.reason = args[0]  
	print ("add the action 'drop' \n")

	return action
Ejemplo n.º 6
0
def action_drop(action_drop_data):
    drop = of.ofp_action_drop()
    reason = action_drop_data[0]['Reason']
    drop.reason = of.ofp_drop_reason_rev_map[reason]
    
    return drop 
Ejemplo n.º 7
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)