sorry sir , here is my code source , and what i do , i hope that an other personne could help me:
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/sixlowpan-module.h"
#include "ns3/lr-wpan-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/propagation-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/wifi-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("Ping6WsnExample");
int main (int argc, char **argv)
{
std::string phyMode ("DsssRate1Mbps");
double rss = -80; // -dBm
bool verbose = false;
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("verbose", "turn on log components", verbose);
cmd.Parse (argc, argv);
if (verbose)
{
LogComponentEnable ("Ping6WsnExample", LOG_LEVEL_INFO);
LogComponentEnable ("Ipv6EndPointDemux", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6ListRouting", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
LogComponentEnable ("SixLowPanNetDevice", LOG_LEVEL_ALL);
}
NS_LOG_INFO ("Create nodes.");
NodeContainer nodes;
NodeContainer sink;
NodeContainer ch;
sink.Create(1);
ch.Create (9);
NodeContainer allNodes = NodeContainer (sink, ch);
nodes.Create (10);
// Set seed for random numbers
SeedManager::SetSeed (167);
// Install mobility
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
Ptr<ListPositionAllocator> nodesPositionAlloc = CreateObject<ListPositionAllocator> ();
nodesPositionAlloc->Add (Vector (0.0, 0.0, 0.0));
nodesPositionAlloc->Add (Vector (50.0, 0.0, 0.0));
nodesPositionAlloc->Add (Vector (-50.0, 0.0, 0.0));
nodesPositionAlloc->Add (Vector (0.0, 50.0, 0.0));
nodesPositionAlloc->Add (Vector (0.0, -50.0, 0.0));
nodesPositionAlloc->Add (Vector (0.0, 0.0, 50.0));
nodesPositionAlloc->Add (Vector (0.0, 0.0, -50.0));
nodesPositionAlloc->Add (Vector (-50.0, -50.0, 50.0));
nodesPositionAlloc->Add (Vector (50.0, 0.0, 50.0));
nodesPositionAlloc->Add (Vector (50.0, 50.0, -50.0));
mobility.SetPositionAllocator (nodesPositionAlloc);
mobility.Install (nodes);
NS_LOG_INFO ("Create channels.");
LrWpanHelper lrWpanHelper;
// Add and install the LrWpanNetDevice for each node
// lrWpanHelper.EnableLogComponents();
NetDeviceContainer devContainer = lrWpanHelper.Install(nodes);
lrWpanHelper.AssociateToPan (devContainer, 10);
std::cout << "Created " << devContainer.GetN() << " devices" << std::endl;
std::cout << "There are " << nodes.GetN() << " nodes" << std::endl;
/* Install IPv4/IPv6 stack */
NS_LOG_INFO ("Install Internet stack.");
InternetStackHelper internetv6;
internetv6.SetIpv4StackInstall (false);
internetv6.Install (nodes);
// Install 6LowPan layer
NS_LOG_INFO ("Install 6LoWPAN.");
SixLowPanHelper sixlowpan;
NetDeviceContainer six1 = sixlowpan.Install (devContainer);
NS_LOG_INFO ("Assign addresses.");
Ipv6AddressHelper ipv6;
ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
Ipv6InterfaceContainer i = ipv6.Assign (six1);
NS_LOG_INFO ("Create Applications.");
/* Create a Ping6 application to send ICMPv6 echo request from node zero to
* all-nodes (ff02::1).
*/
uint32_t packetSize = 10;
uint32_t maxPacketCount = 5;
Time interPacketInterval = Seconds (1.);
Ping6Helper ping6;
ping6.SetLocal (i.GetAddress (0, 1));
ping6.SetRemote (i.GetAddress (1, 1));
// ping6.SetRemote (Ipv6Address::GetAllNodesMulticast ());
ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address::GetAny (), 50000);
PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", local);
ApplicationContainer apps = ping6.Install (sink);
apps.Start (Seconds (1.0));
apps.Stop (Seconds (100.0));
AsciiTraceHelper ascii;
lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream ("
ping6wsn.tr"));
lrWpanHelper.EnablePcapAll (std::string ("ping6wsn"), true);
ApplicationContainer clientApps;
// Create the OnOff applications to send UDP to the server
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
clientHelper.SetAttribute("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
//normally wouldn't need a loop here but the server IP address is different
//on each p2p subnet
for(uint32_t j=0; j<ch.GetN (); ++j)
{
AddressValue remoteAddress (Inet6SocketAddress (i.GetAddress (0,1), 50000));
//Inet6SocketAddress remoteAddress = Inet6SocketAddress (i.GetAddress (0,1), 50000);
clientHelper.SetAttribute ("Remote", remoteAddress);
clientApps.Add (clientHelper.Install (ch.Get (j)));
}
clientApps.Start (Seconds (1.0));
clientApps.Stop (Seconds (100.0));
// Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
// Run simulation for 10 seconds
Simulator::Stop (Seconds (120));
// Print per flow statistics
monitor->CheckForLostPackets ();
Ptr<Ipv6FlowClassifier> classifier = DynamicCast<Ipv6FlowClassifier> (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 v = stats.begin (); v != stats.end (); ++v)
{
Ipv6FlowClassifier::FiveTuple t = classifier->FindFlow (v->first);
std::cout << "Flow " << v->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
txPacketsum += v->second.txPackets;
rxPacketsum += v->second.rxPackets;
rxBytesum += v->second.rxBytes;
LostPacketsum += v->second.lostPackets;
DropPacketsum += v->second.packetsDropped.size();
Delaysum += v->second.delaySum.GetSeconds();
std::cout << " Tx : " << v->second.txPackets << "(" << v->second.txBytes<< ")" << "\n";
std::cout << " Rx : " << v->second.rxPackets << "(" << v->second.rxBytes<< ")" << "\n";
std::cout << "------------------------------------------------------------------" << "\n";
std::cout << " Lost Packets: " << v->second.lostPackets << "\n";
std::cout << " Drop Packets: " << v->second.packetsDropped.size() << "\n";
std::cout << "------------------------------------------------------------------" << "\n";
std::cout << " Packets Delivery Ratio: " << ((rxPacketsum * 100) /txPacketsum ) << "%" << "\n";
std::cout << " Packets Lost Ratio: " << ((LostPacketsum * 100) /txPacketsum) << "%" << "\n";
std::cout << " Throughput: " << v->second.rxBytes * 8.0 / 10.0 / 1024 / 1024 << " Mbps\n";
std::cout << "---------------------------------------------------------------------------------------" << "\n";
}
std::cout << "********************************************************************************" << "\n";
std::cout << " All Tx Packets: " << txPacketsum <<" " << " All Rx Packets: " << rxPacketsum << "\n";
std::cout << " All Lost Packets: " << LostPacketsum <<" " << " All Drop Packets: " << DropPacketsum << "\n";
std::cout << "********************************************************************************" << "\n";
// std::cout << " Packets Delivery Ratio: " << ((rxPacketsum * 100) /txPacketsum ) << "%" << " " << " Packets Lost Ratio: " << ((LostPacketsum * 100) /txPacketsum) << "%" << "\n";
std::cout << " All Delay: " << Delaysum / txPacketsum << "\n";
std::cout << " Throughput: " << rxBytesum * 8.0 / 10.0 / 1024 / 1024 << " Mbps\n";
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}