Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building stand-alone programs #363

Merged
merged 30 commits into from
Mar 1, 2015
Merged

Conversation

lukego
Copy link
Member

@lukego lukego commented Feb 6, 2015

Add support for building stand-alone programs based on Snabb Switch.

This is (proposed to be) the new standard way to write programs based on Snabb Switch. You build your application as a single executable (instead of a separate script). This executable will be portable to all recent Linux distributions (see #359). Each program will have its own command-line syntax (based on unix-style getopt) and documentation (man page).

The default build will create one executable that can run all programs (like BusyBox). You can run a specific application with either:

./snabb myprogram args...

or equivalently:

ln -s snabb myprogram
./myprogram

and you can distribute as easily as:

scp snabb somehost:myprogram

The initial programs will be based on the designs/ scripts:

  • snsh (snabb shell): The new name for the traditional ./snabb and #!snabb interface.
  • packetblaster: The new name for loadgen.
  • ... everything else in designs/ with a suitably catchy stand-alone name :-)

The current draft pull request extends the build with:

LINK      snabb
BINARY    980K snabb
PROGRAM   bin/snabb
PROGRAM   bin/packetblaster
PROGRAM   bin/snsh

and running a program looks like this:

$ sudo bin/snsh
Usage: snsh [OPTION]... [SCRIPT] [PARAMETER]...

Snabb Shell: Load the Snabb Switch core and execute Lua source code.

Execute SCRIPT if specified and then exit.

  -i,        --interactive   Start an interactive Read-Eval-Print Loop.
  -e EXPR,   --eval EXPR     Evaluate the Lua expression EXPR.
  -l MODULE, --load MODULE   Load (require) the Lua module MODULE.
  -t MODULE, --test MODULE   Test (selftest) the Lua module MODULE.
  -d,        --debug         Enable additional debugging checks.
  -j CMD,    --jit CMD       Control LuaJIT behavior. Available commands:
               -jv=FILE, --jit v=FILE
                 Write verbose JIT trace output to FILE.
               -jdump=OPTS[,FILE] --jit dump=OPTS[,FILE]
                 Output JIT traces, optionally to a file.
               -jp=OPTS[,FILE] --jit p=OPTS[,FILE]
                 Profile execution with low-overhead sampling.
             See luajit documentation for more information:
               http://luajit.org/running.html
  -P PATH,   --package-path PATH
             Use PATH as the Lua 'package.path'.
  -h,        --help          Print this usage message.

or:

$ sudo bin/packetblaster
Usage: packetblaster <PCAP-FILE> <PCI>...

Transmit packets from PCAP-FILE continuously to one or more network
adapters. The PCI arguments are Lua pattern strings that are used to
match the network adapters to use.

Examples:
  packetblaster myfile.cap 0000:01:00.0
  packetblaster myfile.cap 01:00

See mailing list thread.

lukego added 26 commits February 6, 2015 16:25
This is a getopt_long(3)-compatible command line arguments parser.

Homepage:
  http://luaforge.net/projects/alt-getopt/
The module is now called lib.lua.alt_getopt. (It was simply
"alt_getopt" before.)
./snabb now supports many different front-ends ("programs"), like
busybox.

The program is chosen either with:

  snabb <PROGRAM> [ARGS]..

or by renaming (or symlinking) the 'snabb' executable with the name of
the desired program.
This commit reintroduces (most of) the traditional ./snabb command
line functionality under the name snsh (snabb shell). This program can
be executed either with "snabb snsh ..." or with "snsh ..." if you
rename/symlink the snabb binary.

    Usage: snsh [OPTION]... [SCRIPT] [PARAMETER]...

    Snabb Shell: Load the Snabb Switch core and execute Lua source code.

    Execute SCRIPT if specified and then exit.

      -i,        --interactive   Start an interactive Read-Eval-Print Loop.
      -e EXPR,   --eval EXPR     Evaluate the Lua expression EXPR.
      -l MODULE, --load MODULE   Load (require) the Lua module MODULE.
      -t MODULE, --test MODULE   Test (selftest) the Lua module MODULE.
      -d,        --debug         Enable additional debugging checks.
      -j CMD,    --jit CMD       Control LuaJIT behavior. Available commands:
				   -jv=FILE, --jit v=FILE
				     Write verbose JIT trace output to FILE.
				   -jdump=OPTS[,FILE] --jit dump=OPTS[,FILE]
				     Output JIT traces, optionally to a file.
				   -jp=OPTS[,FILE] --jit p=OPTS[,FILE]
				     Profile execution with low-overhead sampling.
				 See luajit documentation for more information:
				   http://luajit.org/running.html
      -P PATH,   --package-path PATH
				 Use PATH as the Lua 'package.path'.
      -h,        --help          Print this usage message.
The new way to run loadgen is:
  snabb packetblaster ...
or simply:
  packetblaster ...
