Пример #1
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        pktlen = 104
        mpls_label = 0xa5f05 # no specific meaning
        mpls_tc = 5
        mpls_ttl = 129
        pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                 mpls_label=mpls_label,
                                                 mpls_tc=mpls_tc,
                                                 mpls_ttl=mpls_ttl)

        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        new_mpls_ttl = mpls_ttl+1
        exp_pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                     mpls_label=mpls_label,
                                                     mpls_tc=mpls_tc,
                                                     mpls_ttl=new_mpls_ttl)

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        act = action.action_set_mpls_ttl()
        act.mpls_ttl = new_mpls_ttl
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_dec_mpls_ttl()
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match = match,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Пример #2
0
    def runTest(self):
        of_ports = pa_port_map.keys()
        of_ports.sort()
        self.assertTrue(len(of_ports) > 2, "Not enough ports for test")
        # For making the test simpler...
        ing_port = of_ports[0]
        egr_port = of_ports[1]

        mpls_label = 0xa5f05 # no specific meaning
        mpls_tc = 5
        mpls_ttl = 129
        mpls_label_int = 0x5a0fa
        mpls_tc_int = 4
        mpls_ttl_int = 193

        pkt = testutils.simple_tcp_packet_w_mpls(
                                  mpls_label=mpls_label,
                                  mpls_tc=mpls_tc,
                                  mpls_ttl=mpls_ttl,
                                  mpls_label_int=mpls_label_int,
                                  mpls_tc_int=mpls_tc_int,
                                  mpls_ttl_int=mpls_ttl_int)

        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        exp_pkt = testutils.simple_tcp_packet_w_mpls(
                                      mpls_label=mpls_label_int,
                                      mpls_tc=mpls_tc_int,
                                      mpls_ttl=mpls_ttl_int,
                                      mpls_label_int=mpls_label_int,
                                      mpls_tc_int=mpls_tc_int,
                                      mpls_ttl_int=mpls_ttl_int)

        # Create parameters for each table
        act_list = []
        next_avail = []
        chk_expire = []

        #Table 0
        act = action.action_output()
        act.port = egr_port
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 1
        act = action.action_push_mpls()
        act.ethertype = ETHERTYPE_MPLS
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_pop_mpls()
        act.ethertype = ETHERTYPE_MPLS
        act_list.append([act])
        next_avail.append(False)
        chk_expire.append(False)

        write_action_test_multi_tables(self, ing_port, egr_port,
            match = match,
            wildcards = wildcards,
            act_list = act_list,
            next_avail = next_avail,
            chk_expire = chk_expire,
            pkt = pkt,
            exp_pkt = exp_pkt)
Пример #3
0
def flow_match_test_port_pair_mpls_two_tables(
        parent,
        ing_port,
        egr_port,
        wildcards=0,
        mpls_type=ETHERTYPE_MPLS,
        mpls_label=-1,
        mpls_tc=0,
        mpls_ttl=64,
        mpls_label_int=-1,
        mpls_tc_int=0,
        mpls_ttl_int=32,
        ip_ttl=192,
        label_match_tbl0=0,
        tc_match_tbl0=0,
        dl_type_match_tbl0=ETHERTYPE_MPLS,
        action_list_tbl0=None,
        check_expire_tbl0=False,
        match_exp_tbl0=True,
        exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED,
        exp_msg_type_tbl0=0,
        exp_msg_code_tbl0=0,
        label_match_tbl1=0,
        tc_match_tbl1=0,
        dl_type_match_tbl1=ETHERTYPE_MPLS,
        check_expire_tbl1=False,
        match_exp_tbl1=True,
        exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED,
        exp_msg_type_tbl1=0,
        exp_msg_code_tbl1=0,
        add_tag_exp=False,
        exp_mpls_type=ETHERTYPE_MPLS,
        exp_mpls_label=-1,
        exp_mpls_tc=0,
        exp_mpls_ttl=64,
        exp_mpls_ttl_int=32,
        exp_ip_ttl=192,
        pkt=None,
        exp_pkt=None):
    """
    Flow match test for various mpls matching patterns on single TCP packet

    Run test with packet through switch from ing_port to egr_port
    See flow_match_test for parameter descriptions
    """
    parent.logger.info("Pkt match test: " + str(ing_port) + " to " +
                       str(egr_port))
    parent.logger.debug("  WC: " + hex(wildcards) + " mpls label: " +
                        str(mpls_label) + " mpls tc: " + str(mpls_tc) +
                        " expire_table0: " + str(check_expire_tbl0) +
                        " expire_table1: " + str(check_expire_tbl1))

    # Check if the switch supports all the MPLS actions
    sup_act_dic = mplsact.mpls_action_support_check(parent)
    sup_act_elm = sup_act_dic.keys()
    for i in sup_act_elm:
        if sup_act_dic[i] == False:
            testutils.skip_message_emit(
                parent, "Switch doesn't support " +
                "one or more of MPLS actions : " + i)
            return

    len = 100
    len_w_shim = len + 4
    len_w_2shim = len_w_shim + 4
    len_w_3shim = len_w_2shim + 4
    if pkt is None:
        if mpls_label >= 0:
            if mpls_label_int >= 0:
                pktlen = len_w_2shim
            else:
                pktlen = len_w_shim
        else:
            pktlen = len
        pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                 mpls_type=mpls_type,
                                                 mpls_label=mpls_label,
                                                 mpls_tc=mpls_tc,
                                                 mpls_ttl=mpls_ttl,
                                                 mpls_label_int=mpls_label_int,
                                                 mpls_tc_int=mpls_tc_int,
                                                 mpls_ttl_int=mpls_ttl_int,
                                                 ip_ttl=ip_ttl)

    if exp_pkt is None:
        if exp_mpls_label >= 0:
            if add_tag_exp:
                if mpls_label_int >= 0:
                    exp_pktlen = len_w_3shim
                else:
                    exp_pktlen = len_w_2shim
            else:
                if mpls_label_int >= 0:
                    exp_pktlen = len_w_2shim
                else:
                    exp_pktlen = len_w_shim
        else:
            #subtract action
            if mpls_label_int >= 0:
                exp_pktlen = len_w_shim
            else:
                exp_pktlen = len

        if add_tag_exp:
            exp_pkt = testutils.simple_tcp_packet_w_mpls(
                pktlen=exp_pktlen,
                mpls_type=exp_mpls_type,
                mpls_label_ext=exp_mpls_label,
                mpls_tc_ext=exp_mpls_tc,
                mpls_ttl_ext=exp_mpls_ttl,
                mpls_label=mpls_label,
                mpls_tc=mpls_tc,
                mpls_ttl=mpls_ttl,
                mpls_label_int=mpls_label_int,
                mpls_tc_int=mpls_tc_int,
                mpls_ttl_int=exp_mpls_ttl_int,
                ip_ttl=exp_ip_ttl)
        else:
            if (exp_mpls_label < 0) and (mpls_label_int >= 0):
                exp_pkt = testutils.simple_tcp_packet_w_mpls(
                    pktlen=exp_pktlen,
                    mpls_type=mpls_type,
                    mpls_label=mpls_label_int,
                    mpls_tc=mpls_tc_int,
                    mpls_ttl=exp_mpls_ttl_int,
                    ip_ttl=exp_ip_ttl)
            else:
                exp_pkt = testutils.simple_tcp_packet_w_mpls(
                    pktlen=exp_pktlen,
                    mpls_type=exp_mpls_type,
                    mpls_label=exp_mpls_label,
                    mpls_tc=exp_mpls_tc,
                    mpls_ttl=exp_mpls_ttl,
                    mpls_label_int=mpls_label_int,
                    mpls_tc_int=mpls_tc_int,
                    mpls_ttl_int=exp_mpls_ttl_int,
                    ip_ttl=exp_ip_ttl)

    # Flow Mod for Table0
    match = parse.packet_to_flow_match(pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")

    match.mpls_label = label_match_tbl0
    match.mpls_tc = tc_match_tbl0
    match.dl_type = dl_type_match_tbl0
    if ((dl_type_match_tbl0 == ETHERTYPE_MPLS)
            or (dl_type_match_tbl0 == ETHERTYPE_MPLS_MC)):
        match.nw_tos = 0
        match.nw_proto = 0
        match.nw_src = 0
        match.nw_src_mask = 0
        match.nw_dst = 0
        match.nw_dst_mask = 0
        match.tp_src = 0
        match.tp_dst = 0

    inst_1 = instruction.instruction_apply_actions()
    inst_2 = instruction.instruction_goto_table()
    inst_2.table_id = 1
    inst_list = [inst_1, inst_2]
    request0 = testutils.flow_msg_create(parent,
                                         pkt,
                                         ing_port=ing_port,
                                         instruction_list=inst_list,
                                         action_list=action_list_tbl0,
                                         wildcards=wildcards,
                                         match=match,
                                         check_expire=check_expire_tbl0,
                                         table_id=0)
    testutils.flow_msg_install(parent, request0)

    # Flow Mod for Table1
    match = parse.packet_to_flow_match(exp_pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")

    match.mpls_label = label_match_tbl1
    match.mpls_tc = tc_match_tbl1
    match.dl_type = dl_type_match_tbl1

    if ((dl_type_match_tbl1 == ETHERTYPE_MPLS)
            or (dl_type_match_tbl1 == ETHERTYPE_MPLS_MC)):
        match.nw_tos = 0
        match.nw_proto = 0
        match.nw_src = 0
        match.nw_src_mask = 0
        match.nw_dst = 0
        match.nw_dst_mask = 0
        match.tp_src = 0
        match.tp_dst = 0

    request1 = testutils.flow_msg_create(parent,
                                         pkt,
                                         ing_port=ing_port,
                                         wildcards=wildcards,
                                         match=match,
                                         check_expire=check_expire_tbl1,
                                         table_id=1,
                                         egr_port=egr_port)
    testutils.flow_msg_install(parent, request1)

    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..
    if match_exp_tbl0:
        if check_expire_tbl0:
            flow_removed_verify(parent,
                                request0,
                                pkt_count=1,
                                byte_count=pktlen)
    else:
        if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED:
            if check_expire_tbl0:
                flow_removed_verify(parent,
                                    request0,
                                    pkt_count=0,
                                    byte_count=0)
        elif exp_msg_tbl0 is ofp.OFPT_ERROR:
            error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0)
        else:
            parent.assertTrue(0,
                              "Rcv: Unexpected Message: " + str(exp_msg_tbl0))

    if match_exp_tbl1:
        if check_expire_tbl1:
            flow_removed_verify(parent,
                                request1,
                                pkt_count=1,
                                byte_count=exp_pktlen)
    else:
        if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED:
            if check_expire_tbl1:
                flow_removed_verify(parent,
                                    request1,
                                    pkt_count=0,
                                    byte_count=0)
        elif exp_msg_tbl1 is ofp.OFPT_ERROR:
            error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1)
        else:
            parent.assertTrue(0,
                              "Rcv: Unexpected Message: " + str(exp_msg_tbl1))

    # Check pkt
    if match_exp_tbl0 and match_exp_tbl1:
        testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
    else:
        (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1)
        parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")
