Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Helium/VPP/vpp-22.02/src/plugins/dpdk/device/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* Abstraction Layer and pcap Tx Trace.
*/

u16 intf_outer_vlan[12] = {0};
u16 intf_inner_vlan[12] = {0};

static clib_error_t *
show_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
Expand Down Expand Up @@ -376,6 +378,66 @@ VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
};
/* *INDENT-ON* */

static clib_error_t *
set_dpdk_if_vlan (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
u16 outer_vlan_id = (u16) ~ 0;
u16 inner_vlan_id = 0;
clib_error_t *error = NULL;
u32 intf_index = (u16) ~ 0;

if (!unformat_user (input, unformat_line_input, line_input))
{
return 0;
}

while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "intf_id %d", &intf_index))
;
else if (unformat (line_input, "outer_vlan %d", &outer_vlan_id))
;
else if (unformat (line_input, "inner_vlan %d", &inner_vlan_id))
;
else
{
error = clib_error_return (0, "parse error: '%U'",
format_unformat_error, line_input);
goto done;
}
}

if (intf_index == (u16) ~ 0 || outer_vlan_id == (u16) ~ 0)
{
error = clib_error_return (0, "please specify valid interface index and outer vlan id");
goto done;
}

if (intf_index > 12)
{
error = clib_error_return (0, "please specify valid interface index");
goto done;
}

intf_outer_vlan[intf_index - 1] = outer_vlan_id;
intf_inner_vlan[intf_index - 1] = inner_vlan_id;

done:
unformat_free (line_input);
//unformat_free (intf);

return error;
}

VLIB_CLI_COMMAND (cmd_set_dpdk_if_vlan,static) = {
.path = "set dpdk interface vlan",
.short_help = "set dpdk interface vlan intf_id <interface index> outer_vlan <vlan id> [inner_vlan <vlan id>]",
.function = set_dpdk_if_vlan,
};


/* Dummy function to get us linked in. */
void
dpdk_cli_reference (void)
Expand Down
6 changes: 5 additions & 1 deletion Helium/VPP/vpp-22.02/src/plugins/dpdk/device/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ dpdk_device_setup (dpdk_device_t * xd, dpdk_device_config_t *devconf)
format_dpdk_rte_device, dev_info.device);

/* create rx and tx offload wishlist */
rxo = DEV_RX_OFFLOAD_IPV4_CKSUM | DEV_RX_OFFLOAD_VLAN_STRIP;
rxo = DEV_RX_OFFLOAD_IPV4_CKSUM;
if (0 == xd->port_id)
{
rxo |= DEV_RX_OFFLOAD_VLAN_STRIP;
}
txo = 0;

if (xd->conf.enable_tcp_udp_checksum)
Expand Down
100 changes: 74 additions & 26 deletions Helium/VPP/vpp-22.02/src/plugins/dpdk/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <vppinfra/error.h>
#include <vlib/unix/unix.h>

extern u16 intf_outer_vlan[12];
extern u16 intf_inner_vlan[12];

#define foreach_dpdk_tx_func_error \
_(BAD_RETVAL, "DPDK tx function returned an error") \
_(PKT_DROP, "Tx packet drops (dpdk tx failure)")
Expand Down Expand Up @@ -357,6 +360,41 @@ dpdk_mempools_deplete_to_vlib (vlib_main_t *vm, vlib_node_runtime_t *node,
}
}

