-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rs-example code #168
Comments
Hello, |
First of all, please use ns-3.41 as that is the officially supported version of ns-3 by the latest version of the lorawan module. |
Hello Alessandro,
First of all thanks for responding. Allow me to also apologise for taking
it for granted that the terms rs-example and RS LoRa are known. I am
studying and following up the following work in the article: "Improving
Reliability and Scalability of
LoRaWANs Through Lightweight Scheduling", where the authors developed the
RS LoRa algorithm (R for Reliability and S for Scalability). I downloaded
the code from the following provided in the article: https://github.com/
networkedsystems/lora-ns
I was trying to run the code in the examples folder to understand how it
works and that's how the error mentioned earlier was coming up. Here is a
sample of the code i was running known as rs-example.cc
#include "ns3/non-communicating-net-device.h"
#include <ns3/okumura-hata-propagation-loss-model.h>
#include <ns3/core-module.h>
#include <ns3/packet.h>
#include <ns3/lora-module.h>
#include <ns3/spectrum-module.h>
#include <ns3/mobility-module.h>
#include <ns3/spectrum-value.h>
#include <ns3/spectrum-analyzer.h>
//#include <ns3/log.h>
//#include <string>
#include <iostream>
#include <ns3/isotropic-antenna-model.h>
#include <ns3/trace-helper.h>
#include <ns3/drop-tail-queue.h>
#include <unordered_map>
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include <ns3/gw-trailer.h>
NS_LOG_COMPONENT_DEFINE ("lora");
using namespace ns3;
using namespace std;
/////////////////////////////////
// Configuration
/////////////////////////////////
//std::vector <int, double> marked_list;
double length = 2000; //!< Square city with length as distance
int pktsize = 51; //!< size of packets, in bytes
int duration = 60*60;//10000; //!< Duration of the simulation
double interval = 10; // interval between packets, minutes
bool verbose = false; // enable logging (different from trace)
bool nakagami = true; // enable nakagami path loss
bool dynamic = false; // enable random moving of pan node
uint32_t nSensors = 10; // numbenir of sent packets
uint32_t nGateways = 1; // numbenir of sent packets
Ptr<OutputStreamWrapper> m_stream = 0; // stream for waterfallcurve
Ptr<UniformRandomVariable> randT = CreateObject<UniformRandomVariable> ();
uint32_t interT = 600; // time between a retransmissions.
std::unordered_map<uint32_t,std::tuple<uint32_t,uint32_t,uint32_t,uint32_t,
uint32_t,uint32_t> > errorMap;
//errormap: transmitted, received, received unique, received original,
xlocation, ylocation
std::unordered_map<uint32_t,Ptr<LoRaNetDevice> > deviceMap;
Mac32Address server;
NetDeviceContainer gateways;
uint8_t offsets [7] = {2,3,3,1,2,2,3};
/////////////////////////////////
// End configuration
/////////////////////////////////
uint32_t
GetClosestGateway (Ptr<MobilityModel> location)
{
uint32_t closestNode;
double smallestDistance = 99999999;
for (uint32_t i = 0; i<gateways.GetN (); i++)
{
double distanceToI = location->GetDistanceFrom (gateways.Get(i)->
GetNode ()->GetObject<MobilityModel> ());
if (distanceToI < smallestDistance)
{
smallestDistance = distanceToI;
closestNode = gateways.Get(i)->GetNode ()->GetId();
}
}
return closestNode;
}
/// Save that teh message has been transmitted
void
Transmitted (const Ptr<const Packet> packet)
{
Ptr<Packet> copy = packet->Copy();
LoRaMacHeader header;
copy->RemoveHeader(header);
uint32_t addr = Mac32Address::ConvertFrom(header.GetAddr()).GetUInt();
//std::tuple<uint32_t,uint32_t,uint32_t,uint32_t,uint32_t,uint32_t>
tuple = errorMap[addr];
std::get<0>(errorMap[addr])++;// =
std::make_tuple(++std::get<0>(tuple),std::get<1>(tuple),std::get<2>(tuple),std::get<3>(tuple),std::get<4>(tuple));
}
// save that a message has been received
void
Received (const Ptr<const Packet> packet)
{
Ptr<Packet> copy = packet->Copy();
LoRaMacHeader header;
copy->RemoveHeader(header);
GwTrailer trailer;
copy->RemoveTrailer (trailer);
uint32_t addr = Mac32Address::ConvertFrom(header.GetAddr()).GetUInt();
std::get<1>(errorMap[addr])++;
if ( trailer.GetGateway () == GetClosestGateway (deviceMap[addr]->
GetNode ()->GetObject<MobilityModel>()))
std::get<3>(errorMap[addr])++;
}
// save that a message has been uniquely received
void
ReceivedUnique (const Ptr<const Packet> packet)
{
Ptr<Packet> copy = packet->Copy();
LoRaMacHeader header;
copy->RemoveHeader(header);
uint32_t addr = Mac32Address::ConvertFrom(header.GetAddr()).GetUInt();
std::get<2>(errorMap[addr])++;
}
int
mainBody ()
{
randT->SetAttribute("Max",DoubleValue(600));
//Enable checksum (FCS)
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
// Logging
if (verbose)
{
LogComponentEnableAll (LOG_PREFIX_TIME);
LogComponentEnableAll (LOG_PREFIX_FUNC);
}
//Create nodes
NodeContainer loraNetworkNode;
loraNetworkNode.Create (1);
NodeContainer loraCoordinatorNodes;
loraCoordinatorNodes.Create (nGateways);
NodeContainer loraDeviceNodes;
loraDeviceNodes.Create(nSensors);
NodeContainer loraBackendNodes(loraNetworkNode, loraCoordinatorNodes);
//std::cout << "Create mobility of basestations" << std::endl;
MobilityHelper mobility;
Ptr<ListPositionAllocator> basePositionList = CreateObject<
ListPositionAllocator> ();
basePositionList->Add (Vector (0.0,0.0,0.0)); //network
//basePositionList->Add (Vector (1000,500,50.0)); //main base station
//basePositionList->Add (Vector (2000,500,50.0)); //main base station
//basePositionList->Add (Vector (500,std::sqrt(3)*500+500,50.0));
//main base station
//basePositionList->Add (Vector (1500,std::sqrt(3)*500+500,50.0));
//main base station
basePositionList->Add (Vector
(1000,1000,50));//std::sqrt(3)*500+500,50.0));
//main base station
//basePositionList->Add (Vector (2500,std::sqrt(3)*500+500,50.0));
//main base station
//basePositionList->Add (Vector (1000,std::sqrt(3)*500*2+500,50.0));
//main base station
//basePositionList->Add (Vector (2000,std::sqrt(3)*500*2+500,50.0));
//main base station
mobility.SetPositionAllocator (basePositionList);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install(loraBackendNodes);
//Mobility nodes
std::cout << "Create mobility of nodes" << std::endl;
MobilityHelper mobility2;
Ptr<ListPositionAllocator> nodePositionList = CreateObject<
ListPositionAllocator>();
for(uint32_t nodePositionsAssigned = 0; nodePositionsAssigned <
nSensors; nodePositionsAssigned++){
double x,y;
do{
x = randT->GetInteger(0,length);
y = randT->GetInteger(0,length);
}
while ((x-1000)*(x-1000)+(y-1000)*(y-1000) > 1000*1000);
std::cout << x << "," << y << std::endl;
nodePositionList->Add (Vector (x,y,1.0));
}
mobility2.SetPositionAllocator (nodePositionList);
mobility2.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility2.Install (loraDeviceNodes);
//Channel
std::cout << "Create channel" << std::endl;
SpectrumChannelHelper channelHelper;
channelHelper.SetChannel ("ns3::MultiModelSpectrumChannel");
if (nakagami)
{
channelHelper.AddPropagationLoss (
"ns3::OkumuraHataPropagationLossModel","Frequency",DoubleValue(868e6));
channelHelper.AddPropagationLoss (
"ns3::NakagamiPropagationLossModel","m0",DoubleValue(1),"m1",DoubleValue(1),
"m2",DoubleValue(1));
}
else
{
channelHelper.AddPropagationLoss (
"ns3::OkumuraHataPropagationLossModel","Frequency",DoubleValue(868e6));
}
channelHelper.SetPropagationDelay (
"ns3::ConstantSpeedPropagationDelayModel");
Ptr<SpectrumChannel> channel = channelHelper.Create ();
LoRaHelper lorahelper;
lorahelper.SetChannel (channel);
// Configure gateways
std::cout << "Create gateways" << std::endl;
gateways = lorahelper.InstallRsGateways (loraCoordinatorNodes);
for (uint32_t i = 0; i< gateways.GetN(); i++)
gateways.Get(i)->SetAttribute ("Offset",UintegerValue(offsets[i]-1
));
// Create the nodes
std::cout << "Create nodes" << std::endl;
NetDeviceContainer loraNetDevices;
loraNetDevices = lorahelper.InstallRs (loraDeviceNodes);
for (uint32_t i = 0; i< loraNetDevices.GetN (); i++)
{
// this is a dirty workaround. Make sure to create first the
network and then the gateways
loraNetDevices.Get(i)->SetAttribute ("Offset2",UintegerValue(offsets
[GetClosestGateway(loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>())-1]-1));
uint32_t x = loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>()->GetPosition ().x;
uint32_t y = loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>()->GetPosition ().y;
std::cout << x << "," << y << "," << (uint32_t)offsets[
GetClosestGateway(loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>())-1] << std::endl;;
}
// Connect gateways with network
std::cout << "Create wired network" << std::endl;
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("1000Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (60)));
std::cout << "Connect devices with wired network" << std::endl;
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (loraBackendNodes);
std::cout << "Install IP/TCP" << std::endl;
InternetStackHelper stack;
stack.Install (loraBackendNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (csmaDevices);
// set addresses
std::cout << "Set the addresses" << std::endl;
lorahelper.FinishGateways (loraCoordinatorNodes, gateways, interfaces.
GetAddress(0));
Ptr<LoRaNetwork> loraNetwork = lorahelper.InstallBackend (
loraNetworkNode.Get (0),loraNetDevices);
// Let the nodes generate data
std::cout << " Generate data from the nodes in the LoRa network" << std
::endl;
ApplicationContainer apps = lorahelper.GenerateTraffic (randT,
loraDeviceNodes, pktsize, 0, duration, 120);
// hookup functions to the netdevices of each node to measure the
performance
for (uint32_t i = 0; i< loraNetDevices.GetN(); i++)
{
deviceMap[ Mac32Address::ConvertFrom(loraNetDevices.Get(i)->
GetAddress()).GetUInt()]=DynamicCast<LoRaNetDevice>(loraNetDevices.Get(i));
uint32_t x = loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>()->GetPosition ().x;
uint32_t y = loraNetDevices.Get(i)->GetNode()->GetObject
<MobilityModel>()->GetPosition ().y;
errorMap[ Mac32Address::ConvertFrom(loraNetDevices.Get(i)->
GetAddress()).GetUInt()] = make_tuple (0,0,0,0,x,y);
DynamicCast<LoRaNetDevice>(loraNetDevices.Get(i))->
TraceConnectWithoutContext ("MacTx",MakeCallback(&Transmitted));
}
// hookup functions to the network for measuring performance
loraNetwork->TraceConnectWithoutContext("NetRx",MakeCallback
(&ReceivedUnique));
loraNetwork->TraceConnectWithoutContext("NetPromiscRx",MakeCallback(&Received));
// Start the simulation
std::cout << "start the fun" << std::endl;
Simulator::Stop (Seconds (duration));
Simulator::Run ();
return 0;
}
int
main (int argc, char** argv)
{
AsciiTraceHelper ascii;
m_stream = ascii.CreateFileStream("data7loraTSCH1_100.csv");
*m_stream->GetStream() << "#Scenario 100 nodes with " << (int)nGateways
<< " gateways and " << (int)nSensors << " nodes on a square field with side
" << length << " meter" <<std::endl;
for (uint8_t iterationI=0;iterationI<10;iterationI++){
std::cout << "Iteration: " << (int)iterationI << std::endl;
mainBody();
for ( auto it = errorMap.begin(); it !=errorMap.end();++it)
{
uint32_t addr = it->first;
Ptr<LoRaNetDevice> netdevice = deviceMap[addr];
std::tuple<uint32_t,uint32_t,uint32_t,uint32_t,uint32_t,uint32_t>
tuple = it->second;
*m_stream->GetStream() << addr << "," << std::get<0>(tuple)<<
"," << std::get<1>(tuple) << "," << std::get<2>(tuple) << "," << std::get<
3>(tuple) << "," << std::get<4>(tuple) << "," << std::get<5>(tuple) <<","<<
netdevice->GetAvgRetransmissionCount() << "," << netdevice->GetAvgTime() <<
"," << netdevice->GetMissed() << "," << netdevice->GetArrived() << std
::endl;
}
errorMap.clear();
Simulator::Destroy ();
}
return 0;
}
…On Tue, Jul 16, 2024 at 2:34 PM Alessandro Aimi ***@***.***> wrote:
Hello,
What are *rs-example* and *RS LoRa*? To my knowledge, they are not part
of this repository.
That may be where the problematic code comes from.
Let me know.
Reply to this email directly, view it on GitHub
<#168 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJ4QHRTHQNMVEIW7WHXIN7TZMUHMZAVCNFSM6AAAAABK6KRLHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZQG43TMNRZGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This comment was marked as duplicate.
This comment was marked as duplicate.
Hi @SonileKM, Your questions are about a different codebase, please open an issue on the correct repository. |
Thanks so much Alessandro. Will do as advised.
…On Thu, Jul 18, 2024 at 4:17 PM Alessandro Aimi ***@***.***> wrote:
Closed #168 <#168> as
completed.
—
Reply to this email directly, view it on GitHub
<#168 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJ4QHRQAX3V2B7F5P5GIODTZM7E6LAVCNFSM6AAAAABK6KRLHSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTGU2TMNZZHAYTAMI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I am running example code for RS LoRa and its giving the following error:
fatal error: ns3/lora-module.h: no such file or directory.
In the code there is a statement ; #include <ns3/lora-module.h>
I tried to check for this header file and associated code but i cant find it in either the ns3.40 folder or the ns-3-Dev folder. I have also tried to check online. Please help me resolve this.
Specifications
The text was updated successfully, but these errors were encountered: