[TOC]
# weekly plan
|time | work |status|
|-----------|------------------------|------|
| 10/4~10/6 | research ns-3 document | done |
| 10/7 | Start to install the ns3|done |
| 10/9 | Simulate the LTE network using ns-3|done|
| 10/14 |Record presentation video & Record the demo vedio|done|
# Network topology
## Environment
- A square of 10km x 10km.
- The center point is (0,0).
- 9 macro cells are located in (5,5), (0, 5) (-5, 5), (5,0), (0,0), (-5,0), (5,-5), (0, -5) (-5, -5). The cell radius of each macro cell is 5 km
- 30 micro cells, each has radius of 1 km, are randomly distributed in the square area
- 50 UEs are randomly distributed in the square area
:::success
- Scnerio1 : eNBs and Random Walk UEs
| gNB | 1 |
| --- | - |
| UE |30 |
![](https://hackmd.io/_uploads/S1PNeEdWp.png)
### Execution
**Create** `LTE_2.cc`
```=
cd ns-allinone-3.35/ns-3.35/scratch
sudo nano LTE_2.cc
```
```=
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/netanim-module.h"
#include "ns3/config-store.h"
using namespace ns3;
static void
CourseChange (std::string context, Ptr<const MobilityModel> position)
{
Vector pos = position->GetPosition ();
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
<< ", z=" << pos.z << std::endl;
}
int main(int argc, char *argv[])
{
// 初始化 ns-3
LogComponentEnable("LteHelper", LOG_LEVEL_INFO);
LogComponentEnable("UdpClient", LOG_LEVEL_INFO);
LogComponentEnable("UdpServer", LOG_LEVEL_INFO);
// 創建 LTE 網路模擬環境
Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
// 創建節點 (eNodeB)
NodeContainer enbNodes;
enbNodes.Create(1); // 1個 eNodeBs
// 創建節點 (UE)
NodeContainer ueNodes;
ueNodes.Create(30); // 30 個 UE
// 設定 UE 的位置
MobilityHelper mobilityUe;
mobilityUe.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue(Rectangle(-5000, 5000, -5000, 5000)));
mobilityUe.Install(ueNodes);
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeCallback (&CourseChange));
// 將節點連接至 LTE 網路
NetDeviceContainer enbDevs = lteHelper->InstallEnbDevice(enbNodes);
NetDeviceContainer ueDevs = lteHelper->InstallUeDevice(ueNodes);
// 模擬運行時間
Simulator::Stop(Seconds(10.0)); // 模擬運行時間為 10 秒
AnimationInterface anim("LTE_2.xml");
// 運行模擬
Simulator::Run();
// 釋放資源
Simulator::Destroy();
return 0;
}
```
**Run** `LTE_2.cc`
```=
cd ~/ns-allinone-3.35/ns-3.35
./waf --run scratch/LTE_2.cc
```
**Use NetAnim**
```=
cd ~/ns-allinone-3.35/netanim-3.108
./NetAnim
```
And then open `LTE_2.xml`
:::
# study notes(install ns-3)
:::success
## Prerequisites
![](https://hackmd.io/_uploads/Syi_hFU-a.png)
- Install the dependent tools
```=
sudo apt-get update
sudo apt-get install -y git vim g++ python3-pip cmake
sudo apt-get install -y libc6-dev sqlite sqlite3 libsqlite3-dev
sudo apt-get install gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3
python3 -m pip install --user cppyy
```
## Downloading ns-3 using Git
The ns-3 code is available in Git repositories on the GitLab.com service at https://gitlab.com/nsnam/. The group name nsnam organizes the various repositories used by the open source project.
The simplest way to get started using Git repositories is to fork or clone the ns-3-allinone environment. This is a set of scripts that manages the downloading and building of the most commonly used subsystems of ns-3 for you. If you are new to Git, the terminology of fork and clone may be foreign to you; if so, we recommend that you simply clone (create your own replica) of the repository found on GitLab.com, as follows:
```=
cd ~/
mkdir workspace
cd workspace
git clone https://gitlab.com/nsnam/ns-3-allinone.git
cd ns-3-allinone
```
download the python3
```=
python3 download.py
```
After this step, the additional repositories of ns-3, bake, pybindgen, and netanim will be downloaded to the ns-3-allinone directory.
## Building ns-3
- Building with the ns3 CMake wrapper
```=
./download.py
./build.py --enable-examples --enable-tests
```
```=
cd /ns-3-dev
./ns3 clean
./ns3 configure --build-profile=optimized --enable-examples --enable-tests
./ns3 clean
./ns3 configure --build-profile=debug --enable-examples --enable-tests
./ns3 build
./test.py
```
test
`./ns3 run hello-simulator`
![](https://hackmd.io/_uploads/B1zBXj8-a.png)
:::
:::info
## ns-3 basic concept
- node :
- basic abstract device.
- Written in C++, the node class provides .methods for managing computing devices.
- Computers to which various functions can be added.
- channel :
- Channel for data transmission in the network.
- The channel class manages communication subnet objects and various methods for connecting nodes to channels.
- Network equipment(NetDevice) :
- Hardware and software combination.
- Network devices in the ns-3 environment are equivalent to being installed on nodes, allowing nodes to communicate with other nodes through channels.
- application
![](https://hackmd.io/_uploads/SJvDRhIb6.png) //圖形畫界面
![](https://hackmd.io/_uploads/HJbdA3UZa.png) //產出檔案
:::
## reference
[怎麼使用NS3和怎麼使用NS3進行圖形化模擬](https://www.twblogs.net/a/5eecc21133e47b02063c29fc)
[ns-3運行例子](https://blog.csdn.net/hhhhh11123/article/details/115530856?spm=1001.2101.3001.6661.1&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-115530856-blog-52386462.235%5Ev38%5Epc_relevant_sort_base2&utm_relevant_index=1)
[ns-3的基本知識](https://blog.csdn.net/tttabcgy/article/details/77295201?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-77295201-blog-115530856.235^v38^pc_relevant_sort&spm=1001.2101.3001.4242.2&utm_relevant_index=4)