Skip to content

Instantly share code, notes, and snippets.

@dpino
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpino/323f5c43802449b8e041 to your computer and use it in GitHub Desktop.
Save dpino/323f5c43802449b8e041 to your computer and use it in GitHub Desktop.
Snabb basic app
#!/usr/bin/env snabb
-- Run as: sudo ./snabb snsh snabb-basic.lua
--
-- Source: https://github.com/dverbeir/snabbswitch/blob/2bfec54a55146f36aa0e988b90c58ce110df6522/src/designs/dv/fwd
local config = require("core.config")
local app = require("core.app")
local link = require("core.link")
local Intel82599 = require("apps.intel.intel_app").Intel82599
local C = require("ffi").C
function run (parameters)
local c = config.new()
config.app(c, "nic1", Intel82599, {pciaddr="0000:04:00.0"})
config.app(c, "nic2", Intel82599, {pciaddr="0000:04:00.1"})
config.link(c, "nic1.tx -> nic2.rx");
engine.configure(c)
local old_packets = 0
while true do
local start = C.get_monotonic_time()
engine.main({duration = 10})
local finish = C.get_monotonic_time()
local runtime = finish - start
local packets = engine.app_table.nic1.output.tx.stats.txpackets - old_packets
old_packets = engine.app_table.nic1.output.tx.stats.txpackets
-- engine.report()
print(("Processed %.1f million packets in %.2f seconds"):format(packets / 1e6, runtime))
print(("Rate(Mpps):\t%.3f"):format(packets / runtime / 1e6))
end
end
run(main.parameters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment