summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon Loeliger <jdl@netgate.com>2017-02-09 12:17:50 -0600
committerOle Trøan <otroan@employees.org>2017-02-13 15:15:20 +0000
commit466f0d46d242aea1a598f5a9922528aa38d1653b (patch)
tree7af41f9939d8377ab80616e46c1acdd82117176e /src
parentce1b4c7f05ce28d7b73eb7ed0a8ea4bd483f09e9 (diff)
Augment IP_DETAILS, IP_ADDRESS_DETAILS with a few context fields.
When handling the IP_DETAILS and IP_ADDRESS_DETAILS replies, it is almost certainly going to require having both the is_ipv6 and sw_if_index context to handle them properly. Placing these values in an essentially global location as the current VAT does isn't thread-safe. Fruthermore, rather than forcing every API user to hoop-jump to establish these context values, simply provide them in their DETAILS reply messages. Change-Id: I6a9e0cb16ecdbf87fca8fc5c7663e98d3a53c26c Signed-off-by: Jon Loeliger <jdl@netgate.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/ip/ip.api3
-rw-r--r--src/vnet/ip/ip_api.c17
2 files changed, 15 insertions, 5 deletions
diff --git a/src/vnet/ip/ip.api b/src/vnet/ip/ip.api
index 65f6e7a79ed..0a4a9c9773c 100644
--- a/src/vnet/ip/ip.api
+++ b/src/vnet/ip/ip.api
@@ -436,6 +436,8 @@ define ip_address_details
u32 context;
u8 ip[16];
u8 prefix_length;
+ u32 sw_if_index;
+ u8 is_ipv6;
};
define ip_address_dump
@@ -450,6 +452,7 @@ define ip_details
{
u32 sw_if_index;
u32 context;
+ u8 is_ipv6;
};
define ip_dump
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 437d26749cd..1cc712eb3e7 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -990,7 +990,8 @@ vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp)
static void
send_ip_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
+ unix_shared_memory_queue_t * q, u32 sw_if_index,
+ u8 is_ipv6, u32 context)
{
vl_api_ip_details_t *mp;
@@ -999,6 +1000,7 @@ send_ip_details (vpe_api_main_t * am,
mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
mp->sw_if_index = ntohl (sw_if_index);
+ mp->is_ipv6 = is_ipv6;
mp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & mp);
@@ -1007,7 +1009,8 @@ send_ip_details (vpe_api_main_t * am,
static void
send_ip_address_details (vpe_api_main_t * am,
unix_shared_memory_queue_t * q,
- u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
+ u8 * ip, u16 prefix_length,
+ u32 sw_if_index, u8 is_ipv6, u32 context)
{
vl_api_ip_address_details_t *mp;
@@ -1026,6 +1029,8 @@ send_ip_address_details (vpe_api_main_t * am,
}
mp->prefix_length = prefix_length;
mp->context = context;
+ mp->sw_if_index = htonl (sw_if_index);
+ mp->is_ipv6 = is_ipv6;
vl_msg_api_send_shmem (q, (u8 *) & mp);
}
@@ -1061,7 +1066,8 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
({
r6 = ip_interface_address_get_address (lm6, ia);
u16 prefix_length = ia->address_length;
- send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
+ send_ip_address_details(am, q, (u8*)r6, prefix_length,
+ sw_if_index, 1, mp->context);
}));
/* *INDENT-ON* */
}
@@ -1073,7 +1079,8 @@ vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
({
r4 = ip_interface_address_get_address (lm4, ia);
u16 prefix_length = ia->address_length;
- send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
+ send_ip_address_details(am, q, (u8*)r4, prefix_length,
+ sw_if_index, 0, mp->context);
}));
/* *INDENT-ON* */
}
@@ -1116,7 +1123,7 @@ vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
continue;
}
sw_if_index = si->sw_if_index;
- send_ip_details (am, q, sw_if_index, mp->context);
+ send_ip_details (am, q, sw_if_index, mp->is_ipv6, mp->context);
}
}
}
d='n99' href='#n99'>99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
# Copyright (c) 2017 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 MAC address range:     ca:fe:00:00:00:00 - ca:fe:00:00:00:63
   - Source IP address range:      10.0.0.2 - 10.0.0.101
   - Destination IP address range: 20.0.0.1
 - Direction 1 --> 0:
   - Source MAC address range:     fa:ce:00:00:00:00 - fa:ce:00:00:00:63
   - Source IP address range:      20.0.0.2 - 20.0.0.101
   - Destination IP address range: 10.0.0.1
"""

from trex_stl_lib.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.clients = 100

        # MACs used in packet headers.
        self.p1_src_start_mac = 'ca:fe:00:00:00:00'  # mask: 00:00:FF:FF:FF:FF

        self.p2_src_start_mac = 'fa:ce:00:00:00:00'  # mask: 00:00:FF:FF:FF:FF

        # IPs used in packet headers.
        self.p1_src_start_ip = '10.0.0.2'
        self.p1_src_end_ip = '10.0.0.101'
        self.p1_dst_start_ip = '20.0.0.1'

        self.p2_src_start_ip = '20.0.0.2'
        self.p2_src_end_ip = '20.0.0.101'
        self.p2_dst_start_ip = '10.0.0.1'

    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(src=self.p1_src_start_mac) /
                      IP(src=self.p1_src_start_ip,
                         dst=self.p1_dst_start_ip,
                         proto=61))
        # Direction 1 --> 0
        base_pkt_b = (Ether(src=self.p2_src_start_mac) /
                      IP(src=self.p2_src_start_ip,
                         dst=self.p2_dst_start_ip,
                         proto=61))

        # Direction 0 --> 1
        vm1 = STLScVmRaw([STLVmFlowVar(name="mac_src",
                                       min_value=0,
                                       max_value=self.clients-1,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="mac_src", pkt_offset=8),
                          STLVmFlowVar(name="src",
                                       min_value=self.p1_src_start_ip,
                                       max_value=self.p1_src_end_ip,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
                          STLVmFixIpv4(offset="IP")])
        # Direction 1 --> 0
        vm2 = STLScVmRaw([STLVmFlowVar(name="mac_src",
                                       min_value=0,
                                       max_value=self.clients-1,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="mac_src", pkt_offset=8),
                          STLVmFlowVar(name="src",
                                       min_value=self.p2_src_start_ip,
                                       max_value=self.p2_src_end_ip,
                                       size=4, op="inc"),
                          STLVmWrFlowVar(fv_name="src", pkt_offset="IP.src"),
                          STLVmFixIpv4(offset="IP")])

        return base_pkt_a, base_pkt_b, vm1, vm2


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

    Do not change this function.

    :returns: Traffic streams.
    :rtype: Object
    """
    return TrafficStreams()