Example #1
0
def mpls_set_ttl_act_tests(parent):
    """
    Test mpls set_ttl action 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_set_mpls_ttl') == False:
        testutils.skip_message_emit(parent,
            "MPLS set_ttl action test. SET_TTL not supported")
        return

    act = action.action_set_mpls_ttl()

    exp_label = parent.label
    exp_tc = parent.tc

    act.mpls_ttl = parent.ttl + 2
    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
        exp_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 = act.mpls_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,
                    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)
Example #2
0
def mpls_dec_ttl_act_tests(parent):
    """
    Test mpls dec_ttl action 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_dec_mpls_ttl') == False:
        testutils.skip_message_emit(
            parent, "MPLS dec_ttl action test. DEC_TTL not supported")
        return

    act = action.action_dec_mpls_ttl()

    exp_label = parent.label
    exp_tc = parent.tc

    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
        exp_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 = parent.ttl - 1

    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,
                                   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)
Example #3
0
def mpls_push_act_tests(parent):
    """
    Test mpls push action 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 push action test. PUSH not supported")
        return

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

    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]

    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,
                                   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,
                                   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)
Example #4
0
def mpls_push_act_tests(parent):
    """
    Test mpls push action 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 push action test. PUSH not supported")
        return

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

    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]

    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,
                    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,
                    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)
Example #5
0
def mpls_set_tc_act_tests(parent, test_condition=0):
    """
    Test mpls set_tc action 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_set_mpls_tc') == False:
        testutils.skip_message_emit(
            parent, "MPLS set_tc action test. SET_TC not supported")
        return

    #act = action.action_set_mpls_tc()
    act = action.action_set_field()

    exp_label = parent.label
    exp_ttl = parent.ttl

    if test_condition == 0:
        #act.mpls_tc = parent.tc + 2
        act.field = match.mpls_tc(parent.tc + 2)
        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
            exp_tc = parent.tc

        else:
            match_exp = True
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0  #NOT_EXPECTED
            exp_msg_code = 0  #NOT_EXPECTED
            exp_tc = parent.tc + 2

        action_list = [act]

    elif test_condition == 1:
        #act.mpls_tc = 8
        act.field = match.mpls_tc(8)
        match_exp = False
        if parent.num_tags == 0:
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
            exp_tc = parent.tc

        else:
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT
            exp_tc = 8

        action_list = [act]

    else:
        return

    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,
                                   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)
Example #6
0
def mpls_multipush3_act_tests(parent, test_condition=0):
    """
    Test mpls push and set with out-of-range value 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_set_mpls_label') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. SET_LABEL not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_tc') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. SET_TC not supported")
        return

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

    if test_condition == 0:
        #act2 = action.action_set_mpls_label()
        #act2.mpls_label = 1048576
        #exp_label = act2.mpls_label
        act2 = action.action_set_field()
        act2.field = match.mpls_label(1048576)
        exp_label = 1048576
        exp_tc = 0
        exp_ttl = 0  # Not expected

    elif test_condition == 1:
        #act2 = action.action_set_mpls_tc()
        #act2.mpls_tc = 8
        #exp_tc = act2.mpls_tc
        act2 = action.action_set_field()
        act2.field = match.mpls_tc(8)
        exp_tc = 8
        exp_label = 0
        exp_ttl = 0  # Not expected

    else:
        return

    match_exp = False
    exp_msg = ofp.OFPT_ERROR
    exp_msg_type = ofp.OFPET_BAD_ACTION
    exp_msg_code = ofp.OFPBAC_BAD_SET_ARGUMENT

    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,
                                   exp_msg=exp_msg,
                                   exp_msg_type=exp_msg_type,
                                   exp_msg_code=exp_msg_code,
                                   action_list=action_list,
                                   max_test=1)
