Skip to content

Commit

Permalink
fixes/enhancements based on pull feedback from @dpino
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Wiget committed Mar 30, 2016
1 parent df8c732 commit 8a5b147
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
23 changes: 13 additions & 10 deletions src/apps/test/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local packet = require("core.packet")
local link = require("core.link")
local ethernet = require("lib.protocol.ethernet")
local ipv4 = require("lib.protocol.ipv4")
local udp = require("lib.protocol.udp")
local ipv6 = require("lib.protocol.ipv6")
local ipsum = require("lib.checksum").ipsum

Expand All @@ -30,6 +29,7 @@ struct {
} __attribute__((packed))
]]
local ether_header_ptr_type = ffi.typeof("$*", ether_header_t)
local ethernet_header_size = ffi.sizeof(ether_header_t)
local OFFSET_ETHERTYPE = 12

local ipv4hdr_t = ffi.typeof[[
Expand Down Expand Up @@ -123,14 +123,15 @@ function Lwaftrgen:new(arg)
eth_hdr.ether_dhost, eth_hdr.ether_shost = dst_mac, src_mac
eth_hdr.ether_type = PROTO_IPV4

local ipv4_hdr = cast(ipv4_header_ptr_type, ipv4_pkt.data + 14)
local ipv4_hdr = cast(ipv4_header_ptr_type, ipv4_pkt.data + ethernet_header_size)
ipv4_hdr.src_ip = public_ipv4
ipv4_hdr.dst_ip = b4_ipv4
ipv4_hdr.ttl = 15
ipv4_hdr.ihl_v_tos = C.htons(0x4500) -- v4
ipv4_hdr.id = 0
ipv4_hdr.frag_off = 0

local ipv4_udp_hdr, ip4_payload
local ipv4_udp_hdr, ipv4_payload

ipv4_hdr.protocol = 17 -- UDP(17)
ipv4_udp_hdr = cast(udp_header_ptr_type, ipv4_pkt.data + 34)
Expand All @@ -147,14 +148,14 @@ function Lwaftrgen:new(arg)
eth_hdr.ether_dhost, eth_hdr.ether_shost = dst_mac, src_mac
eth_hdr.ether_type = C.htons(0x86DD)

local ipv6_hdr = cast(ipv6_header_ptr_type, ipv6_pkt.data + 14)
local ipv6_hdr = cast(ipv6_header_ptr_type, ipv6_pkt.data + ethernet_header_size)
lib.bitfield(32, ipv6_hdr, 'v_tc_fl', 0, 4, 6) -- IPv6 Version
lib.bitfield(32, ipv6_hdr, 'v_tc_fl', 4, 8, 1) -- Traffic class
ipv6_hdr.next_header = PROTO_IPV4_ENCAPSULATION
ipv6_hdr.hop_limit = DEFAULT_TTL
ipv6_hdr.dst_ip = aftr_ipv6

local ipv6_ipv4_hdr = cast(ipv4_header_ptr_type, ipv6_pkt.data + 14 + ipv6_header_size)
local ipv6_ipv4_hdr = cast(ipv4_header_ptr_type, ipv6_pkt.data + ethernet_header_size + ipv6_header_size)
ipv6_ipv4_hdr.dst_ip = public_ipv4
ipv6_ipv4_hdr.ttl = 15
ipv6_ipv4_hdr.ihl_v_tos = C.htons(0x4500) -- v4
Expand Down Expand Up @@ -231,7 +232,7 @@ function Lwaftrgen:push ()
if cast(uint16_ptr_t, pkt.data + OFFSET_ETHERTYPE)[0] == PROTO_IPV6 then
ipv6_bytes = ipv6_bytes + pkt.length
ipv6_packets = ipv6_packets + 1
payload = cast(payload_ptr_type, pkt.data + 34 + ipv6_header_size + udp_header_size)
local payload = cast(payload_ptr_type, pkt.data + 34 + ipv6_header_size + udp_header_size)
if payload.magic == MAGIC then
if self.last_rx_ipv6_packet_number > 0 then
lost_packets = lost_packets + payload.number - self.last_rx_ipv6_packet_number - 1
Expand All @@ -241,7 +242,7 @@ function Lwaftrgen:push ()
else
ipv4_bytes = ipv4_bytes + pkt.length
ipv4_packets = ipv4_packets + 1
payload = cast(payload_ptr_type, pkt.data + 34 + udp_header_size)
local payload = cast(payload_ptr_type, pkt.data + 34 + udp_header_size)
if payload.magic == MAGIC then
if self.last_rx_ipv4_packet_number > 0 then
lost_packets = lost_packets + payload.number - self.last_rx_ipv4_packet_number - 1
Expand Down Expand Up @@ -288,6 +289,8 @@ function Lwaftrgen:push ()
self.total_packet_count <= self.bucket_content do
self.bucket_content = self.bucket_content - self.total_packet_count

ipv4_hdr.dst_ip = self.b4_ipv4
ipv6_ipv4_hdr.src_ip = self.b4_ipv4
ipv6_hdr.src_ip = self.b4_ipv6
local ipdst = C.ntohl(rd32(ipv4_hdr.dst_ip))
ipdst = C.htonl(ipdst + self.b4_ipv4_offset)
Expand All @@ -302,10 +305,10 @@ function Lwaftrgen:push ()
if not self.ipv6_only then
ipv4_hdr.total_length = C.htons(size)
ipv4_udp_hdr.len = C.htons(size - 28)
self.ipv4_pkt.length = size + 14
self.ipv4_pkt.length = size + ethernet_header_size
ipv4_hdr.checksum = 0
ipv4_hdr.checksum = C.htons(ipsum(self.ipv4_pkt.data + 14, 20, 0))
ipv4_payload.number = self.ipv4_packet_number;
ipv4_hdr.checksum = C.htons(ipsum(self.ipv4_pkt.data + ethernet_header_size, 20, 0))
self.ipv4_payload.number = self.ipv4_packet_number;
self.ipv4_packet_number = self.ipv4_packet_number + 1
local ipv4_pkt = packet.clone(self.ipv4_pkt)
transmit(output, ipv4_pkt)
Expand Down
2 changes: 1 addition & 1 deletion src/program/packetblaster/lwaftr/README
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Example with Linux tap interface:

$ sudo ip tuntap add dev tap0 mode tap
$ sudo ifconfig tap0 mtu 9000 up
$ tcpdump -n -i tap0 -e -s 1500 -c 12 &
$ sudo tcpdump -n -i tap0 -e -s 1500 -c 12 &
$ sudo ./snabb packetblaster lwaftr --rate 0.001 --pci tap0 -v4only -D 1
packetblaster lwaftr: Sending 1 clients at 0.001 MPPS to tap0

Expand Down
19 changes: 15 additions & 4 deletions src/program/packetblaster/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local long_opts = {
size = "S", -- packet size list (defaults to IMIX)
src_mac = "s", -- source ethernet address
dst_mac = "d", -- destination ethernet address
vlan = "v", -- VLAN id
b4 = "b", -- B4 start IPv6_address,IPv4_address,port
aftr = "a", -- fix AFTR public IPv6_address
ipv4 = "I", -- fix public IPv4 address
Expand Down Expand Up @@ -56,7 +57,7 @@ function run (args)

function opt.h (arg)
print(usage)
main.exit(1)
main.exit(0)
end

local sizes = { 64, 64, 64, 64, 64, 64, 64, 594, 594, 594, 1500 }
Expand Down Expand Up @@ -121,8 +122,13 @@ function run (args)
local ipv6_only = false
function opt.E () ipv6_only = true end

local vlan = nil
function opt.v ()
vlan = assert(tonumber(arg), "duration is not a number!")
end

-- TODO how can I use digit options like -4? function opt.4 isn't valid in lua
args = lib.dogetopt(args, opt, "VD:hS:s:a:d:b:iI:c:r:PEp:", long_opts)
args = lib.dogetopt(args, opt, "VD:hS:s:a:d:b:iI:c:r:PEp:v:", long_opts)

if not pciaddr then
print(usage)
Expand All @@ -145,7 +151,7 @@ function run (args)
print("IPv4 packet sizes: " .. table.concat(sizes,","))
end

print()
print()

if ipv4_only and ipv6_only then
print("Remove options v4only and v6only to generate both")
Expand All @@ -171,9 +177,14 @@ function run (args)
input, output = "tap.input", "tap.output"
else
local device_info = pci.device_info(pciaddr)
print(string.format("src_mac=%s", src_mac))
if device_info then
local vmdq = false
if vlan then
vmdq = true
end
config.app(c, "nic", require(device_info.driver).driver,
{pciaddr = pciaddr, vmdq = false, mtu = 9500})
{pciaddr = pciaddr, vmdq = vmdq, vlan = vlan, mtu = 9500})
input, output = "nic.rx", "nic.tx"
else
fatal(("Couldn't find device info for PCI or tap device %s"):format(pciaddr))
Expand Down
7 changes: 1 addition & 6 deletions src/program/packetblaster/replay/replay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ local config = require("core.config")
local timer = require("core.timer")
local pci = require("lib.hardware.pci")
local intel10g = require("apps.intel.intel10g")
local intel_app = require("apps.intel.intel_app")
local basic_apps = require("apps.basic.basic_apps")
local main = require("core.main")
local PcapReader= require("apps.pcap.pcap").PcapReader
local LoadGen = require("apps.intel.loadgen").LoadGen
local lib = require("core.lib")
local ffi = require("ffi")
local C = ffi.C

local usage = require("program.packetblaster.replay.README_inc")

local long_opts = {
duration = "D",
help = "h",
src = "s",
dst = "d",
sizes = "S"
help = "h"
}

function run (args)
Expand Down
6 changes: 1 addition & 5 deletions src/program/packetblaster/synth/synth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ local config = require("core.config")
local timer = require("core.timer")
local pci = require("lib.hardware.pci")
local intel10g = require("apps.intel.intel10g")
local intel_app = require("apps.intel.intel_app")
local basic_apps = require("apps.basic.basic_apps")
local main = require("core.main")
local Synth = require("apps.test.synth").Synth
local LoadGen = require("apps.intel.loadgen").LoadGen
local lib = require("core.lib")
local ffi = require("ffi")
local C = ffi.C

local usage = require("program.packetblaster.synth.README_inc")

Expand Down Expand Up @@ -52,8 +49,7 @@ function run (args)

args = lib.dogetopt(args, opt, "hD:s:d:S:", long_opts)
config.app(c, "source", Synth, { sizes = sizes,
src = source,
dst = destination })
src = source, dst = destination })

local patterns = args
local nics = 0
Expand Down

0 comments on commit 8a5b147

Please sign in to comment.