if you rename/symlink the snabb executable.
The standard make target now ends with:

    LINK      snabb
    BINARY    932K snabb
    PROGRAM   bin/snabb
    PROGRAM   bin/packetblaster
    PROGRAM   bin/snsh

and then you can run for example:

    $ sudo bin/packetblaster
    Usage: packetblaster <PCAP-FILE> <PCI>...

    Transmit packets from PCAP-FILE continuously to one or more network
    adapters. The PCI arguments are Lua pattern strings that are used to
    match the network adapters to use.

    Examples:
      packetblaster myfile.cap 0000:01:00.0
      packetblaster myfile.cap 01:00
'make all' builds all programs in bin/

'make bin/foo' builds only program foo (e.g. 'make bin/snsh')

(Currently all programs are exactly the same binary but with different
names and thus default behaviors.)
Previously supported the elaborate syntax:
  snabbnfv-traffic ...
mapped to module:
  program.snabbnfv.snabbnfv_traffic

but now we drop the hyphen business and expect you to use this syntax:
  snabbnfv traffic
mapped to module:
  program.snabbnfv.snabbnfv
The scripts in designs/bench/ are now folded into this program (and
those files deleted).

    Usage:
      snabbmark basic1    <npackets>
	Benchmark basic app network packet flow.

      snabbmark nfvconfig  <pci-address> <config-file-x> <config-file-y> <n>
	Benchmark loading <config-file-y> and transitioning from <config-file-x>
	to <config-file-y> <n> times.
The traffic handling scripts in designs/neutron/ are now folded into
this program, and those files are deleted.

    Usage:
      snabbnfv traffic <pci-address> <config-file> <socket-path>
      snabbnfv bench   <pci-address> <config-file> <socket-path> <npackets>

    Process traffic between Neutron ports and a physical NIC.

    In benchmark mode, measure the throughput for the first <npackets> and
    then report and terminate.
Previously snabbnfv-traffic and snabbnfv-bench were considered to be
two different programs. Now they are one and benchmark-mode is
optionally enabled by an argument.

This change unifies the command-line. There are currently still
separate functions to implement each mode.
'make' will now build only ./snabb. If you want to create files in
bin/ (e.g. bin/snabbnfv) then use 'make bin/<program>' or 'make all'.

Files named *.inc are now (inc)luded in the executable.

Specifically, the contents of a file named

    src/foo/bar.inc

can be loaded as a string with

    require("foo.bar_inc")

This is useful in several ways:

- Command-line documentation can be written into a README file
  (visible on Github) and this can be included in the binary.

- Shell scripts can be written in .sh files and embdedded.
  (This is handy for snabbnfv shell scripts at the moment.)

- Version information could be generated and included too.
Certain C structs were defined by both which causes a naming conflict
in the LuaJIT FFI.
This should be rewritten on top of ljsyscall.
There are potential conflicts between ljsyscall FFI definitions and
Snabb Switch ones. Now we load ljsyscall early in order to detect
these in testing.
Now we distinguish a program not existing from errors during loading.
The entire nfv/neutron software suite is now built into the ./snabb
binary. This involves several changes that affect many files.

The #!snabb Lua scripts (snabbnfv-traffic, snabbnfv-bench,
neutron2snabb, snabbnfv-fuzz) are now ordinary modules.

The shell scripts (neutron-sync-master and neutron-sync-agent) are now
embedded in the executable and given Lua module wrappers. (The
wrappers run the script with execve("/bin/bash", ...) via ljsyscall.)

src/test_fixtures/ is moved into src/programs/snabbnfv/test_fixtures/

The usage for all commands is refactored into README files.

The API documentation for the NFV module is currently not
present. (The README gives usage information instead now.) The
documentation could be reintroduced, or we could consider the NFV APIs
to be private to this application and simply document them with
comments.
This code has all been refactored elsewhere.
This was the largest conflict I have ever resolved with git. I tried
to be careful and I hope I did not make too many mistakes!

(I was impressed at how well git dealt with files that had been
renamed and modified, but maybe I will eat those words later...)

Conflicts:
	.gitignore
	src/Makefile
	src/apps/vhost/vhost.lua
	src/apps/vhost/vhost_apps.lua
	src/core/main.lua
	src/designs/neutron/selftest.sh
	src/lib/nfv/README.md
	src/lib/nfv/README.md.src
	src/program/snabbnfv/selftest.sh
	src/program/snabbnfv/test_fixtures/nfvconfig/test_functions/rate_limit.ports
	src/program/snabbnfv/traffic/traffic.lua
	src/test_fixtures/nfvconfig/test_functions/rate_limit.ports
	src/test_fixtures/nfvconfig/test_functions/rx_rate_limit.ports
@lukego
Copy link
Member Author

lukego commented Feb 22, 2015

I have pushed substantial updates and I hope to merge this onto master soon. (The changes touch so many files that it is a challenge to keep this branch compatible with master. I did a large and necessary merge from master today.)

Please review @eugeneia and anybody else who is willing and interested! Here is what is new today:

