def mpls_ttl_inout_two_tables_tests(parent, test_inwards=True):
    """
    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    wildcards = 0
    label = random.randint(16, 1048574)
    tc = random.randint(0, 6)
    ttl = 64
    ip_ttl = 192

    # Match condition on TBL0 (match)
    label_match_tbl0 = label
    tc_match_tbl0 = tc
    dl_type_match_tbl0 = ETHERTYPE_MPLS

    exp_label = label
    exp_tc = tc
    # Copy TTL inwards
    if (test_inwards):
        exp_ttl = ttl
        exp_ip_ttl = ttl
        # Create action_list for TBL0
        act = action.action_copy_ttl_in()
    # Copy TTL outwards
    else:
        exp_ttl = ip_ttl
        exp_ip_ttl = ip_ttl
        # Create action_list for TBL0
        act = action.action_copy_ttl_out()
    action_list_tbl0 = [act]

    # Expect modified pkt on TBL1 (match)
    label_match_tbl1 = exp_label
    tc_match_tbl1 = exp_tc
    dl_type_match_tbl1 = ETHERTYPE_MPLS

    # Output action for table1 will be set in the framework

    flow_match_test_mpls_two_tables(parent,
                                    pa_port_map,
                                    wildcards=wildcards,
                                    mpls_label=label,
                                    mpls_tc=tc,
                                    mpls_ttl=ttl,
                                    ip_ttl=ip_ttl,
                                    label_match_tbl0=label_match_tbl0,
                                    tc_match_tbl0=tc_match_tbl0,
                                    dl_type_match_tbl0=dl_type_match_tbl0,
                                    action_list_tbl0=action_list_tbl0,
                                    match_exp_tbl0=True,
                                    label_match_tbl1=label_match_tbl1,
                                    tc_match_tbl1=tc_match_tbl1,
                                    dl_type_match_tbl1=dl_type_match_tbl1,
                                    match_exp_tbl1=True,
                                    exp_mpls_label=exp_label,
                                    exp_mpls_tc=exp_tc,
                                    exp_mpls_ttl=exp_ttl,
                                    exp_ip_ttl=exp_ip_ttl,
                                    max_test=1)
    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
        pkt = testutils.simple_tcp_packet_w_mpls(mpls_label=mpls_label,
                                                 mpls_tc=mpls_tc,
                                                 mpls_ttl=mpls_ttl)

        match = parse.packet_to_flow_match(pkt)
        wildcards = 0

        exp_pkt = testutils.simple_tcp_packet_w_mpls(ip_ttl=mpls_ttl-1)

        # 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_dec_nw_ttl()
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

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

        #Table 3
        act = action.action_copy_ttl_in()
        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)
def mpls_ttl_inout_two_tables_tests(parent, test_inwards=True):
    """
    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    wildcards = 0
    label = random.randint(16, 1048574)
    tc = random.randint(0, 6)
    ttl = 64
    ip_ttl = 192

    # Match condition on TBL0 (match)
    label_match_tbl0 = label
    tc_match_tbl0 = tc
    dl_type_match_tbl0 = ETHERTYPE_MPLS

    exp_label = label
    exp_tc = tc
    # Copy TTL inwards
    if (test_inwards):
        exp_ttl= ttl
        exp_ip_ttl=ttl
        # Create action_list for TBL0
        act = action.action_copy_ttl_in()
    # Copy TTL outwards
    else:
        exp_ttl= ip_ttl
        exp_ip_ttl=ip_ttl
        # Create action_list for TBL0
        act = action.action_copy_ttl_out()
    action_list_tbl0 = [act]

    # Expect modified pkt on TBL1 (match)
    label_match_tbl1 = exp_label
    tc_match_tbl1 = exp_tc
    dl_type_match_tbl1 = ETHERTYPE_MPLS

    # Output action for table1 will be set in the framework

    flow_match_test_mpls_two_tables(parent, pa_port_map,
                    wildcards=wildcards,
                    mpls_label=label,
                    mpls_tc=tc,
                    mpls_ttl=ttl,
                    ip_ttl=ip_ttl,
                    label_match_tbl0=label_match_tbl0,
                    tc_match_tbl0=tc_match_tbl0,
                    dl_type_match_tbl0=dl_type_match_tbl0,
                    action_list_tbl0 = action_list_tbl0,
                    match_exp_tbl0=True,
                    label_match_tbl1=label_match_tbl1,
                    tc_match_tbl1=tc_match_tbl1,
                    dl_type_match_tbl1=dl_type_match_tbl1,
                    match_exp_tbl1=True,
                    exp_mpls_label=exp_label,
                    exp_mpls_tc=exp_tc,
                    exp_mpls_ttl=exp_ttl,
                    exp_ip_ttl=exp_ip_ttl,
                    max_test=1)
    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

        exp_pkt = testutils.simple_tcp_packet_w_mpls(pktlen=pktlen,
                                                     mpls_label=mpls_label,
                                                     mpls_tc=mpls_tc,
                                                     mpls_ttl=mpls_ttl-1,
                                                     ip_ttl=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_dec_mpls_ttl()
        act_list.append([act])
        next_avail.append(True)
        chk_expire.append(False)

        #Table 2
        act = action.action_copy_ttl_in()
        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)
