summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhiyong Yang <zhiyong.yang@intel.com>2019-05-08 22:57:53 -0400
committerDamjan Marion <dmarion@me.com>2019-05-20 11:32:31 +0000
commitb388e1a50603a07e20007141221ca4f4a18ab698 (patch)
tree04b2e569fde16ed37cdc0b96e58b4f3c3f85735e
parenta474894a4a39edd5dc96151e6f95f8122e06a450 (diff)
bonding: clean up redundant code
1. remove unnecessary cast for void * pointer. 2. remove the unused input parameter. Change-Id: Ic0324364fc0c772200d30fb18a0ba959ed4f7ea4 Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
-rw-r--r--src/vnet/bonding/device.c99
1 files changed, 44 insertions, 55 deletions
diff --git a/src/vnet/bonding/device.c b/src/vnet/bonding/device.c
index 0ca7f9eab31..b76396a99e8 100644
--- a/src/vnet/bonding/device.c
+++ b/src/vnet/bonding/device.c
@@ -150,7 +150,7 @@ bond_tx_add_to_queue (bond_per_thread_data_t * ptd, u32 port, u32 bi)
}
static_always_inline u32
-bond_lb_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node,
+bond_lb_broadcast (vlib_main_t * vm,
bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
{
bond_main_t *bm = &bond_main;
@@ -176,10 +176,9 @@ bond_lb_broadcast (vlib_main_t * vm, vlib_node_runtime_t * node,
}
static_always_inline u32
-bond_lb_l2 (vlib_main_t * vm, vlib_node_runtime_t * node,
- bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
+bond_lb_l2 (vlib_buffer_t * b0)
{
- ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ ethernet_header_t *eth = vlib_buffer_get_current (b0);
u64 *dst = (u64 *) & eth->dst_address[0];
u64 a = clib_mem_unaligned (dst, u64);
u32 *src = (u32 *) & eth->src_address[2];
@@ -212,10 +211,9 @@ bond_locate_ethertype (ethernet_header_t * eth)
}
static_always_inline u32
-bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node,
- bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
+bond_lb_l23 (vlib_buffer_t * b0)
{
- ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ ethernet_header_t *eth = vlib_buffer_get_current (b0);
u8 ip_version;
ip4_header_t *ip4;
u16 ethertype, *ethertype_p;
@@ -226,7 +224,7 @@ bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node,
if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
(ethertype != htons (ETHERNET_TYPE_IP6)))
- return (bond_lb_l2 (vm, node, bif, b0, n_slaves));
+ return bond_lb_l2 (b0);
ip4 = (ip4_header_t *) (ethertype_p + 1);
ip_version = (ip4->ip_version_and_header_length >> 4);
@@ -269,14 +267,13 @@ bond_lb_l23 (vlib_main_t * vm, vlib_node_runtime_t * node,
uword), a);
return c;
}
- return (bond_lb_l2 (vm, node, bif, b0, n_slaves));
+ return bond_lb_l2 (b0);
}
static_always_inline u32
-bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node,
- bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
+bond_lb_l34 (vlib_buffer_t * b0)
{
- ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ ethernet_header_t *eth = vlib_buffer_get_current (b0);
u8 ip_version;
uword is_tcp_udp;
ip4_header_t *ip4;
@@ -287,7 +284,7 @@ bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node,
if ((ethertype != htons (ETHERNET_TYPE_IP4)) &&
(ethertype != htons (ETHERNET_TYPE_IP6)))
- return (bond_lb_l2 (vm, node, bif, b0, n_slaves));
+ return (bond_lb_l2 (b0));
ip4 = (ip4_header_t *) (ethertype_p + 1);
ip_version = (ip4->ip_version_and_header_length >> 4);
@@ -346,13 +343,11 @@ bond_lb_l34 (vlib_main_t * vm, vlib_node_runtime_t * node,
return c;
}
- return (bond_lb_l2 (vm, node, bif, b0, n_slaves));
+ return bond_lb_l2 (b0);
}
static_always_inline u32
-bond_lb_round_robin (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
+bond_lb_round_robin (bond_if_t * bif, vlib_buffer_t * b0, uword n_slaves)
{
bif->lb_rr_last_index++;
if (bif->lb_rr_last_index >= n_slaves)
@@ -362,8 +357,7 @@ bond_lb_round_robin (vlib_main_t * vm,
}
static_always_inline void
-bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
- bond_if_t * bif, vlib_buffer_t ** b,
+bond_tx_inline (vlib_main_t * vm, bond_if_t * bif, vlib_buffer_t ** b,
u32 * h, u32 n_left, uword n_slaves, u32 lb_alg)
{
while (n_left >= 4)
@@ -391,38 +385,38 @@ bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
if (lb_alg == BOND_LB_L2)
{
- h[0] = bond_lb_l2 (vm, node, bif, b[0], n_slaves);
- h[1] = bond_lb_l2 (vm, node, bif, b[1], n_slaves);
- h[2] = bond_lb_l2 (vm, node, bif, b[2], n_slaves);
- h[3] = bond_lb_l2 (vm, node, bif, b[3], n_slaves);
+ h[0] = bond_lb_l2 (b[0]);
+ h[1] = bond_lb_l2 (b[1]);
+ h[2] = bond_lb_l2 (b[2]);
+ h[3] = bond_lb_l2 (b[3]);
}
else if (lb_alg == BOND_LB_L34)
{
- h[0] = bond_lb_l34 (vm, node, bif, b[0], n_slaves);
- h[1] = bond_lb_l34 (vm, node, bif, b[1], n_slaves);
- h[2] = bond_lb_l34 (vm, node, bif, b[2], n_slaves);
- h[3] = bond_lb_l34 (vm, node, bif, b[3], n_slaves);
+ h[0] = bond_lb_l34 (b[0]);
+ h[1] = bond_lb_l34 (b[1]);
+ h[2] = bond_lb_l34 (b[2]);
+ h[3] = bond_lb_l34 (b[3]);
}
else if (lb_alg == BOND_LB_L23)
{
- h[0] = bond_lb_l23 (vm, node, bif, b[0], n_slaves);
- h[1] = bond_lb_l23 (vm, node, bif, b[1], n_slaves);
- h[2] = bond_lb_l23 (vm, node, bif, b[2], n_slaves);
- h[3] = bond_lb_l23 (vm, node, bif, b[3], n_slaves);
+ h[0] = bond_lb_l23 (b[0]);
+ h[1] = bond_lb_l23 (b[1]);
+ h[2] = bond_lb_l23 (b[2]);
+ h[3] = bond_lb_l23 (b[3]);
}
else if (lb_alg == BOND_LB_RR)
{
- h[0] = bond_lb_round_robin (vm, node, bif, b[0], n_slaves);
- h[1] = bond_lb_round_robin (vm, node, bif, b[1], n_slaves);
- h[2] = bond_lb_round_robin (vm, node, bif, b[2], n_slaves);
- h[3] = bond_lb_round_robin (vm, node, bif, b[3], n_slaves);
+ h[0] = bond_lb_round_robin (bif, b[0], n_slaves);
+ h[1] = bond_lb_round_robin (bif, b[1], n_slaves);
+ h[2] = bond_lb_round_robin (bif, b[2], n_slaves);
+ h[3] = bond_lb_round_robin (bif, b[3], n_slaves);
}
else if (lb_alg == BOND_LB_BC)
{
- h[0] = bond_lb_broadcast (vm, node, bif, b[0], n_slaves);
- h[1] = bond_lb_broadcast (vm, node, bif, b[1], n_slaves);
- h[2] = bond_lb_broadcast (vm, node, bif, b[2], n_slaves);
- h[3] = bond_lb_broadcast (vm, node, bif, b[3], n_slaves);
+ h[0] = bond_lb_broadcast (vm, bif, b[0], n_slaves);
+ h[1] = bond_lb_broadcast (vm, bif, b[1], n_slaves);
+ h[2] = bond_lb_broadcast (vm, bif, b[2], n_slaves);
+ h[3] = bond_lb_broadcast (vm, bif, b[3], n_slaves);
}
else
{
@@ -439,15 +433,15 @@ bond_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]);
if (bif->lb == BOND_LB_L2)
- h[0] = bond_lb_l2 (vm, node, bif, b[0], n_slaves);
+ h[0] = bond_lb_l2 (b[0]);
else if (bif->lb == BOND_LB_L34)
- h[0] = bond_lb_l34 (vm, node, bif, b[0], n_slaves);
+ h[0] = bond_lb_l34 (b[0]);
else if (bif->lb == BOND_LB_L23)
- h[0] = bond_lb_l23 (vm, node, bif, b[0], n_slaves);
+ h[0] = bond_lb_l23 (b[0]);
else if (bif->lb == BOND_LB_RR)
- h[0] = bond_lb_round_robin (vm, node, bif, b[0], n_slaves);
+ h[0] = bond_lb_round_robin (bif, b[0], n_slaves);
else if (bif->lb == BOND_LB_BC)
- h[0] = bond_lb_broadcast (vm, node, bif, b[0], n_slaves);
+ h[0] = bond_lb_broadcast (vm, bif, b[0], n_slaves);
else
{
ASSERT (0);
@@ -621,7 +615,7 @@ bond_tx_trace (vlib_main_t * vm, vlib_node_runtime_t * node, bond_if_t * bif,
vlib_trace_buffer (vm, node, next0, b[0], 0 /* follow_chain */ );
vlib_set_trace_count (vm, node, --n_trace);
t0 = vlib_add_trace (vm, node, b[0], sizeof (*t0));
- eth = (ethernet_header_t *) vlib_buffer_get_current (b[0]);
+ eth = vlib_buffer_get_current (b[0]);
t0->ethernet = *eth;
t0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
if (!h)
@@ -698,8 +692,7 @@ VNET_DEVICE_CLASS_TX_FN (bond_dev_class) (vlib_main_t * vm,
{
sw_if_index = *vec_elt_at_index (bif->active_slaves, 0);
- bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves,
- BOND_LB_BC);
+ bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_BC);
bond_tx_trace (vm, node, bif, bufs, frame->n_vectors, 0);
bond_update_sw_if_index (ptd, bif, from, bufs, &sw_if_index, n_left,
/* single_sw_if_index */ 1);
@@ -707,17 +700,13 @@ VNET_DEVICE_CLASS_TX_FN (bond_dev_class) (vlib_main_t * vm,
}
if (bif->lb == BOND_LB_L2)
- bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves,
- BOND_LB_L2);
+ bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L2);
else if (bif->lb == BOND_LB_L34)
- bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves,
- BOND_LB_L34);
+ bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L34);
else if (bif->lb == BOND_LB_L23)
- bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves,
- BOND_LB_L23);
+ bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_L23);
else if (bif->lb == BOND_LB_RR)
- bond_tx_inline (vm, node, bif, bufs, hashes, n_left, n_slaves,
- BOND_LB_RR);
+ bond_tx_inline (vm, bif, bufs, hashes, n_left, n_slaves, BOND_LB_RR);
else
ASSERT (0);
amespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# Copyright (c) 2020 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.

