#include "ns3/simulator-module.h" #include "ns3/node-module.h" #include "ns3/core-module.h" #include "ns3/common-module.h" #include "ns3/global-route-manager.h" #include "ns3/helper-module.h" #include "ns3/bridge-module.h" #include "ns3/wifi-module.h" #include "ns3/mobility-module.h" #include "ns3/contrib-module.h" using namespace ns3; int main(int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); /* Configuration. */ /* Build nodes. */ NodeContainer term_0; term_0.Create (1); NodeContainer station_0; station_0.Create (1); NodeContainer station_1; station_1.Create (1); NodeContainer term_1; term_1.Create (1); NodeContainer term_2; term_2.Create (1); NodeContainer bridge_0; bridge_0.Create (1); NodeContainer router_0; router_0.Create (1); NodeContainer ap_0; ap_0.Create (1); /* Build link. */ CsmaHelper csma_bridge_0; csma_bridge_0.SetChannelAttribute ("DataRate", DataRateValue (100000000)); csma_bridge_0.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10000))); YansWifiPhyHelper wifiPhy_ap_0 = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel_ap_0 = YansWifiChannelHelper::Default (); wifiPhy_ap_0.SetChannel (wifiChannel_ap_0.Create ()); CsmaHelper csma_hub_0; csma_hub_0.SetChannelAttribute ("DataRate", DataRateValue (100000000)); csma_hub_0.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10000))); /* Build link net device container. */ NodeContainer all_bridge_0; all_bridge_0.Add (router_0); all_bridge_0.Add (term_0); all_bridge_0.Add (term_1); all_bridge_0.Add (term_2); NetDeviceContainer terminalDevices_bridge_0; NetDeviceContainer BridgeDevices_bridge_0; for (int i = 0; i < 4; i++) { NetDeviceContainer link = csma_bridge_0.Install(NodeContainer(all_bridge_0.Get(i), bridge_0)); terminalDevices_bridge_0.Add (link.Get(0)); BridgeDevices_bridge_0.Add (link.Get(1)); } BridgeHelper bridge_bridge_0; bridge_bridge_0.Install (bridge_0.Get(0), BridgeDevices_bridge_0); NetDeviceContainer ndc_bridge_0 = terminalDevices_bridge_0; NodeContainer all_ap_0; NetDeviceContainer ndc_ap_0; Ssid ssid_ap_0 = Ssid ("wifi-default-0"); WifiHelper wifi_ap_0 = WifiHelper::Default (); NqosWifiMacHelper wifiMac_ap_0 = NqosWifiMacHelper::Default (); wifi_ap_0.SetRemoteStationManager ("ns3::ArfWifiManager"); wifiMac_ap_0.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid_ap_0), "BeaconGeneration", BooleanValue (true), "BeaconInterval", TimeValue (Seconds (2.5))); ndc_ap_0.Add (wifi_ap_0.Install (wifiPhy_ap_0, wifiMac_ap_0, ap_0)); wifiMac_ap_0.SetType ("ns3::NqstaWifiMac", "Ssid", SsidValue (ssid_ap_0), "ActiveProbing", BooleanValue (false)); ndc_ap_0.Add (wifi_ap_0.Install (wifiPhy_ap_0, wifiMac_ap_0, all_ap_0 )); MobilityHelper mobility_ap_0; mobility_ap_0.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility_ap_0.Install (ap_0); mobility_ap_0.Install(all_ap_0); NodeContainer all_hub_0; all_hub_0.Add (router_0); NetDeviceContainer ndc_hub_0 = csma_hub_0.Install (all_hub_0); /* Install the IP stack. */ InternetStackHelper internetStackH; internetStackH.Install (term_0); internetStackH.Install (station_0); internetStackH.Install (station_1); internetStackH.Install (term_1); internetStackH.Install (term_2); internetStackH.Install (router_0); internetStackH.Install (ap_0); /* IP assign. */ Ipv4AddressHelper ipv4; ipv4.SetBase ("10.0.0.0", "255.255.255.0"); Ipv4InterfaceContainer iface_ndc_bridge_0 = ipv4.Assign (ndc_bridge_0); ipv4.SetBase ("10.0.1.0", "255.255.255.0"); Ipv4InterfaceContainer iface_ndc_ap_0 = ipv4.Assign (ndc_ap_0); ipv4.SetBase ("10.0.2.0", "255.255.255.0"); Ipv4InterfaceContainer iface_ndc_hub_0 = ipv4.Assign (ndc_hub_0); /* Generate Route. */ Ipv4GlobalRoutingHelper::PopulateRoutingTables (); /* Generate Application. */ InetSocketAddress dst_ping_0 = InetSocketAddress (iface_ndc_bridge_0.GetAddress(3)); OnOffHelper onoff_ping_0 = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst_ping_0); onoff_ping_0.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); onoff_ping_0.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); ApplicationContainer apps_ping_0 = onoff_ping_0.Install(term_0.Get(0)); apps_ping_0.Start (Seconds (10.1)); apps_ping_0.Stop (Seconds (20.1)); PacketSinkHelper sink_ping_0 = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst_ping_0); apps_ping_0 = sink_ping_0.Install (term_2.Get(0)); apps_ping_0.Start (Seconds (10.0)); apps_ping_0.Stop (Seconds (20.2)); V4PingHelper ping_ping_0 = V4PingHelper(iface_ndc_bridge_0.GetAddress(3)); apps_ping_0 = ping_ping_0.Install(term_0.Get(0)); apps_ping_0.Start (Seconds (10.2)); apps_ping_0.Stop (Seconds (20.0)); uint16_t port_udpEcho_0 = 26; UdpEchoServerHelper server_udpEcho_0 (port_udpEcho_0); ApplicationContainer apps_udpEcho_0 = server_udpEcho_0.Install (term_1.Get(0)); apps_udpEcho_0.Start (Seconds (23.0)); apps_udpEcho_0.Stop (Seconds (33.0)); Time interPacketInterval_udpEcho_0 = Seconds (1.0); UdpEchoClientHelper client_udpEcho_0 (iface_ndc_bridge_0.GetAddress(2), 26); client_udpEcho_0.SetAttribute ("MaxPackets", UintegerValue (1)); client_udpEcho_0.SetAttribute ("Interval", TimeValue (interPacketInterval_udpEcho_0)); client_udpEcho_0.SetAttribute ("PacketSize", UintegerValue (1024)); apps_udpEcho_0 = client_udpEcho_0.Install (station_1.Get (0)); apps_udpEcho_0.Start (Seconds (23.1)); apps_udpEcho_0.Stop (Seconds (33.0)); /* Simulation. */ /* Pcap output. */ /* Stop the simulation after x seconds. */ uint32_t stopTime = 34; Simulator::Stop (Seconds (stopTime)); /* Start and clean simulation. */ Simulator::Run (); Simulator::Destroy (); }