Exemple #1
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]

        testutils.delete_all_flows(self.controller, self.logger)
        flow_add = message.flow_mod()
        flow_add.buffer_id = 0xffffffff;
        flow_add.header.xid = 123
        flow_add.table_id = 0
        flow_add.command = ofp.OFPFC_ADD
        flow_add.match_fields.add(match.eth_type(value = 0x86dd))
        flow_add.match_fields.add(match.ipv4_src(value = 3232235521))
        flow_add.match_fields.add(match.ipv4_dst(value = 3232235522))
        flow_add.match_fields.add(match.metadata(value = 0))
        "new a instruction"
        inst = instruction.instruction_write_actions()
        "new a output actions"
        act = action.action_output()
        act.port = out_port1
        inst.actions.add(act)
        flow_add.instructions.add(inst)
        #self.controller.message_send(flow_add)
        #print(flow_add.show())
	testutils.ofmsg_send(self, flow_add)

        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
        self.assertTrue(response is not None, 'No error message received')
        self.assertEqual(ofp.OFPET_BAD_MATCH, response.type,
                       'Error message type mismatch: ' +
                       str(ofp.OFPET_BAD_MATCH) + " != " +
                       str(response.type))
        self.assertEqual(ofp.OFPBMC_BAD_PREREQ, response.code,
                       'Error message code mismatch: ' +
                       str(ofp.OFPBMC_BAD_PREREQ) + " != " +
                       str(response.code))
Exemple #2
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self,
                                         pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)
     inst = None
     inst = instruction.instruction_write_actions(
     )  #instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(
         ofp.OFPET_BAD_INSTRUCTION, response.type,
         'Error message type mismatch: ' +
         str(ofp.OFPET_BAD_INSTRUCTION, ) + " != " + str(response.type))
     self.assertEqual(
         ofp.OFPBIC_UNKNOWN_INST, response.code,
         'Error message code mismatch: ' + str(ofp.OFPBIC_UNKNOWN_INST) +
         " != " + str(response.code))
Exemple #3
0
def write_goto_action(parent, set_id, next_id, act, ip_src=MT_TEST_IP):
    """
    Make Goto instruction with/without write_action
    """
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    write_goto(parent, set_id, next_id, ip_src=ip_src, add_inst=inst)
Exemple #4
0
def exact_table_goto_table(parent = None, first_table = 0, second_table = 1, match_ls = None, actions = []):
    """
    exact table goto table
    """
    if parent == None or match_ls == None:
        print("parent == None or match_ls == None")
        return

    if first_table >= second_table :
        print( "first_table >= second_table")
        return

    request = message.flow_mod()
    request.table_id = first_table
    request.command = ofp.OFPFC_ADD

    request.match_fields = match_ls

    if(len(actions) != 0):
        inst = instruction.instruction_write_actions();
        inst.actions = actions
        request.instructions.add(inst)

    inst_goto = instruction.instruction_goto_table();
    inst_goto.table_id = second_table
    request.instructions.add(inst_goto)
    testutils.ofmsg_send(parent,request)
Exemple #5
0
def exact_table_output(parent=None,
                       table_id=None,
                       match_ls=None,
                       actions=[],
                       egr_port=None):
    """
    exact table output
    """
    if parent == None or table_id == None or match_ls == None:
        print("parent == None or table_id == None or match_ls == None:")
        return

    if egr_port is None:
        of_ports = exact_port_map.keys()
        egr_port = of_ports[len(of_ports) - 1]
    request = message.flow_mod()
    request.table_id = table_id
    request.command = ofp.OFPFC_ADD
    request.match_fields = match_ls

    inst = instruction.instruction_write_actions()
    for item in actions:
        inst.actions.add(item)
    #print( inst.actions.show())
    #inst.actions.actions = actions

    act_out = action.action_output()
    act_out.port = egr_port
    inst.actions.add(act_out)
    request.instructions.add(inst)

    testutils.ofmsg_send(parent, request)