"""
This module exists to provide the l3fwd test for DPDK on topology nodes.
"""

from resources.libraries.python.Constants import Constants
from resources.libraries.python.DpdkUtil import DpdkUtil
from resources.libraries.python.ssh import exec_cmd_no_error, exec_cmd
from resources.libraries.python.topology import NodeType, Topology


class L3fwdTest:
    """Test the DPDK l3fwd performance."""

    @staticmethod
    def start_l3fwd(
            nodes, node, if1, if2, lcores_list, nb_cores, queue_nums,
            jumbo_frames):
        """
        Execute the l3fwd on the dut_node.

        :param nodes: All the nodes info in the topology file.
        :param node: DUT node.
        :param if1: The test link interface 1.
        :param if2: The test link interface 2.
        :param lcores_list: The lcore list string for the l3fwd routing
        :param nb_cores: The cores number for the forwarding
        :param queue_nums: The queues number for the NIC
        :param jumbo_frames: Indication if the jumbo frames are used (True) or
                             not (False).
        :type nodes: dict
        :type node: dict
        :type if1: str
        :type if2: str
        :type lcores_list: str
        :type nb_cores: str
        :type queue_nums: str
        :type jumbo_frames: bool
        """
        if node[u"type"] == NodeType.DUT:
            adj_mac0, adj_mac1, if_pci0, if_pci1 = L3fwdTest.get_adj_mac(
                nodes, node, if1, if2
            )

            list_cores = [int(item) for item in lcores_list.split(u",")]

            # prepare the port config param
            nb_cores = int(nb_cores)
            index = 0
            port_config = ''
            for port in range(0, 2):
                for queue in range(0, int(queue_nums)):
                    index = 0 if nb_cores == 1 else index
                    port_config += f"({port}, {queue}, {list_cores[index]}),"
                    index += 1

            if jumbo_frames:
                l3fwd_args = DpdkUtil.get_l3fwd_args(
                    eal_corelist=f"0,{lcores_list}",
                    eal_driver=False,
                    eal_pci_whitelist0=if_pci0,
                    eal_pci_whitelist1=if_pci1,
                    eal_in_memory=True,
                    pmd_config=f"\\\"{port_config.rstrip(u',')}\\\"",
                    pmd_eth_dest_0=f"\\\"0,{adj_mac0}\\\"",
                    pmd_eth_dest_1=f"\\\"1,{adj_mac1}\\\"",
                    pmd_parse_ptype=True,
                    pmd_enable_jumbo=jumbo_frames,
                    pmd_max_pkt_len=jumbo_frames
                )
            else:
                l3fwd_args = DpdkUtil.get_l3fwd_args(
                    eal_corelist=f"0,{lcores_list}",
                    eal_driver=False,
                    eal_pci_whitelist0=if_pci0,
                    eal_pci_whitelist1=if_pci1,
                    eal_in_memory=True,
                    pmd_config=f"\\\"{port_config.rstrip(u',')}\\\"",
                    pmd_eth_dest_0=f"\\\"0,{adj_mac0}\\\"",
                    pmd_eth_dest_1=f"\\\"1,{adj_mac1}\\\"",
                    pmd_parse_ptype=True
                )

            command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
                f"/entry/run_l3fwd.sh \"{l3fwd_args} -P -L -p 0x3\""
            message = f"Failed to execute l3fwd test at node {node['host']}"
            exec_cmd_no_error(node, command, timeout=1800, message=message)


    @staticmethod
    def get_adj_mac(nodes, node, if1, if2):
        """
        Get adjacency MAC addresses of the DUT node.

        :param nodes: All the nodes info in the topology file.
        :param node: DUT node.
        :param if1: The test link interface 1.
        :param if2: The test link interface 2.
        :type nodes: dict
        :type node: dict
        :type if1: str
        :type if2: str
        :returns: Returns MAC addresses of adjacency DUT nodes and PCI
            addresses.
        :rtype: str
        """
        if_key0 = if1
        if_key1 = if2
        if_pci0 = Topology.get_interface_pci_addr(node, if_key0)
        if_pci1 = Topology.get_interface_pci_addr(node, if_key1)

        # Detect which is the port 0.
        if min(if_pci0, if_pci1) != if_pci0:
            if_key0, if_key1 = if_key1, if_key0
            L3fwdTest.patch_l3fwd(node, u"patch_l3fwd_flip_routes")

        adj_node0, adj_if_key0 = Topology.get_adjacent_node_and_interface(
            nodes, node, if_key0
        )
        adj_node1, adj_if_key1 = Topology.get_adjacent_node_and_interface(
            nodes, node, if_key1
        )
        if_pci0 = Topology.get_interface_pci_addr(node, if_key0)
        if_pci1 = Topology.get_interface_pci_addr(node, if_key1)
        adj_mac0 = Topology.get_interface_mac(adj_node0, adj_if_key0)
        adj_mac1 = Topology.get_interface_mac(adj_node1, adj_if_key1)

        return adj_mac0, adj_mac1, if_pci0, if_pci1

    @staticmethod
    def patch_l3fwd(node, patch):
        """
        Patch l3fwd application and recompile.

        :param node: DUT node.
        :param patch: Patch to apply.
        :type node: dict
        :type patch: str
        :raises RuntimeError: Patching of l3fwd failed.
        """
        command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
            f"/entry/patch_l3fwd.sh " \
            f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
            f"/entry/{patch}"
        message = f"Failed to patch l3fwd at node {node['host']}"
        ret_code, stdout, _ = exec_cmd(node, command, timeout=1800)
        if ret_code != 0 and u"Skipping patch." not in stdout:
            raise RuntimeError(message)