Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 5
0
    def runTest(self):
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_SET_NW_TOS):
            testutils.skip_message_emit(self, "ModifyTOS test")
            return

        (pkt, exp_pkt, acts) = testutils.pkt_action_setup(self, mod_fields=['ip_tos'],
                                                check_test_params=True)
        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt, 
                        apply_action_list=acts, max_test=2)
Exemplo n.º 6
0
    def runTest(self):
        old_vid = 2
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_POP_VLAN):
            testutils.skip_message_emit(self, "Strip VLAN tag test")
            return

        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet()
        vid_act = action.action_pop_vlan()

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 7
0
    def runTest(self):
        old_vid = 2
        new_vid = 3
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_SET_VLAN_VID):
            testutils.skip_message_emit(self, "Modify VLAN tag test")
            return

        pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': old_vid}])
        exp_pkt = testutils.simple_tcp_packet(vlan_tags=[{'vid': new_vid}])
        vid_act = action.action_set_vlan_vid()
        vid_act.vlan_vid = new_vid

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 8
0
    def runTest(self):
        old_vid = 2
        sup_acts = supported_actions_get(self)
        if not (sup_acts & 1 << ofp.OFPAT_POP_VLAN):
            testutils.skip_message_emit(self, "Strip VLAN tag test")
            return

        len_w_vid = 104
        len = 100
        pkt = testutils.simple_tcp_packet(pktlen=len_w_vid, dl_vlan_enable=True, 
                                dl_vlan=old_vid)
        exp_pkt = testutils.simple_tcp_packet(pktlen=len)
        vid_act = action.action_pop_vlan()

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, exp_pkt=exp_pkt,
                        apply_action_list=[vid_act])
Exemplo n.º 9
0
    def runTest(self):
        new_vid = 4002
        sup_acts = supported_actions_get(self)
        if not(sup_acts & 1<<ofp.OFPAT_SET_VLAN_VID):
            testutils.skip_message_emit(self, "Add VLAN tag test")
            return

        pkt = testutils.simple_tcp_packet()
        exp_pkt = testutils.simple_tcp_packet(
                                    vlan_tags=[{'vid': new_vid}])
        push_act = action.action_push_vlan()
        push_act.ethertype = 0x8100
        

        vid_act = action.action_set_vlan_vid()
        vid_act.vlan_vid = new_vid

        testutils.flow_match_test(self, pa_port_map, pkt=pkt, 
                        exp_pkt=exp_pkt, apply_action_list=[push_act, vid_act])
