#include <sstream>
#include <fstream>
#include <ns3/core-module.h>
#include <ns3/network-module.h>
#include <ns3/applications-module.h>
#include <ns3/mobility-module.h>
#include <ns3/internet-module.h>
#include <ns3/yans-wifi-helper.h>
#include <ns3/aodv-helper.h>
#include <ns3/adhoc-wifi-mac.h>
#include <ns3/wifi-mac-queue.h>
#include <ns3/netanim-module.h>
#include <ns3/flow-monitor-module.h>
#include <ns3/qos-txop.h>
#include <vector>
#include <string>
#include <ns3/flow-monitor-module.h>
#include <ns3/netanim-module.h>
using namespace ns3;
std::vector<std::vector<std::string>> Data;
uint32_t APnum = 3;
void makeCsvFile(const std::string& filename, const std::vector<std::vector<std::string>>& data){
std::ofstream file(filename);
for(const auto& row : data){
for(auto it = row.begin(); it!=row.end(); ++it){
file<<*it;
if(next(it)!=row.end()){
file<<",";
}
}
file<<std::endl;
}
file.close();
}
void TracingParameter(NetDeviceContainer n){
for(uint32_t i=0; i<n.GetN(); i++){
PointerValue ptr;
n.Get(i)->GetAttribute("Mac",ptr);
Ptr<AdhocWifiMac> mac = ptr.Get<AdhocWifiMac>();
Ptr<WifiMacQueue> txop = mac->GetTxopQueue(AC_BE);
Ptr<PacketSink> psink;
ApplicationContainer app = n.Get(i)->GetNode()->GetApplication(0);
psink = StaticCast<PacketSink>(app.Get(0));
double averageTL = ((psink->GetTotalRx()*8)/(1e6*Simulator::Now().GetSeconds()));
Data.push_back({std::to_string(Simulator::Now().GetSeconds()),std::to_string(i),std::to_string(txop->GetNPackets()),std::to_string(averageTL)});
}
Simulator::Schedule(Seconds(1.0),&TracingParameter,n);
}
int
main(int argc, char* argv[]){
Data.push_back({"Second","NodeID","QueueLength","AverageTP"});
double TotalTime = 500.0;
NodeContainer AdhocNodes;
AdhocNodes.Create(30);
NetDeviceContainer AdhocDevices;
Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",StringValue("0"));
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::RandomRectanglePositionAllocator","X",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"),
"Y",StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
mobility.Install(AdhocNodes);
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211ac);
YansWifiPhyHelper phy;
YansWifiChannelHelper channel;
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
channel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(250.0));
phy.SetErrorRateModel("ns3::YansErrorRateModel");
phy.SetChannel(channel.Create());
WifiMacHelper mac;
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager");
mac.SetType("ns3::AdhocWifiMac","QosSupported",BooleanValue(true));
AdhocDevices = wifi.Install(phy,mac,AdhocNodes);
InternetStackHelper internet;
AodvHelper aodv;
internet.SetRoutingHelper(aodv);
internet.Install(AdhocNodes);
Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer ipv4Interface = ipv4.Assign(AdhocDevices);
uint64_t port = 10000;
ApplicationContainer sink_app, source_app;
for(uint32_t i=0; i<AdhocNodes.GetN(); i++){
InetSocketAddress localAddress (Ipv4Address::GetAny(), port);
localAddress.SetTos(0x70);
PacketSinkHelper sink ("ns3::TcpSocketFactory", localAddress);
sink_app.Add(sink.Install(AdhocNodes.Get(i)));
}
sink_app.Start(Seconds(0));
sink_app.Stop(Seconds(TotalTime));
for(uint32_t i=0; i<AdhocNodes.GetN(); i++){
for(uint32_t j=0; j<AdhocNodes.GetN();j++){
if(i==j) continue;
InetSocketAddress sinkSocket (ipv4Interface.GetAddress(j),port);
sinkSocket.SetTos(0x70);
BulkSendHelper bulk ("ns3::TcpSocketFactory",sinkSocket);
bulk.SetAttribute("StartTime",TimeValue(Seconds(1)));
bulk.SetAttribute("StopTime",TimeValue(Seconds(TotalTime-1)));
source_app.Add(bulk.Install(AdhocNodes.Get(i)));
}
}
Simulator::Schedule(Seconds(4.0),&TracingParameter,AdhocDevices);
Simulator::Stop(Seconds(TotalTime));
Simulator::Run();
Simulator::Destroy();
makeCsvFile("QueueLength.csv",Data);
}
//csv 파일을 결과로 출력해내는 최종 코드이다. 추후 데이터 소스의 문제가 있다고 판단될 시,
//데이터를 구하는 Tracing 부분만 수정해서 사용하면 될 것이다.
우선 NetAnim xml file을 생성하는 코드와 Bulk Send Application의 송신 데이터 크기 규격을 1024 byte로 수정하는 코드를 추가하였다.
그 후 시뮬레이션을 실행해봤으나, 결과에 별 차이가 없었다.
아마 BulkSend application만 돌아가고 PacketSinkApplication이 처리를 하지 않아서 그런 것 같다.
따라서 각 노드에 PacketSinkApplication을 설치해주었다.
이렇게 구해진 csv 파일을 학습에 사용하기로 결정하였다.
정리해보면 다음의 csv 파일의 정보를 토대로 ρ 자리에 ThroughPut을, L 자리에 QueueLength를 넣으면 되는 것이다.
여기까지 진행 후, Traffic load란 어떻게 주어야 하는지 등 논문에 기재되어있지 않은 필요한 정보가 존재함을 알게 되었다.
추가 구현을 진행하는 것은 남의 논문을 구현하는데 너무 많은 시간을 소모하는 것 같다는 교수님의 의견에 이번 IRSML 구현은 NS3의 사용법과 실제 구현을 하는 법을 배웠다는 점을 의의로 마무리 짓기로하였다.
그러나 이러한 Traffic load 등을 어떻게 주었는지는 논문의 저자들에게 질문을 할 예정이다.
이제 내 목표인 학부생 때 논문 쓰기를 하기 위해 나만의 주제로 넘어갈 것이다.
현재 구체적이지는 않으나 추상적인 주제는 수립되어있으므로 이와 관련된 포스팅으로 다시 논문 관련 포스팅을 하도록 하겠다.
'구현' 카테고리의 다른 글
문제 해결을 위한 시뮬레이션 제작 및 Tracing source 추출-추가 구현 (0) | 2024.03.28 |
---|---|
IRSML 시뮬레이션 직접 구성하기 - 5 (0) | 2024.02.26 |
IRSML 시뮬레이션 직접 구성하기 - 4 (0) | 2024.02.22 |
IRSML 시뮬레이션 직접 구성하기 - 3 (0) | 2024.02.14 |
(NS-3) IRSML 시뮬레이션 직접 구성하기 - 2 (0) | 2024.02.06 |