aboutsummaryrefslogtreecommitdiffstats
path: root/resources/traffic_profiles/trex/trex-sl-3n-ethip4-ip4dst400-8cnf.py
blob: 00721d5d103c47fd23233b212c3642cca4bc2077 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .
# Copyright (c) 2019 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Stream profile for T-rex traffic generator.

Stream profile:
 - Two streams sent in directions 0 --> 1 and 1 --> 0 at the same time.
 - Packet: ETH / IP /
 - Direction 0 --> 1:
   - Source IP address range:      10.0.0.1
   - Destination IP address range: 20.0.0.0 - 20.0.1.143
 - Direction 1 --> 0:
   - Source IP address range:      20.0.0.1
   - Destination IP address range: 10.0.0.0 - 10.0.1.143
"""

from trex.stl.api import *
from profile_trex_stateless_base_class import TrafficStreamsBaseClass


class TrafficStreams(TrafficStreamsBaseClass):
    """Stream profile."""

    def __init__(self):
        """Initialization and setting of streams' parameters."""

        super(TrafficStreamsBaseClass, self).__init__()

        self.p1_dst_start_mac = u"02:02:00:00:12:00"
        self.p1_dst_end_mac = u"02:02:00:00:12:07"

        self.p2_dst_start_mac = u"02:02:00:00:02:00"
        self.p2_dst_end_mac = u"02:02:00:00:02:07"

        # IPs used in packet headers.
        self.p1_src_start_ip = u"10.0.0.1"
        self.p1_dst_start_ip = u"20.0.0.0"
        self.p1_dst_end_ip = u"20.0.1.143"

        self.p2_src_start_ip = u"20.0.0.1"
        self.p2_dst_start_ip = u"10.0.0.0"
        self.p2_dst_end_ip = u"10.0.1.143"

    def define_packets(self):
        """Defines the packets to be sent from the traffic generator.

        Packet definition: | ETH | IP |

        :returns: Packets to be sent from the traffic generator.
        :rtype: tuple
        """

        # Direction 0 --> 1
        base_pkt_a = (Ether(dst=self.p1_dst_start_mac) /
                      IP(src=self.p1_src_start_ip,
                         dst=self.p1_dst_start_ip,
                         proto=61))
        # Direction 1 --> 0
        base_pkt_b = (Ether(dst=self.p2_dst_start_mac) /
                      IP(src=self.p2_src_start_ip,
                         dst=self.p2_dst_start_ip,
                         proto=61))

        # Direction 0 --> 1
        vm1 = STLScVmRaw([STLVmFlowVar(name=u"mac_dst",
                                       min_value=0,
                                       max_value=7,
                                       size=1, op=u"inc"),
                          STLVmWrFlowVar(fv_name=u"mac_dst", pkt_offset=5),
                          STLVmFlowVar(name=u"dst",
                                       min_value=self.p1_dst_start_ip,
                                       max_value=self.p1_dst_end_ip,
                                       size=4, op=u"inc"),
                          STLVmWrFlowVar(fv_name=u"dst", pkt_offset=u"IP.dst"),
                          STLVmFixIpv4(offset=u"IP")])
        # Direction 1 --> 0
        vm2 = STLScVmRaw([STLVmFlowVar(name=u"mac_dst",
                                       min_value=0,
                                       max_value=7,
                                       size=1, op=u"inc"),
                          STLVmWrFlowVar(fv_name=u"mac_dst", pkt_offset=5),
                          STLVmFlowVar(name=u"dst",
                                       min_value=self.p2_dst_start_ip,
                                       max_value=self.p2_dst_end_ip,
                                       size=4, op=u"inc"),
                          STLVmWrFlowVar(fv_name=u"dst", pkt_offset=u"IP.dst"),
                          STLVmFixIpv4(offset=u"IP")])

        return base_pkt_a, base_pkt_b, vm1, vm2


def register():
    """Register this traffic profile to T-rex.

    Do not change this function.

    :return: Traffic streams.
    :rtype: Object
    """
    return TrafficStreams()