Пример #4
0
def flow_match_test_port_pair_mpls_two_tables(parent, ing_port, egr_port,
                                   wildcards=0,
                                   mpls_type=ETHERTYPE_MPLS,
                                   mpls_label=-1,
                                   mpls_tc=0,
                                   mpls_ttl=64,
                                   mpls_label_int=-1,
                                   mpls_tc_int=0,
                                   mpls_ttl_int=32,
                                   ip_ttl=192,
                                   label_match_tbl0=0,
                                   tc_match_tbl0=0,
                                   dl_type_match_tbl0=ETHERTYPE_MPLS,
                                   action_list_tbl0=None,
                                   check_expire_tbl0=False,
                                   match_exp_tbl0=True,
                                   exp_msg_tbl0=ofp.OFPT_FLOW_REMOVED,
                                   exp_msg_type_tbl0=0,
                                   exp_msg_code_tbl0=0,
                                   label_match_tbl1=0,
                                   tc_match_tbl1=0,
                                   dl_type_match_tbl1=ETHERTYPE_MPLS,
                                   check_expire_tbl1=False,
                                   match_exp_tbl1=True,
                                   exp_msg_tbl1=ofp.OFPT_FLOW_REMOVED,
                                   exp_msg_type_tbl1=0,
                                   exp_msg_code_tbl1=0,
                                   add_tag_exp=False,
                                   exp_mpls_type=ETHERTYPE_MPLS,
                                   exp_mpls_label=-1,
                                   exp_mpls_tc=0,
                                   exp_mpls_ttl=64,
                                   exp_mpls_ttl_int=32,
                                   exp_ip_ttl=192,
                                   pkt=None, exp_pkt=None):
    """
    Flow match test for various mpls matching patterns on single TCP packet

    Run test with packet through switch from ing_port to egr_port
    See flow_match_test for parameter descriptions
    """
    parent.logger.info("Pkt match test: " + str(ing_port) + " to "
                       + str(egr_port))
    parent.logger.debug("  WC: " + hex(wildcards) + " mpls label: " +
                    str(mpls_label) +
                    " mpls tc: " + str(mpls_tc) +
                    " expire_table0: " + str(check_expire_tbl0) +
                    " expire_table1: " + str(check_expire_tbl1))

    # Check if the switch supports all the MPLS actions
    sup_act_dic = mplsact.mpls_action_support_check(parent)
    sup_act_elm = sup_act_dic.keys()
    for i in sup_act_elm:
        if sup_act_dic[i] == False:
            testutils.skip_message_emit(parent, "Switch doesn't support " +
                "one or more of MPLS actions : " + i)
            return

        pkt = testutils.simple_tcp_packet_w_mpls(
                                       mpls_type=mpls_type,
                                       mpls_label=mpls_label,
                                       mpls_tc=mpls_tc,
                                       mpls_ttl=mpls_ttl,
                                       mpls_label_int=mpls_label_int,
                                       mpls_tc_int=mpls_tc_int,
                                       mpls_ttl_int=mpls_ttl_int,
                                       ip_ttl=ip_ttl)

    if exp_pkt is None:
        if add_tag_exp:
            exp_pkt = testutils.simple_tcp_packet_w_mpls(
                                           mpls_type=exp_mpls_type,
                                           mpls_label_ext=exp_mpls_label,
                                           mpls_tc_ext=exp_mpls_tc,
                                           mpls_ttl_ext=exp_mpls_ttl,
                                           mpls_label=mpls_label,
                                           mpls_tc=mpls_tc,
                                           mpls_ttl=mpls_ttl,
                                           mpls_label_int=mpls_label_int,
                                           mpls_tc_int=mpls_tc_int,
                                           mpls_ttl_int=exp_mpls_ttl_int,
                                           ip_ttl=exp_ip_ttl)
        else:
            if (exp_mpls_label < 0) and (mpls_label_int >= 0):
                exp_pkt = testutils.simple_tcp_packet_w_mpls(
                                           mpls_type=mpls_type,
                                           mpls_label=mpls_label_int,
                                           mpls_tc=mpls_tc_int,
                                           mpls_ttl=exp_mpls_ttl_int,
                                           ip_ttl=exp_ip_ttl)
            else:
                exp_pkt = testutils.simple_tcp_packet_w_mpls(
                                           mpls_type=exp_mpls_type,
                                           mpls_label=exp_mpls_label,
                                           mpls_tc=exp_mpls_tc,
                                           mpls_ttl=exp_mpls_ttl,
                                           mpls_label_int=mpls_label_int,
                                           mpls_tc_int=mpls_tc_int,
                                           mpls_ttl_int=exp_mpls_ttl_int,
                                           ip_ttl=exp_ip_ttl)

    # Flow Mod for Table0
    match = parse.packet_to_flow_match(pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")

    match.mpls_label = label_match_tbl0
    match.mpls_tc = tc_match_tbl0
    match.dl_type = dl_type_match_tbl0
    if ((dl_type_match_tbl0 == ETHERTYPE_MPLS) or
       (dl_type_match_tbl0 == ETHERTYPE_MPLS_MC)):
        match.nw_tos = 0
        match.nw_proto = 0
        match.nw_src = 0
        match.nw_src_mask = 0
        match.nw_dst = 0
        match.nw_dst_mask = 0
        match.tp_src = 0
        match.tp_dst = 0

    inst_1 = instruction.instruction_apply_actions()
    inst_2 = instruction.instruction_goto_table()
    inst_2.table_id = 1
    inst_list = [inst_1, inst_2]
    request0 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port,
                              instruction_list=inst_list,
                              action_list=action_list_tbl0,
                              wildcards=wildcards,
                              match=match,
                              check_expire=check_expire_tbl0,
                              table_id=0)
    testutils.flow_msg_install(parent, request0)

    # Flow Mod for Table1
    match = parse.packet_to_flow_match(exp_pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")

    match.mpls_label = label_match_tbl1
    match.mpls_tc = tc_match_tbl1
    match.dl_type = dl_type_match_tbl1

    if ((dl_type_match_tbl1 == ETHERTYPE_MPLS) or
       (dl_type_match_tbl1 == ETHERTYPE_MPLS_MC)):
        match.nw_tos = 0
        match.nw_proto = 0
        match.nw_src = 0
        match.nw_src_mask = 0
        match.nw_dst = 0
        match.nw_dst_mask = 0
        match.tp_src = 0
        match.tp_dst = 0

    request1 = testutils.flow_msg_create(parent, pkt, ing_port=ing_port,
                              wildcards=wildcards,
                              match=match,
                              check_expire=check_expire_tbl1,
                              table_id=1,
                              egr_port=egr_port)
    testutils.flow_msg_install(parent, request1)

    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..
    if match_exp_tbl0:
        if check_expire_tbl0:
            flow_removed_verify(parent, request0, pkt_count=1,
                                byte_count=pktlen)
    else:
        if exp_msg_tbl0 is ofp.OFPT_FLOW_REMOVED:
            if check_expire_tbl0:
                flow_removed_verify(parent, request0, pkt_count=0,
                                    byte_count=0)
        elif exp_msg_tbl0 is ofp.OFPT_ERROR:
            error_verify(parent, exp_msg_type_tbl0, exp_msg_code_tbl0)
        else:
            parent.assertTrue(0, "Rcv: Unexpected Message: " +
                              str(exp_msg_tbl0))

    if match_exp_tbl1:
        if check_expire_tbl1:
            flow_removed_verify(parent, request1, pkt_count=1,
                                byte_count=exp_pktlen)
    else:
        if exp_msg_tbl1 is ofp.OFPT_FLOW_REMOVED:
            if check_expire_tbl1:
                flow_removed_verify(parent, request1, pkt_count=0,
                                    byte_count=0)
        elif exp_msg_tbl1 is ofp.OFPT_ERROR:
            error_verify(parent, exp_msg_type_tbl1, exp_msg_code_tbl1)
        else:
            parent.assertTrue(0, "Rcv: Unexpected Message: " +
                              str(exp_msg_tbl1))

    # Check pkt
    if match_exp_tbl0 and match_exp_tbl1:
        testutils.receive_pkt_verify(parent, egr_port, exp_pkt)
    else:
        (_, rcv_pkt, _) = parent.dataplane.poll(timeout=1)
        parent.assertFalse(rcv_pkt is not None, "Packet on dataplane")