static_always_inline void dpdk_add_inner_vlan(vlib_buffer_t *b, u16 vlan_tci, u16 *intf_vlan_in, u16 *intf_vlan_out)
{
u8 *pkt_start = NULL;
u16 *pkt_start_tmp = NULL;

if (vlan_tci >= 12)
{
return;
}

if (0 != intf_vlan_in[vlan_tci - 1])
{
vlib_buffer_advance(b, -4);
pkt_start = vlib_buffer_get_current (b);
memcpy(pkt_start, pkt_start + 4, 12);
*(pkt_start + 12) = 0x81;
*(pkt_start + 13) = 0x00;
pkt_start_tmp = (u16 *)(pkt_start + 14);
*pkt_start_tmp = htons(intf_vlan_in[vlan_tci - 1]);
}

if (0 != intf_vlan_out[vlan_tci - 1])
{
vlib_buffer_advance(b, -4);
pkt_start = vlib_buffer_get_current (b);
memcpy(pkt_start, pkt_start + 4, 12);
*(pkt_start + 12) = 0x81;
*(pkt_start + 13) = 0x00;
pkt_start_tmp = (u16 *)(pkt_start + 14);
*pkt_start_tmp = htons(intf_vlan_out[vlan_tci - 1]);
}

return;
}

/**
* Transmits the packets on the frame to the interface associated with the
* node. It first copies packets on the frame to a per-thread arrays
Expand Down Expand Up @@ -416,6 +454,24 @@ dpdk_device_output (vlib_main_t *vm, vlib_node_runtime_t *node,
b[2] = vlib_buffer_from_rte_mbuf (mb[2]);
b[3] = vlib_buffer_from_rte_mbuf (mb[3]);

if(has_subintf)
{
mb[0]->ol_flags |= PKT_TX_VLAN_PKT;
mb[1]->ol_flags |= PKT_TX_VLAN_PKT;
mb[2]->ol_flags |= PKT_TX_VLAN_PKT;
mb[3]->ol_flags |= PKT_TX_VLAN_PKT;

mb[0]->vlan_tci = vnet_buffer(b[0])->sw_if_index[VLIB_TX] - 4 + 1;
mb[1]->vlan_tci = vnet_buffer(b[1])->sw_if_index[VLIB_TX] - 4 + 1;
mb[2]->vlan_tci = vnet_buffer(b[2])->sw_if_index[VLIB_TX] - 4 + 1;
mb[3]->vlan_tci = vnet_buffer(b[3])->sw_if_index[VLIB_TX] - 4 + 1;

dpdk_add_inner_vlan(b[0], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
dpdk_add_inner_vlan(b[1], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
dpdk_add_inner_vlan(b[2], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
dpdk_add_inner_vlan(b[3], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
}

or_flags = b[0]->flags | b[1]->flags | b[2]->flags | b[3]->flags;

if (or_flags & VLIB_BUFFER_NEXT_PRESENT)
Expand All @@ -433,19 +489,6 @@ dpdk_device_output (vlib_main_t *vm, vlib_node_runtime_t *node,
dpdk_validate_rte_mbuf (vm, b[3], 0, mempool_deplete_enable, ptd);
}

if(has_subintf)
{
mb[0]->ol_flags |= PKT_TX_VLAN_PKT;
mb[1]->ol_flags |= PKT_TX_VLAN_PKT;
mb[2]->ol_flags |= PKT_TX_VLAN_PKT;
mb[3]->ol_flags |= PKT_TX_VLAN_PKT;

mb[0]->vlan_tci = vnet_buffer(b[0])->sw_if_index[VLIB_TX] - 4 + 1;
mb[1]->vlan_tci = vnet_buffer(b[1])->sw_if_index[VLIB_TX] - 4 + 1;
mb[2]->vlan_tci = vnet_buffer(b[2])->sw_if_index[VLIB_TX] - 4 + 1;
mb[3]->vlan_tci = vnet_buffer(b[3])->sw_if_index[VLIB_TX] - 4 + 1;
}

if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_TX_OFFLOAD) &&
(or_flags & VNET_BUFFER_F_OFFLOAD)))
{
Expand Down Expand Up @@ -486,6 +529,18 @@ dpdk_device_output (vlib_main_t *vm, vlib_node_runtime_t *node,
b[0] = vlib_buffer_from_rte_mbuf (mb[0]);
b[1] = vlib_buffer_from_rte_mbuf (mb[1]);

if(has_subintf)
{
mb[0]->ol_flags |= PKT_TX_VLAN_PKT;
mb[1]->ol_flags |= PKT_TX_VLAN_PKT;

mb[0]->vlan_tci = vnet_buffer(b[0])->sw_if_index[VLIB_TX] - 4 + 1;
mb[1]->vlan_tci = vnet_buffer(b[1])->sw_if_index[VLIB_TX] - 4 + 1;

dpdk_add_inner_vlan(b[0], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
dpdk_add_inner_vlan(b[1], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
}

or_flags = b[0]->flags | b[1]->flags;

if (or_flags & VLIB_BUFFER_NEXT_PRESENT)
Expand All @@ -499,15 +554,6 @@ dpdk_device_output (vlib_main_t *vm, vlib_node_runtime_t *node,
dpdk_validate_rte_mbuf (vm, b[1], 0, mempool_deplete_enable, ptd);
}

if(has_subintf)
{
mb[0]->ol_flags |= PKT_TX_VLAN_PKT;
mb[1]->ol_flags |= PKT_TX_VLAN_PKT;

mb[0]->vlan_tci = vnet_buffer(b[0])->sw_if_index[VLIB_TX] - 4 + 1;
mb[1]->vlan_tci = vnet_buffer(b[1])->sw_if_index[VLIB_TX] - 4 + 1;
}

if (PREDICT_FALSE ((xd->flags & DPDK_DEVICE_FLAG_TX_OFFLOAD) &&
(or_flags & VNET_BUFFER_F_OFFLOAD)))
{
Expand All @@ -532,15 +578,17 @@ dpdk_device_output (vlib_main_t *vm, vlib_node_runtime_t *node,
{
b[0] = vlib_buffer_from_rte_mbuf (mb[0]);

dpdk_validate_rte_mbuf (vm, b[0], 1, mempool_deplete_enable, ptd);
dpdk_buffer_tx_offload (xd, b[0], mb[0]);

if(has_subintf)
if(has_subintf)
{
mb[0]->ol_flags |= PKT_TX_VLAN_PKT;
mb[0]->vlan_tci = vnet_buffer(b[0])->sw_if_index[VLIB_TX] - 4 + 1;

dpdk_add_inner_vlan(b[0], mb[0]->vlan_tci, intf_inner_vlan, intf_outer_vlan);
}

dpdk_validate_rte_mbuf (vm, b[0], 1, mempool_deplete_enable, ptd);
dpdk_buffer_tx_offload (xd, b[0], mb[0]);

if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
dpdk_tx_trace_buffer (dm, node, xd, queue_id, b[0]);
Expand Down
27 changes: 27 additions & 0 deletions Helium/VPP/vpp-22.02/src/vnet/ethernet/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,10 +1850,37 @@ VLIB_NODE_FN (ethernet_input_node) (vlib_main_t * vm,
{
vnet_main_t *vnm = vnet_get_main ();
u32 *from = vlib_frame_vector_args (frame);
u32 *from_tmp = vlib_frame_vector_args (frame);
u32 n_packets = frame->n_vectors;

u32 n_left_from = frame->n_vectors;

ethernet_input_trace (vm, node, frame);

while (n_left_from > 0)
{
u32 bi0;
vlib_buffer_t *b0;
ethernet_header_t *e0;

bi0 = from_tmp[0];
from_tmp += 1;
n_left_from -= 1;

b0 = vlib_get_buffer (vm, bi0);
e0 = vlib_buffer_get_current (b0);
if (clib_net_to_host_u16(e0->type) == 0x8100 && vnet_buffer(b0)->sw_if_index[VLIB_RX] == 1)
{
u8 *pkt_start = vlib_buffer_get_current (b0);
for (int i = 11; i > 0; i--)
{
*(pkt_start + i + 4) = *(pkt_start + i);
}
vlib_buffer_advance(b0, 4);
}

}

if (frame->flags & ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX)
{
ethernet_input_frame_t *ef = vlib_frame_scalar_args (frame);
Expand Down