Exemplo n.º 10
0
def vlan_pop_act_tests(parent):
    """
    Test vlan pop 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_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = \
        vlan_action_support_check(parent)

    if sup_pop_vlan == False:
        testutils.skip_message_emit(parent,
                                    "Vlan pop action test. POP not supported")
        return

    act = action.action_pop_vlan()
    exp_vlan_type = ETHERTYPE_VLAN

    if parent.num_tags == 0:
        match_exp = False
        exp_vid = parent.vid
        exp_pcp = parent.pcp

        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_vid = -1
        exp_pcp = 0

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

    else:
        match_exp = True
        exp_vid = -1
        exp_pcp = 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_vlan(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   dl_vlan=parent.vid,
                                   dl_vlan_pcp=parent.pcp,
                                   dl_vlan_type=parent.vlan_type,
                                   dl_vlan_int=parent.vid_2nd,
                                   dl_vlan_pcp_int=parent.pcp_2nd,
                                   vid_match=parent.vid_match,
                                   pcp_match=parent.pcp_match,
                                   exp_vid=exp_vid,
                                   exp_pcp=exp_pcp,
                                   exp_vlan_type=exp_vlan_type,
                                   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)
Exemplo n.º 11
0
def vlan_multipush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(parent, "Vlan multiple push action test. PUSH not supported")
        return
    if sup_pop_vlan == False:
        testutils.skip_message_emit(parent, "Vlan multiple push action test. POP not supported")
        return
    if sup_set_vlan_vid == False:
        testutils.skip_message_emit(parent, "Vlan multiple push action test. SET VLAN VID not supported")
        return
    if sup_set_vlan_pcp == False:
        testutils.skip_message_emit(parent, "Vlan multiple push action test. SET VLAN PCP not supported")
        return

    new_vid = parent.vid + 2
    new_pcp = parent.pcp + 2

    act = action.action_push_vlan()
    act.ethertype = ETHERTYPE_VLAN

    act3 = None
    if test_condition == 0:
        act2 = action.action_set_vlan_vid()
        act2.vlan_vid = new_vid
        add_tag_exp = True
        exp_vid = new_vid
        exp_vlan_type = act.ethertype
        if parent.num_tags == 0:
            exp_pcp = 0
        else:
            exp_pcp = parent.pcp

    elif test_condition == 1:
        act2 = action.action_set_vlan_pcp()
        act2.vlan_pcp = new_pcp
        add_tag_exp = True
        exp_pcp = new_pcp
        exp_vlan_type = act.ethertype
        if parent.num_tags == 0:
            exp_vid = 0
        else:
            exp_vid = parent.vid

    elif test_condition == 2:
        act2 = action.action_set_vlan_vid()
        act2.vlan_vid = new_vid
        act3 = action.action_set_vlan_pcp()
        act3.vlan_pcp = new_pcp
        add_tag_exp = True
        exp_vid = new_vid
        exp_pcp = new_pcp
        exp_vlan_type = act.ethertype

    elif test_condition == 3:
        act2 = action.action_pop_vlan()
        add_tag_exp = False
        exp_vid = parent.vid
        exp_pcp = parent.pcp
        exp_vlan_type = parent.vlan_type

    else:
        return

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

    action_list = [act, act2]
    if act3 is not None:
        action_list.append(act3)

    testutils.flow_match_test_vlan(
        parent,
        pa_port_map,
        wildcards=0,
        dl_vlan=parent.vid,
        dl_vlan_pcp=parent.pcp,
        dl_vlan_type=parent.vlan_type,
        dl_vlan_int=parent.vid_2nd,
        dl_vlan_pcp_int=parent.pcp_2nd,
        vid_match=parent.vid_match,
        pcp_match=parent.pcp_match,
        exp_vid=exp_vid,
        exp_pcp=exp_pcp,
        exp_vlan_type=exp_vlan_type,
        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,
    )
Exemplo n.º 12
0
def vlan_singlepush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(parent, "Vlan single push action test. SET VLAN VID not supported")
        return

    if test_condition == 0:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 0
            exp_pcp = 0
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  # NOT_EXPECTED
        exp_msg_code = 0  # NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN_PBB
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 0
            exp_pcp = 0
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  # NOT_EXPECTED
        exp_msg_code = 0  # NOT_EXPECTED

    elif test_condition == 2:
        act = action.action_push_vlan()
        act.ethertype = 0xAAA  # Other than 0x8100 and 0x88a8
        match_exp = False
        add_tag_exp = False
        exp_vid = 0
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    action_list = [act]

    testutils.flow_match_test_vlan(
        parent,
        pa_port_map,
        wildcards=0,
        dl_vlan=parent.vid,
        dl_vlan_pcp=parent.pcp,
        dl_vlan_type=parent.vlan_type,
        dl_vlan_int=parent.vid_2nd,
        dl_vlan_pcp_int=parent.pcp_2nd,
        vid_match=parent.vid_match,
        pcp_match=parent.pcp_match,
        exp_vid=exp_vid,
        exp_pcp=exp_pcp,
        exp_vlan_type=act.ethertype,
        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,
    )
Exemplo n.º 13
0
def vlan_set_act_tests(parent, test_condition=0):
    """
    Test vlan set_vid and set_pcp action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = vlan_action_support_check(parent)

    new_vid = parent.vid + 2
    new_pcp = parent.pcp + 2

    if sup_set_vlan_vid == False:
        testutils.skip_message_emit(parent, "Vlan set action test. SET VLAN VID not supported")
        return
    if sup_set_vlan_pcp == False:
        testutils.skip_message_emit(parent, "Vlan set action test. SET VLAN PCP not supported")
        return

    exp_vlan_type = parent.vlan_type

    if test_condition == 0:
        act = action.action_set_vlan_vid()
        act.vlan_vid = new_vid
        if parent.num_tags == 0:
            match_exp = False
            exp_vid = -1
            exp_pcp = 0
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
        else:
            match_exp = True
            exp_vid = new_vid
            exp_pcp = parent.pcp
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0  # NOT_EXPECTED
            exp_msg_code = 0  # NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_set_vlan_vid()
        act.vlan_vid = 4096  # OUT OF RANGE
        match_exp = False
        exp_vid = -1
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    elif test_condition == 2:
        act = action.action_set_vlan_pcp()
        act.vlan_pcp = new_pcp
        if parent.num_tags == 0:
            match_exp = False
            exp_vid = -1
            exp_pcp = 0
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
        else:
            match_exp = True
            exp_vid = parent.vid
            exp_pcp = new_pcp
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0  # NOT_EXPECTED
            exp_msg_code = 0  # NOT_EXPECTED

    elif test_condition == 3:
        act = action.action_set_vlan_pcp()
        act.vlan_pcp = 8  # OUT OF RANGE
        match_exp = False
        exp_vid = -1
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    action_list = [act]

    testutils.flow_match_test_vlan(
        parent,
        pa_port_map,
        wildcards=0,
        dl_vlan=parent.vid,
        dl_vlan_pcp=parent.pcp,
        dl_vlan_type=parent.vlan_type,
        dl_vlan_int=parent.vid_2nd,
        dl_vlan_pcp_int=parent.pcp_2nd,
        vid_match=parent.vid_match,
        pcp_match=parent.pcp_match,
        exp_vid=exp_vid,
        exp_pcp=exp_pcp,
        exp_vlan_type=exp_vlan_type,
        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,
    )