"p">(self): """ Encapsulation test Send frames from pg1 Verify receipt of encapsulated frames on pg0 """ self.pg1.add_stream([self.frame_reply]) self.pg0.enable_capture() self.pg_start() # Pick first received frame and check if it's corectly encapsulated. out = self.pg0.get_capture(1) pkt = out[0] self.check_encapsulation(pkt, self.single_tunnel_bd) # payload = self.decapsulate(pkt) # self.assert_eq_pkts(payload, self.frame_reply) def test_ucast_flood(self): """ Unicast flood test Send frames from pg3 Verify receipt of encapsulated frames on pg0 """ self.pg3.add_stream([self.frame_reply]) self.pg0.enable_capture() self.pg_start() # Get packet from each tunnel and assert it's corectly encapsulated. out = self.pg0.get_capture(self.n_ucast_tunnels) for pkt in out: self.check_encapsulation(pkt, self.ucast_flood_bd, True) # payload = self.decapsulate(pkt) # self.assert_eq_pkts(payload, self.frame_reply) def test_mcast_flood(self): """ Multicast flood test Send frames from pg2 Verify receipt of encapsulated frames on pg0 """ self.pg2.add_stream([self.frame_reply]) self.pg0.enable_capture() self.pg_start() # Pick first received frame and check if it's corectly encapsulated. out = self.pg0.get_capture(1) pkt = out[0] self.check_encapsulation(pkt, self.mcast_flood_bd, local_only=False, mcast_pkt=True) # payload = self.decapsulate(pkt) # self.assert_eq_pkts(payload, self.frame_reply) @classmethod def create_vxlan_gpe_flood_test_bd(cls, vni, n_ucast_tunnels): # Create 10 ucast vxlan_gpe tunnels under bd ip_range_start = 10 ip_range_end = ip_range_start + n_ucast_tunnels next_hop_address = cls.pg0.remote_ip4n for dest_ip4n in ip4n_range(next_hop_address, ip_range_start, ip_range_end): # add host route so dest_ip4n will not be resolved cls.vapi.ip_add_del_route(dest_ip4n, 32, next_hop_address) r = cls.vapi.vxlan_gpe_add_del_tunnel( src_addr=cls.pg0.local_ip4n, dst_addr=dest_ip4n, vni=vni) cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni) @classmethod def add_del_shared_mcast_dst_load(cls, is_add): """ add or del tunnels sharing the same mcast dst to test vxlan_gpe ref_count mechanism """ n_shared_dst_tunnels = 20 vni_start = 1000 vni_end = vni_start + n_shared_dst_tunnels for vni in range(vni_start, vni_end): r = cls.vapi.vxlan_gpe_add_del_tunnel( src_addr=cls.pg0.local_ip4n, dst_addr=cls.mcast_ip4n, mcast_sw_if_index=1, vni=vni, is_add=is_add) if r.sw_if_index == 0xffffffff: raise "bad sw_if_index" @classmethod def add_shared_mcast_dst_load(cls): cls.add_del_shared_mcast_dst_load(is_add=1) @classmethod def del_shared_mcast_dst_load(cls): cls.add_del_shared_mcast_dst_load(is_add=0) @classmethod def add_del_mcast_tunnels_load(cls, is_add): """ add or del tunnels to test vxlan_gpe stability """ n_distinct_dst_tunnels = 20 ip_range_start = 10 ip_range_end = ip_range_start + n_distinct_dst_tunnels for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start, ip_range_end): vni = bytearray(dest_ip4n)[3] cls.vapi.vxlan_gpe_add_del_tunnel( src_addr=cls.pg0.local_ip4n, dst_addr=dest_ip4n, mcast_sw_if_index=1, vni=vni, is_add=is_add) @classmethod def add_mcast_tunnels_load(cls): cls.add_del_mcast_tunnels_load(is_add=1) @classmethod def del_mcast_tunnels_load(cls): cls.add_del_mcast_tunnels_load(is_add=0) # Class method to start the VXLAN-GPE test case. # Overrides setUpClass method in VppTestCase class. # Python try..except statement is used to ensure that the tear down of # the class will be executed even if exception is raised. # @param cls The class pointer. @classmethod def setUpClass(cls): super(TestVxlanGpe, cls).setUpClass() try: cls.dport = 4790 cls.flags = 0xc # Create 2 pg interfaces. cls.create_pg_interfaces(range(4)) for pg in cls.pg_interfaces: pg.admin_up() # Configure IPv4 addresses on VPP pg0. cls.pg0.config_ip4() # Resolve MAC address for VPP's IP address on pg0. cls.pg0.resolve_arp() # Our Multicast address cls.mcast_ip4 = '239.1.1.1' cls.mcast_ip4n = socket.inet_pton(socket.AF_INET, cls.mcast_ip4) iplong = atol(cls.mcast_ip4) cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) # Create VXLAN-GPE VTEP on VPP pg0, and put vxlan_gpe_tunnel0 # and pg1 into BD. cls.single_tunnel_bd = 11 r = cls.vapi.vxlan_gpe_add_del_tunnel( src_addr=cls.pg0.local_ip4n, dst_addr=cls.pg0.remote_ip4n, vni=cls.single_tunnel_bd) cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=cls.single_tunnel_bd) cls.vapi.sw_interface_set_l2_bridge(cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd) # Setup vni 2 to test multicast flooding cls.n_ucast_tunnels = 10 cls.mcast_flood_bd = 12 cls.create_vxlan_gpe_flood_test_bd(cls.mcast_flood_bd, cls.n_ucast_tunnels) r = cls.vapi.vxlan_gpe_add_del_tunnel( src_addr=cls.pg0.local_ip4n, dst_addr=cls.mcast_ip4n, mcast_sw_if_index=1, vni=cls.mcast_flood_bd) cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=cls.mcast_flood_bd) cls.vapi.sw_interface_set_l2_bridge(cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd) # Add and delete mcast tunnels to check stability cls.add_shared_mcast_dst_load() cls.add_mcast_tunnels_load() cls.del_shared_mcast_dst_load() cls.del_mcast_tunnels_load() # Setup vni 3 to test unicast flooding cls.ucast_flood_bd = 13 cls.create_vxlan_gpe_flood_test_bd(cls.ucast_flood_bd, cls.n_ucast_tunnels) cls.vapi.sw_interface_set_l2_bridge(cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd) except Exception: super(TestVxlanGpe, cls).tearDownClass() raise # Method to define VPP actions before tear down of the test case. # Overrides tearDown method in VppTestCase class. # @param self The object pointer. def tearDown(self): super(TestVxlanGpe, self).tearDown() if not self.vpp_dead: self.logger.info(self.vapi.cli("show bridge-domain 11 detail")) self.logger.info(self.vapi.cli("show bridge-domain 12 detail")) self.logger.info(self.vapi.cli("show bridge-domain 13 detail")) self.logger.info(self.vapi.cli("show int")) self.logger.info(self.vapi.cli("show vxlan-gpe tunnel")) self.logger.info(self.vapi.cli("show trace")) if __name__ == '__main__': unittest.main(testRunner=VppTestRunner)