Hello Users,
I am trying to implement a mobile ad hoc network with 100 nodes and
using CSMA/CA protocol. But the trace files and flow monitor do not
show any activity at all. They are totally blank. I need some urgently
about that. I have the following code:
#include <fstream>
#include <iostream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-helper.h"
#include "ns3/applications-module.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/ipv4-global-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("first_broadcast");
int
main (int argc, char *argv[])
{
int numNodes = 100;
std::string phyMode ("DsssRate11Mbps");
double txp = 7.5;
int nodeSpeed = 20;
double TotalTime = 20.0;
std::string rate ("2048bps");
NodeContainer manetNodes;
manetNodes.Create (numNodes);
//NodeContainer nCsma;
//nCsma.Add (manetNodes.Get (1));
//nCsma.Create (mCsma);
Config::SetDefault
("ns3::WifiRemoteStationManager::NonUnicastMode",StringValue
(phyMode));
WifiHelper manetWifi;
manetWifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay
("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
manetWifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
wifiPhy.Set ("TxPowerStart",DoubleValue (txp));
wifiPhy.Set ("TxPowerEnd", DoubleValue (txp));
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer manetDevices = manetWifi.Install (wifiPhy,
wifiMac, manetNodes);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
//csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Dix"));
//csma.SetDeviceAttribute ("FrameSize", UintegerValue (2000));
NetDeviceContainer csmaDevices = csma.Install(manetNodes);
MobilityHelper mobilityManet;
Ipv4ListRoutingHelper list;
InternetStackHelper internet;
internet.SetRoutingHelper (list);
internet.Install (manetNodes);
NS_LOG_INFO ("assigning ip address");
Ipv4AddressHelper addressManet;
addressManet.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer manetInterfaces;
manetInterfaces = addressManet.Assign (manetDevices);
ObjectFactory pos;
pos.SetTypeId ("ns3::RandomRectanglePositionAllocator");
pos.Set ("X", RandomVariableValue (UniformVariable (0.0, 50.0)));
pos.Set ("Y", RandomVariableValue (UniformVariable (0.0, 50.0)));
Ptr<PositionAllocator> taPositionAlloc = pos.Create ()-
>GetObject<PositionAllocator> ();
mobilityManet.SetMobilityModel ("ns3::RandomWaypointMobilityModel",
"Speed", RandomVariableValue
(UniformVariable (0.0, nodeSpeed)),
"Pause", RandomVariableValue
(ConstantVariable (0)),
"PositionAllocator", PointerValue
(taPositionAlloc));
mobilityManet.SetPositionAllocator (taPositionAlloc);
mobilityManet.Install (manetNodes);
Config::SetDefault ("ns3::OnOffApplication::PacketSize",StringValue
("64"));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue
(rate));
uint32_t port = 100;
OnOffHelper onoff1 ("ns3::UdpSocketFactory",Address ());
onoff1.SetAttribute ("OnTime", RandomVariableValue
(ConstantVariable (1)));
onoff1.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable (0)));
for (int i = 0; i <= 9; i++)
{
AddressValue remoteAddress (InetSocketAddress
(manetInterfaces.GetAddress (i), port));
onoff1.SetAttribute ("Remote", remoteAddress);
UniformVariable var;
ApplicationContainer temp = onoff1.Install (manetNodes.Get (i));
temp.Start (Seconds (var.GetValue (0.1,1.0)));
temp.Stop (Seconds (TotalTime));
}
AsciiTraceHelper ascii;
Ptr<OutputStreamWrapper> osw = ascii.CreateFileStream
("
myfirstmanet.tr");
wifiPhy.EnableAsciiAll (osw);
std::ofstream os;
MobilityHelper::EnableAsciiAll (os);
FlowMonitorHelper flowmonHelper;
Ptr<FlowMonitor> flowmon = flowmonHelper.InstallAll();
flowmon-> SetAttribute("DelayBinWidth", DoubleValue (0.001));
flowmon-> SetAttribute("JitterBinWidth", DoubleValue (0.001));
flowmon-> SetAttribute("PacketSizeBinWidth", DoubleValue(20));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
wifiPhy.EnablePcapAll ("manet");
csma.EnablePcap ("manet", true, true);
NS_LOG_INFO ("Run Simulation.");
Simulator::Stop (Seconds (TotalTime));
Simulator::Run ();
flowmon->SerializeToXmlFile (("myfirstmanet.flowmon"), false, false);
Simulator::Destroy ();
}
Can anyone suggest what I am doing wrong?
Thank you,
Shagor.