Random Static Wireless Sensor Network in NS3

95 views
Skip to first unread message

Adam Dean

unread,
May 28, 2019, 10:46:58 AM5/28/19
to ns-3-users
Hello All, 

I am relatively new to ns-3 as part of a research group. I am in charge of using ns-3 to create a random position and static wireless sensor network. The goal being to simulate sensors being dropped in random positions (i.e. out of a helicopter into an non-enterable zone where the sensor's position will be fixed from that point forward). From there, only certain sensors will be able to talk to each other based on position/proximity and then be able to look at affect on battery, throughput, dropped packets, etc. I am for sure not all the way there, yet. 

To get where I am, I have used the tutorials, examples/wifi-simple-adhoc.cc, and wifi-adhoc.cc along with https://groups.google.com/forum/#!topic/ns-3-users/klAS-HqU92I which goes pretty extensively into WSNs. There have been a few other Google searches as well, but for the most part, those have been my resources. 

For simplicity right now, I am just using pre-assigned positions in using MobilityHelper (random can come later). Where I am stuck/confused as to what is truly happening is with the recvSink and Source sockets that are created. I wanted every node to be able to send AND receive information from every other node (that is within proximity, but again, not relevant right now). Currently, I am doing this by copy/pasting the UdpSocketFactory section and changing variables and nodes. Node 0 sends to 4, and 4 sends back to 0. See below attempt

  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
 
Ptr<Socket> recvSink = Socket::CreateSocket (wifiNodes.Get (0), tid);
 
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink
->Bind (local);
  recvSink
->SetRecvCallback (MakeCallback (&ReceivePacket));


 
Ptr<Socket> source = Socket::CreateSocket (wifiNodes.Get (4), tid);
 
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
  source
->SetAllowBroadcast (true);
  source
->Connect (remote);
 
 
TypeId tid2 = TypeId::LookupByName ("ns3::UdpSocketFactory");
 
Ptr<Socket> recvSink2 = Socket::CreateSocket (wifiNodes.Get (4), tid);
 
InetSocketAddress local2 = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink2
->Bind (local2);
  recvSink2
->SetRecvCallback (MakeCallback (&ReceivePacket));


 
Ptr<Socket> source2 = Socket::CreateSocket (wifiNodes.Get (0), tid);
 
InetSocketAddress remote2 = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
  source2
->SetAllowBroadcast (true);
  source2
->Connect (remote2);


 
Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
                                 
Seconds (1.0), &GenerateTraffic,
                                  source
, packetSize, numPackets, interPacketInterval);


 
Simulator::ScheduleWithContext (source2->GetNode ()->GetId (),
                                 
Seconds (1.0), &GenerateTraffic,
                                  source2
, packetSize, numPackets, interPacketInterval);



Now, when I go to the trace file and pcaps to see what is going on, I see some of the expected behavior - device 4 tx and device 0 tx. However, are the rx for the other devices coming from packets being transferred through each device? How can I skip and get a direct conversation between 4 and 0? Trace file: 

t 1 /NodeList/4/DeviceList/0/$ns3::WifiNetDevice/Phy/State/Tx DsssRate1Mbps ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:05, BSSID=00:00:00:00:00:05, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1028 10.1.1.5 > 255.255.255.255) ns3::UdpHeader (length: 1008 49153 > 80) Payload (size=1000) ns3::WifiMacTrailer ()
t
1 /NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/State/Tx DsssRate1Mbps ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=00:00:00:00:00:01, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1028 10.1.1.1 > 255.255.255.255) ns3::UdpHeader (length: 1008 49153 > 80) Payload (size=1000) ns3::WifiMacTrailer ()
r
1.0087 DsssRate1Mbps/NodeList/3/DeviceList/0/$ns3::WifiNetDevice/Phy/State/RxOk ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:05, BSSID=00:00:00:00:00:05, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1028 10.1.1.5 > 255.255.255.255) ns3::UdpHeader (length: 1008 49153 > 80) Payload (size=1000) ns3::WifiMacTrailer ()
r
1.0087 DsssRate1Mbps/NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/State/RxOk ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=00:00:00:00:00:01, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1028 10.1.1.1 > 255.255.255.255) ns3::UdpHeader (length: 1008 49153 > 80) Payload (size=1000) ns3::WifiMacTrailer ()
r
1.0087 DsssRate1Mbps/NodeList/2/DeviceList/0/$ns3::WifiNetDevice/Phy/State/RxOk ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=00:00:00:00:00:01, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1028 10.1.1.1 > 255.255.255.255) ns3::UdpHeader (length: 1008 49153 > 80) Payload (size=1000) ns3::WifiMacTrailer ()



Part 2

On https://groups.google.com/forum/#!topic/ns-3-users/klAS-HqU92I the guy uses FlowMonitor to get an output of Dropped Packets, throughput, and lost packets. I want some of this data as well and I 'like' his implementation. However, I do not get an output from it using almost the exact same things. To me, it looks like a bunch of print statements and calculations. When I run it, I just get the blinky dot on the command line even with a successful build. I am not re-posting all the print statements, but below is how I set up the FlowMonitor.

  FlowMonitorHelper flowmon;
 
Ptr<FlowMonitor> monitor = flowmon.InstallAll();


 
Simulator::Run ();
  monitor
->CheckForLostPackets ();
 
 
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
  std
::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
 


        uint32_t txPacketsum
= 0;
        uint32_t rxPacketsum
= 0;
        uint32_t rxBytesum
= 0;
        uint32_t
DropPacketsum = 0;
        uint32_t
LostPacketsum = 0;
       
double Delaysum = 0;




for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
   
{
         
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
          std
::cout << "Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";  
         
                txPacketsum
+= i->second.txPackets;
                rxPacketsum
+= i->second.rxPackets;
                rxBytesum
+= i->second.rxBytes;
               
LostPacketsum += i->second.lostPackets;
               
DropPacketsum += i->second.packetsDropped.size();
               
Delaysum += i->second.delaySum.GetSeconds();


          std
::cout << "  Tx :   " << i->second.txPackets << "(" << i->second.txBytes<< ")" << "\n";


Appreciate all the help in advance. Any additional tips or obvious things I am doing wrong are welcomed as well. Just trying to learn. 

Thank you 
 

Reply all
Reply to author
Forward
0 new messages