/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/core-module.h" #include "ns3/helper-module.h" #include "ns3/mobility-module.h" #include "ns3/simulator-module.h" #include "ns3/aodv-module.h" #include "ns3/node-module.h" #include "ns3/wifi-module.h" #include "ns3/common-module.h" #include #include #include using namespace ns3; int main (int argc, char *argv[]) { uint32_t size=100; uint32_t source= 70; SeedManager::SetRun (3); Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",StringValue ("0")); Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("3000")); NodeContainer c; c.Create (size); Ptr ll = CreateObject(); ll->SetX(UniformVariable (1,600)); ll->SetY(UniformVariable (1,600)); MobilityHelper mobility; mobility.SetPositionAllocator (ll); mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install (c); WifiHelper wifi = WifiHelper::Default (); NetDeviceContainer staDevs; NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); Ssid ssid = Ssid ("wifi-default"); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", StringValue ("OfdmRate6Mbps"),"ControlMode",StringValue ("OfdmRate6Mbps"),"NonUnicastMode",StringValue ("OfdmRate6Mbps")); wifiMac.SetType ("ns3::AdhocWifiMac"); staDevs = wifi.Install (wifiPhy, wifiMac, c); Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/TxPowerStart",DoubleValue(5.0)); Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/TxPowerEnd",DoubleValue(5.0)); InternetStackHelper stack; AodvHelper aodv; stack.SetRoutingHelper(aodv); stack.Install (c); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer ifs; ifs = address.Assign (staDevs); OnOffHelper onoff ("ns3::UdpSocketFactory",Address(InetSocketAddress(Ipv4Address("10.1.1.1"),80))); onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (2))); onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); onoff.SetAttribute ("DataRate", DataRateValue (DataRate (10e6))); onoff.SetAttribute ("PacketSize", UintegerValue (1200)); ApplicationContainer apps; uint32_t start=50,stop=55; for (uint32_t i=1;i<=source;i++) { apps = onoff.Install (c.Get(i)); apps.Start (Seconds (start)); apps.Stop (Seconds (stop)); start=stop+1; stop+=5; } PacketSinkHelper sink("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),80)); apps = sink.Install(c.Get(0)); apps.Start(Seconds(50.0)); Ptr flowmon; FlowMonitorHelper flowmonHelper; flowmon = flowmonHelper.InstallAll(); Simulator::Stop (Seconds (stop)); Simulator::Run (); flowmon->SerializeToXmlFile("wirelesshops100-70.xml",false,false); Simulator::Destroy(); return 0; }