Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --bridge <interface> option to packetblaster lwaftr #1123

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
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
25 changes: 24 additions & 1 deletion src/apps/test/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ function Lwaftrgen:pull ()

local output = self.output.output
local input = self.input.input
local bridge_in = self.input.output
local bridge_out = self.output.input
local ipv6_packets = self.ipv6_packets
local ipv6_bytes = self.ipv6_bytes
local ipv4_packets = self.ipv4_packets
Expand All @@ -288,6 +290,14 @@ function Lwaftrgen:pull ()
main.exit(0)
end

-- optional passthru of packets from a bridged interface
if bridge_in then
for _=1,link.nreadable(bridge_in) do
local pkt = receive(bridge_in)
transmit(output, pkt)
end
end

-- count and trash incoming packets
for _=1,link.nreadable(input) do
local pkt = receive(input)
Expand All @@ -300,6 +310,13 @@ function Lwaftrgen:pull ()
lost_packets = lost_packets + payload.number - self.last_rx_ipv6_packet_number - 1
end
self.last_rx_ipv6_packet_number = payload.number
packet.free(pkt)
else
if bridge_out then
transmit(bridge_out, pkt)
else
packet.free(pkt)
end
end
else
ipv4_bytes = ipv4_bytes + pkt.length
Expand All @@ -310,9 +327,15 @@ function Lwaftrgen:pull ()
lost_packets = lost_packets + payload.number - self.last_rx_ipv4_packet_number - 1
end
self.last_rx_ipv4_packet_number = payload.number
packet.free(pkt)
else
if bridge_out then
transmit(bridge_out, pkt)
else
packet.free(pkt)
end
end
end
packet.free(pkt)
end

local cur_now = tonumber(app.now())
Expand Down
24 changes: 24 additions & 0 deletions src/program/packetblaster/lwaftr/README
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Usage: packetblaster lwaftr [OPTIONS]

--sock <SOCKET> Socket name for virtio interface

--bridge <interface> Bridge traffic to Linux interface (optional)

--vlan VLANID VLAN tag traffic with VLANID if set

--src_mac SOURCE
Expand Down Expand Up @@ -169,3 +171,25 @@ Example with Linux tap interface:
14:04:43.573161 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 608: 8.8.8.8.12345 > 0.0.0.0.1024: UDP, length 558
14:04:43.573297 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 1514: 8.8.8.8.12345 > 0.0.0.0.1024: UDP, length 1464
14:04:43.573430 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 78: 8.8.8.8.12345 > 0.0.0.0.1024: UDP, length 28


Example with non-generator traffic bridged to a Linux interface:

In addition to just generating traffic and measuring the return rate, it is also possible to transparently
pass packets from a Linux network interface thru packetblaster in both directions. This allows e.g.
to offer network connectivity between a 10GE port and a linux interface (e.g. eno1), while injecting
traffic at the same time:

$ sudo ./snabb packetblaster lwaftr -4 --pci 0000:04:00.0 --bridge eth0 --rate 1

IPv4: 8.8.8.8:12345 > 10.0.0.0:1024
destination IPv4 and Port adjusted per client
IPv4 packet sizes: 64
Bridge traffic to interface eno1
v6+v4: 0.000+0.000 = 0.000000 MPPS, 0.000+0.000 = 0.000000 Gbps, lost nan%
v6+v4: 0.000+0.358 = 0.357769 MPPS, 0.000+0.223 = 0.223248 Gbps, lost 20.232%
v6+v4: 0.000+2.000 = 2.000007 MPPS, 0.000+1.248 = 1.248004 Gbps, lost 0.000%
v6+v4: 0.000+2.000 = 1.999986 MPPS, 0.000+1.248 = 1.247996 Gbps, lost 0.000%



16 changes: 15 additions & 1 deletion src/program/packetblaster/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local Tap = require("apps.tap.tap").Tap
local raw = require("apps.socket.raw")
local pcap = require("apps.pcap.pcap")
local VhostUser = require("apps.vhost.vhost_user").VhostUser
local raw = require("apps.socket.raw")
local lib = require("core.lib")
local ffi = require("ffi")

Expand All @@ -37,6 +38,7 @@ local long_opts = {
rate = "r", -- rate in MPPS (0 => listen only)
v4only = "4", -- generate only public IPv4 traffic
v6only = "6", -- generate only public IPv6 encapsulated traffic
bridge = "B", -- optional bridge to raw interface
pcap = "o" -- output packet to the pcap file
}

Expand Down Expand Up @@ -160,7 +162,12 @@ function run (args)
single_pass = true
end

args = lib.dogetopt(args, opt, "VD:hS:s:a:d:b:iI:c:r:46p:v:o:t:i:k:", long_opts)
local bridge = nil
function opt.B (arg)
bridge = arg
end

args = lib.dogetopt(args, opt, "VD:hS:s:a:d:b:iI:c:r:46p:v:o:t:i:k:B:", long_opts)

if not target then
print("either --pci, --tap, --sock, --int or --pcap are required parameters")
Expand Down Expand Up @@ -195,6 +202,13 @@ function run (args)
public_ipv4 = public_ipv4, single_pass = single_pass,
ipv4_only = ipv4_only, ipv6_only = ipv6_only })

if bridge then
print("Bridge traffic to interface " .. bridge)
config.app(c, "raw", raw.RawSocket, bridge)
config.link(c, "generator.input -> raw.rx")
config.link(c, "raw.tx -> generator.output")
end

local input, output

if tap_interface then
Expand Down