A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
nix-simple.cc
Go to the documentation of this file.
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/network-module.h"
19 #include "ns3/internet-module.h"
20 #include "ns3/point-to-point-module.h"
21 #include "ns3/applications-module.h"
22 #include "ns3/ipv4-static-routing-helper.h"
23 #include "ns3/ipv4-list-routing-helper.h"
24 #include "ns3/ipv4-nix-vector-helper.h"
25 
26 /*
27  * Simple point to point links:
28  *
29  * n0 -- n1 -- n2 -- n3
30  *
31  * n0 has UdpEchoClient
32  * n3 has UdpEchoServer
33  *
34  * n0 IP: 10.1.1.1
35  * n1 IP: 10.1.1.2, 10.1.2.1
36  * n2 IP: 10.1.2.2, 10.1.3.1
37  * n3 IP: 10.1.3.2
38  *
39  */
40 
41 using namespace ns3;
42 
43 NS_LOG_COMPONENT_DEFINE ("NixSimpleExample");
44 
45 int
46 main (int argc, char *argv[])
47 {
48  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
49  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
50 
51  NodeContainer nodes12;
52  nodes12.Create (2);
53 
54  NodeContainer nodes23;
55  nodes23.Add (nodes12.Get (1));
56  nodes23.Create (1);
57 
58  NodeContainer nodes34;
59  nodes34.Add (nodes23.Get (1));
60  nodes34.Create (1);
61 
63  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
64  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
65 
66  NodeContainer allNodes = NodeContainer (nodes12, nodes23.Get (1), nodes34.Get (1));
67 
68  // NixHelper to install nix-vector routing
69  // on all nodes
70  Ipv4NixVectorHelper nixRouting;
71  Ipv4StaticRoutingHelper staticRouting;
72 
74  list.Add (staticRouting, 0);
75  list.Add (nixRouting, 10);
76 
78  stack.SetRoutingHelper (list); // has effect on the next Install ()
79  stack.Install (allNodes);
80 
81  NetDeviceContainer devices12;
82  NetDeviceContainer devices23;
83  NetDeviceContainer devices34;
84  devices12 = pointToPoint.Install (nodes12);
85  devices23 = pointToPoint.Install (nodes23);
86  devices34 = pointToPoint.Install (nodes34);
87 
88  Ipv4AddressHelper address1;
89  address1.SetBase ("10.1.1.0", "255.255.255.0");
90  Ipv4AddressHelper address2;
91  address2.SetBase ("10.1.2.0", "255.255.255.0");
92  Ipv4AddressHelper address3;
93  address3.SetBase ("10.1.3.0", "255.255.255.0");
94 
95  address1.Assign (devices12);
96  address2.Assign (devices23);
97  Ipv4InterfaceContainer interfaces = address3.Assign (devices34);
98 
100 
101  ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
102  serverApps.Start (Seconds (1.0));
103  serverApps.Stop (Seconds (10.0));
104 
105  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
106  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
107  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
108  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
109 
110  ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
111  clientApps.Start (Seconds (2.0));
112  clientApps.Stop (Seconds (10.0));
113 
114  // Trace routing tables
115  Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("nix-simple.routes", std::ios::out);
116  nixRouting.PrintRoutingTableAllAt (Seconds (8), routingStream);
117 
118  Simulator::Run ();
120  return 0;
121 }
holds a vector of ns3::Application pointers.
tuple pointToPoint
Definition: first.py:28
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
hold variables of type string
Definition: string.h:19
NetDeviceContainer Install(NodeContainer c)
tuple echoServer
Definition: first.py:42
Create an application which sends a UDP packet and waits for an echo of this packet.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
tuple clientApps
Definition: first.py:53
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
Create a server application which waits for input UDP packets and sends them back to the original sen...
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
tuple interfaces
Definition: first.py:40
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
#define list
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
tuple echoClient
Definition: first.py:48
tuple serverApps
Definition: first.py:44
keep track of a set of node pointers.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
tuple stack
Definition: first.py:34
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Helper class that adds ns3::Ipv4ListRouting objects.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
int main(int argc, char *argv[])
Definition: nix-simple.cc:46
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const