Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void
- RoutingExperiment::Run (double txp, std::string CSVfileName)
- {
- Packet::EnablePrinting ();
- m_txp = txp;
- std::cout<<"Setting various parameters\n";
- //Number of cars
- int nWifis = 0;
- int dist=24;
- //Simulation time
- double TotalTime = 990000.0;
- //Road
- uint32_t road = 4000;
- uint32_t bord= (road/300)-1;
- //Other parameters
- std::string rate ("2048bps");
- std::string phyMode ("DsssRate11Mbps");
- Config::SetDefault ("ns3::OnOffApplication::PacketSize",StringValue ("64"));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (rate));
- Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",StringValue (phyMode));
- NodeContainer adhocNodes;
- MobilityHelper mobility;
- Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
- std::cout<<"Creating nodes\n";
- //Left side
- uint32_t borders=0, cont=0;
- while (cont<bord)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector (0.0, (cont+1)*300, 0.0));
- cont++;
- borders++;
- nWifis++;
- }
- cont=0;
- //Bottom side
- while (cont<bord)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector ((cont+1)*300, road, 0.0));
- cont++;
- borders++;
- nWifis++;
- }
- cont=0;
- //Right side
- while (cont<bord)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector (road, (cont+1)*300, 0.0));
- cont++;
- borders++;
- nWifis++;
- }
- cont=0;
- //Top side
- while (cont<bord)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector ((cont+1)*300, 0.0, 0.0));
- cont++;
- borders++;
- nWifis++;
- }
- //Other nodes
- for (uint i=0; i<bord; i++)
- {
- int r=road;
- int d=dist;
- while(r>0)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector ((i+1)*300, d, 0.0));
- borders++;
- d=d+dist;
- r=r-dist;
- nWifis++;
- }
- }
- for (uint i=0; i<bord; i++)
- {
- int r=road;
- int d=dist;
- while(r>0)
- {
- adhocNodes.Add(CreateObject<Node> ());
- positionAlloc->Add (Vector (d, (i+1)*300, 0.0));
- borders++;
- d=d+dist;
- r=r-dist;
- nWifis++;
- }
- }
- std::cout<<"Nodes created\n";
- //Nodes with constant speed
- std::cout<<"Setting mobility model\n";
- mobility.SetPositionAllocator (positionAlloc);
- mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
- mobility.Install (adhocNodes);
- for (uint n=0 ; n < adhocNodes.GetN() ; n++)
- {
- Ptr<ConstantVelocityMobilityModel> mob = adhocNodes.Get(n)->GetObject<ConstantVelocityMobilityModel>();
- //mob->SetVelocity(Vector(-1, 0, 0));
- mob->SetVelocity(Vector(0, 0, 0));
- }
- std::cout<<"Mobility model set\n";
- //Setting up wifi phy and channel using helpers
- WifiHelper wifi;
- wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
- //Setting max range
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel;
- wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
- wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", "MaxRange", DoubleValue (RoutingExperiment::m_range+100));
- wifiPhy.SetChannel (wifiChannel.Create ());
- //Add a mac and disable rate control
- WifiMacHelper wifiMac;
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode",StringValue (phyMode),
- "ControlMode",StringValue (phyMode));
- wifiPhy.Set ("TxPowerStart",DoubleValue (txp));
- wifiPhy.Set ("TxPowerEnd", DoubleValue (txp));
- wifiMac.SetType ("ns3::AdhocWifiMac");
- NetDeviceContainer adhocDevices = wifi.Install (wifiPhy, wifiMac, adhocNodes);
- InternetStackHelper internet;
- internet.Install (adhocNodes);
- NS_LOG_INFO ("Sssigning ip address");
- Ipv4AddressHelper addressAdhoc;
- addressAdhoc.SetBase ("10.1.0.0", "255.255.0.0");
- Ipv4InterfaceContainer adhocInterfaces;
- adhocInterfaces = addressAdhoc.Assign (adhocDevices);
- OnOffHelper onoff1 ("ns3::UdpSocketFactory",Address ());
- onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
- onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
- std::cout<<"Setting connections\n";
- //Receiver j (da sistemare un attimo)
- for (int j = 0; j < nWifis; j++)
- {
- Ptr<Socket> sink = SetupPacketReceive (adhocInterfaces.GetAddress (j), adhocNodes.Get (j));
- AddressValue remoteAddress (InetSocketAddress (ns3::Ipv4Address::GetAny (), port));
- onoff1.SetAttribute ("Remote", remoteAddress);
- Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
- }
- //Sender i
- for (int i = 0; i < nWifis; i++)
- {
- //Sender i>broadcast
- Ptr<Socket> sender = SetupPacketSend (ns3::Ipv4Address("10.1.255.255"), adhocNodes.Get (i));
- sender->SetAllowBroadcast (true);
- //Add the socket to the node
- adhocNodes.Get(i)->setBroadcast(sender);
- }
- std::cout<<"Connections set\n";
- //Generate alert message
- uint start=2275;
- Simulator::ScheduleWithContext (adhocNodes.Get (start)->GetId (), Seconds (45000), &RoutingExperiment::GenerateTraffic, adhocNodes.Get (start), adhocNodes);
- std::cout<<"Alert scheduled\n";
- std::cout<<"Run Simulation\n\n----------------------------------------\n";
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Stop (Seconds (TotalTime));
- Simulator::Run ();
- Simulator::Destroy ();
- }
Advertisement
Add Comment
Please, Sign In to add comment