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 
36 /**
37  * Sample simulation script for LTE+EPC. It instantiates several eNodeB,
38  * attaches one UE per eNodeB starts a flow for remote host to  and from the first UE.
39  * It also starts yet another flow between other UE pair.
40  */
41 
42 NS_LOG_COMPONENT_DEFINE ("EpcSecondExampleForIpv6");
43 
44 int
main(int argc,char * argv[])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     }
81   MobilityHelper mobility;
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 ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
93 
94   Ipv6InterfaceContainer ueIpIface;
95 
96   // Assign IP address to UEs
97   ueIpIface = epcHelper->AssignUeIpv6Address (NetDeviceContainer (ueLteDevs));
98 
99 
100   Ipv6StaticRoutingHelper ipv6RoutingHelper;
101 
102   for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
103     {
104       Ptr<Node> ueNode = ueNodes.Get (u);
105       // Set the default gateway for the UE
106       Ptr<Ipv6StaticRouting> ueStaticRouting = ipv6RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv6> ());
107       ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress6 (), 1);
108     }
109 
110   // Attach one UE per eNodeB
111   for (uint16_t i = 0; i < 2; i++)
112     {
113       lteHelper->Attach (ueLteDevs.Get (i), enbLteDevs.Get (i));
114       // side effect: the default EPS bearer will be activated
115     }
116 
117   Ipv6AddressHelper ipv6h;
118   ipv6h.SetBase (Ipv6Address ("6001:db80::"), Ipv6Prefix (64));
119   Ipv6InterfaceContainer internetIpIfaces = ipv6h.Assign (internetDevices);
120 
121   internetIpIfaces.SetForwarding (0, true);
122   internetIpIfaces.SetDefaultRouteInAllNodes (0);
123 
124   Ptr<Ipv6StaticRouting> remoteHostStaticRouting = ipv6RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv6> ());
125   remoteHostStaticRouting->AddNetworkRouteTo ("7777:f00d::", Ipv6Prefix (64), internetIpIfaces.GetAddress (0, 1), 1, 0);
126 
127 
128   // Start applications on UEs and remote host
129 
130   UdpEchoServerHelper echoServer (9);
131 
132   ApplicationContainer serverApps = echoServer.Install (ueNodes.Get (0));
133 
134 
135   serverApps.Start (Seconds (1.0));
136   serverApps.Stop (Seconds (20.0));
137 
138 
139   UdpEchoClientHelper echoClient1 (ueIpIface.GetAddress (0,1), 9);
140   UdpEchoClientHelper echoClient2 (ueIpIface.GetAddress (0,1), 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 (remoteHost);
151   ApplicationContainer clientApps2 = echoClient2.Install (ueNodes.Get (1));
152 
153 
154   clientApps1.Start (Seconds (1.0));
155   clientApps1.Stop (Seconds (14.0));
156 
157   clientApps2.Start (Seconds (1.5));
158   clientApps2.Stop (Seconds (14.5));
159 
160   LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_ALL);
161   LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_ALL);
162 
163   internet.EnablePcapIpv6 ("LenaIpv6-Ue-Ue-Ue0.pcap", ueNodes.Get (0)->GetId (), 1, true);
164   internet.EnablePcapIpv6 ("LenaIpv6-Ue-Ue-Ue1.pcap", ueNodes.Get (1)->GetId (), 1, true);
165   internet.EnablePcapIpv6 ("LenaIpv6-Ue-Ue-RH.pcap", remoteHostContainer.Get (0)->GetId (), 1, true);
166   internet.EnablePcapIpv6 ("LenaIpv6-Ue-Ue-Pgw-Iface1.pcap", pgw->GetId (), 1, true);
167   internet.EnablePcapIpv6 ("LenaIpv6-Ue-Ue-Pgw-Iface2.pcap", pgw->GetId (), 2, true);
168 
169   Simulator::Stop (Seconds (20));
170   Simulator::Run ();
171 
172   Simulator::Destroy ();
173   return 0;
174 
175 }
176 
177