모각코(개인 활동 계획)

모각코 여섯 번째 모임 개인 계획, 활동 과정 및 결과

Beige00 2024. 2. 7. 18:17

이번 모각코 활동의 계획은 시뮬레이터 데이터의 완성이다.

저번의 토폴로지에서 Transmission Range를 250m로 늘려주었다.

그 후, pcap, xml 파일을 뽑았다.

#include <sstream>
#include <ns3/core-module.h>
#include <ns3/network-module.h>
#include <ns3/applications-module.h>
#include <ns3/netanim-module.h>
#include <ns3/mobility-module.h>
#include <ns3/internet-module.h>
#include <ns3/flow-monitor-module.h>
#include <ns3/yans-wifi-helper.h>
#include <ns3/aodv-helper.h>

using namespace ns3;

Ptr<PacketSink> psink1;
Ptr<PacketSink> psink2;
Ptr<PacketSink> psink3;

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

    static unsigned int seed = 5323;

    seed = 8253729*seed + 2396403;

    int runN = seed%3;

    seed %= 32768;


    uint32_t APnum = 3;
    double TotalTime = 250.0;
    SeedManager::SetSeed(seed);
    SeedManager::SetRun(runN);

    NodeContainer ApNodes;
    ApNodes.Create(APnum);
    NodeContainer mobileNodes;
    mobileNodes.Create(12);

    NodeContainer adhocNodes;
    adhocNodes.Add(ApNodes);
    adhocNodes.Add(mobileNodes);
    
    NetDeviceContainer mobileDevices;
    NetDeviceContainer APDevices;

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


    MobilityHelper mobility;
    Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
    positionAlloc->Add(Vector(250,350,0));
    positionAlloc->Add(Vector(125,150,0));
    positionAlloc->Add(Vector(375,150,0));
    mobility.SetPositionAllocator(positionAlloc);
    mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
    mobility.Install(ApNodes);

    ObjectFactory points;
    points.SetTypeId("ns3::RandomRectanglePositionAllocator");
    points.Set("X",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=500.0]"));
    points.Set("Y",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=500.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.Install(mobileNodes);

    WifiHelper wifi;
    wifi.SetStandard(WIFI_STANDARD_80211ac);
    YansWifiPhyHelper wifiPhy;
    YansWifiChannelHelper wifiChannel;
    wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
    wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(250.0));
    wifiPhy.SetErrorRateModel("ns3::YansErrorRateModel");
    wifiPhy.SetChannel(wifiChannel.Create());
    WifiMacHelper mac;
    wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager");
    mac.SetType("ns3::AdhocWifiMac");
    mobileDevices = wifi.Install(wifiPhy,mac,mobileNodes);
    APDevices = wifi.Install(wifiPhy,mac,ApNodes);
    NetDeviceContainer allDevices = NetDeviceContainer(APDevices,mobileDevices);

    InternetStackHelper internet;
    AodvHelper aodv;
    internet.SetRoutingHelper(aodv);
    internet.Install(adhocNodes);
    Ipv4AddressHelper address;
    address.SetBase("10.1.1.0","255.255.255.0");
    Ipv4InterfaceContainer allInterfaces;
    allInterfaces = address.Assign(allDevices);

    uint16_t port1 = 50000;
    uint16_t port2 = 50001;
    uint16_t port3 = 50002;

    BulkSendHelper sourceHelper1 ("ns3::TcpSocketFactory",InetSocketAddress(allInterfaces.GetAddress(0),port1));
    ApplicationContainer sourceApp1 = sourceHelper1.Install(mobileNodes);
    sourceApp1.Start(Seconds(20.0));
    sourceApp1.Stop(Seconds(TotalTime-20.0));

    BulkSendHelper sourceHelper2 ("ns3::TcpSocketFactory",InetSocketAddress(allInterfaces.GetAddress(1),port2));
    ApplicationContainer sourceApp2 = sourceHelper2.Install(mobileNodes);
    sourceApp2.Start(Seconds(20.0));
    sourceApp2.Stop(Seconds(TotalTime-20.0));

    BulkSendHelper sourceHelper3 ("ns3::TcpSocketFactory",InetSocketAddress(allInterfaces.GetAddress(2),port3));
    ApplicationContainer sourceApp3 = sourceHelper3.Install(mobileNodes);
    sourceApp3.Start(Seconds(20.0));
    sourceApp3.Stop(Seconds(TotalTime-20.0));

    PacketSinkHelper sinkHelper1 ("ns3::TcpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(), port1));
    ApplicationContainer sinkApp1 = sinkHelper1.Install(ApNodes.Get(0));
    sinkApp1.Start(Seconds(0.0));
    sinkApp1.Stop(Seconds(TotalTime));

    PacketSinkHelper sinkHelper2 ("ns3::TcpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(), port2));
    ApplicationContainer sinkApp2 = sinkHelper2.Install(ApNodes.Get(1));
    sinkApp2.Start(Seconds(0.0));
    sinkApp2.Stop(Seconds(TotalTime));

    PacketSinkHelper sinkHelper3 ("ns3::TcpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(), port3));
    ApplicationContainer sinkApp3 = sinkHelper3.Install(ApNodes.Get(2));
    sinkApp3.Start(Seconds(0.0));
    sinkApp3.Stop(Seconds(TotalTime));

    psink1 = StaticCast<PacketSink> (sinkApp1.Get(0));
    psink2 = StaticCast<PacketSink> (sinkApp2.Get(0));
    psink3 = StaticCast<PacketSink> (sinkApp3.Get(0));


    Ptr<FlowMonitor> flowmon;
    FlowMonitorHelper flow;
    flowmon = flow.InstallAll();
    AnimationInterface anim ("IRSML_demo.xml");
    anim.SetMaxPktsPerTraceFile(100000000);
    anim.UpdateNodeDescription(0,"AP-1");
    anim.UpdateNodeDescription(1,"AP-2");
    anim.UpdateNodeDescription(2,"AP-3");
    anim.EnablePacketMetadata(true);
    anim.EnableIpv4RouteTracking("IRSML_routes.xml",Seconds(1),Seconds(TotalTime),Seconds(TotalTime/2));
    anim.EnableIpv4L3ProtocolCounters(Seconds(0),Seconds(TotalTime-1));
    anim.EnableQueueCounters(Seconds(0),Seconds(TotalTime-1));
    
    wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
    wifiPhy.EnablePcap("IRSML",allDevices.Get(0));
    wifiPhy.EnablePcap("IRSML-Mobile",allDevices.Get(6));

    Simulator::Stop(Seconds(TotalTime));

    Simulator::Run();
    flowmon->SerializeToXmlFile("IRSML_flowmetrics.xml",true,true);
    Simulator::Destroy();
    double averageThro1 = ((psink1->GetTotalRx()*8)/(1e6*TotalTime));
    double averageThro2 = ((psink2->GetTotalRx()*8)/(1e6*TotalTime));
    double averageThro3 = ((psink3->GetTotalRx()*8)/(1e6*TotalTime));
    std::cout<<"Access Point 1 info:"<<std::endl;
    std::cout<<"TotalRx : "<<psink1->GetTotalRx()<<" bytes"<<std::endl;
    std::cout<<"Average Throughput : "<<averageThro1<<" Mbit/s"<<std::endl;
    std::cout<<"Access Point 2 info:"<<std::endl;
    std::cout<<"TotalRx : "<<psink2->GetTotalRx()<<" bytes"<<std::endl;
    std::cout<<"Average Throughput : "<<averageThro2<<" Mbit/s"<<std::endl;
    std::cout<<"Access Point 3 info:"<<std::endl;
    std::cout<<"TotalRx : "<<psink3->GetTotalRx()<<" bytes"<<std::endl;
    std::cout<<"Average Throughput : "<<averageThro3<<" Mbit/s"<<std::endl;


}

 

1. 첫 실행 라우팅 프로토콜 Aodv 가정.

2. 3 AP, 12 MH node

3. MH는 TCP bulk send application, AP는 PacketSink Application

이 데이터를 기반으로 기계학습을 시작할 예정이다.

 

논문에 따르면, 학습을 위한 데이터는 Queue Length, Traffic load이다.

Regression Function

Traffic load는 다양한 요인에 의해 정의되는 개념이기 때문에, 조금 더 생각해보고 교수님께 질문을 드리기로 하였다.

그러니 우선 Queue Length를 가져오는 법을 고안해야할 것 같다.

Regression Function에서 L이 Queue Length이다.

여기서 L은 논문에 정의에 의하면 hop(ij) node i의 QueueLength인 것 같다.

ns3.40 doxygen을 보자.(https://www.nsnam.org/docs/release/3.40/doxygen/d3/d79/_attribute_list.html)

이런 Attribute나 TraceSource를 잘 활용해서 QueueLength를 간접적으로 알아내야할 것 같다.

바로 QueueLength를 가져오기 위한 Attribute나 Trace Source는 없는 것 같다.

지금 생각을 해본 방안은 다음과 같다.

 

1. MacRx, MacTx, MacRxDrop, MacTxDrop 정보를 전부 Trace해서 Drop이 일어나는 시점의 Rx,Tx 확인

=> 어떤 식으로 확인해야할지를 모르겠음.

2. Txop Queue로 확인.

=> QoS 관련 공부를 더 해야 알 것 같음.

 

어떤 방안을 선택하든 인터넷 ns3 커뮤니티에 이를 질문한 사람은 있으나 해결한 사람은 없는 것 같다.

 

한편, 검색을 해보니 Omnet++ 에는 Queue Length를 가져오기 위한 메소드가 준비되어있는 것 같다.

(https://stackoverflow.com/questions/65660798/how-to-display-queue-size)

 

ns3는 방법을 더 알아봐야하는 반면, Omnet++는 더 쉽게 접근할 수 있을거 같아서 Omnet++로도 한번 토폴로지를 구현하기 시작하기로 결정하였다.

 

아무튼, 어떻게든 Feature들을 csv로 정리해내면 COLAB으로 해당 파일을 옮겨 학습을 진행해봐야할 것 같다.

어짜피 ML phase는 Regression model, Reinforcement Model이 전부 주어져 있어 별 다른 문제가 없을 것 같다.

(의사 코드는 이미 한번 직접 짜놓기까지 했다.)

그러나 다시 해당 ML Result를 Omnet이든 ns-3든 시뮬레이션에 끌고 와서 라우팅에 반영시키는 과정에 많은 차질이 생길 것 같다.

모각코 활동은 여기서 종료되나, 방학 그리고 방학이 끝나고 학기 중에도 틈틈히 이에 관한 고민과 해결 과정을 포스팅 해나갈 것이다.