NodeContainer Nodes;
Nodes.Create(nWifi);
WifiHelper wifi;
WifiMacHelper mac;
mac.SetType("ns3::AdhocWifiMac");
YansWifiChannelHelper channel;// = YansWifiChannelHelper::Default();
channel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(100));
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel(channel.Create());
//first netdevice
NetDeviceContainer AdhocDevices = wifi.Install(phy,mac,Nodes);
//second netdevice
//mac.SetType("ns3::AdhocWifiMac");
YansWifiChannelHelper channel2;
YansWifiPhyHelper phy2 = YansWifiPhyHelper::Default ();
channel2.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",DoubleValue(100));
channel2.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
phy2.SetChannel(channel2.Create());
NetDeviceContainer secondDevices = wifi.Install(phy2,mac,Nodes);
//mobility model
/* ... */
//routing protocol
OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (olsr, 10);
InternetStackHelper stack;
stack.SetRoutingHelper(list);
stack.Install(Nodes);
//first interface
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interface1;
interface1 = address.Assign (AdhocDevices);
//second interface
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer interface2;
interface2 = address.Assign (secondDevices);
Simulator::Stop (Seconds (30.0));
OnOffHelper onoff1 ("ns3::UdpSocketFactory",InetSocketAddress (interface2.GetAddress (nWifi-1), 9));
onoff1.SetConstantRate (DataRate("10kbps"));
onoff1.SetAttribute("OffTime",StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
onoff1.SetAttribute("PacketSize",UintegerValue(512));
ApplicationContainer onOffApp1 = onoff1.Install (Nodes.Get (0));
onOffApp1.Start (Seconds(0));
onOffApp1.Stop (Seconds (30.0));
PacketSinkHelper sink ("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), 9));
NodeContainer sinks = NodeContainer (Nodes.Get (nWifi-1));
ApplicationContainer sinkApps = sink.Install (sinks);
sinkApps.Start (Seconds(0));
sinkApps.Stop (Seconds (30.0));