Exemple #6
0
def write_goto_action(parent, set_id, next_id, act, ip_src=MT_TEST_IP):
    """
    Make Goto instruction with/without write_action
    """
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    write_goto(parent, set_id, next_id, ip_src=ip_src, add_inst=inst)
Exemple #7
0
def exact_table_goto_table(parent=None,
                           first_table=0,
                           second_table=1,
                           match_ls=None,
                           actions=[]):
    """
    exact table goto table
    """
    if parent == None or match_ls == None:
        print("parent == None or match_ls == None")
        return

    if first_table >= second_table:
        print("first_table >= second_table")
        return

    request = message.flow_mod()
    request.table_id = first_table
    request.command = ofp.OFPFC_ADD

    request.match_fields = match_ls

    if (len(actions) != 0):
        inst = instruction.instruction_write_actions()
        inst.actions = actions
        request.instructions.add(inst)

    inst_goto = instruction.instruction_goto_table()
    inst_goto.table_id = second_table
    request.instructions.add(inst_goto)
    testutils.ofmsg_send(parent, request)
Exemple #8
0
def exact_table_output(parent = None, table_id = None, match_ls = None, actions = [], egr_port = None):
    """
    exact table output
    """
    if parent == None or table_id == None or match_ls == None:
        print( "parent == None or table_id == None or match_ls == None:")
        return

    if egr_port is None:
        of_ports = exact_port_map.keys()
        egr_port = of_ports[len(of_ports)-1]
    request = message.flow_mod()
    request.table_id = table_id
    request.command = ofp.OFPFC_ADD
    request.match_fields = match_ls


    inst = instruction.instruction_write_actions();
    for item in actions:
        inst.actions.add(item)
    #print( inst.actions.show())
    #inst.actions.actions = actions

    act_out = action.action_output()
    act_out.port = egr_port
    inst.actions.add(act_out)
    request.instructions.add(inst)

    testutils.ofmsg_send(parent, request)
Exemple #9
0
 def runTest(self):
     ing_port = flow_mods_port_map.keys()[0]
     out_port1 = flow_mods_port_map.keys()[1]
     out_port2 = flow_mods_port_map.keys()[2]
     pkt = testutils.simple_tcp_packet()
     testutils.delete_all_flows(self.controller, self.logger)
     fm_orig = testutils.flow_msg_create(self, pkt,
                                         ing_port=ing_port,
                                         egr_port=out_port1)
     inst = None
     inst = instruction.instruction_write_actions()#instruct is the same, action is different
     act = action.action_output()
     act.port = out_port2
     rv = inst.actions.add(act)
     self.assertTrue(rv, "Could not add action" + act.show())
     fm_orig.instructions.add(inst)
     #print(fm_orig.show())
     testutils.ofmsg_send(self, fm_orig)
     (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 5)
     self.assertTrue(response is not None, 'No error message received')
     self.assertEqual(ofp.OFPET_BAD_INSTRUCTION, response.type,
                    'Error message type mismatch: ' +
                    str(ofp.OFPET_BAD_INSTRUCTION,) + " != " +
                    str(response.type))
     self.assertEqual(ofp.OFPBIC_UNKNOWN_INST, response.code,
                    'Error message code mismatch: ' +
                    str(ofp.OFPBIC_UNKNOWN_INST) + " != " +
                    str(response.code))
Exemple #10
0
    def runTest(self):
        ing_port = flow_mods_port_map.keys()[0]
        out_port1 = flow_mods_port_map.keys()[1]

        testutils.delete_all_flows(self.controller, self.logger)
        flow_add = message.flow_mod()
        flow_add.buffer_id = 0xffffffff
        flow_add.header.xid = 123
        flow_add.table_id = 0
        flow_add.command = ofp.OFPFC_ADD
        flow_add.match_fields.add(match.eth_type(value=0x86dd))
        flow_add.match_fields.add(match.ipv4_src(value=3232235521))
        flow_add.match_fields.add(match.ipv4_dst(value=3232235522))
        flow_add.match_fields.add(match.metadata(value=0))
        "new a instruction"
        inst = instruction.instruction_write_actions()
        "new a output actions"
        act = action.action_output()
        act.port = out_port1
        inst.actions.add(act)
        flow_add.instructions.add(inst)
        #self.controller.message_send(flow_add)
        #print(flow_add.show())
        testutils.ofmsg_send(self, flow_add)

        (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 2)
        self.assertTrue(response is not None, 'No error message received')
        self.assertEqual(
            ofp.OFPET_BAD_MATCH, response.type,
            'Error message type mismatch: ' + str(ofp.OFPET_BAD_MATCH) +
            " != " + str(response.type))
        self.assertEqual(
            ofp.OFPBMC_BAD_PREREQ, response.code,
            'Error message code mismatch: ' + str(ofp.OFPBMC_BAD_PREREQ) +
            " != " + str(response.code))
