Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ns3/core-module.h>
- #include <ns3/network-module.h>
- #include <ns3/internet-module.h>
- #include <ns3/point-to-point-module.h>
- #include <ns3/applications-module.h>
- using namespace ns3;
- int main ()
- {
- LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
- LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
- NodeContainer nodes;
- nodes.Create (14);
- NodeContainer nodes01 (allNodes.Get (0), allNodes.Get (1));
- NodeContainer nodes14 (allNodes.Get (1), allNodes.Get (4));
- NodeContainer nodes24 (allNodes.Get (2), allNodes.Get (4));
- NodeContainer nodes34 (allNodes.Get (3), allNodes.Get (4));
- NodeContainer nodes45 (allNodes.Get (4), allNodes.Get (5));
- NodeContainer nodes56 (allNodes.Get (5), allNodes.Get (6));
- NodeContainer nodes511 (allNodes.Get (5), allNodes.Get (11));
- NodeContainer nodes512 (allNodes.Get (5), allNodes.Get (12));
- NodeContainer nodes67 (allNodes.Get (6), allNodes.Get (7));
- NodeContainer nodes78 (allNodes.Get (7), allNodes.Get (8));
- NodeContainer nodes69 (allNodes.Get (6), allNodes.Get (9));
- NodeContainer nodes910 (allNodes.Get (9), allNodes.Get (10));
- NodeContainer nodes1213 (allNodes.Get (12), allNodes.Get (13));
- NodeContainer nodes1214 (allNodes.Get (12), allNodes.Get (14));
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("15Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("6ms"));
- NetDeviceContainer devices;
- devices = pointToPoint.Install (nodes);
- devices01 = pointToPoint.Install (nodes01);
- devices14 = pointToPoint.Install (nodes14);
- devices24 = pointToPoint.Install (nodes24);
- devices34 = pointToPoint.Install (nodes34);
- devices45 = pointToPoint.Install (nodes45);
- devices56 = pointToPoint.Install (nodes56);
- devices67 = pointToPoint.Install (nodes67);
- devices78 = pointToPoint.Install (nodes78);
- devices69 = pointToPoint.Install (nodes69);
- devices910 = pointToPoint.Install (nodes910);
- devices511 = pointToPoint.Install (nodes511);
- devices512 = pointToPoint.Install (nodes512);
- devices1213 = pointToPoint.Install (nodes1213);
- devices1214 = pointToPoint.Install (nodes1214);
- InternetStackHelper stack;
- stack.Install (nodes);
- Ipv4AddressHelper address;
- address.SetBase ("192.168.0.1", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices01);
- address.SetBase ("192.168.0.2", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices14);
- address.SetBase ("192.168.0.3", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices24);
- address.SetBase ("192.168.0.4", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices34);
- address.SetBase ("192.168.0.5", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices45);
- address.SetBase ("192.168.0.6", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices56);
- address.SetBase ("192.168.0.7", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices67);
- address.SetBase ("192.168.0.8", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices78);
- address.SetBase ("192.168.0.9", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices69);
- address.SetBase ("192.168.0.10", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices910);
- address.SetBase ("192.168.0.11", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices511);
- address.SetBase ("192.168.0.12", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices512);
- address.SetBase ("192.168.0.13", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices1213);
- address.SetBase ("192.168.0.14", "255.255.0.0");
- Ipv4InterfaceContainer interfaces12 = address.Assign (devices1214);
- PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
- ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (14));
- sinkApps.Start (Seconds (0.));
- sinkApps.Stop (Seconds (20.));
- OnOffHelper onOffApp ("ns3::TcpSocketFactory", InetSocketAddress (interfaces.GetAddress (0), 9));
- onOffApp.SetAttribute ("DataRate", StringValue ("8Mbps"));
- onOffApp.SetAttribute ("PacketSize", UintegerValue (12500));
- onOffApp.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=2.5]"));
- onOffApp.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=4.0|Max=11.0]"));
- ApplicationContainer clientApps = onOffApp.Install (nodes.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
- }
Add Comment
Please, Sign In to add comment