Exemple #5
0
def mpls_ttl_in_act_tests(parent):
    """
    Test mpls ttl_in action for the packets with/without tags
    It tests if outermost TTL value has been copied to the next outermost TTL

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)),
                      "Parameter num_tags not within an acceptable range")

    sup_mpls_act = mpls_action_support_check(parent)

    if sup_mpls_act.has_key('sup_copy_ttl_in') == False:
        testutils.skip_message_emit(
            parent, "MPLS copy_ttl_in action test. TTL_IN not supported")
        return

    act = action.action_copy_ttl_in()

    exp_label = parent.label
    exp_tc = parent.tc
    exp_ttl = parent.ttl
    exp_ttl_int = parent.ttl_int
    exp_ip_ttl = parent.ip_ttl

    if parent.num_tags == 0:
        match_exp = False
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT

    elif parent.num_tags == 1:
        match_exp = True
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED
        exp_ip_ttl = parent.ttl

    else:
        match_exp = True
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED
        exp_ttl_int = parent.ttl

    action_list = [act]

    testutils.flow_match_test_mpls(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   mpls_label=parent.label,
                                   mpls_tc=parent.tc,
                                   mpls_ttl=parent.ttl,
                                   mpls_label_int=parent.label_int,
                                   mpls_tc_int=parent.tc_int,
                                   mpls_ttl_int=parent.ttl_int,
                                   ip_ttl=parent.ip_ttl,
                                   label_match=parent.label_match,
                                   tc_match=parent.tc_match,
                                   dl_type_match=parent.dl_type_match,
                                   exp_mpls_label=exp_label,
                                   exp_mpls_tc=exp_tc,
                                   exp_mpls_ttl=exp_ttl,
                                   exp_mpls_ttl_int=exp_ttl_int,
                                   exp_ip_ttl=exp_ip_ttl,
                                   match_exp=match_exp,
                                   exp_msg=exp_msg,
                                   exp_msg_type=exp_msg_type,
                                   exp_msg_code=exp_msg_code,
                                   action_list=action_list,
                                   max_test=1)
Exemple #6
0
def mpls_multipush1_act_tests(parent, test_condition=0):
    """
    Test mpls push and copy actions for the packets with/without tags

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)),
                      "Parameter num_tags not within an acceptable range")

    sup_mpls_act = mpls_action_support_check(parent)

    if sup_mpls_act.has_key('sup_push_mpls') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. PUSH not supported")
        return
    if sup_mpls_act.has_key('sup_copy_ttl_in') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. TTL_IN not supported")
        return
    if sup_mpls_act.has_key('sup_copy_ttl_out') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. TTL_OUT not supported")
        return

    act = action.action_push_mpls()
    act.ethertype = 0x8847

    exp_mpls_ttl_int = 32
    exp_ip_ttl = parent.ip_ttl

    if test_condition == 0:
        act2 = action.action_copy_ttl_in()
        if parent.num_tags == 1:
            exp_ip_ttl = parent.ttl
        elif parent.num_tags == 2:
            exp_mpls_ttl_int = parent.ttl  #copy the outmost ttl to the second ttl
        else:
            return

    elif test_condition == 1:
        act2 = action.action_copy_ttl_out()

    else:
        return

    if parent.num_tags == 0:
        exp_label = 0
        exp_tc = 0
        exp_ttl = parent.ip_ttl
    else:
        exp_label = parent.label
        exp_tc = parent.tc
        exp_ttl = parent.ttl

    match_exp = True
    add_tag_exp = parent.num_tags > 0
    exp_msg = ofp.OFPT_FLOW_REMOVED
    exp_msg_type = 0  #NOT_EXPECTED
    exp_msg_code = 0  #NOT_EXPECTED

    action_list = [act, act2]

    testutils.flow_match_test_mpls(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   mpls_label=parent.label,
                                   mpls_tc=parent.tc,
                                   mpls_label_int=parent.label_int,
                                   mpls_tc_int=parent.tc_int,
                                   label_match=parent.label_match,
                                   tc_match=parent.tc_match,
                                   dl_type_match=parent.dl_type_match,
                                   exp_mpls_label=exp_label,
                                   exp_mpls_tc=exp_tc,
                                   exp_mpls_ttl=exp_ttl,
                                   exp_mpls_ttl_int=exp_mpls_ttl_int,
                                   exp_ip_ttl=exp_ip_ttl,
                                   match_exp=match_exp,
                                   add_tag_exp=add_tag_exp,
                                   exp_msg=exp_msg,
                                   exp_msg_type=exp_msg_type,
                                   exp_msg_code=exp_msg_code,
                                   action_list=action_list,
                                   max_test=1)
