Lr-wpan Throughput calculation

140 views
Skip to first unread message

Krishna

unread,
Jun 9, 2016, 7:13:42 AM6/9/16
to ns-3-users
Hi,
I am a beginner in ns3 programming. 
I have created an application program which will calculate the throughput for lr-wpan devices. 

But I am getting some Error named Segmentation fault . I am not getting why this error is occurring. 

If anyone can help me solving out this issue , i would really appreciate it . 

MY code is : (Sorry i was unable to attach the file so pasting the code in this space but, will keep in mind from next time )

#include <fstream>
#include "ns3/core-module.h"
#include "ns3/core-module.h"
#include "ns3/csma-module.h"
#include "ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/internet-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/ipv6-static-routing-helper.h"
#include "ns3/mobility-module.h"
#include "ns3/spectrum-module.h"
#include "ns3/propagation-loss-model.h"
#include "ns3/log.h"
#include "ns3/ipv6-routing-table-entry.h"
#include "ns3/sixlowpan-module.h"
#include "ns3/lr-wpan-module.h"



using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("UdpClientServerExample");


//void ThroughputMonitor (FlowMonitorHelper *fmhelper, Ptr<FlowMonitor> flowMon);

int
main (int argc, char *argv[])
{
//
// Enable logging for UdpClient and
//
//  LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
            LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);

Address serverAddress;

NS_LOG_INFO ("Create nodes.");
NodeContainer nodes;
nodes.Create (2);

LrWpanHelper lrWpanHelper;
// Add and install the LrWpanNetDevice for each node
NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(nodes);

// Fake PAN association and short address assignment.
lrWpanHelper.AssociateToPan (lrwpanDevices, 0);

InternetStackHelper internetv6;
internetv6.Install (nodes);

SixLowPanHelper sixlowpan;
NetDeviceContainer devices = sixlowpan.Install (lrwpanDevices);



NS_LOG_INFO ("Create channels.");
//
//
Ipv6AddressHelper ipv6;
ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
Ipv6InterfaceContainer i6 = ipv6.Assign (devices);
serverAddress = Address(i6.GetAddress (1,1));

NS_LOG_INFO ("Create Applications.");
//
// Create one udpServer applications on node one.
//
uint16_t port = 9;
UdpServerHelper server (port);
ApplicationContainer apps = server.Install (nodes.Get (1));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (20.0));

//
// Create one UdpClient application to send UDP datagrams from node zero to
// node one.
//
uint32_t MaxPacketSize = 104;
Time interPacketInterval = Seconds (0.05);
uint32_t maxPacketCount = 320;
UdpClientHelper client (serverAddress, port);
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize));
apps = client.Install (nodes.Get (0));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (20.0));

///
// FlowMonitor
///
FlowMonitorHelper fmHelper;
Ptr<FlowMonitor> allMon = fmHelper.InstallAll();
//Simulator::Schedule(Seconds(3),&ThroughputMonitor,&fmHelper, allMon);
// Now, do the actual simulation.
//
NS_LOG_INFO ("Run Simulation.");
Simulator::Stop(Seconds(20));
Simulator::Run ();
allMon->CheckForLostPackets ();

Ptr<Ipv6FlowClassifier> classing = DynamicCast<Ipv6FlowClassifier> (fmHelper.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> flowStats = allMon->GetFlowStats();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator stats = flowStats.begin (); stats != flowStats.end (); ++stats)
{
Ipv6FlowClassifier::FiveTuple fiveTuple = classing->FindFlow (stats->first);
std::cout<<"Flow ID : " << stats->first <<" ; "<< fiveTuple.sourceAddress <<" -----> "<<fiveTuple.destinationAddress<<std::endl;
// std::cout<<"Tx Packets = " << stats->second.txPackets<<std::endl;
// std::cout<<"Rx Packets = " << stats->second.rxPackets<<std::endl;
std::cout<<"Duration : "<<stats->second.timeLastRxPacket.GetSeconds()-stats->second.timeFirstTxPacket.GetSeconds()<<std::endl;
std::cout<<"Last Received Packet : "<< stats->second.timeLastRxPacket.GetSeconds()<<" Seconds"<<std::endl;
std::cout<<"Throughput: " << stats->second.rxBytes * 8.0 / (stats->second.timeLastRxPacket.GetSeconds()-stats->second.timeFirstTxPacket.GetSeconds())/1024/1024  << " Mbps"<<std::endl;
std::cout<<"---------------------------------------------------------------------------"<<std::endl;
}

Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}

Konstantinos

unread,
Jun 9, 2016, 7:18:13 AM6/9/16
to ns-3-users

Tanmay Kathpalia

unread,
Jun 13, 2016, 3:28:21 AM6/13/16
to ns-3-users
Dear Krishna

You are using GetClassifier which is used for IPv4 while assigning it to IPv6FlowClassifier. Kindly use GetClassifier6 for IPv6.

Regards
Tanmay Kathpalia

After going through your program, 
it seems that you are using IPv6 for everything as it should be, except while 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages