1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| [root@localhost ~]# cat ~/l3_ipv4_udp_97_X2.lua local mg = require "moongen" local memory = require "memory" local device = require "device" local ts = require "timestamping" local filter = require "filter" local hist = require "histogram" local stats = require "stats" local timer = require "timer" local arp = require "proto.arp" local log = require "log"
-- set addresses here local SRC_MAC = "FE:DC:BA:98:76:54" local DST_MAC = "12:34:45:78:9A:BC" local SRC_IP_BASE = "172.1.1.1" local DST_IP = "192.1.1.1" local SRC_PORT = 8080 local DST_PORT = 16285
function configure(parser) parser:option("-r --rate", "Transmit rate in Mbit/s."):default(10000):convert(tonumber) parser:option("-f --flows", "Number of flows (randomized source IP)."):default(4):convert(tonumber) parser:option("-s --size", "Packet size."):default(60):convert(tonumber) end
function master(args) -- use port 0 txDev0 = device.config{port = 0, rxQueues = 3, txQueues = 3} rxDev0 = device.config{port = 0, rxQueues = 3, txQueues = 3}
-- use port 1 txDev1 = device.config{port = 1, rxQueues = 3, txQueues = 3} rxDev1 = device.config{port = 1, rxQueues = 3, txQueues = 3}
device.waitForLinks() -- max 1kpps timestamping traffic timestamping -- rate will be somewhat off for high-latency links at low rates if args.rate > 0 then txDev0:getTxQueue(0):setRate(args.rate - (args.size + 4) * 8 / 1000) txDev1:getTxQueue(0):setRate(args.rate - (args.size + 4) * 8 / 1000) end
mg.startTask("loadSlave", txDev0:getTxQueue(0), rxDev0, args.size, args.flows) mg.startTask("loadSlave", txDev1:getTxQueue(0), rxDev1, args.size, args.flows) mg.waitForTasks() end
local function fillUdpPacket(buf, len) buf:getUdpPacket():fill{ ethSrc = queue, ethDst = DST_MAC, ip4Src = SRC_IP, ip4Dst = DST_IP, udpSrc = SRC_PORT, udpDst = DST_PORT, pktLength = len } end
function loadSlave(queue, rxDev, size, flows) local mempool = memory.createMemPool(function(buf) fillUdpPacket(buf, size) end) local i = 0; local acc = 0; local bufs = mempool:bufArray() local counter = 0 local txCtr = stats:newDevTxCounter(queue, "plain") local rxCtr = stats:newDevRxCounter(rxDev, "plain") local baseIP = parseIPAddress(SRC_IP_BASE) while mg.running() do bufs:alloc(size) for i, buf in ipairs(bufs) do local pkt = buf:getUdpPacket()
pkt.ip4.src:set(baseIP + counter) -- new flow by randomized ip src
pkt.udp:setDstPort(16285) pkt.udp:setSrcPort(65535)
-- Prefix pkt.payload.uint8[0] = 0x97 pkt.payload.uint8[1] = 0x11
-- Resv pkt.payload.uint8[2] = 0 pkt.payload.uint8[3] = 0 pkt.payload.uint8[4] = 0 pkt.payload.uint8[5] = 0
-- Session id pkt.payload.uint8[6] = 0xAB pkt.payload.uint8[7] = 0xAC pkt.payload.uint8[8] = 0xAD pkt.payload.uint8[9] = acc % 256 -- randomized Session id
-- SEQ pkt.payload.uint8[12] = acc / 256 pkt.payload.uint8[13] = acc % 256
acc = acc + 1 counter = incAndWrap(counter, flows) end -- UDP checksums are optional, so using just IPv4 checksums would be sufficient here bufs:offloadUdpChecksums() queue:send(bufs) txCtr:update() rxCtr:update() end txCtr:finalize() rxCtr:finalize() end
|