Exemple #11
0
def write_output(parent, set_id, outport, ip_src=MT_TEST_IP, match=None):
    """
    Make flow_mod of Write_action instruction of Output
    """
    act = action.action_output()
    act.port = outport
    request = message.flow_mod()
    if match is None:
        request.match = make_match(ip_src=ip_src)
    else:
        request.match = match
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Exemple #12
0
def write_output(parent, set_id, outport, ip_src=MT_TEST_IP, match=None):
    """
    Make flow_mod of Write_action instruction of Output
    """
    act = action.action_output()
    act.port = outport
    request = message.flow_mod()
    if match is None:
        request.match = make_match(ip_src=ip_src)
    else:
        request.match = match
    request.buffer_id = 0xffffffff
    request.table_id = set_id
    inst = instruction.instruction_write_actions()
    parent.assertTrue(inst.actions.add(act), "Can't add action")
    parent.assertTrue(request.instructions.add(inst), "Can't add inst")
    pa_logger.info("Inserting flow")
    rv = parent.controller.message_send(request)
    parent.assertTrue(rv != -1, "Error installing flow mod")
    testutils.do_barrier(parent.controller)
Exemple #13
0
 def runTest(self):
     #testutils.skip_message_emit(self, 'skip!')
     #return
     #'instruction goto'
     inst_goto = instruction.instruction_goto_table()
     #'instruction table 0'
     inst = instruction.instruction_write_actions()
     #"action setfield"
     act = action.action_set_field()
     inst.actions.add(act)
     #"action output"
     act = action.action_output()
     act.port = 1
     inst.actions.add(act)
     #"table 0 instructions"
     request = message.flow_mod()
     request.table_id = 0
     request.instructions.add(inst)
     inst_goto.table_id = 1;
     request.instructions.add(inst_goto)
Exemple #14
0
 def runTest(self):
     #testutils.skip_message_emit(self, 'skip!')
     #return
     #'instruction goto'
     inst_goto = instruction.instruction_goto_table()
     #'instruction table 0'
     inst = instruction.instruction_write_actions()
     #"action setfield"
     act = action.action_set_field()
     inst.actions.add(act)
     #"action output"
     act = action.action_output()
     act.port = 1
     inst.actions.add(act)
     #"table 0 instructions"
     request = message.flow_mod()
     request.table_id = 0
     request.instructions.add(inst)
     inst_goto.table_id = 1
     request.instructions.add(inst_goto)
def write_action_test_multi_tables(parent, ing_port, egr_port,
        match = None,
        wildcards = 0,
        act_list = None,
        next_avail = None,
        chk_expire = None,
        pkt = None,
        exp_pkt = None):
    """
    Testing framework for write_action tests with multiple tables

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param ing_port Ingress OF port
    @param egr_port Egress OF port
    @match Match field in flow_mod commans for all the tables
    @param wildcard Match.wildcard filed in flow_mod commands for all the tables
    @param act_list Array of action list for each table
    @param next_avail Array. Indicate False for no more tables are used
    @param chk_expire Array. Indicate True if you want flow_removed msg
    @param pkt Pkt to be sent
    @param exp_pkt Expected pkt
    """

    parent.assertTrue(match is not None, "Match param doesn't exist")
    parent.assertTrue(act_list is not None, "act_list param doesn't exist")
    parent.assertTrue(next_avail is not None, "next_avail param doesn't exist")
    parent.assertTrue(chk_expire is not None, "chk_expire param doesn't exist")
    wildcards = wildcards & 0xfffffffff # mask out anything out of range

    request_list = []
    for table_id in range(MAX_TABLE):
        inst_list = []
        inst = instruction.instruction_write_actions()
        inst_list.append(inst)
        action_list = act_list[table_id]
        check_expire = chk_expire[table_id]
        if next_avail[table_id]:
            inst = instruction.instruction_goto_table()
            inst.table_id = table_id + 1
            inst_list.append(inst)
        else:
            pass

        request = testutils.flow_msg_create(parent, pkt, ing_port=ing_port,
                              instruction_list=inst_list,
                              action_list=action_list,
                              wildcards=wildcards,
                              match=match,
                              check_expire=check_expire,
                              table_id=table_id)
        request_list.append(request)
        testutils.flow_msg_install(parent, request_list[table_id])

        if next_avail[table_id]:
            pass
        else:
            num_table_used = table_id + 1
            break

    parent.logger.debug("Send packet: " + str(ing_port)
        + " to " + str(egr_port))
    parent.dataplane.send(ing_port, str(pkt))

    # Check response from switch
    #@todo Not all HW supports both pkt and byte counters
    #@todo We shouldn't expect the order of coming response..
    for table_id in range(num_table_used):
        if chk_expire[table_id]:
            flow_removed_verify(parent, request_list[table_id], pkt_count=1,
                            byte_count=pktlen)

    testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
