From 0125c1acc744326e006be3d8bc61bc034d82ad9a Mon Sep 17 00:00:00 2001 From: Marcel Wiget Date: Tue, 11 Apr 2017 15:15:34 +0200 Subject: [PATCH] add --bridge option to packetblaster lwaftr --- src/apps/test/lwaftr.lua | 25 ++++++++++++++++++++- src/program/packetblaster/lwaftr/README | 24 ++++++++++++++++++++ src/program/packetblaster/lwaftr/lwaftr.lua | 16 ++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/apps/test/lwaftr.lua b/src/apps/test/lwaftr.lua index bf72ccd107..ba32e813a8 100644 --- a/src/apps/test/lwaftr.lua +++ b/src/apps/test/lwaftr.lua @@ -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 @@ -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) @@ -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 @@ -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()) diff --git a/src/program/packetblaster/lwaftr/README b/src/program/packetblaster/lwaftr/README index c575470d5a..3d5e7b7861 100644 --- a/src/program/packetblaster/lwaftr/README +++ b/src/program/packetblaster/lwaftr/README @@ -14,6 +14,8 @@ Usage: packetblaster lwaftr [OPTIONS] --sock Socket name for virtio interface + --bridge Bridge traffic to Linux interface (optional) + --vlan VLANID VLAN tag traffic with VLANID if set --src_mac SOURCE @@ -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% + + + diff --git a/src/program/packetblaster/lwaftr/lwaftr.lua b/src/program/packetblaster/lwaftr/lwaftr.lua index bcb3dbf9cf..8348b24b9b 100644 --- a/src/program/packetblaster/lwaftr/lwaftr.lua +++ b/src/program/packetblaster/lwaftr/lwaftr.lua @@ -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") @@ -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 } @@ -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") @@ -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