| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
| 2 /* | |
| 3 * This program is free software; you can redistribute it and/or modify | |
| 4 * it under the terms of the GNU General Public License version 2 as | |
| 5 * published by the Free Software Foundation; | |
| 6 * | |
| 7 * This program is distributed in the hope that it will be useful, | |
| 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 * GNU General Public License for more details. | |
| 11 * | |
| 12 * You should have received a copy of the GNU General Public License | |
| 13 * along with this program; if not, write to the Free Software | |
| 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 15 */ | |
| 16 | |
| 17 #include "ns3/core-module.h" | |
| 18 #include "ns3/simulator-module.h" | |
| 19 #include "ns3/node-module.h" | |
| 20 #include "ns3/helper-module.h" | |
| 21 | |
| 22 /* | |
| 23 * Simple point to point links: | |
| 24 * | |
| 25 * n0 -- n1 -- n2 -- n3 | |
| 26 * | |
| 27 * n0 has UdpEchoClient | |
| 28 * n3 has UdpEchoServer | |
| 29 * | |
| 30 * n0 IP: 10.1.1.1 | |
| 31 * n1 IP: 10.1.1.2, 10.1.2.1 | |
| 32 * n2 IP: 10.1.2.2, 10.1.3.1 | |
| 33 * n3 IP: 10.1.3.2 | |
| 34 * | |
| 35 */ | |
| 36 | |
| 37 using namespace ns3; | |
| 38 | |
| 39 NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); | |
| 40 | |
| 41 int | |
| 42 main (int argc, char *argv[]) | |
| 43 { | |
| 44 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); | |
| 45 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); | |
| 46 | |
| 47 NodeContainer nodes12; | |
| 48 nodes12.Create (2); | |
| 49 | |
| 50 NodeContainer nodes23; | |
| 51 nodes23.Add(nodes12.Get(1)); | |
| 52 nodes23.Create(1); | |
| 53 | |
| 54 NodeContainer nodes34; | |
| 55 nodes34.Add(nodes23.Get(1)); | |
| 56 nodes34.Create(1); | |
| 57 | |
| 58 PointToPointHelper pointToPoint; | |
| 59 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); | |
| 60 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); | |
| 61 | |
| 62 NodeContainer allNodes = NodeContainer(nodes12, nodes23.Get(1), nodes34.Get(1) ); | |
| 63 | |
| 64 // NixHelper to install nix-vector routing | |
| 65 // on all nodes | |
| 66 Ipv4NixVectorHelper nixHelper; | |
| 67 Ipv4StaticRoutingHelper staticRouting; | |
|
craigdo
2009/09/11 22:38:17
Why have nixHelper, and staticRouting? It seems c
jpelkey
2009/09/12 18:34:14
On 2009/09/11 22:38:17, craigdo wrote:
> Why have
| |
| 68 | |
| 69 Ipv4ListRoutingHelper list; | |
| 70 list.Add (staticRouting, 0); | |
| 71 list.Add (nixHelper, 10); | |
| 72 | |
| 73 InternetStackHelper stack; | |
| 74 stack.SetRoutingHelper (list); | |
| 75 stack.Install (allNodes); | |
| 76 | |
| 77 NetDeviceContainer devices12; | |
| 78 NetDeviceContainer devices23; | |
| 79 NetDeviceContainer devices34; | |
| 80 devices12 = pointToPoint.Install (nodes12); | |
| 81 devices23 = pointToPoint.Install (nodes23); | |
| 82 devices34 = pointToPoint.Install (nodes34); | |
| 83 | |
| 84 Ipv4AddressHelper address1; | |
| 85 address1.SetBase ("10.1.1.0", "255.255.255.0"); | |
| 86 Ipv4AddressHelper address2; | |
| 87 address2.SetBase ("10.1.2.0", "255.255.255.0"); | |
| 88 Ipv4AddressHelper address3; | |
| 89 address3.SetBase ("10.1.3.0", "255.255.255.0"); | |
| 90 | |
| 91 | |
| 92 address1.Assign (devices12); | |
| 93 address2.Assign (devices23); | |
| 94 Ipv4InterfaceContainer interfaces = address3.Assign (devices34); | |
| 95 | |
| 96 UdpEchoServerHelper echoServer (9); | |
| 97 | |
| 98 ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1)); | |
| 99 serverApps.Start (Seconds (1.0)); | |
| 100 serverApps.Stop (Seconds (10.0)); | |
| 101 | |
| 102 UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); | |
| 103 echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); | |
| 104 echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); | |
| 105 echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); | |
| 106 | |
| 107 ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0)); | |
| 108 clientApps.Start (Seconds (2.0)); | |
| 109 clientApps.Stop (Seconds (10.0)); | |
| 110 | |
| 111 | |
| 112 Simulator::Run (); | |
| 113 Simulator::Destroy (); | |
| 114 return 0; | |
| 115 } | |
| OLD | NEW |