Example #7
0
def mpls_multipush2_act_tests(parent, test_condition=0):
    """
    Test mpls push and set 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_set_mpls_label') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. SET_LABEL not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_tc') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. SET_TC not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_ttl') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. SET_TTL not supported")
        return
    if sup_mpls_act.has_key('sup_dec_mpls_ttl') == False:
        testutils.skip_message_emit(
            parent, "MPLS multipush action test. DEC_TTL not supported")
        return

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

    if test_condition == 0:
        #act2 = action.action_set_mpls_label()
        #act2.mpls_label = parent.label + 2
        act2 = action.action_set_field()
        act2.field = match.mpls_label(parent.label + 2)
        exp_label = parent.label + 2
        if parent.num_tags == 0:
            exp_tc = 0
            exp_ttl = parent.ip_ttl
        else:
            exp_tc = parent.tc
            exp_ttl = parent.ttl

    elif test_condition == 1:
        #act2 = action.action_set_mpls_tc()
        #act2.mpls_tc = parent.tc + 2
        #exp_tc = act2.mpls_tc
        act2 = action.action_set_field()
        act2.field = match.mpls_tc(parent.tc + 2)
        exp_tc = parent.tc + 2
        if parent.num_tags == 0:
            exp_label = 0
            exp_ttl = parent.ip_ttl
        else:
            exp_label = parent.label
            exp_ttl = parent.ttl

    elif test_condition == 2:
        act2 = action.action_set_mpls_ttl()
        act2.mpls_ttl = parent.ttl + 2
        exp_ttl = act2.mpls_ttl
        if parent.num_tags == 0:
            exp_label = 0
            exp_tc = 0
        else:
            exp_label = parent.label
            exp_tc = parent.tc

    elif test_condition == 3:
        act2 = action.action_dec_mpls_ttl()
        if parent.num_tags == 0:
            exp_ttl = parent.ip_ttl - 1
            exp_label = 0
            exp_tc = 0
        else:
            exp_ttl = parent.ttl - 1
            exp_label = parent.label
            exp_tc = parent.tc

    else:
        return

    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)
Example #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

    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)
Example #9
0
def mpls_none_tests(parent, mpls_label_mask=False, mpls_tc_mask=False,
                    test_condition=0, tag_mpls=0):
    """
    MPLS match test when matching type is not MPLS

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param mpls_label_mask If True, MPLS LABEL is wildcarded
    @param mpls_tc_mask If True, MPLS TC is wildcarded
    @param test_condition Value between 0 and 2
    """
    wildcards = 0
    if mpls_label_mask == True:
        wildcards = 1<< ofp.OFPXMT_OFB_MPLS_LABEL
    if mpls_tc_mask == True:
        wildcards = wildcards + (1 << ofp.OFPXMT_OFB_MPLS_TC)
    #print(wildcards)
    
    dl_type_match = ETHERTYPE_IP
    label_match = random.randint(16,1048574)
    tc = random.randint(0, 7)
    ttl = 128

    exp_msg = ofp.OFPT_FLOW_REMOVED
    exp_msg_type = 0 #NOT_EXPECTED
    exp_msg_code = 0 #NOT_EXPECTED

    if test_condition == 0:
        label = -1
        tc_match = tc
        match_exp = True

    elif test_condition == 1:
        label = label_match + 1 # unmatching value
        tc_match = 7 - tc # unmatching value
        match_exp = False

    elif test_condition == 2:
        label = label_match + 1 # unmatching value
        tc_match = tc
        match_exp = False

    else:
        return

    if match_exp == True:
        #MPLS tag Not Expected
        exp_label = -1
        exp_tc = 0
        exp_ttl = 0
    else:
        #PKT Not Expected
        exp_label = 0
        exp_tc = 0
        exp_ttl = 0
    #print(tc)
    #print(tc_match)
    testutils.flow_match_test_mpls(parent, pa_port_map,
                wildcards=wildcards,
                mpls_label=label,
                mpls_tc=tc,
                mpls_ttl=ttl,
                mpls_label_int=-1,
                mpls_tc_int=0,
                label_match=label_match,
                tc_match=tc_match,
                dl_type_match=dl_type_match,
                exp_mpls_label=exp_label,
                exp_mpls_tc=exp_tc,
                exp_mpls_ttl=exp_ttl,
                match_exp=match_exp,
                exp_msg=exp_msg,
                exp_msg_type=exp_msg_type,
                exp_msg_code=exp_msg_code,
                max_test=1,tag_mpls=tag_mpls)
Example #10
0
def mpls_outrange_tests(parent, mpls_label_mask=False, mpls_tc_mask=False,
                        test_condition=0):
    """
    MPLS match test with out-of-range matching value, expecting an error

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param mpls_label_mask If True, MPLS LABEL is wildcarded
    @param mpls_tc_mask If True, MPLS TC is wildcarded
    @param test_condition Value between 0 and 4
    """
    wildcards = 0
    if mpls_label_mask == True:
        wildcards = 1<< ofp.OFPXMT_OFB_MPLS_LABEL
    if mpls_tc_mask == True:
        wildcards = wildcards + (1<< ofp.OFPXMT_OFB_MPLS_TC)

    label = random.randint(16, 1048575)
    tc = random.randint(0, 7)
    ttl = 128

    if test_condition == 2:
        label_match = label + 1048576  #out of range
        tc_match = tc
        if mpls_label_mask == True:
            match_exp = True
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0 #NOT EXPECTED
            exp_msg_code = 0 #NOT EXPECTED
        else:
            match_exp = False
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_MATCH
            exp_msg_code = ofp.OFPBMC_BAD_VALUE

    elif test_condition == 3:
        label_match = label
        tc_match = tc + 8  #out of range
        if mpls_tc_mask == True:
            match_exp = True
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0 #NOT EXPECTED
            exp_msg_code = 0 #NOT EXPECTED
        else:
            match_exp = False
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_MATCH
            exp_msg_code = ofp.OFPBMC_BAD_VALUE

    elif test_condition == 4:
        label_match = label + 1048576  #out of range
        tc_match = tc + 8  #out of range
        if (mpls_label_mask == True) and (mpls_tc_mask == True):
            match_exp = True
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0 #NOT EXPECTED
            exp_msg_code = 0 #NOT EXPECTED
        else:
            match_exp = False
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_MATCH
            exp_msg_code = ofp.OFPBMC_BAD_VALUE

    else:
        return

    if match_exp == True:
        exp_label = label
        exp_tc = tc
        exp_ttl = ttl
    else:
        exp_label = 0 #NOT EXPECTED
        exp_tc = 0 #NOT EXPECTED
        exp_ttl = 0 #NOT EXPECTED

    testutils.flow_match_test_mpls(parent, pa_port_map,
                wildcards=wildcards,
                mpls_label=label,
                mpls_tc=tc,
                mpls_ttl=ttl,
                mpls_label_int=-1,
                mpls_tc_int=0,
                label_match=label_match,
                tc_match=tc_match,
                exp_mpls_label=exp_label,
                exp_mpls_tc=exp_tc,
                exp_mpls_ttl=exp_ttl,
                match_exp=match_exp,
                exp_msg=exp_msg,
                exp_msg_type=exp_msg_type,
                exp_msg_code=exp_msg_code,
                max_test=1)
Example #11
0
def mpls_specific_tests(parent, mpls_label_mask=False, mpls_tc_mask=False,
                        test_condition=0, tag_mpls=0):
    """
    MPLS match test with specific matching value

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param mpls_label_mask If True, MPLS LABEL is wildcarded
    @param mpls_tc_mask If True, MPLS TC is wildcarded
    @param test_condition Value between 0 and 5
    """
    wildcards = 0
    if mpls_label_mask == True:
        #wildcards = ofp.OFPFW_MPLS_LABEL  OFPXMT_OFB_MPLS_LABEL
        wildcards = 1 << ofp.OFPXMT_OFB_MPLS_LABEL
    if mpls_tc_mask == True:
        #wildcards = wildcards + ofp.OFPFW_MPLS_TC
        wildcards = wildcards + (1 << ofp.OFPXMT_OFB_MPLS_TC)
        
    #print(hex(wildcards))

    ttl = 128
    label_match = random.randint(16, 1048575)
    tc_match = random.randint(0, 6)

    exp_msg = ofp.OFPT_FLOW_REMOVED
    exp_msg_type = 0 #NOT_EXPECTED
    exp_msg_code = 0 #NOT_EXPECTED

    label_int = -1
    tc_int = 0
    ttl_int = 0

    if test_condition == 0:
        label = -1
        tc = 0
        match_exp = False

    elif test_condition == 1:
        label = label_match
        tc = tc_match
        match_exp = True

    elif test_condition == 2:
        label = label_match
        tc = tc_match + 1
        if mpls_tc_mask == True:
            match_exp = True
        else:
            match_exp = False

    elif test_condition == 3:
        label = label_match + 1
        tc = tc_match
        if mpls_label_mask == True:
            match_exp = True
        else:
            match_exp = False

    elif test_condition == 4:
        label = label_match
        tc = tc_match
        label_int = label_match + 1
        tc_int = tc_match + 1
        ttl_int = ttl + 1
        match_exp = True

    elif test_condition == 5:
        label = label_match + 1
        tc = tc_match + 1
        if (mpls_label_mask == True) and (mpls_tc_mask == True):
            match_exp = True
        else:
            match_exp = False

    else:
        return

    if match_exp == True:
        exp_label = label
        exp_tc = tc
        exp_ttl = ttl
        exp_ttl_int = ttl_int
    else:
        exp_label = 0 #NOT_EXPECTED
        exp_tc = 0 #NOT_EXPECTED
        exp_ttl = 0 #NOT_EXPECTED
        exp_ttl_int = 0 #NOT_EXPECTED

    testutils.flow_match_test_mpls(parent, pa_port_map,
                wildcards=wildcards,
                mpls_label=label,
                mpls_tc=tc,
                mpls_ttl=ttl,
                mpls_label_int=label_int,
                mpls_tc_int=tc_int,
                mpls_ttl_int=ttl_int,
                label_match=label_match,
                tc_match=tc_match,
                exp_mpls_label=exp_label,
                exp_mpls_tc=exp_tc,
                exp_mpls_ttl=exp_ttl,
                exp_mpls_ttl_int=exp_ttl_int,
                match_exp=match_exp,
                exp_msg=exp_msg,
                exp_msg_type=exp_msg_type,
                exp_msg_code=exp_msg_code,
                max_test=1,tag_mpls=tag_mpls)
Example #12
0
def mpls_multipush3_act_tests(parent, test_condition=0):
    """
    Test mpls push and set with out-of-range value 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_set_mpls_label') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. SET_LABEL not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_tc') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. SET_TC not supported")
        return

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

    if test_condition == 0:
        act2 = action.action_set_mpls_label()
        act2.mpls_label = 1048576
        exp_label = act2.mpls_label
        exp_tc = 0
        exp_ttl = 0 # Not expected

    elif test_condition == 1:
        act2 = action.action_set_mpls_tc()
        act2.mpls_tc = 8
        exp_tc = act2.mpls_tc
        exp_label = 0
        exp_ttl = 0 # Not expected

    else:
        return

    match_exp = False
    exp_msg = ofp.OFPT_ERROR
    exp_msg_type = ofp.OFPET_BAD_ACTION
    exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    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,
                exp_msg=exp_msg,
                exp_msg_type=exp_msg_type,
                exp_msg_code=exp_msg_code,
                action_list=action_list,
                max_test=1)
