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