Exemple #7
0
def mpls_ttl_in_act_tests(parent):
    """
    Test mpls ttl_in action for the packets with/without tags
    It tests if outermost TTL value has been copied to the next outermost TTL

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)),
        "Parameter num_tags not within an acceptable range")

    sup_mpls_act = mpls_action_support_check(parent)

    if sup_mpls_act.has_key('sup_copy_ttl_in') == False:
        testutils.skip_message_emit(parent,
            "MPLS copy_ttl_in action test. TTL_IN not supported")
        return

    act = action.action_copy_ttl_in()

    exp_label = parent.label
    exp_tc = parent.tc
    exp_ttl = parent.ttl
    exp_ttl_int = parent.ttl_int
    exp_ip_ttl = parent.ip_ttl

    if parent.num_tags == 0:
        match_exp = False
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
        
    elif parent.num_tags == 1:
        match_exp = True
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0 #NOT_EXPECTED
        exp_msg_code = 0 #NOT_EXPECTED
        exp_ip_ttl = parent.ttl

    else:
        match_exp = True
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0 #NOT_EXPECTED
        exp_msg_code = 0 #NOT_EXPECTED
        exp_ttl_int = parent.ttl

    action_list=[act]

    testutils.flow_match_test_mpls(parent, pa_port_map,
                    wildcards=0,
                    mpls_label=parent.label,
                    mpls_tc=parent.tc,
                    mpls_ttl=parent.ttl,
                    mpls_label_int=parent.label_int,
                    mpls_tc_int=parent.tc_int,
                    mpls_ttl_int=parent.ttl_int,
                    ip_ttl=parent.ip_ttl,
                    label_match=parent.label_match,
                    tc_match=parent.tc_match,
                    dl_type_match=parent.dl_type_match,
                    exp_mpls_label=exp_label,
                    exp_mpls_tc=exp_tc,
                    exp_mpls_ttl=exp_ttl,
                    exp_mpls_ttl_int=exp_ttl_int,
                    exp_ip_ttl=exp_ip_ttl,
                    match_exp=match_exp,
                    exp_msg=exp_msg,
                    exp_msg_type=exp_msg_type,
                    exp_msg_code=exp_msg_code,
                    action_list=action_list,
                    max_test=1)
Exemple #8
0
def mpls_multipush1_act_tests(parent, test_condition=0):
    """
    Test mpls push and copy actions for the packets with/without tags

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    """
    parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)),
        "Parameter num_tags not within an acceptable range")

    sup_mpls_act = mpls_action_support_check(parent)

    if sup_mpls_act.has_key('sup_push_mpls') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. PUSH not supported")
        return
    if sup_mpls_act.has_key('sup_copy_ttl_in') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. TTL_IN not supported")
        return
    if sup_mpls_act.has_key('sup_copy_ttl_out') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. TTL_OUT not supported")
        return

    act = action.action_push_mpls()
    act.ethertype = 0x8847

    if test_condition == 0:
        act2 = action.action_copy_ttl_in()

    elif test_condition == 1:
        act2 = action.action_copy_ttl_out()

    else:
        return

    if parent.num_tags == 0:
        exp_label = 0
        exp_tc = 0
        exp_ttl = parent.ip_ttl
    else:
        exp_label = parent.label
        exp_tc = parent.tc
        exp_ttl = parent.ttl

    match_exp = True
    add_tag_exp = parent.num_tags > 0
    exp_msg = ofp.OFPT_FLOW_REMOVED
    exp_msg_type = 0 #NOT_EXPECTED
    exp_msg_code = 0 #NOT_EXPECTED

    action_list=[act, act2]

    testutils.flow_match_test_mpls(parent, pa_port_map,
                wildcards=0,
                mpls_label=parent.label,
                mpls_tc=parent.tc,
                mpls_label_int=parent.label_int,
                mpls_tc_int=parent.tc_int,
                label_match=parent.label_match,
                tc_match=parent.tc_match,
                dl_type_match=parent.dl_type_match,
                exp_mpls_label=exp_label,
                exp_mpls_tc=exp_tc,
                exp_mpls_ttl=exp_ttl,
                match_exp=match_exp,
                add_tag_exp=add_tag_exp,
                exp_msg=exp_msg,
                exp_msg_type=exp_msg_type,
                exp_msg_code=exp_msg_code,
                action_list=action_list,
                max_test=1)