|
|
|
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) |
| 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: Jaume Nin <jaume.nin@cttc.cat> |
| 19 |
* Tommaso Pecorella <tommaso.pecorella@unifi.it> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "ns3/lte-helper.h" |
| 23 |
#include "ns3/epc-helper.h" |
| 24 |
#include "ns3/core-module.h" |
| 25 |
#include "ns3/network-module.h" |
| 26 |
#include "ns3/ipv4-global-routing-helper.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/csma-helper.h" |
| 32 |
#include "ns3/config-store.h" |
| 33 |
//#include "ns3/gtk-config-store.h" |
| 34 |
|
| 35 |
using namespace ns3; |
| 36 |
|
| 37 |
/** |
| 38 |
* Sample simulation script for LTE+EPC. It instantiates several eNodeB, |
| 39 |
* attaches one UE per eNodeB starts a flow for each UE to and from a remote host. |
| 40 |
* It also starts yet another flow between each UE pair. |
| 41 |
*/ |
| 42 |
|
| 43 |
NS_LOG_COMPONENT_DEFINE ("EpcFirstExample"); |
| 44 |
|
| 45 |
int |
| 46 |
main (int argc, char *argv[]) |
| 47 |
{ |
| 48 |
|
| 49 |
uint16_t numberOfNodes = 2; |
| 50 |
double simTime = 1.1; |
| 51 |
double distance = 60.0; |
| 52 |
double interPacketInterval = 100; |
| 53 |
bool useCa = false; |
| 54 |
|
| 55 |
// LogComponentEnable ("PointToPointEpcHelper", LOG_LEVEL_ALL); |
| 56 |
|
| 57 |
// Command line arguments |
| 58 |
CommandLine cmd; |
| 59 |
cmd.AddValue("numberOfNodes", "Number of eNodeBs + UE pairs", numberOfNodes); |
| 60 |
cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime); |
| 61 |
cmd.AddValue("distance", "Distance between eNBs [m]", distance); |
| 62 |
cmd.AddValue("interPacketInterval", "Inter packet interval [ms])", interPacketInterval); |
| 63 |
cmd.AddValue("useCa", "Whether to use carrier aggregation.", useCa); |
| 64 |
cmd.Parse(argc, argv); |
| 65 |
|
| 66 |
ConfigStore inputConfig; |
| 67 |
inputConfig.ConfigureDefaults(); |
| 68 |
|
| 69 |
// parse again so you can override default values from the command line |
| 70 |
cmd.Parse(argc, argv); |
| 71 |
|
| 72 |
if (useCa) |
| 73 |
{ |
| 74 |
Config::SetDefault ("ns3::LteHelper::UseCa", BooleanValue (useCa)); |
| 75 |
Config::SetDefault ("ns3::LteHelper::NumberOfComponentCarriers", UintegerValue (2)); |
| 76 |
Config::SetDefault ("ns3::LteHelper::EnbComponentCarrierManager", StringValue ("ns3::RrComponentCarrierManager")); |
| 77 |
} |
| 78 |
|
| 79 |
InternetStackHelper internet; |
| 80 |
Ipv4StaticRoutingHelper ipv4RoutingHelper; |
| 81 |
|
| 82 |
// Network A |
| 83 |
Ptr<LteHelper> lteAHelper = CreateObject<LteHelper> (); |
| 84 |
Ptr<PointToPointEpcHelper> epcAHelper = CreateObject<PointToPointEpcHelper> (); |
| 85 |
lteAHelper->SetEpcHelper (epcAHelper); |
| 86 |
|
| 87 |
Ptr<Node> pgwA = epcAHelper->GetPgwNode (); |
| 88 |
|
| 89 |
NodeContainer ueNodesA; |
| 90 |
NodeContainer enbNodesA; |
| 91 |
enbNodesA.Create(numberOfNodes); |
| 92 |
ueNodesA.Create(numberOfNodes); |
| 93 |
|
| 94 |
// Install Mobility Model |
| 95 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
| 96 |
for (uint16_t i = 0; i < numberOfNodes; i++) |
| 97 |
{ |
| 98 |
positionAlloc->Add (Vector(distance * i, 0, 0)); |
| 99 |
} |
| 100 |
MobilityHelper mobilityA; |
| 101 |
mobilityA.SetMobilityModel("ns3::ConstantPositionMobilityModel"); |
| 102 |
mobilityA.SetPositionAllocator(positionAlloc); |
| 103 |
mobilityA.Install(enbNodesA); |
| 104 |
mobilityA.Install(ueNodesA); |
| 105 |
|
| 106 |
// Install LTE Devices to the nodes |
| 107 |
NetDeviceContainer enbLteADevs = lteAHelper->InstallEnbDevice (enbNodesA); |
| 108 |
NetDeviceContainer ueLteADevs = lteAHelper->InstallUeDevice (ueNodesA); |
| 109 |
|
| 110 |
// Install the IP stack on the UEs |
| 111 |
internet.Install (ueNodesA); |
| 112 |
Ipv4InterfaceContainer ueAIpIface; |
| 113 |
ueAIpIface = epcAHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteADevs)); |
| 114 |
// Assign IP address to UEs, and install applications |
| 115 |
for (uint32_t u = 0; u < ueNodesA.GetN (); ++u) |
| 116 |
{ |
| 117 |
Ptr<Node> ueNode = ueNodesA.Get (u); |
| 118 |
// Set the default gateway for the UE |
| 119 |
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ()); |
| 120 |
ueStaticRouting->SetDefaultRoute (epcAHelper->GetUeDefaultGatewayAddress (), 1); |
| 121 |
} |
| 122 |
|
| 123 |
// Attach one UE per eNodeB |
| 124 |
for (uint16_t i = 0; i < numberOfNodes; i++) |
| 125 |
{ |
| 126 |
lteAHelper->Attach (ueLteADevs.Get(i), enbLteADevs.Get(i)); |
| 127 |
// side effect: the default EPS bearer will be activated |
| 128 |
} |
| 129 |
|
| 130 |
// Network B |
| 131 |
Ptr<LteHelper> lteBHelper = CreateObject<LteHelper> (); |
| 132 |
lteBHelper->SetUplinkSpectrumChannel (lteAHelper->GetUplinkSpectrumChannel ()); |
| 133 |
lteBHelper->SetDownlinkSpectrumChannel (lteAHelper->GetDownlinkSpectrumChannel ()); |
| 134 |
|
| 135 |
Ptr<PointToPointEpcHelper> epcBHelper = CreateObject<PointToPointEpcHelper> (); |
| 136 |
lteBHelper->SetEpcHelper (epcBHelper); |
| 137 |
|
| 138 |
Ptr<Node> pgwB = epcBHelper->GetPgwNode (); |
| 139 |
|
| 140 |
NodeContainer ueNodesB; |
| 141 |
NodeContainer enbNodesB; |
| 142 |
enbNodesB.Create(numberOfNodes); |
| 143 |
ueNodesB.Create(numberOfNodes); |
| 144 |
|
| 145 |
// Install Mobility Model |
| 146 |
Ptr<ListPositionAllocator> positionAllocB = CreateObject<ListPositionAllocator> (); |
| 147 |
for (uint16_t i = 0; i < numberOfNodes; i++) |
| 148 |
{ |
| 149 |
positionAllocB->Add (Vector(distance * i, 500, 0)); |
| 150 |
} |
| 151 |
MobilityHelper mobilityB; |
| 152 |
mobilityB.SetMobilityModel("ns3::ConstantPositionMobilityModel"); |
| 153 |
mobilityB.SetPositionAllocator(positionAllocB); |
| 154 |
mobilityB.Install(enbNodesB); |
| 155 |
mobilityB.Install(ueNodesB); |
| 156 |
|
| 157 |
// Install LTE Devices to the nodes |
| 158 |
NetDeviceContainer enbLteBDevs = lteBHelper->InstallEnbDevice (enbNodesB); |
| 159 |
NetDeviceContainer ueLteBDevs = lteBHelper->InstallUeDevice (ueNodesB); |
| 160 |
|
| 161 |
// Install the IP stack on the UEs |
| 162 |
internet.Install (ueNodesB); |
| 163 |
Ipv4InterfaceContainer ueBIpIface; |
| 164 |
ueBIpIface = epcBHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteBDevs)); |
| 165 |
// Assign IP address to UEs, and install applications |
| 166 |
for (uint32_t u = 0; u < ueNodesB.GetN (); ++u) |
| 167 |
{ |
| 168 |
Ptr<Node> ueNode = ueNodesB.Get (u); |
| 169 |
// Set the default gateway for the UE |
| 170 |
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ()); |
| 171 |
ueStaticRouting->SetDefaultRoute (epcBHelper->GetUeDefaultGatewayAddress (), 1); |
| 172 |
} |
| 173 |
|
| 174 |
// Attach one UE per eNodeB |
| 175 |
for (uint16_t i = 0; i < numberOfNodes; i++) |
| 176 |
{ |
| 177 |
lteBHelper->Attach (ueLteBDevs.Get(i), enbLteBDevs.Get(i)); |
| 178 |
// side effect: the default EPS bearer will be activated |
| 179 |
} |
| 180 |
|
| 181 |
// Create a single RemoteHost |
| 182 |
NodeContainer remoteHostContainer; |
| 183 |
remoteHostContainer.Create (1); |
| 184 |
Ptr<Node> remoteHost = remoteHostContainer.Get (0); |
| 185 |
internet.Install (remoteHostContainer); |
| 186 |
|
| 187 |
// Create the Internet |
| 188 |
CsmaHelper csma; |
| 189 |
NodeContainer internetNodes; |
| 190 |
internetNodes.Add (remoteHost); |
| 191 |
internetNodes.Add (pgwA); |
| 192 |
internetNodes.Add (pgwB); |
| 193 |
|
| 194 |
csma.SetDeviceAttribute ("Mtu", UintegerValue (1500)); |
| 195 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); |
| 196 |
csma.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010))); |
| 197 |
NetDeviceContainer internetDevices = csma.Install (internetNodes); |
| 198 |
Ipv4AddressHelper ipv4h; |
| 199 |
ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); |
| 200 |
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); |
| 201 |
// interface 0 is localhost, 1 is the csma device |
| 202 |
Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1); |
| 203 |
|
| 204 |
Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); |
| 205 |
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.0.0"), 1); |
| 206 |
|
| 207 |
|
| 208 |
// Install and start applications on UEs and remote host |
| 209 |
uint16_t dlPort = 1234; |
| 210 |
uint16_t ulPort = 2000; |
| 211 |
uint16_t otherPort = 3000; |
| 212 |
ApplicationContainer clientApps; |
| 213 |
ApplicationContainer serverApps; |
| 214 |
for (uint32_t u = 0; u < ueNodesA.GetN (); ++u) |
| 215 |
{ |
| 216 |
++ulPort; |
| 217 |
++otherPort; |
| 218 |
PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort)); |
| 219 |
PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort)); |
| 220 |
PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort)); |
| 221 |
serverApps.Add (dlPacketSinkHelper.Install (ueNodesA.Get(u))); |
| 222 |
serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); |
| 223 |
serverApps.Add (packetSinkHelper.Install (ueNodesA.Get(u))); |
| 224 |
|
| 225 |
UdpClientHelper dlClient (ueAIpIface.GetAddress (u), dlPort); |
| 226 |
dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 227 |
dlClient.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 228 |
|
| 229 |
UdpClientHelper ulClient (remoteHostAddr, ulPort); |
| 230 |
ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 231 |
ulClient.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 232 |
|
| 233 |
UdpClientHelper client (ueAIpIface.GetAddress (u), otherPort); |
| 234 |
client.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 235 |
client.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 236 |
|
| 237 |
clientApps.Add (dlClient.Install (remoteHost)); |
| 238 |
clientApps.Add (ulClient.Install (ueNodesA.Get(u))); |
| 239 |
if (u+1 < ueNodesA.GetN ()) |
| 240 |
{ |
| 241 |
clientApps.Add (client.Install (ueNodesA.Get(u+1))); |
| 242 |
} |
| 243 |
else |
| 244 |
{ |
| 245 |
clientApps.Add (client.Install (ueNodesA.Get(0))); |
| 246 |
} |
| 247 |
} |
| 248 |
for (uint32_t u = 0; u < ueNodesB.GetN (); ++u) |
| 249 |
{ |
| 250 |
++ulPort; |
| 251 |
++otherPort; |
| 252 |
PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort)); |
| 253 |
PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort)); |
| 254 |
PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort)); |
| 255 |
serverApps.Add (dlPacketSinkHelper.Install (ueNodesB.Get(u))); |
| 256 |
serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); |
| 257 |
serverApps.Add (packetSinkHelper.Install (ueNodesB.Get(u))); |
| 258 |
|
| 259 |
UdpClientHelper dlClient (ueBIpIface.GetAddress (u), dlPort); |
| 260 |
dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 261 |
dlClient.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 262 |
|
| 263 |
UdpClientHelper ulClient (remoteHostAddr, ulPort); |
| 264 |
ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 265 |
ulClient.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 266 |
|
| 267 |
UdpClientHelper client (ueBIpIface.GetAddress (u), otherPort); |
| 268 |
client.SetAttribute ("Interval", TimeValue (MilliSeconds(interPacketInterval))); |
| 269 |
client.SetAttribute ("MaxPackets", UintegerValue(1000000)); |
| 270 |
|
| 271 |
clientApps.Add (dlClient.Install (remoteHost)); |
| 272 |
clientApps.Add (ulClient.Install (ueNodesB.Get(u))); |
| 273 |
if (u+1 < ueNodesB.GetN ()) |
| 274 |
{ |
| 275 |
clientApps.Add (client.Install (ueNodesB.Get(u+1))); |
| 276 |
} |
| 277 |
else |
| 278 |
{ |
| 279 |
clientApps.Add (client.Install (ueNodesB.Get(0))); |
| 280 |
} |
| 281 |
} |
| 282 |
serverApps.Start (Seconds (0.01)); |
| 283 |
clientApps.Start (Seconds (0.01)); |
| 284 |
// lteAHelper->EnableTraces (); |
| 285 |
// lteBHelper->EnableTraces (); |
| 286 |
// Uncomment to enable PCAP tracing |
| 287 |
//p2ph.EnablePcapAll("lena-epc-first"); |
| 288 |
|
| 289 |
Simulator::Stop (Seconds (simTime)); |
| 290 |
Simulator::Run (); |
| 291 |
|
| 292 |
/*GtkConfigStore config; |
| 293 |
config.ConfigureAttributes();*/ |
| 294 |
|
| 295 |
Simulator::Destroy(); |
| 296 |
return 0; |
| 297 |
|
| 298 |
} |
| 299 |
|