Network Simulator - ns-3: Difference between revisions
imported>EyJhb ns-3 is a discrete-event network simulator for Internet systems, targeted primarily for research and educational use. This shows how to do development using ns-3 |
Improve nix expr for cross compilation combatibility, builds without clang, make the makefile work. |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
== Developing with ns-3 == | == Developing with ns-3 == | ||
ns-3 heavily relies on way for running simulations (examples, tutorials, etc.), but we can start developing using a simple Makefile and a shell.nix. | ns-3 heavily relies on way for running simulations (examples, tutorials, etc.), but we can start developing using a simple Makefile and a shell.nix. | ||
We will use [https://www.nsnam.org/doxygen/hello-simulator_8cc_source.html hello-simulator.cc] for this example. | We will use [https://www.nsnam.org/docs/release/3.43/doxygen/d4/d87/hello-simulator_8cc_source.html hello-simulator.cc] for this example. | ||
First create a <code>shell.nix</code>, with the requirements to compile our simulation. | First create a <code>shell.nix</code>, with the requirements to compile our simulation. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | |||
pkgs ? import <nixpkgs> { }, | |||
mkShell | }: | ||
pkgs.callPackage ( | |||
ns-3 | { | ||
mkShell, | |||
pkg-config | pkg-config, | ||
ns-3, | |||
} | }: | ||
mkShell { | |||
strictDeps = true; | |||
nativeBuildInputs = [ pkg-config ]; | |||
buildInputs = [ ns-3 ]; | |||
} | |||
) { } | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Then we can create our <code>Makefile</code>, do note the LIBS argument, which is the modules required (not all are build by default, might have to override some settings in ns-3). | Then we can create our <code>Makefile</code>, do note the LIBS argument, which is the modules required (not all are build by default, might have to override some settings in ns-3). | ||
<syntaxhighlight> | <syntaxhighlight lang="make"> | ||
CC ?= gcc | |||
CXX ?= g++ | |||
PKG_CONFIG ?= pkg-config | |||
DEBUG=-DNS3_LOG_ENABLE | DEBUG=-DNS3_LOG_ENABLE | ||
LIBS = | LIBS = ns3-core | ||
# compiler flags: | # compiler flags: | ||
# -g adds debugging information to the executable file | # -g adds debugging information to the executable file | ||
# -Wall turns on most, but not all, compiler warnings | # -Wall turns on most, but not all, compiler warnings | ||
CFLAGS = -g -Wall -Wextra $(shell | CFLAGS = -g -Wall -Wextra $(shell $(PKG_CONFIG) --cflags $(LIBS)) | ||
LDFLAGS=$(shell | LDFLAGS=$(shell $(PKG_CONFIG) --libs $(LIBS)) | ||
# the build target executable: | # the build target executable: | ||
| Line 41: | Line 48: | ||
$(TARGET): $(TARGET).cc | $(TARGET): $(TARGET).cc | ||
$( | $(CXX) $(DEBUG) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(TARGET).cc | ||
clean: | clean: | ||
| Line 56: | Line 63: | ||
Please keep in mind our flag when we compile, regarding debug <code>NS3_LOG_ENABLE</code>. | Please keep in mind our flag when we compile, regarding debug <code>NS3_LOG_ENABLE</code>. | ||
[[Category:Applications]] | |||