void FlameRegressionTest::CreateDevices () { int64_t streamsUsed = 0; // 1. setup WiFi YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // This test suite output was originally based on YansErrorRateModel wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel"); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); Ptr<YansWifiChannel> chan = wifiChannel.Create (); wifiPhy.SetChannel (chan); // 2. setup mesh MeshHelper mesh = MeshHelper::Default (); mesh.SetStackInstaller ("ns3::FlameStack"); mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1))); mesh.SetNumberOfInterfaces (1); NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes); // Three devices, two streams per device streamsUsed += mesh.AssignStreams (meshDevices, streamsUsed); NS_TEST_ASSERT_MSG_EQ (streamsUsed, (meshDevices.GetN () * 2), "Stream assignment unexpected value"); streamsUsed += wifiChannel.AssignStreams (chan, streamsUsed); NS_TEST_ASSERT_MSG_EQ (streamsUsed, (meshDevices.GetN () * 2), "Stream assignment unexpected value"); // 3. setup TCP/IP InternetStackHelper internetStack; internetStack.Install (*m_nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); m_interfaces = address.Assign (meshDevices); // 4. write PCAP if needed wifiPhy.EnablePcapAll (CreateTempDirFilename (PREFIX)); }
void AodvExample::CreateDevices () { NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifiMac.SetType ("ns3::AdhocWifiMac"); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); WifiHelper wifi = WifiHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0)); devices = wifi.Install (wifiPhy, wifiMac, nodes); if (pcap) { wifiPhy.EnablePcapAll (std::string ("aodv")); } }
int main (int argc, char *argv[]) { std::string mode = "ConfigureLocal"; std::string tapName = "thetap"; CommandLine cmd; cmd.AddValue ("mode", "Mode setting of TapBridge", mode); cmd.AddValue ("tapName", "Name of the OS tap device", tapName); cmd.Parse (argc, argv); GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); // // The topology has a Wifi network of four nodes on the left side. We'll make // node zero the AP and have the other three will be the STAs. // NodeContainer nodesLeft; nodesLeft.Create (4); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); Ssid ssid = Ssid ("left"); WifiHelper wifi = WifiHelper::Default (); NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0)); wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3)))); MobilityHelper mobility; mobility.Install (nodesLeft); InternetStackHelper internetLeft; internetLeft.Install (nodesLeft); Ipv4AddressHelper ipv4Left; ipv4Left.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft); TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1)); tapBridge.SetAttribute ("Mode", StringValue (mode)); tapBridge.SetAttribute ("DeviceName", StringValue (tapName)); tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0)); // // Now, create the right side. // NodeContainer nodesRight; nodesRight.Create (4); CsmaHelper csmaRight; csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer devicesRight = csmaRight.Install (nodesRight); InternetStackHelper internetRight; internetRight.Install (nodesRight); Ipv4AddressHelper ipv4Right; ipv4Right.SetBase ("10.1.3.0", "255.255.255.0"); Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight); // // Stick in the point-to-point line between the sides. // PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps")); p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); NodeContainer nodes = NodeContainer (nodesLeft.Get (3), nodesRight.Get (0)); NetDeviceContainer devices = p2p.Install (nodes); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.2.0", "255.255.255.192"); Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); // // Simulate some CBR traffic over the point-to-point link // uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port)); onoff.SetConstantRate (DataRate ("500kb/s")); ApplicationContainer apps = onoff.Install (nodesLeft.Get (3)); apps.Start (Seconds (1.0)); // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (nodesRight.Get (0)); apps.Start (Seconds (1.0)); wifiPhy.EnablePcapAll ("tap-wifi-dumbbell"); csmaRight.EnablePcapAll ("tap-wifi-dumbbell", false); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Simulator::Stop (Seconds (60.)); Simulator::Run (); Simulator::Destroy (); }