Exemplo n.º 14
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)
Exemplo n.º 15
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")
Exemplo n.º 16
0
def vlan_multipush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = \
        vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(
            parent, "Vlan multiple push action test. PUSH not supported")
        return
    if sup_pop_vlan == False:
        testutils.skip_message_emit(
            parent, "Vlan multiple push action test. POP not supported")
        return
    if sup_set_vlan_vid == False:
        testutils.skip_message_emit(
            parent,
            "Vlan multiple push action test. SET VLAN VID not supported")
        return
    if sup_set_vlan_pcp == False:
        testutils.skip_message_emit(
            parent,
            "Vlan multiple push action test. SET VLAN PCP not supported")
        return

    new_vid = parent.vid + 2
    new_pcp = parent.pcp + 2

    act = action.action_push_vlan()
    act.ethertype = ETHERTYPE_VLAN

    act3 = None
    if test_condition == 0:
        act2 = action.action_set_vlan_vid()
        act2.vlan_vid = new_vid
        add_tag_exp = True
        exp_vid = new_vid
        exp_vlan_type = act.ethertype
        if parent.num_tags == 0:
            exp_pcp = 0
        else:
            exp_pcp = parent.pcp

    elif test_condition == 1:
        act2 = action.action_set_vlan_pcp()
        act2.vlan_pcp = new_pcp
        add_tag_exp = True
        exp_pcp = new_pcp
        exp_vlan_type = act.ethertype
        if parent.num_tags == 0:
            exp_vid = 0
        else:
            exp_vid = parent.vid

    elif test_condition == 2:
        act2 = action.action_set_vlan_vid()
        act2.vlan_vid = new_vid
        act3 = action.action_set_vlan_pcp()
        act3.vlan_pcp = new_pcp
        add_tag_exp = True
        exp_vid = new_vid
        exp_pcp = new_pcp
        exp_vlan_type = act.ethertype

    elif test_condition == 3:
        act2 = action.action_pop_vlan()
        add_tag_exp = False
        exp_vid = parent.vid
        exp_pcp = parent.pcp
        exp_vlan_type = parent.vlan_type

    else:
        return

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

    action_list = [act, act2]
    if act3 is not None:
        action_list.append(act3)

    testutils.flow_match_test_vlan(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   dl_vlan=parent.vid,
                                   dl_vlan_pcp=parent.pcp,
                                   dl_vlan_type=parent.vlan_type,
                                   dl_vlan_int=parent.vid_2nd,
                                   dl_vlan_pcp_int=parent.pcp_2nd,
                                   vid_match=parent.vid_match,
                                   pcp_match=parent.pcp_match,
                                   exp_vid=exp_vid,
                                   exp_pcp=exp_pcp,
                                   exp_vlan_type=exp_vlan_type,
                                   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)