The whole designs/ directory is gone. The scripts have all been refactored into modules in programs/. (This includes the Neutron shell scripts!) See commit 49cadd6.

Makefile now automatically embeds files named *.inc into the snabb binary. (The Neutron shell scripts are bundled this way and so are the READMEs containing usage information.) See 3b8d459.

NFV related files have been refactored to live under programs/snabbnfv/ instead of more general locations (lib/nfv/ and test_fixtures/).

The vhost-user client app has been removed. This was bit-rotten and its C declarations of Linux ioctl data structures clash with ljsyscall. The app should be revived on top of ljsyscall. See commit e49a292.

Documentation structure is modified. As before, the public API code (core lib apps) is documented for Lua developers. However, the application code (program.nfv program.snsh ...) is now documented for end-users, in the style of man pages. This is proposed as policy: the programs are for non-programmer end-users while the APIs are for programmers writing programs. This implies that we should revise the program syntax (e.g. NFV config file) to be less Lua-centric (mea culpa). (I may have also lost some useful documentation e.g. from the NFV modules by not finding a suitable place to put it under this model.)

Question and comments welcome! (we can also throw this whole branch away if it is really a bad idea.)

(Committed accidentally.)
@plajjan
Copy link
Contributor

plajjan commented Feb 23, 2015

I quite like the idea of being able to compile and ship a contained binary that performs a specific duty. It obviously removes a lot of complexity for end users and seeing how Snabbswitch is more of a framework for developers, I think this is a great move. I haven't read through all of the code but did have a peek at the packetblaster app. What I do wonder is if we sacrifice flexibility through this? Can I still specify an app network the classic way?

I'm still not sure how I will deploy Snabb in real production environments and how static/dynamic those environments will be, but let's say I have some NC/YANG integration for Snabb so that I can describe a Snabb design, complete with links, apps and configuration for those apps. Would I be able to deploy a Snabb-instance and configure a app network through YANG just the way I want it or would I need to build a specific binary for that and map some form of input to that? I think YANG is easier to map to the config language (albeit I agree that it's a tad Lua-centric) than to pure command line arguments and having a compile step in between app network config and deployment is obviously rather cumbersome.

@lukego
Copy link
Member Author

lukego commented Feb 23, 2015

Thank you for the great question!

You should now be able to decide how generic your binary is. The extremes are packetblaster that does one narrow task and snsh that is the same full-blown Lua scripting interface that we have always had. You could ship snsh and do the rest with scripts if you want to. You could also create something medium-generic e.g. a new front-end that reads a YANG-based config file and translates to Lua internally. (That is kind-of how the snabbnfv command works except with YANG.)

You can still run your old scripts/designs with snsh <script> or snabb snsh <script> so there is no loss of functionality in this new style. The command-line syntax is not backwards compatible though. (Maybe we should deprecate the snabb <script> syntax instead of removing it? I'm not sure.)

@plajjan
Copy link
Contributor

plajjan commented Feb 23, 2015

Ok, cool. Then I'm all for!

Again, I haven't looked much at the code but from a high level functional perspective I like it a lot!

lukego added 3 commits March 1, 2015 12:58
packetblaster (previously 'loadgen') now takes a new first argument
saying how to operate. The only currently valid value is 'replay' to
load packets from a pcap file (the traditional behavior).

This is to make it easier to add new behaviors with different keywords
in the future. For example, to generate synthetic traffic, generate
tcp/udp sessions, and so on.
Try to make it harder to get into trouble with missing or stale git
submodules (luajit and ljsyscall):

'make' now automatically clones submodules instead of telling the user
to do this manually.

The git version of each submodule is recorded at build-time in files
deps/luajit.vsn and deps/ljsyscall.vsn.

src/Makefile errors if the built submodules do not have the exact
right versions.
@lukego lukego merged commit e1a2b50 into snabbco:master Mar 1, 2015
lukego added a commit that referenced this pull request Mar 1, 2015
Snabb Switch binary is now changed:

- BusyBox-like build that includes nfv/loadgen/etc.
- Scripts in designs/ refactored as modules in program/
- Now you extend Snabb Switch by creating a new programs/ directory

Here is the new usage for Snabb Switch:

    # scripting interface we have always had
    snabb snsh ...

    # loadgen
    snabb packetblaster replay ...

    # snabbnfv
    snabb snabbnfv traffic ...
    snabb snabbnfv neutron-sync-master ...
    snabb snabbnfv neutron-sync-agent ...
    snabb snabbnfv neutron2snabb ...
    snabb snabbnfv fuzz ...

    # benchmarking
    snabb snabbmark basic1 ...

See README files in programs/*/ for exact command line usage.

See PR #363 (#363) for the
detailed discussion of this design change.
@lukego lukego deleted the program branch March 10, 2015 05:03
wingo added a commit that referenced this pull request Jun 17, 2016
snabbnfv traffic: Only re-start engine when configuration changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants