A Discrete-Event Network Simulator
API
lena-ipv6-addr-conf.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Jadavpur University, India
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Manoj Kumar Rana <manoj24.rana@gmail.com>
18  */
19 
20 #include "ns3/applications-module.h"
21 #include "ns3/core-module.h"
22 #include "ns3/epc-helper.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/ipv4-global-routing-helper.h"
25 #include "ns3/ipv6-static-routing.h"
26 #include "ns3/lte-helper.h"
27 #include "ns3/lte-module.h"
28 #include "ns3/mobility-module.h"
29 #include "ns3/network-module.h"
30 #include "ns3/point-to-point-helper.h"
31 
32 using namespace ns3;
33 
40 NS_LOG_COMPONENT_DEFINE("EpcFirstExampleForIpv6");
41 
42 int
43 main(int argc, char* argv[])
44 {
45  CommandLine cmd(__FILE__);
46  cmd.Parse(argc, argv);
47 
48  Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
49  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
50  lteHelper->SetEpcHelper(epcHelper);
51 
52  Ptr<Node> pgw = epcHelper->GetPgwNode();
53 
54  // Create a single RemoteHost
55  NodeContainer remoteHostContainer;
56  remoteHostContainer.Create(1);
57  Ptr<Node> remoteHost = remoteHostContainer.Get(0);
59  internet.Install(remoteHostContainer);
60 
61  // Create the Internet
62  PointToPointHelper p2ph;
63  p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
64  p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
65  p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
66  NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
67 
68  NodeContainer ueNodes;
69  NodeContainer enbNodes;
70  enbNodes.Create(2);
71  ueNodes.Create(2);
72 
73  // Install Mobility Model
74  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
75  for (uint16_t i = 0; i < 2; i++)
76  {
77  positionAlloc->Add(Vector(60.0 * i, 0, 0));
78  }
80  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
81  mobility.SetPositionAllocator(positionAlloc);
82  mobility.Install(enbNodes);
83  mobility.Install(ueNodes);
84 
85  // Install the IP stack on the UEs
86  internet.Install(ueNodes);
87 
88  // Install LTE Devices to the nodes
89  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
90  NetDeviceContainer ueLteDevs1 = lteHelper->InstallUeDevice(NodeContainer(ueNodes.Get(0)));
91  NetDeviceContainer ueLteDevs2 = lteHelper->InstallUeDevice(NodeContainer(ueNodes.Get(1)));
92 
93  Ipv6AddressHelper ipv6h;
94  ipv6h.SetBase(Ipv6Address("6001:db80::"), Ipv6Prefix(64));
95  Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign(internetDevices);
96 
97  internetIpIfaces.SetForwarding(0, true);
98  internetIpIfaces.SetDefaultRouteInAllNodes(0);
99 
100  Ipv6InterfaceContainer ueIpIface;
101 
102  // Assign IP address to the first UE
103  ueIpIface = epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs1));
104 
105  Ipv6StaticRoutingHelper ipv6RoutingHelper;
106  Ptr<Ipv6StaticRouting> remoteHostStaticRouting =
107  ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
108  remoteHostStaticRouting
109  ->AddNetworkRouteTo("7777:f00d::", Ipv6Prefix(64), internetIpIfaces.GetAddress(0, 1), 1, 0);
110 
111  // Assign IP address to the second UE
112  ueIpIface.Add(epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs2)));
113 
114  for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
115  {
116  Ptr<Node> ueNode = ueNodes.Get(u);
117  // Set the default gateway for the UEs
118  Ptr<Ipv6StaticRouting> ueStaticRouting =
119  ipv6RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv6>());
120  ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress6(), 1);
121  }
122 
123  // Attach one UE per eNodeB
124  lteHelper->Attach(ueLteDevs1.Get(0), enbLteDevs.Get(0));
125  lteHelper->Attach(ueLteDevs2.Get(0), enbLteDevs.Get(1));
126 
127  // interface 0 is localhost, 1 is the p2p device
128  Ipv6Address remoteHostAddr = internetIpIfaces.GetAddress(1, 1);
129 
130  // Install and start applications on UEs and remote host
131 
133 
134  ApplicationContainer serverApps = echoServer.Install(remoteHost);
135 
136  serverApps.Start(Seconds(4.0));
137  serverApps.Stop(Seconds(20.0));
138 
139  UdpEchoClientHelper echoClient1(remoteHostAddr, 9);
140  UdpEchoClientHelper echoClient2(remoteHostAddr, 9);
141 
142  echoClient1.SetAttribute("MaxPackets", UintegerValue(1000));
143  echoClient1.SetAttribute("Interval", TimeValue(Seconds(1.0)));
144  echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
145 
146  echoClient2.SetAttribute("MaxPackets", UintegerValue(1000));
147  echoClient2.SetAttribute("Interval", TimeValue(Seconds(1.0)));
148  echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
149 
150  ApplicationContainer clientApps1 = echoClient1.Install(ueNodes.Get(0));
151  ApplicationContainer clientApps2 = echoClient2.Install(ueNodes.Get(1));
152 
153  clientApps1.Start(Seconds(4.0));
154  clientApps1.Stop(Seconds(14.0));
155 
156  clientApps2.Start(Seconds(4.5));
157  clientApps2.Stop(Seconds(14.5));
158 
159  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
160  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
161 
162  internet.EnablePcapIpv6("LenaIpv6-AddrConf-Ue0.pcap", ueNodes.Get(0)->GetId(), 1, true);
163  internet.EnablePcapIpv6("LenaIpv6-AddrConf-Ue1.pcap", ueNodes.Get(1)->GetId(), 1, true);
164  internet.EnablePcapIpv6("LenaIpv6-AddrConf-RH.pcap",
165  remoteHostContainer.Get(0)->GetId(),
166  1,
167  true);
168  internet.EnablePcapIpv6("LenaIpv6-AddrConf-Pgw-Iface1.pcap", pgw->GetId(), 1, true);
169  internet.EnablePcapIpv6("LenaIpv6-AddrConf-Pgw-Iface2.pcap", pgw->GetId(), 2, true);
170 
172  Simulator::Run();
173 
175  return 0;
176 }
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
Definition: command-line.h:232
aggregate IP/TCP/UDP functionality to existing Nodes.
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
void Add(Ptr< Ipv6 > ipv6, uint32_t interface)
Add a couple IPv6/interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
void SetEpcHelper(Ptr< EpcHelper > h)
Set the EpcHelper to be used to setup the EPC network in conjunction with the setup of the LTE radio ...
Definition: lte-helper.cc:285
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:485
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:1039
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:500
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Ipv6Address GetUeDefaultGatewayAddress6() override
Ptr< Node > GetPgwNode() const override
Get the PGW node.
Ipv6InterfaceContainer AssignUeIpv6Address(NetDeviceContainer ueDevices) override
Assign IPv6 addresses to UE devices.
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t GetId() const
Definition: node.cc:117
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
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
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
serverApps
Definition: first.py:54
echoServer
Definition: first.py:52
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:302
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
cmd
Definition: second.py:40
mobility
Definition: third.py:105