Exemplo n.º 17
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)
Exemplo n.º 18
0
 def runTest(self):
     testutils.skip_message_emit(self, 'skip!')
     return
Exemplo n.º 19
0
def vlan_singlepush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param test_condition Value between 0 and 2
    """
    parent.assertTrue(((parent.num_tags>=0) and (parent.num_tags<=2)),
        "Parameter num_tags not within an acceptable range")
    #print("parent vid="+str(parent.vid))
    #print("parent pcp="+str(parent.pcp))
    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True)
    #    vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(parent,
            "Vlan single push action test. SET VLAN VID not supported")
        return

    if test_condition == 0:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 1
            exp_pcp = 0
            vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = 1
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
            vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = parent.vid
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0 #NOT_EXPECTED
        exp_msg_code = 0 #NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN_PBB
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 1
            exp_pcp = 0
            vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = 1
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
            vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = parent.vid
#        parent.vid_2nd = parent.vid
#        parent.pcp_2nd = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0 #NOT_EXPECTED
        exp_msg_code = 0 #NOT_EXPECTED

    elif test_condition == 2:
        act = action.action_push_vlan()
        act.ethertype = 0xaaa  #Other than 0x8100 and 0x88a8
        match_exp = False
        add_tag_exp = False
        exp_vid = 1
        exp_pcp = 0
        vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
        act2 = action.action_set_field()
        act2.field = vlan_vid
        #act2 = action.action_set_vlan_vid()
        #act2.vlan_vid = 1
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    #NOTE need to set a VLAN vid value, as vid=0 is stripped by the system
    action_list=[act, act2]
    wildcards = 0
    if parent.num_tags == 0:
        wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_VID
        wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_PCP

    testutils.flow_match_test_vlan(parent, pa_port_map,
                    wildcards=wildcards,
                    dl_vlan=parent.vid,
                    dl_vlan_pcp=parent.pcp,
                    dl_vlan_type=parent.vlan_type,
                    dl_vlan_int=parent.vid_2nd,
                    dl_vlan_pcp_int=parent.pcp_2nd,
                    vid_match=parent.vid_match,
                    pcp_match=parent.pcp_match,
                    exp_vid=exp_vid,
                    exp_pcp=exp_pcp,
                    exp_vlan_type=act.ethertype,
                    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)
Exemplo n.º 20
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)
Exemplo n.º 21
0
def vlan_set_act_tests(parent, test_condition=0):
    """
    Test vlan set_vid and set_pcp action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = \
        vlan_action_support_check(parent)

    new_vid = parent.vid + 2
    new_pcp = parent.pcp + 2

    if sup_set_vlan_vid == False:
        testutils.skip_message_emit(
            parent, "Vlan set action test. SET VLAN VID not supported")
        return
    if sup_set_vlan_pcp == False:
        testutils.skip_message_emit(
            parent, "Vlan set action test. SET VLAN PCP not supported")
        return

    exp_vlan_type = parent.vlan_type

    if test_condition == 0:
        act = action.action_set_vlan_vid()
        act.vlan_vid = new_vid
        if parent.num_tags == 0:
            match_exp = False
            exp_vid = -1
            exp_pcp = 0
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
        else:
            match_exp = True
            exp_vid = new_vid
            exp_pcp = parent.pcp
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0  #NOT_EXPECTED
            exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_set_vlan_vid()
        act.vlan_vid = 4096  #OUT OF RANGE
        match_exp = False
        exp_vid = -1
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    elif test_condition == 2:
        act = action.action_set_vlan_pcp()
        act.vlan_pcp = new_pcp
        if parent.num_tags == 0:
            match_exp = False
            exp_vid = -1
            exp_pcp = 0
            exp_msg = ofp.OFPT_ERROR
            exp_msg_type = ofp.OFPET_BAD_ACTION
            exp_msg_code = ofp.OFPBAC_MATCH_INCONSISTENT
        else:
            match_exp = True
            exp_vid = parent.vid
            exp_pcp = new_pcp
            exp_msg = ofp.OFPT_FLOW_REMOVED
            exp_msg_type = 0  #NOT_EXPECTED
            exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 3:
        act = action.action_set_vlan_pcp()
        act.vlan_pcp = 8  #OUT OF RANGE
        match_exp = False
        exp_vid = -1
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    action_list = [act]

    testutils.flow_match_test_vlan(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   dl_vlan=parent.vid,
                                   dl_vlan_pcp=parent.pcp,
                                   dl_vlan_type=parent.vlan_type,
                                   dl_vlan_int=parent.vid_2nd,
                                   dl_vlan_pcp_int=parent.pcp_2nd,
                                   vid_match=parent.vid_match,
                                   pcp_match=parent.pcp_match,
                                   exp_vid=exp_vid,
                                   exp_pcp=exp_pcp,
                                   exp_vlan_type=exp_vlan_type,
                                   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)
