A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lena-ipv6-addr-conf.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 each UE to and from a remote host.
26 * It configures IPv6 addresses for UEs by setting the 48 bit prefix attribute in epc helper
27 */
28
29NS_LOG_COMPONENT_DEFINE("EpcFirstExampleForIpv6");
30
31int
32main(int argc, char* argv[])
33{
35 cmd.Parse(argc, argv);
36
39 lteHelper->SetEpcHelper(epcHelper);
40
41 Ptr<Node> pgw = epcHelper->GetPgwNode();
42
43 // Create a single RemoteHost
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)));
56
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
81
83 ipv6h.SetBase(Ipv6Address("6001:db80::"), Ipv6Prefix(64));
85
87 internetIpIfaces.SetDefaultRouteInAllNodes(0);
88
90
91 // Assign IP address to the first UE
92 ueIpIface = epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs1));
93
96 ipv6RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv6>());
98 ->AddNetworkRouteTo("7777:f00d::", Ipv6Prefix(64), internetIpIfaces.GetAddress(0, 1), 1, 0);
99
100 // Assign IP address to the second UE
101 ueIpIface.Add(epcHelper->AssignUeIpv6Address(NetDeviceContainer(ueLteDevs2)));
102
103 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
104 {
105 Ptr<Node> ueNode = ueNodes.Get(u);
106 // Set the default gateway for the UEs
108 ipv6RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv6>());
109 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress6(), 1);
110 }
111
112 // Attach one UE per eNodeB
113 lteHelper->Attach(ueLteDevs1.Get(0), enbLteDevs.Get(0));
114 lteHelper->Attach(ueLteDevs2.Get(0), enbLteDevs.Get(1));
115
116 // interface 0 is localhost, 1 is the p2p device
118
119 // Install and start applications on UEs and remote host
120
122
124
125 serverApps.Start(Seconds(4));
126 serverApps.Stop(Seconds(20));
127
130
131 echoClient1.SetAttribute("MaxPackets", UintegerValue(1000));
132 echoClient1.SetAttribute("Interval", TimeValue(Seconds(1)));
133 echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
134
135 echoClient2.SetAttribute("MaxPackets", UintegerValue(1000));
136 echoClient2.SetAttribute("Interval", TimeValue(Seconds(1)));
137 echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
138
141
143 clientApps1.Stop(Seconds(14));
144
145 clientApps2.Start(Seconds(4.5));
146 clientApps2.Stop(Seconds(14.5));
147
148 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
149 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
150
151 internet.EnablePcapIpv6("LenaIpv6-AddrConf-Ue0.pcap", ueNodes.Get(0)->GetId(), 1, true);
152 internet.EnablePcapIpv6("LenaIpv6-AddrConf-Ue1.pcap", ueNodes.Get(1)->GetId(), 1, true);
153 internet.EnablePcapIpv6("LenaIpv6-AddrConf-RH.pcap",
154 remoteHostContainer.Get(0)->GetId(),
155 1,
156 true);
157 internet.EnablePcapIpv6("LenaIpv6-AddrConf-Pgw-Iface1.pcap", pgw->GetId(), 1, true);
158 internet.EnablePcapIpv6("LenaIpv6-AddrConf-Pgw-Iface2.pcap", pgw->GetId(), 2, true);
159
162
164 return 0;
165}
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.
Parse command-line arguments.
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
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.
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.
Describes an IPv6 prefix.
Helper class that adds ns3::Ipv6StaticRouting objects.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
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
AttributeValue implementation for Time.
Definition nstime.h:1431
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 > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
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