A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lena-ipv6-ue-ue.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Jadavpur University, India
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manoj Kumar Rana <manoj24.rana@gmail.com>
7 */
8
9#include "ns3/applications-module.h"
10#include "ns3/core-module.h"
11#include "ns3/epc-helper.h"
12#include "ns3/internet-module.h"
13#include "ns3/ipv4-global-routing-helper.h"
14#include "ns3/ipv6-static-routing.h"
15#include "ns3/lte-helper.h"
16#include "ns3/lte-module.h"
17#include "ns3/mobility-module.h"
18#include "ns3/network-module.h"
19#include "ns3/point-to-point-helper.h"
20
21using namespace ns3;
22
23/**
24 * Sample simulation script for LTE+EPC. It instantiates several eNodeB,
25 * attaches one UE per eNodeB starts a flow for remote host to and from the first UE.
26 * It also starts yet another flow between other UE pair.
27 */
28
29NS_LOG_COMPONENT_DEFINE("EpcSecondExampleForIpv6");
30
31int
32main(int argc, char* argv[])
33{
34 CommandLine cmd(__FILE__);
35 cmd.Parse(argc, argv);
36
39 lteHelper->SetEpcHelper(epcHelper);
40
41 Ptr<Node> pgw = epcHelper->GetPgwNode();
42
43 // Create a single RemoteHost
44 NodeContainer remoteHostContainer;
45 remoteHostContainer.Create(1);
46 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
48 internet.Install(remoteHostContainer);
49
50 // Create the Internet
52 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
53 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
54 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
55 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
56
57 NodeContainer ueNodes;
58 NodeContainer enbNodes;
59 enbNodes.Create(2);
60 ueNodes.Create(2);
61
62 // Install Mobility Model
64 for (uint16_t i = 0; i < 2; i++)
65 {
66 positionAlloc->Add(Vector(60.0 * i, 0, 0));
67 }
69 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
70 mobility.SetPositionAllocator(positionAlloc);
71 mobility.Install(enbNodes);
72 mobility.Install(ueNodes);
73
74 // Install the IP stack on the UEs
75 internet.Install(ueNodes);
76
77 // Install LTE Devices to the nodes
78 NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice(enbNodes);
79 NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice(ueNodes);
80
81 Ipv6InterfaceContainer ueIpIface;
82
83 // Assign IP address to UEs
84 ueIpIface = epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs));
85
86 Ipv6StaticRoutingHelper ipv6RoutingHelper;
87
88 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
89 {
90 Ptr<Node> ueNode = ueNodes.Get(u);
91 // Set the default gateway for the UE
92 Ptr<Ipv6StaticRouting> ueStaticRouting =
93 ipv6RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv6>());
94 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress6(), 1);
95 }
96
97 // Attach one UE per eNodeB
98 for (uint16_t i = 0; i < 2; i++)
99 {
100 lteHelper->Attach(ueLteDevs.Get(i), enbLteDevs.Get(i));
101 // side effect: the default EPS bearer will be activated
102 }
103
104 Ipv6AddressHelper ipv6h;
105 ipv6h.SetBase(Ipv6Address("6001:db80::"), Ipv6Prefix(64));
106 Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign(internetDevices);
107
108 internetIpIfaces.SetForwarding(0, true);
109 internetIpIfaces.SetDefaultRouteInAllNodes(0);
110
111 Ptr<Ipv6StaticRouting> remoteHostStaticRouting =
112 ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
113 remoteHostStaticRouting
114 ->AddNetworkRouteTo("7777:f00d::", Ipv6Prefix(64), internetIpIfaces.GetAddress(0, 1), 1, 0);
115
116 // Start applications on UEs and remote host
117
119
120 ApplicationContainer serverApps = echoServer.Install(ueNodes.Get(0));
121
122 serverApps.Start(Seconds(1.0));
123 serverApps.Stop(Seconds(20.0));
124
125 UdpEchoClientHelper echoClient1(ueIpIface.GetAddress(0, 1), 9);
126 UdpEchoClientHelper echoClient2(ueIpIface.GetAddress(0, 1), 9);
127
128 echoClient1.SetAttribute("MaxPackets", UintegerValue(1000));
129 echoClient1.SetAttribute("Interval", TimeValue(Seconds(1.0)));
130 echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
131
132 echoClient2.SetAttribute("MaxPackets", UintegerValue(1000));
133 echoClient2.SetAttribute("Interval", TimeValue(Seconds(1.0)));
134 echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
135
136 ApplicationContainer clientApps1 = echoClient1.Install(remoteHost);
137 ApplicationContainer clientApps2 = echoClient2.Install(ueNodes.Get(1));
138
139 clientApps1.Start(Seconds(1.0));
140 clientApps1.Stop(Seconds(14.0));
141
142 clientApps2.Start(Seconds(1.5));
143 clientApps2.Stop(Seconds(14.5));
144
145 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
146 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
147
148 internet.EnablePcapIpv6("LenaIpv6-Ue-Ue-Ue0.pcap", ueNodes.Get(0)->GetId(), 1, true);
149 internet.EnablePcapIpv6("LenaIpv6-Ue-Ue-Ue1.pcap", ueNodes.Get(1)->GetId(), 1, true);
150 internet.EnablePcapIpv6("LenaIpv6-Ue-Ue-RH.pcap", remoteHostContainer.Get(0)->GetId(), 1, true);
151 internet.EnablePcapIpv6("LenaIpv6-Ue-Ue-Pgw-Iface1.pcap", pgw->GetId(), 1, true);
152 internet.EnablePcapIpv6("LenaIpv6-Ue-Ue-Pgw-Iface2.pcap", pgw->GetId(), 2, true);
153
156
158 return 0;
159}
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.
Class for representing data rates.
Definition data-rate.h:78
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.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
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.
Describes an IPv6 prefix.
Helper class that adds ns3::Ipv6StaticRouting objects.
Ptr< Ipv6StaticRouting > GetStaticRouting(Ptr< Ipv6 > ipv6) const
Get Ipv6StaticRouting pointer from IPv6 stack.
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.
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:106
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)
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
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:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
serverApps
Definition first.py:43
echoServer
Definition first.py:41
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:291
@ LOG_LEVEL_ALL
Print everything.
Definition log.h:105
mobility
Definition third.py:92