Skip to content

Commit 86453e8

Browse files
authored
Merge pull request #94 from ShenMuyuan/cmake
updated README and removed interference-pattern example
2 parents bcfb7ea + 38e5413 commit 86453e8

File tree

7 files changed

+75
-775
lines changed

7 files changed

+75
-775
lines changed

README.md

Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,71 @@
11
# ns3-ai
2+
23
## Online Tutorial:
3-
Join us in this [online recording](https://vimeo.com/566296651) to get better knowledge about ns3-ai! The slides introduce the ns3-ai model could also be found [here](https://www.nsnam.org/wp-content/uploads/2021/tutorials/ns3-ai-tutorial-June-2021.pdf)!
4+
5+
Join us in this [online recording](https://vimeo.com/566296651) to get better knowledge about ns3-ai! The slides
6+
introduce the ns3-ai model could also be
7+
found [here](https://www.nsnam.org/wp-content/uploads/2021/tutorials/ns3-ai-tutorial-June-2021.pdf)!
8+
49
## Description
5-
The [ns–3](https://www.nsnam.org/) simulator is an open-source networking simulation tool implemented by C++ and wildly used for network research and education. Currently, more and more researchers are willing to apply AI algorithms to network research. Most AI algorithms are likely to rely on open source frameworks such as [TensorFlow](https://www.tensorflow.org/) and [PyTorch](https://pytorch.org/). These two parts are developed independently and extremely hard to merge, so it is more reasonable and convenient to connect these two tasks with data interaction. Our model provides a high-efficiency solution to enable the data interaction between ns-3 and other python based AI frameworks.
610

7-
This module does not provide any AI algorithms or rely on any frameworks but instead is providing a Python module that enables AI interconnect, so the AI framework needs to be separately installed. You only need to clone or download this work, then import the Python modules, you could use this work to exchange data between ns-3 and your AI algorithms.
11+
The [ns–3](https://www.nsnam.org/) simulator is an open-source networking simulation tool implemented by C++ and wildly
12+
used for network research and education. Currently, more and more researchers are willing to apply AI algorithms to
13+
network research. Most AI algorithms are likely to rely on open source frameworks such
14+
as [TensorFlow](https://www.tensorflow.org/) and [PyTorch](https://pytorch.org/). These two parts are developed
15+
independently and extremely hard to merge, so it is more reasonable and convenient to connect these two tasks with data
16+
interaction. Our model provides a high-efficiency solution to enable the data interaction between ns-3 and other python
17+
based AI frameworks.
818

19+
This module does not provide any AI algorithms or rely on any frameworks but instead is providing a Python module that
20+
enables AI interconnect, so the AI framework needs to be separately installed. You only need to clone or download this
21+
work, then import the Python modules, you could use this work to exchange data between ns-3 and your AI algorithms.
922

10-
Inspired by [ns3-gym](https://github.com/tkn-tub/ns3-gym), but using a different approach which is faster and more flexible.
23+
Inspired by [ns3-gym](https://github.com/tkn-tub/ns3-gym), but using a different approach which is faster and more
24+
flexible.
1125

1226
### Features
13-
- High-performance data interaction module (using shared memory).
27+
28+
- High-performance data interaction module (using shared memory).
1429
- Provide a high-level interface for different AI algorithms.
1530
- Easy to integrate with other AI frameworks.
1631

17-
1832
## Installation
33+
1934
### 1. Install this module in ns-3
20-
#### Get ns-3:
35+
36+
#### Get ns-3:
37+
2138
This module needs to be built within ns-3, so you need to get a ns-3-dev or other ns-3 codes first.
2239

2340
Check [ns-3 installation wiki](https://www.nsnam.org/wiki/Installation) for detailed instructions.
2441

2542
#### Add this module
43+
2644
```Shell
2745
cd $YOUR_NS3_CODE/contrib
2846
git clone https://github.com/hust-diangroup/ns3-ai.git
2947
```
3048

31-
#### Rebuild ns-3
49+
#### Reconfigure ns-3
50+
3251
```Shell
33-
./waf configure
34-
./waf
52+
./ns3 clean
53+
./ns3 configure
3554
```
3655

3756
### 2. Add Python interface
3857

3958
#### Install
40-
Python3 is used and tested.
59+
60+
Python 3 is used and tested. It's recommended to use ns3-ai under a Conda environment.
4161

4262
```Shell
4363
cd $YOUR_NS3_CODE/contrib/ns3-ai/py_interface
44-
4564
pip3 install . --user
4665
```
4766

48-
#### Baisc usage
67+
#### Basic usage
68+
4969
``` Python
5070
import py_interface
5171
mempool_key = 1234 # memory pool key, arbitrary integer large than 1000
@@ -59,9 +79,21 @@ with v as o:
5979
print(*o)
6080
py_interface.FreeMemory()
6181
```
82+
6283
## Shared Memory Pool
63-
The ns3-ai module interconnects the ns-3 and AI frameworks by transferring data through the shared memory pool. The memory can be accessed by both sides and controlled mainly in ns-3. The shared memory pool is defined in `ns3-ai/model/memory-pool.h`.
64-
The `CtrlInfoBlock` is the control block of the all shared memory pool, the `SharedMemoryCtrl` is the control block of each shared memory, and the `SharedMemoryLockable` is the actual shared memory used for data exchange. In each memory block, we use version and nextVersion as the lock indicator. The synchronization for reading/writing locks and the events update are accomplished by the lock indicator. For every process that wants to access or modify the data, it will compare the `version` variable and the `nextVersion` variable. If they are the same, it means that the memory is reachable. Then it will add one to the next version atomically to lock the memory and also add one to the version after its operation to the memory to unlock the memory. Besides the version of the memory acts as the signal to tell different processes the current state of the memory block, which provides different methods to synchronize.
84+
85+
The ns3-ai module interconnects the ns-3 and AI frameworks by transferring data through the shared memory pool. The
86+
memory can be accessed by both sides and controlled mainly in ns-3. The shared memory pool is defined
87+
in `ns3-ai/model/memory-pool.h`.
88+
The `CtrlInfoBlock` is the control block of the all shared memory pool, the `SharedMemoryCtrl` is the control block of
89+
each shared memory, and the `SharedMemoryLockable` is the actual shared memory used for data exchange. In each memory
90+
block, we use version and nextVersion as the lock indicator. The synchronization for reading/writing locks and the
91+
events update are accomplished by the lock indicator. For every process that wants to access or modify the data, it will
92+
compare the `version` variable and the `nextVersion` variable. If they are the same, it means that the memory is
93+
reachable. Then it will add one to the next version atomically to lock the memory and also add one to the version after
94+
its operation to the memory to unlock the memory. Besides the version of the memory acts as the signal to tell different
95+
processes the current state of the memory block, which provides different methods to synchronize.
96+
6597
```
6698
|SharedMemoryBlock1|
6799
|SharedMemoryBlock2|
@@ -75,44 +107,59 @@ The `CtrlInfoBlock` is the control block of the all shared memory pool, the `Sha
75107
|MemoryPoolContrlBlk|
76108
```
77109

110+
## Examples
78111

112+
### Quick Start on how to us ns3-ai - [a_plus_b](https://github.com/hust-diangroup/ns3-ai/tree/master/examples/a_plus_b)
79113

80-
## Examples
81-
### Quick Statrt on how to us ns3-ai - [a_plus_b](https://github.com/hust-diangroup/ns3-ai/tree/master/examples/a_plus_b)
82-
This example show how you can use ns3-ai by a very simple case that you transfer the data from ns-3 to python side and calculate a + b in the python to put back the results. Please check the README in it for more details.
114+
This example show how you can use ns3-ai by a very simple case that you transfer the data from ns-3 to python side and
115+
calculate a + b in the python to put back the results. Please check the README in it for more details.
83116

84117
### [RL-TCP](https://github.com/hust-diangroup/ns3-ai/blob/master/examples/rl-tcp/)
85-
This example is inspired by [ns3-gym example](https://github.com/tkn-tub/ns3-gym#rl-tcp). We bulid this example for the benchmarking and to compare with their module.
118+
119+
This example is inspired by [ns3-gym example](https://github.com/tkn-tub/ns3-gym#rl-tcp). We build this example for the
120+
benchmarking and to compare with their module.
86121

87122
#### Build and Run
123+
88124
Run ns-3 example:
125+
89126
```
90-
cp -r contrib/ns3-ai/example/rl-tcp scratch/
127+
cp -r contrib/ns3-ai/examples/rl-tcp scratch/
128+
cd scratch/rl-tcp/
91129
python3 run_tcp_rl.py --use_rl --result
92130
```
93131

94132
### [LTE_CQI](https://github.com/hust-diangroup/ns3-ai/blob/master/examples/lte_cqi/)
95-
This original work is done based on [5G NR](https://5g-lena.cttc.es/) branch in ns-3. We made some changes to make it also run in LTE codebase in ns-3 mainline. We didn't reproduce all the experiments on LTE, and the results used in this document are based on NR work.
133+
134+
This original work is done based on [5G NR](https://5g-lena.cttc.es/) branch in ns-3. We made some changes to make it
135+
also run in LTE codebase in ns-3 mainline. We didn't reproduce all the experiments on LTE, and the results used in this
136+
document are based on NR work.
96137

97138
#### Build and Run
98139

99140
Run ns-3 example:
100-
If you want to test the LSTM, you can run another python script but you may need to install [TensorFlow](https://www.tensorflow.org/) environment first.
141+
If you want to test the LSTM, you can run another python script but you may need to
142+
install [TensorFlow](https://www.tensorflow.org/) environment first.
143+
101144
```Shell
145+
cp -r contrib/ns3-ai/examples/lte_cqi scratch/
102146
cd scratch/lte_cqi/
103-
104147
python3 run_online_lstm.py 1
105148
```
106-
**NOTE: If the program does not exit normally, you need to run freeshm.sh to release the shared memory manually.**
149+
150+
**NOTE: If the program does not exit normally, you need to run `freeshm.sh` to release the shared memory manually.**
107151

108152
### [Rate-Control](https://github.com/hust-diangroup/ns3-ai/tree/master/examples/rate-control)
109-
This is an example that shows how to develop a new rate control algorithm for the Wi-Fi model in ns-3 using the ns3-ai model.
153+
154+
This is an example that shows how to develop a new rate control algorithm for the Wi-Fi model in ns-3 using the ns3-ai
155+
model.
156+
110157
#### Usage
111158

112159
Copy this example to scratch:
113160

114161
```shell
115-
cp -r contrib/ns3-ai/example/rate-control scratch/
162+
cp -r contrib/ns3-ai/examples/rate-control scratch/
116163
cd scratch/rate-control
117164
```
118165

@@ -129,7 +176,9 @@ python3 ai_thompson_sampling.py
129176
```
130177

131178
## Cite our work
179+
132180
Please use the following bibtex:
181+
133182
```
134183
@inproceedings{10.1145/3389400.3389404,
135184
author = {Yin, Hao and Liu, Pengyu and Liu, Keshu and Cao, Liu and Zhang, Lytianyang and Gao, Yayu and Hei, Xiaojun},

examples/interference-pattern/cognitive-agent-v1.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)