Exemplo n.º 22
0
def vlan_singlepush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = \
        vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(
            parent, "Vlan single push action test. SET VLAN VID not supported")
        return

    if test_condition == 0:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 0
            exp_pcp = 0
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN_PBB
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 0
            exp_pcp = 0
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 2:
        act = action.action_push_vlan()
        act.ethertype = 0xaaa  #Other than 0x8100 and 0x88a8
        match_exp = False
        add_tag_exp = False
        exp_vid = 0
        exp_pcp = 0
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    action_list = [act]

    testutils.flow_match_test_vlan(parent,
                                   pa_port_map,
                                   wildcards=0,
                                   dl_vlan=parent.vid,
                                   dl_vlan_pcp=parent.pcp,
                                   dl_vlan_type=parent.vlan_type,
                                   dl_vlan_int=parent.vid_2nd,
                                   dl_vlan_pcp_int=parent.pcp_2nd,
                                   vid_match=parent.vid_match,
                                   pcp_match=parent.pcp_match,
                                   exp_vid=exp_vid,
                                   exp_pcp=exp_pcp,
                                   exp_vlan_type=act.ethertype,
                                   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)
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
def vlan_pop_act_tests(parent):
    """
    Test vlan pop 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_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = vlan_action_support_check(parent)

    if sup_pop_vlan == False:
        testutils.skip_message_emit(parent, "Vlan pop action test. POP not supported")
        return

    act = action.action_pop_vlan()
    exp_vlan_type = ETHERTYPE_VLAN

    if parent.num_tags == 0:
        match_exp = False
        exp_vid = parent.vid
        exp_pcp = parent.pcp

        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_vid = -1
        exp_pcp = 0

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

    else:
        match_exp = True
        exp_vid = -1
        exp_pcp = 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_vlan(
        parent,
        pa_port_map,
        wildcards=0,
        dl_vlan=parent.vid,
        dl_vlan_pcp=parent.pcp,
        dl_vlan_type=parent.vlan_type,
        dl_vlan_int=parent.vid_2nd,
        dl_vlan_pcp_int=parent.pcp_2nd,
        vid_match=parent.vid_match,
        pcp_match=parent.pcp_match,
        exp_vid=exp_vid,
        exp_pcp=exp_pcp,
        exp_vlan_type=exp_vlan_type,
        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,
    )
Exemplo n.º 26
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)
Exemplo n.º 27
0
def vlan_multipush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

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

    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid, sup_set_vlan_pcp) = (True, True, True, True)
    #    vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(parent,
            "Vlan multiple push action test. PUSH not supported")
        return
    if sup_pop_vlan == False:
        testutils.skip_message_emit(parent,
            "Vlan multiple push action test. POP not supported")
        return
    if sup_set_vlan_vid == False:
        testutils.skip_message_emit(parent,
            "Vlan multiple push action test. SET VLAN VID not supported")
        return
    if sup_set_vlan_pcp == False:
        testutils.skip_message_emit(parent,
            "Vlan multiple push action test. SET VLAN PCP not supported")
        return
    inst_app_flag = testutils.WRITE_ACTIONS_INSTRUCTION

    new_vid = parent.vid + 2;
    new_pcp = parent.pcp + 2;

    act = action.action_push_vlan()
    act.ethertype = ETHERTYPE_VLAN

    act3 = None
    if test_condition == 0:
        vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT)
        act2 = action.action_set_field()
        act2.field = vlan_vid
        #act2 = action.action_set_vlan_vid()
        #act2.vlan_vid = new_vid
        add_tag_exp = True
        exp_vid = new_vid
        exp_vlan_type = act.ethertype

        if parent.num_tags == 0:
            exp_pcp = 0
        else:
            exp_pcp = parent.pcp

    elif test_condition == 1:
        #act2 = action.action_set_vlan_pcp()
        #act2.vlan_pcp = new_pcp
        vlan_pcp = match.vlan_pcp(new_pcp)
        act2 = action.action_set_field()
        act2.field = vlan_pcp
        add_tag_exp = True
        exp_pcp = new_pcp

        exp_vlan_type = act.ethertype
        #exp_vid = 0

        if parent.num_tags == 0:
            exp_vid = 0
        else:
            exp_vid = parent.vid

    elif test_condition == 2:
        vlan_vid = match.vlan_vid(new_vid + ofp.OFPVID_PRESENT)
        act2 = action.action_set_field()
        act2.field = vlan_vid
        #act2 = action.action_set_vlan_vid()
        #act2.vlan_vid = new_vid
        #act3 = action.action_set_vlan_pcp()
        #act3.vlan_pcp = new_pcp
        vlan_pcp = match.vlan_pcp(new_pcp)
        act3 = action.action_set_field()
        act3.field = vlan_pcp
        add_tag_exp = True
        exp_vid = new_vid
        exp_pcp = new_pcp
        exp_vlan_type = act.ethertype

    elif test_condition == 3:
        act2 = action.action_pop_vlan()
        add_tag_exp = False
        exp_vid = parent.vid
        exp_pcp = parent.pcp
        exp_vlan_type = parent.vlan_type
        inst_app_flag = testutils.APPLY_ACTIONS_INSTRUCTION

    elif test_condition == 4:
        vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
        act3 = action.action_set_field()
        act3.field = vlan_vid

        #act2 = action.action_set_vlan_pcp()
        #act2.vlan_pcp = new_pcp
        vlan_pcp = match.vlan_pcp(new_pcp)
        act2 = action.action_set_field()
        act2.field = vlan_pcp
        add_tag_exp = True
        exp_pcp = new_pcp

        exp_vlan_type = act.ethertype
        #exp_vid = 0

        if parent.num_tags == 0:
            exp_vid = 1
        else:
            exp_vid = parent.vid
    else:
        return

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

    action_list=[act, act2]
    if act3 is not None:
        action_list.append(act3)

    wildcards = 0
    if parent.num_tags == 0:
        wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_VID
        wildcards |= 1<<ofp.OFPXMT_OFB_VLAN_PCP

    testutils.flow_match_test_vlan(parent, pa_port_map,
                    wildcards=wildcards,
                    dl_vlan=parent.vid,
                    dl_vlan_pcp=parent.pcp,
                    dl_vlan_type=parent.vlan_type,
                    dl_vlan_int=parent.vid_2nd,
                    dl_vlan_pcp_int=parent.pcp_2nd,
                    vid_match=parent.vid_match,
                    pcp_match=parent.pcp_match,
                    exp_vid=exp_vid,
                    exp_pcp=exp_pcp,
                    exp_vlan_type=exp_vlan_type,
                    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,
                    inst_app_flag=inst_app_flag,
                    max_test=1)
Exemplo n.º 28
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)
Exemplo n.º 29
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")
Exemplo n.º 30
0
 def runTest(self):
     testutils.skip_message_emit(self, 'skip!')
     return
Exemplo n.º 31
0
def vlan_singlepush_act_tests(parent, test_condition=0):
    """
    Test vlan push action for the packets with/without tags

    @param parent Must implement controller, dataplane, assertTrue, assertEqual
    and logger
    @param test_condition Value between 0 and 2
    """
    parent.assertTrue(((parent.num_tags >= 0) and (parent.num_tags <= 2)),
                      "Parameter num_tags not within an acceptable range")
    #print("parent vid="+str(parent.vid))
    #print("parent pcp="+str(parent.pcp))
    (sup_pop_vlan, sup_push_vlan, sup_set_vlan_vid,
     sup_set_vlan_pcp) = (True, True, True, True)
    #    vlan_action_support_check(parent)

    if sup_push_vlan == False:
        testutils.skip_message_emit(
            parent, "Vlan single push action test. SET VLAN VID not supported")
        return

    if test_condition == 0:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 1
            exp_pcp = 0
            vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = 1
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
            vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = parent.vid
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 1:
        act = action.action_push_vlan()
        act.ethertype = ETHERTYPE_VLAN_PBB
        match_exp = True
        add_tag_exp = True
        if parent.num_tags == 0:
            exp_vid = 1
            exp_pcp = 0
            vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = 1
        else:
            exp_vid = parent.vid
            exp_pcp = parent.pcp
            vlan_vid = match.vlan_vid(parent.vid + ofp.OFPVID_PRESENT)
            act2 = action.action_set_field()
            act2.field = vlan_vid
            #act2 = action.action_set_vlan_vid()
            #act2.vlan_vid = parent.vid


#        parent.vid_2nd = parent.vid
#        parent.pcp_2nd = parent.pcp
        exp_msg = ofp.OFPT_FLOW_REMOVED
        exp_msg_type = 0  #NOT_EXPECTED
        exp_msg_code = 0  #NOT_EXPECTED

    elif test_condition == 2:
        act = action.action_push_vlan()
        act.ethertype = 0xaaa  #Other than 0x8100 and 0x88a8
        match_exp = False
        add_tag_exp = False
        exp_vid = 1
        exp_pcp = 0
        vlan_vid = match.vlan_vid(1 + ofp.OFPVID_PRESENT)
        act2 = action.action_set_field()
        act2.field = vlan_vid
        #act2 = action.action_set_vlan_vid()
        #act2.vlan_vid = 1
        exp_msg = ofp.OFPT_ERROR
        exp_msg_type = ofp.OFPET_BAD_ACTION
        exp_msg_code = ofp.OFPBAC_BAD_ARGUMENT

    else:
        return

    #NOTE need to set a VLAN vid value, as vid=0 is stripped by the system
    action_list = [act, act2]
    wildcards = 0
    if parent.num_tags == 0:
        wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_VID
        wildcards |= 1 << ofp.OFPXMT_OFB_VLAN_PCP

    testutils.flow_match_test_vlan(parent,
                                   pa_port_map,
                                   wildcards=wildcards,
                                   dl_vlan=parent.vid,
                                   dl_vlan_pcp=parent.pcp,
                                   dl_vlan_type=parent.vlan_type,
                                   dl_vlan_int=parent.vid_2nd,
                                   dl_vlan_pcp_int=parent.pcp_2nd,
                                   vid_match=parent.vid_match,
                                   pcp_match=parent.pcp_match,
                                   exp_vid=exp_vid,
                                   exp_pcp=exp_pcp,
                                   exp_vlan_type=act.ethertype,
                                   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)