A Discrete-Event Network Simulator
API
second.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  */
15 
16 #include "ns3/applications-module.h"
17 #include "ns3/core-module.h"
18 #include "ns3/csma-module.h"
19 #include "ns3/internet-module.h"
20 #include "ns3/ipv4-global-routing-helper.h"
21 #include "ns3/network-module.h"
22 #include "ns3/point-to-point-module.h"
23 
24 // Default Network Topology
25 //
26 // 10.1.1.0
27 // n0 -------------- n1 n2 n3 n4
28 // point-to-point | | | |
29 // ================
30 // LAN 10.1.2.0
31 
32 using namespace ns3;
33 
34 NS_LOG_COMPONENT_DEFINE("SecondScriptExample");
35 
36 int
37 main(int argc, char* argv[])
38 {
39  bool verbose = true;
40  uint32_t nCsma = 3;
41 
42  CommandLine cmd(__FILE__);
43  cmd.AddValue("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
44  cmd.AddValue("verbose", "Tell echo applications to log if true", verbose);
45 
46  cmd.Parse(argc, argv);
47 
48  if (verbose)
49  {
50  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
51  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
52  }
53 
54  nCsma = nCsma == 0 ? 1 : nCsma;
55 
57  p2pNodes.Create(2);
58 
60  csmaNodes.Add(p2pNodes.Get(1));
61  csmaNodes.Create(nCsma);
62 
64  pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
65  pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
66 
68  p2pDevices = pointToPoint.Install(p2pNodes);
69 
71  csma.SetChannelAttribute("DataRate", StringValue("100Mbps"));
72  csma.SetChannelAttribute("Delay", TimeValue(NanoSeconds(6560)));
73 
75  csmaDevices = csma.Install(csmaNodes);
76 
78  stack.Install(p2pNodes.Get(0));
79  stack.Install(csmaNodes);
80 
82  address.SetBase("10.1.1.0", "255.255.255.0");
85 
86  address.SetBase("10.1.2.0", "255.255.255.0");
89 
91 
93  serverApps.Start(Seconds(1.0));
94  serverApps.Stop(Seconds(10.0));
95 
97  echoClient.SetAttribute("MaxPackets", UintegerValue(1));
98  echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
99  echoClient.SetAttribute("PacketSize", UintegerValue(1024));
100 
102  clientApps.Start(Seconds(2.0));
103  clientApps.Stop(Seconds(10.0));
104 
106 
107  pointToPoint.EnablePcapAll("second");
108  csma.EnablePcap("second", csmaDevices.Get(1), true);
109 
110  Simulator::Run();
112  return 0;
113 }
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Build a set of PointToPointNetDevice objects.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1423
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1372
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
echoClient
Definition: first.py:53
address
Definition: first.py:40
serverApps
Definition: first.py:48
pointToPoint
Definition: first.py:31
echoServer
Definition: first.py:46
clientApps
Definition: first.py:58
stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:305
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
p2pNodes
Definition: second.py:43
p2pInterfaces
Definition: second.py:68
csmaInterfaces
Definition: second.py:71
csmaNodes
Definition: second.py:46
csma
Definition: second.py:56
p2pDevices
Definition: second.py:54
nCsma
Definition: second.py:31
cmd
Definition: second.py:33
csmaDevices
Definition: second.py:60
bool verbose