Setup - ns3 Simulator

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

wget -c https://www.nsnam.org/releases/ns-allinone-3.36.1.tar.

bz2
7 tar jxvf ns-allinone-3.36.1.tar.bz2
8 cd ns-allinone-3.36.1/
9 ./build.py --enable-examples --enable-tests
10 cd ns-3.36.1/
11 ./ns3 run hello-simulator
download
tar -xzf ns3-gym-1.0.2.tar.gz
move opengym to ns-allinone-3.36.1/contrib
127 apt-get install libzmq5 libzmq5-dev
128 sudo apt-get install libzmq5 libzmq5-dev
129 apt-get install libprotobuf-dev
130 sudo apt-get install libprotobuf-dev
131 apt-get install protobuf-compiler
132 sudo apt-get install protobuf-compiler
133 ./ns3 configure --enable-examples
134 /home/hp/ns-allinone-3.36.1/ns-3.36.1/ns3 configure --enable-examples
135 /home/hp/ns-allinone-3.36.1/ns-3.36.1/ns3 build

cd ./contrib/opengym/
pip3 install -U ./model/ns3gym

cd ./examples/opengym/
172 ./test.py
173 ./simple_test.py

Installation ns3-mmwave
This repository contains a complete ns-3 installation with the addition of the
mmwave module.

Use these commands to download and build ns3-mmwave:

git clone https://github.com/nyuwireless-unipd/ns3-mmwave.git


cd ns3-mmwave
./ns3 configure --disable-python --enable-examples && ./ns3 build

./ns3 configure --enable-examples && ./ns3 build


Usage example
You can use the following command to run the mmwave-simple-epc example.

./ns3 --run mmwave-simple-epc


Other examples are included in src/mmwave/examples/

ns3-gym
OpenAI Gym is a toolkit for reinforcement learning (RL) widely used in research.
The network simulator ns-3 is the de-facto standard for academic and industry
studies in the areas of networking protocols and communication technologies. ns3-
gym is a framework that integrates both OpenAI Gym and ns-3 in order to encourage
usage of RL in networking research.

Installation ns-3 gym


Install all required dependencies required by ns-3.
# minimal requirements for C++:
apt-get install gcc g++ python3 python3-pip cmake
Check ns-3 requirements
Install ZMQ, Protocol Buffers and pkg-config libs:
sudo apt-get update
apt-get install libzmq5 libzmq3-dev
apt-get install libprotobuf-dev
apt-get install protobuf-compiler
apt-get install pkg-config
Clone ns3-gym repository in to contrib directory and change the branch:
cd ./contrib
git clone https://github.com/tkn-tub/ns3-gym.git ./opengym
cd opengym/
git checkout app-ns-3.36+

git checkout -b ns-3.36.1-branch ns-3.36.1


Check working with cmake

It is important to use the opengym as the name of the ns3-gym app directory.

Configure and build ns-3 project:


./ns3 configure --enable-examples
./ns3 build
Note: Opengym Protocol Buffer messages (C++ and Python) are build during configure.

Install ns3gym located in model/ns3gym (Python3 required)


cd ./contrib/opengym/
pip3 install --user ./model/ns3gym
(Optional) Install all libraries required by your agent (like tensorflow, keras,
etc.).

Run example:

cd ./contrib/opengym/examples/opengym/
./simple_test.py
(Optional) Start ns-3 simulation script and Gym agent separately in two terminals
(useful for debugging):
# Terminal 1
./ns3 run "opengym"

# Terminal 2
cd ./contrib/opengym/examples/opengym/
./test.py --start=0
Examples
All examples can be found here.

Basic Interface
Example Python script. Note, that gym.make('ns3-v0') starts ns-3 simulation script
located in current working directory.
import gym
import ns3gym
import MyAgent
from ns3gym import ns3env

#env = gym.make('ns3-v0') <--- causes some errors with the new OpenAI Gym
framework, please use ns3env.Ns3Env()
env = ns3env.Ns3Env()
obs = env.reset()
agent = MyAgent.Agent()

while True:
action = agent.get_action(obs)
obs, reward, done, info = env.step(action)

if done:
break
env.close()
Any ns-3 simulation script can be used as a Gym environment. This requires only to
instantiate OpenGymInterface and implement the ns3-gym C++ interface consisting of
the following functions:
Ptr<OpenGymSpace> GetObservationSpace();
Ptr<OpenGymSpace> GetActionSpace();
Ptr<OpenGymDataContainer> GetObservation();
float GetReward();
bool GetGameOver();
std::string GetExtraInfo();
bool ExecuteActions(Ptr<OpenGymDataContainer> action);
Note, that the generic ns3-gym interface allows to observe any variable or
parameter in a simulation.

A more detailed description can be found in our Paper.

sudo apt-get install autoconf automake libtool curl make g++ unzip -y
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive

Step 1: Add Bazel distribution URI as a package source


Note: This is a one-time setup step.
sudo apt install apt-transport-https curl gnupg -y
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-
archive-keyring.gpg
sudo mv bazel-archive-keyring.gpg /usr/share/keyrings
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg]
https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee
/etc/apt/sources.list.d/bazel.list
The component name "jdk1.8" is kept only for legacy reasons and doesn't relate to
supported or included JDK versions. Bazel releases are Java-version agnostic.
Changing the "jdk1.8" component name would break existing users of the repo.
Step 2: Install and update Bazel
sudo apt update && sudo apt install bazel

for ns3-dev

cd ./ns3-dev

git checkout -b ns-3.36.1-branch ns-3.36.1

to solve the error:

In file included from /usr/include/c++/11/complex.h:38,


from /home/hp/ns-3-dev/src/spectrum/model/matrix-based-channel-
model.h:25,
from /home/hp/ns-3-dev/build/include/ns3/matrix-based-channel-
model.h:1,
from /home/hp/ns-3-dev/build/include/ns3/spectrum-module.h:17,
from /home/hp/ns-3-dev/contrib/opengym/examples/interference-
pattern/mygym.h:27,
from /home/hp/ns-3-dev/contrib/opengym/examples/interference-
pattern/mygym.cc:21:
/home/hp/ns-3-dev/build/include/ns3/attribute-container-accessor-helper.h:138:79:
error: expected ‘>’ before ‘(’ token
138 | template <typename V, typename T, template <typename...> class U,
typename ...I,
|

solution :

updated ns3gym/ns3gym/ns3env.py and start_sim.py

using “https://github.com/tkn-tub/ns3-gym/pull/72/files”

inserted somelines in mygym.h after including the .h filesn to solve conflict in


imported .h files

#ifdef I
#undef I
#endif

You might also like