Skip to content

Commit

Permalink
Allow different IPv4 MAC addresses and VLAN tags; fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wingo committed Mar 8, 2019
1 parent 7886344 commit 14c7255
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
12 changes: 9 additions & 3 deletions src/program/packetblaster/lwaftr/README
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ Usage: packetblaster lwaftr [OPTIONS]

--sock <SOCKET> Socket name for virtio interface

--vlan VLANID VLAN tag traffic with VLANID if set
--vlan4 VLANID Encapsulate IPv4 traffic with IEEE 802.1Q with the given VLANID
--vlan6 VLANID Encapsulate IPv6 traffic with IEEE 802.1Q with the given VLANID
--vlan VLANID Same as --vlan4 VLANID --vlan6 VLANID

--src_mac SOURCE Source MAC-Address
--src_mac4 SOURCE Local MAC Address for IPv4 traffic
--src_mac6 SOURCE Local MAC Address for IPv6 traffic
--src_mac SOURCE Same as --src_mac4 SOURCE --src_mac6 SOURCE
Default: 00:00:00:00:00:00

--dst_mac DESTINATION Destination MAC-Address
--dst_mac4 DEST Remote MAC Address for IPv4 traffic
--dst_mac6 DEST Remote MAC Address for IPv6 traffic
--dst_mac DESTINATION Same as --dst_mac4 DEST --dst_mac6 DEST
Default: 00:00:00:00:00:00

--size SIZES A comma separated list of numbers. Send packets whose
Expand Down
8 changes: 4 additions & 4 deletions src/program/packetblaster/lwaftr/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function B4Gen:pull ()
rx_packets = rx_packets + 1
local payload = cast(payload_ptr_type, pkt.data + rx_payload_offset)
if payload.magic == MAGIC then
if self.last_rx_packet_number > 0 then
if self.last_rx_packet_number and self.last_rx_packet_number > 0 then
lost_packets = lost_packets + payload.number - self.last_rx_packet_number - 1
end
self.last_rx_packet_number = payload.number
Expand Down Expand Up @@ -296,7 +296,7 @@ function B4Gen:pull ()
self.softwire_idx = 0
ipv6_hdr.src_ip = self.b4_ipv6
ipv4_hdr.src_ip = self.b4_ipv4
ipv4_hdr.src_port = htons(self.b4_port)
udp_hdr.src_port = htons(self.b4_port)
end
end
end
Expand Down Expand Up @@ -400,7 +400,7 @@ function InetGen:pull ()
rx_packets = rx_packets + 1
local payload = cast(payload_ptr_type, pkt.data + rx_payload_offset)
if payload.magic == MAGIC then
if self.last_rx_packet_number > 0 then
if self.last_rx_packet_number and self.last_rx_packet_number > 0 then
lost_packets = lost_packets + payload.number - self.last_rx_packet_number - 1
end
self.last_rx_packet_number = payload.number
Expand Down Expand Up @@ -470,7 +470,7 @@ function InetGen:pull ()
-- Reset to initial softwire.
self.softwire_idx = 0
ipv4_hdr.dst_ip = self.b4_ipv4
ipv4_hdr.dst_port = htons(self.b4_port)
udp_hdr.dst_port = htons(self.b4_port)
end
end
end
30 changes: 22 additions & 8 deletions src/program/packetblaster/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ local long_opts = {
size = "S", -- frame size list (defaults to IMIX)
src_mac = "s", -- source ethernet address
dst_mac = "d", -- destination ethernet address
src_mac4 = 1, -- source ethernet address for IPv4 traffic
dst_mac4 = 1, -- destination ethernet address for IPv4 traffic
src_mac6 = 1, -- source ethernet address for IPv6 traffic
dst_mac6 = 1, -- destination ethernet address for IPv6 traffic
vlan = "v", -- VLAN id
vlan4 = 1, -- VLAN id for IPv4 traffic
vlan6 = 1, -- VLAN id for IPv6 traffic
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 @@ -80,12 +86,16 @@ function run (args)
end

local v4_src_mac = "00:00:00:00:00:00"
function opt.src_mac4 (arg) v4_src_mac = arg end
local v6_src_mac = "00:00:00:00:00:00"
function opt.s (arg) v4_src_mac, v6_src_mac = arg, arg end
function opt.src_mac6 (arg) v6_src_mac = arg end
function opt.s (arg) opt.src_mac4(arg); opt.src_mac6(arg) end

local v4_dst_mac = "00:00:00:00:00:00"
function opt.dst_mac4 (arg) v4_dst_mac = arg end
local v6_dst_mac = "00:00:00:00:00:00"
function opt.d (arg) v4_dst_mac, v6_dst_mac = arg, arg end
function opt.dst_mac6 (arg) v6_dst_mac = arg end
function opt.d (arg) opt.dst_mac4(arg); opt.dst_mac6(arg) end

local b4_ipv6, b4_ipv4, b4_port = "2001:db8::", "10.0.0.0", 1024
function opt.b (arg)
Expand Down Expand Up @@ -149,11 +159,15 @@ function run (args)
function opt.v6 () v4 = false end
opt["6"] = opt.v6

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

local pcap_file, single_pass = nil, false
function opt.o (arg)
Expand Down Expand Up @@ -218,8 +232,8 @@ function run (args)
local next_ip = nil -- Assume we have a static dst mac.
config.app(c, "ndp", ndp.NDP,
{ self_ip = tester_ip,
self_mac = ethernet:pton(v4_src_mac),
next_mac = ethernet:pton(v4_dst_mac),
self_mac = ethernet:pton(v6_src_mac),
next_mac = ethernet:pton(v6_dst_mac),
next_ip = next_ip })
config.link(c, output .. ' -> ndp.south')
config.link(c, 'ndp.south -> ' .. input)
Expand Down

0 comments on commit 14c7255

Please sign in to comment.