Example #13
0
def mpls_multipush2_act_tests(parent, test_condition=0):
    """
    Test mpls push and set 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_set_mpls_label') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. SET_LABEL not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_tc') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. SET_TC not supported")
        return
    if sup_mpls_act.has_key('sup_set_mpls_ttl') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. SET_TTL not supported")
        return
    if sup_mpls_act.has_key('sup_dec_mpls_ttl') == False:
        testutils.skip_message_emit(parent,
            "MPLS multipush action test. DEC_TTL not supported")
        return

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

    if test_condition == 0:
        act2 = action.action_set_mpls_label()
        act2.mpls_label = parent.label + 2
        exp_label = act2.mpls_label
        if parent.num_tags == 0:
            exp_tc = 0
            exp_ttl = parent.ip_ttl
        else:
            exp_tc = parent.tc
            exp_ttl = parent.ttl

    elif test_condition == 1:
        act2 = action.action_set_mpls_tc()
        act2.mpls_tc = parent.tc + 2
        exp_tc = act2.mpls_tc
        if parent.num_tags == 0:
            exp_label = 0
            exp_ttl = parent.ip_ttl
        else:
            exp_label = parent.label
            exp_ttl = parent.ttl

    elif test_condition == 2:
        act2 = action.action_set_mpls_ttl()
        act2.mpls_ttl = parent.ttl + 2
        exp_ttl = act2.mpls_ttl
        if parent.num_tags == 0:
            exp_label = 0
            exp_tc = 0
        else:
            exp_label = parent.label
            exp_tc = parent.tc

    elif test_condition == 3:
        act2 = action.action_dec_mpls_ttl()
        if parent.num_tags == 0:
            exp_ttl = parent.ip_ttl - 1
            exp_label = 0
            exp_tc = 0
        else:
            exp_ttl = parent.ttl - 1
            exp_label = parent.label
            exp_tc = parent.tc

    else:
        return

    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)
Example #14
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)