구현

(NS-3) IRSML 시뮬레이션 직접 구성하기 - 1

Beige00 2024. 1. 17. 16:22

이번에는 공부한 NS-3 내용을 바탕으로 IRSML에서 제시한 토폴로지를 직접 구현, 시뮬레이션을 통해

SL,RL 과정을 거쳐 score를 산출해볼 것이다.

구현을 하다가 부족한 부분이 있으면 중간중간 NS-3를 추가로 공부하는 방법으로 접근하려고 한다.


2024.01.17

IRSML Topology
Simulation parameters

논문 상의 내용으로보면, 30~60개의 MH들은 17개의 AP에 연결되어있고, 3개의 AP는 optical fiber with the gigabit ethernet standard로 연결되어있다고 한다. 그리고 해당 시뮬레이션을 1020회 반복했다고 한다.

 

따라서 구현부에서 우선적으로 생각을 해볼 수 있는건  매 반복마다 number of mobile host 값을 정하는 것 이었다.

(참고하면 좋은 attribute name 모음 : https://www.nsnam.org/docs/release/3.4/doxygen/group___attribute_list.html)

 

이후에는 생각을 조금 해봤는데 생각보다 구현이 까다로울 것 같다.

 

1. SWMN 구조를 처음 봄. 따라서 어떻게 구현할 지 아이디어를 떠올리면 먼저 이게 올바른 접근인지를 따져야함.

 

2. 현재 구상 중인 구현 법

- 802.11ac 를 사용하는 17 AP, 30~60 MHs 과 같이 조건에 맞춰 토폴로지 구성.

 

3. 해당 17 AP 들 중 3개의 AP를 GW에 연결시켜주어야 한다.

이 때, 이 3개의 AP는 optical fiber with the gigabit ethernet standard로 GW와 연결되어있다고 하므로 GW node를 하나 만들어 연결해준다.

(유선 P2P link)

 

4.  GW를 타고 SDN Controller에 도착한 데이터들을 기반으로 SDN Controller가 돌아갈 것이다.

 

=> 지금 내가 하고 싶은 것은 그냥 IRSML의 과정을 따라가며 실제로 Score를 똑같이 뽑아낼 수 있는가? 이다.

따라서 3,4번은 굳이 구현할 필요가 없을 것 같다.

결론적으로 그냥 1,2 번의 구현을 통해 시뮬레이션 데이터들을 산출해낸 뒤, 해당 값을 csv로 만들어서 MATLAB이든

COLAB이든 데이터를 집어넣고 돌려 결과 값을 뽑아내는 것까지를 목표로 설정했다.

 

하여 지금 ns-3를 이용하여 해야할 것은 다음과 같다.

 

1. 올바른 조건에 맞추어 토폴로지 구성

2. Tracing 해야할 값은 EED, SNR, PBP, Queue Length 이다.

따라서 해당 값을 데이터화 시킬 CallBack 함수를 작성하여 Tracing  Source, Sink connect가 필요.

 

우선 1. 부터 제대로 하도록 하자.



#include <sstream>
#include <random>
#include <string>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/buildings-module.h"
#include "ns3/config-store-module.h"
#include "ns3/netanim-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/flow-monitor-module.h"


#define SIMULATION_NUM 1020
#define SIMULATION_AREA 1000
#define SIMULATION_TIME 2400
#define APnum 17
#define TransmitPower 12
#define ReceiverSensitivity -76
#define TransmissionRange 250
#define BERthreshold 0.000001
#define MinSNR 25
#define dataRate 54

using namespace ns3;

NS_LOG_COMPONENT_DEFINE("IRSMLResult");

int numberOfMHs[7] = {30,35,40,45,50,55,60};
Ptr<PacketSink> psink1;
Ptr<PacketSink> psink2;
uint64_t lastTotalRx1=0;
uint64_t lastTotalRx2=0;

int
main(int argc, char* argv[]){

    std::random_device rd;

    //for(int i=0; i<SIMULATION_NUM; i++){

        SeedManager::SetSeed(10);
        SeedManager::SetRun(1);

        //node 수 select
        uint32_t nWifi;
        std::mt19937 gen(rd());
        std::uniform_int_distribution<int> dis(0,6);
        nWifi = numberOfMHs[dis(gen)];

        //AP
        NodeContainer sinkNodes;
        sinkNodes.Create(APnum);

        NodeContainer adhocNodes;
        adhocNodes.Create(nWifi);

        NodeContainer allNodes;
        allNodes.Add(sinkNodes);
        allNodes.Add(adhocNodes);
           
        NetDeviceContainer allDevicesMH;
        NetDeviceContainer allDevicesAP;

        //RTS&CTS setting
        Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",StringValue("0"));

        //Set AP mobility model
        MobilityHelper mobility;
        Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
        positionAlloc->Add(Vector(250,166,0));
        positionAlloc->Add(Vector(500,166,0));
        positionAlloc->Add(Vector(750,166,0));
        positionAlloc->Add(Vector(200,333,0));
        positionAlloc->Add(Vector(400,333,0));
        positionAlloc->Add(Vector(600,333,0));
        positionAlloc->Add(Vector(800,333,0));
        positionAlloc->Add(Vector(250,500,0));
        positionAlloc->Add(Vector(500,500,0));
        positionAlloc->Add(Vector(750,500,0));
        positionAlloc->Add(Vector(200,665,0));
        positionAlloc->Add(Vector(400,665,0));
        positionAlloc->Add(Vector(600,665,0));
        positionAlloc->Add(Vector(800,665,0));
        positionAlloc->Add(Vector(250,832,0));
        positionAlloc->Add(Vector(500,832,0));
        positionAlloc->Add(Vector(750,832,0));
        mobility.SetPositionAllocator(positionAlloc);
        mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
        mobility.Install(sinkNodes);
        
        //Set MH mobility Model
        ObjectFactory points;
        points.SetTypeId("ns3::RandomRectanglePositionAllocator");
        points.Set("X",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
        points.Set("Y",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
        Ptr<PositionAllocator> waypos = points.Create() -> GetObject<PositionAllocator>();   
        mobility.SetMobilityModel("ns3::RandomWaypointMobilityModel",
        "Speed",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=20.0]"),
        "Pause",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=2.0]"),
        "PositionAllocator",PointerValue(waypos));
        mobility.SetPositionAllocator(waypos);
        mobility.Install(adhocNodes);


        //Set Wifi
        WifiHelper wifi;
        wifi.SetStandard(WIFI_STANDARD_80211ac);
        YansWifiPhyHelper wifiPhy;
        YansWifiChannelHelper wifiChannel;
        wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
        wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(TransmissionRange));
        wifiPhy.SetErrorRateModel("ns3::YansErrorRateModel");
        wifiPhy.SetChannel(wifiChannel.Create());
        WifiMacHelper wifiMac;
        wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode",StringValue("OfdmRate54Mbps"),"ControlMode",StringValue("VhtMcs0"));
        wifiMac.SetType("ns3::AdhocWifiMac");
        allDevicesMH = wifi.Install(wifiPhy,wifiMac,adhocNodes);
        allDevicesAP = wifi.Install(wifiPhy,wifiMac,sinkNodes);
        NetDeviceContainer allDevices = NetDeviceContainer(allDevicesMH, allDevicesAP);

        //IPv4 setting
        InternetStackHelper internet;
        internet.Install(allNodes);
        Ipv4AddressHelper address;
        address.SetBase("10.1.1.0","255.255.255.0");
        Ipv4InterfaceContainer allInterfaces;
        allInterfaces = address.Assign(allDevices);


        uint16_t port1 = 9;

        //sink app install to AP
        PacketSinkHelper sink1 ("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(), port1));
        ApplicationContainer apps_sink1 = sink1.Install(sinkNodes);
        psink1 = StaticCast<PacketSink> (apps_sink1.Get(0));
        apps_sink1.Start(Seconds(0.0));
        apps_sink1.Stop(Seconds(SIMULATION_TIME));

        OnOffHelper client("ns3::UdpSocketFactory", InetSocketAddress(allInterfaces.GetAddress(0),port1));
        client.SetAttribute ("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
        client.SetAttribute("OffTime",StringValue("ns3::ConstantRandomVariable[Constant=1]"));
        client.SetAttribute("DataRate",DataRateValue(DataRate(dataRate)));
        ApplicationContainer client_sink1 = client.Install(adhocNodes);
        client_sink1.Start(Seconds(2.0));
        client_sink1.Stop(Seconds(SIMULATION_TIME-2));

        // AnimationInterface anim("IRSML_demo.xml");
        // anim.SetMaxPktsPerTraceFile(99999999);
        // for(int i=0; i<APnum; i++){
        //     anim.UpdateNodeDescription(i,std::to_string(i));
        // }
        // anim.EnablePacketMetadata();
        // anim.EnableIpv4RouteTracking("IRSML_demo.xml",Seconds(0),Seconds(SIMULATION_TIME));

        wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
        wifiPhy.EnablePcap("IRSML",allDevicesAP.Get(0));
        wifiPhy.EnablePcap("IRSML-Mobile",allDevicesMH.Get(0));

        Simulator::Stop(Seconds(SIMULATION_TIME));
        Simulator::Run();
        double average1 = ((psink1->GetTotalRx()*8)/(1e6*SIMULATION_TIME));
        lastTotalRx1=psink1->GetTotalRx();
        Simulator::Destroy();
        std::cout<<"\nAverage throughput: "<<average1<<" Mbit/s"<<std::endl;
        std::cout<<"\nLastTotalRx: "<<lastTotalRx1<<" Mbit"<<std::endl;
    //}
    
}

현재까지 구성한 ns3 코드이다. 일단 ad hoc network로 작성이 필요하다는 것을 느껴서 따로 공부했던 예제 코드와는 별개로 도서를 구매해서 공부하였다.

오류는 발생하지 않으나 계속해서 Average thorughput과 LastTotalRx가 0인 결과가 출력이 된다.

따라서 따로 Pcap 을 찍어봤는데, 다음과 같은 사오항이 찍혀있었다.

 

2277.866479 2277866479us tsft 54.0 Mb/s 5210 MHz 11a 16dBm signal -94dBm noise ARP, Reply 10.1.1.58 is-at 00:00:00:00:00:3a, length 28
2277.866495 2277866495us tsft 24.0 Mb/s 5210 MHz 11a Acknowledgment RA:00:00:00:00:00:3a 
2277.866602 2277866602us tsft 5210 MHz 11a User 0 MCS 0 BCC FEC 80 MHz long GI Request-To-Send TA:00:00:00:00:00:01 
2277.866707 2277866707us tsft 6.0 Mb/s 5210 MHz 11a 16dBm signal -94dBm noise Clear-To-Send RA:00:00:00:00:00:01 
2277.866723 2277866723us tsft 54.0 Mb/s 5210 MHz 11a IP 10.1.1.1 > 10.1.1.58: ICMP 10.1.1.1 udp port 10000 unreachable, length 36

 

결론적으로 10.1.1.1 로의 루트가 계속 발견되지 못하는 경우이다. 어디서 어떻게 오류가 발생한지는 추가로 알아봐야할 것 같다.