Exemple #16
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        # Clear flow table
        rv = testutils.initialize_table_config(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to initialize table config")
        rv = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        # Set up first match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.nw_src_mask = 0 # Match nw_src
        match.dl_type = 0x800
        match.nw_src = parse.parse_ip("192.168.1.10")
        act = action.action_output()
        act.port = of_ports[0]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 0
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst1")
        inst = instruction.instruction_goto_table()
        inst.table_id = 1
        self.assertTrue(request.instructions.add(inst), "Could not add inst2")
        pa_logger.info("Inserting flow 1")
        rv = self.controller.message_send(request)
        # pa_logger.debug(request.show())
        self.assertTrue(rv != -1, "Error installing flow mod")

        # Set up second match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.wildcards -= ofp.OFPFW_TP_SRC
        match.dl_type = 0x800
        match.nw_proto = 6 # TCP
        match.tp_src = 80
        act = action.action_output()
        act.port = of_ports[1]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 1
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst3")
        pa_logger.info("Inserting flow 2")
        # pa_logger.debug(request.show())
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")
        testutils.do_barrier(self.controller)

        # Generate a packet matching only flow 1; rcv on port[0]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + 
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port")
        
        # Generate a packet matching both flow 1 and flow 2; rcv on port[1]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " + 
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")
Exemple #17
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")

        # Clear flow table
        rv = testutils.initialize_table_config(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to initialize table config")
        rv = testutils.delete_all_flows(self.controller, pa_logger)
        self.assertEqual(rv, 0, "Failed to delete all flows")

        # Set up first match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.nw_src_mask = 0  # Match nw_src
        match.dl_type = 0x800
        match.nw_src = parse.parse_ip("192.168.1.10")
        act = action.action_output()
        act.port = of_ports[0]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 0
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst1")
        inst = instruction.instruction_goto_table()
        inst.table_id = 1
        self.assertTrue(request.instructions.add(inst), "Could not add inst2")
        pa_logger.info("Inserting flow 1")
        rv = self.controller.message_send(request)
        # pa_logger.debug(request.show())
        self.assertTrue(rv != -1, "Error installing flow mod")

        # Set up second match
        match = ofp.ofp_match()
        match.length = ofp.OFPMT_STANDARD_LENGTH
        testutils.wildcard_all_set(match)
        match.wildcards -= ofp.OFPFW_DL_TYPE
        match.wildcards -= ofp.OFPFW_TP_SRC
        match.dl_type = 0x800
        match.nw_proto = 6  # TCP
        match.tp_src = 80
        act = action.action_output()
        act.port = of_ports[1]

        request = message.flow_mod()
        request.match = match
        request.buffer_id = 0xffffffff
        request.table_id = 1
        inst = instruction.instruction_write_actions()
        self.assertTrue(inst.actions.add(act), "Could not add action")
        self.assertTrue(request.instructions.add(inst), "Could not add inst3")
        pa_logger.info("Inserting flow 2")
        # pa_logger.debug(request.show())
        rv = self.controller.message_send(request)
        self.assertTrue(rv != -1, "Error installing flow mod")
        testutils.do_barrier(self.controller)

        # Generate a packet matching only flow 1; rcv on port[0]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=10)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[0], "Unexpected receive port")

        # Generate a packet matching both flow 1 and flow 2; rcv on port[1]
        pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=80)
        self.dataplane.send(of_ports[2], str(pkt))
        (rcv_port, rcv_pkt, _) = self.dataplane.poll(timeout=5)
        self.assertTrue(rcv_pkt is not None, "Did not receive packet")
        pa_logger.debug("Packet len " + str(len(rcv_pkt)) + " in on " +
                        str(rcv_port))
        self.assertEqual(rcv_port, of_ports[1], "Unexpected receive port")