Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */

#include "ns3/lte-helper.h"
#include "ns3/epc-helper.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/config-store.h"

//#include "ns3/gtk-config-store.h"
#include "ns3/csma-module.h"
#include "ns3/ns2-mobility-helper.h"
#include "ns3/wifi-module.h"
#include "ns3/bridge-helper.h"
#include "ns3/olsr-helper.h"
#include "ns3/mih-module.h"
#include "ns3/projeto-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("CenarioGenerico");
int
main (int argc, char *argv[])
{

#if 1
// LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6ListRouting", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityL4Protocol", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6Mobility", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityDemux", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityHeader", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityOption", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityOptionDemux", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6MobilityOptionHeader", LOG_LEVEL_ALL);
// LogComponentEnable ("Pmipv6Agent", LOG_LEVEL_LOGIC);
// LogComponentEnable ("Pmipv6MagNotifier", LOG_LEVEL_ALL);
// LogComponentEnable ("Pmipv6Profile", LOG_LEVEL_ALL);
// LogComponentEnable ("BindingCache", LOG_LEVEL_ALL);
// LogComponentEnable ("BindingUpdateList", LOG_LEVEL_ALL);
// LogComponentEnable ("UnicastRadvdApplication", LOG_LEVEL_ALL);
// LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
// LogComponentEnable ("Ipv6TunnelL4Protocol", LOG_LEVEL_ALL);
// LogComponentEnable ("TunnelNetDevice", LOG_LEVEL_ALL);
// LogComponentEnable ("CsmaNetDevice", LOG_LEVEL_ALL);
// LogComponentEnable ("CsmaChannel", LOG_LEVEL_ALL);
// LogComponentEnable ("Node", LOG_LEVEL_ALL);
// LogComponentEnable ("Simulator", LOG_LEVEL_ALL);
// LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
// LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
// LogComponentEnable ("BridgeNetDevice", LOG_LEVEL_ALL);
// LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
// LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
// LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
// LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
// LogComponentEnable ("Ns2MobilityHelper",LOG_LEVEL_DEBUG);
// LogComponentEnable ("ComfortApp", LOG_LEVEL_INFO);
// LogComponentEnable ("ComfortAppServer", LOG_LEVEL_INFO);
// LogComponentEnable ("SafetyApp", LOG_LEVEL_INFO);
// LogComponentEnable ("SafetyAppServer", LOG_LEVEL_INFO);
// LogComponentEnable ("UserApp", LOG_LEVEL_INFO);
// LogComponentEnable ("UserAppServer", LOG_LEVEL_INFO);
// LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
// LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);

#endif

//variaveis
int nodeNum=50;
int nodeNaplicaton=5;
double duration=400;
//int cenario=0;

//Parametros de Entrada da simulação


CommandLine cmd;
cmd.AddValue ("Part", "Ns2 movement trace file", nodeNaplicaton);
cmd.Parse (argc,argv);

// Create Ns2MobilityHelper with the specified trace log file as parameter


// Ns2MobilityHelper ns2 = Ns2MobilityHelper
("/home/rodmenega/workspace/ns-3.12.1/ns-3.12.1/src/projeto/examples/ns_trace.tr");
Ns2MobilityHelper ns2 = Ns2MobilityHelper
("/home/rodmenega/repos/lena/src/projeto/examples/mobility.tcl");
// Create all nodes.
NodeContainer stas;
stas.Create (nodeNum);
ns2.Install (); // configure movements for each node, while reading trace
file

//Valores "globais"
InternetStackHelper internet;
Ipv4AddressHelper ipv4;
CsmaHelper csma, csma1;
BridgeHelper bridge;
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();

lteHelper->SetEpcHelper (epcHelper);
lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");

Ipv4StaticRoutingHelper ipv4RoutingHelper;

//Declaração dos stas


NetDeviceContainer staDevs_lte;
NetDeviceContainer staDevs_wifi;
Ipv4InterfaceContainer staIfs_lte;
Ipv4InterfaceContainer staIfs_wifi;

internet.Install (stas);
//Declaração dos aps
NodeContainer aps;
aps.Create(2);

internet.Install (aps.Get(0));

//Criação da lan para a internet

NodeContainer cn;
NodeContainer backbone;
NetDeviceContainer outerDevs;
NetDeviceContainer backboneDevs;
Ipv4InterfaceContainer backboneIfs;
Ipv4InterfaceContainer outerIfs;

cn.Create(1);

Ptr<Node> pgw = epcHelper->GetPgwNode ();


backbone.Create(2);

internet.Install (cn);
internet.Install (backbone);

backbone.Add(pgw);

//Declarando as variaveis para a criação da topologia com o pmipv6


//ref nodes
NodeContainer lma;
NodeContainer mags;
NodeContainer outerNet;
NodeContainer mag1Net;
NodeContainer mag2Net;

NetDeviceContainer mag1Devs;
NetDeviceContainer mag2Devs;
NetDeviceContainer mag1ApDev;
NetDeviceContainer mag2ApDev;
NetDeviceContainer mag1BrDev;
NetDeviceContainer mag2BrDev;
Ipv4InterfaceContainer mag1Ifs;
Ipv4InterfaceContainer mag2Ifs;

//home agent do nó
lma.Add(backbone.Get(0));

//gatewares da redes
mags.Add(backbone.Get(1));
mags.Add(backbone.Get(2));

//rede interna - internet


outerNet.Add(lma);
outerNet.Add(cn);

//rede 1 - wifi
mag1Net.Add(mags.Get(0));
mag1Net.Add(aps.Get(0));

//rede 2 - lte
mag2Net.Add(mags.Get(1));
mag2Net.Add(aps.Get(1));

//configuração dos backbone


//Link between CN and LMA is 100Mbps and 10ms delay
csma1.SetChannelAttribute ("DataRate", DataRateValue
(DataRate(100000000)));
csma1.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(2)));
csma1.SetDeviceAttribute ("Mtu", UintegerValue (1400));
outerDevs = csma1.Install(outerNet);
ipv4.SetBase("192.168.1.0", "255.255.255.0");
outerIfs=ipv4.Assign(outerDevs);

Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
ipv4RoutingHelper.GetStaticRouting (outerNet.Get(1)->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"),
Ipv4Mask ("255.0.0.0"), 1);

//Todos os Links is 100Mbps and 10ms delay


csma.SetChannelAttribute ("DataRate", DataRateValue
(DataRate(100000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(2)));
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
backboneDevs = csma.Install(backbone);
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
backboneIfs=ipv4.Assign(backboneDevs);

// CONFIGURE MOBILITY
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc =
CreateObject<ListPositionAllocator> ();
Ptr<ConstantPositionMobilityModel> enbMobility =
CreateObject<ConstantPositionMobilityModel> ();
enbMobility->SetPosition (Vector (407.5, 254.5, 0.0)); //camada física
positionAlloc->Add (Vector (407.5, 245.5, 0.0)); //MAG1AP
positionAlloc->Add (enbMobility->GetPosition()); //MAG2AP
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator(positionAlloc);
mobility.Install(aps);

//Setting MAG2
NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (aps.Get(1));
NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (stas);

// Attach one UE per eNodeB


for (uint16_t i = 0; i < nodeNum; i++)
{
lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(0));
}

Ipv4InterfaceContainer ueIpIface;
ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer
(ueLteDevs));
// Assign IP address to UEs, and install applications

for (uint32_t u = 0; u < stas.GetN (); ++u)


{
Ptr<Node> ueNode = stas.Get (u);
// Set the default gateway for the UE
Ptr<Ipv4StaticRouting> ueStaticRouting =
ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
ueStaticRouting->SetDefaultRoute (epcHelper-
>GetUeDefaultGatewayAddress (), 1);
}
lteHelper->ActivateEpsBearer (ueLteDevs, EpsBearer
(EpsBearer::NGBR_VOICE_VIDEO_GAMING), EpcTft::Default ());

//Setting MAG1
mag1Devs = csma.Install(mag1Net);

Ssid ssid = Ssid("MAG");


YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard(WIFI_PHY_STANDARD_80211p_SCH);
QosWifiMacHelper wifiMac = QosWifiMacHelper::Default ();
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay
("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss
("ns3::RangePropagationLossModel","MaxRange",DoubleValue (500));
wifiPhy.SetChannel (wifiChannel.Create ());

wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid),
"BeaconGeneration", BooleanValue (true),
"BeaconInterval", TimeValue (MilliSeconds(100)));

mag1ApDev = wifi.Install (wifiPhy, wifiMac, mag1Net.Get(1));

mag1BrDev = bridge.Install (aps.Get(0), NetDeviceContainer(mag1ApDev,


mag1Devs.Get(1)));
mag1Ifs.Add(ipv4.Assign(mag1BrDev));

wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));

staDevs_wifi.Add( wifi.Install (wifiPhy, wifiMac, stas));


staIfs_wifi.Add(ipv4.Assign (staDevs_wifi));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

ApplicationContainer confortserverApp[nodeNaplicaton];
ApplicationContainer confortclienApp[nodeNaplicaton];
ComfortAppServerHelper comfortServer[nodeNaplicaton];
ComfortAppHelper comfortapp[nodeNaplicaton];

ApplicationContainer safetyserverApp[nodeNaplicaton];
ApplicationContainer safetyclienApp[nodeNaplicaton];
SafetyAppServerHelper safetServer[nodeNaplicaton];
SafetyAppHelper safetapp[nodeNaplicaton];

ApplicationContainer userserverApp[nodeNaplicaton];
ApplicationContainer userclienApp[nodeNaplicaton];
UserAppServerHelper UserServer[nodeNaplicaton];
UserAppHelper userapp[nodeNaplicaton];

Ptr<mih::MihVeicular> mihUserwifi[nodeNaplicaton];

for( int i =0; i<nodeNaplicaton;i++){

mihUserwifi[i] = CreateObject<mih::MihVeicular> ();


stas.Get(i)->AggregateObject (mihUserwifi[i]);
mihUserwifi[i]->Start();

UserServer[i] = UserAppServerHelper (200);


userserverApp[i] = UserServer[i].Install (cn.Get(0));
userserverApp[i].Start (Seconds (0.04*(i/10.0)));
userserverApp[i].Stop (Seconds (400));
userapp[i] = UserAppHelper (outerIfs.GetAddress(1), 200);
userapp[i].SetAttribute ("Interval", TimeValue (Seconds (1.0)));
userapp[i].SetAttribute ("PacketSize", UintegerValue (512));
userclienApp[i]=userapp[i].Install (stas.Get (i),mihUserwifi[i]);
userclienApp[i].Start (Seconds (0.57*(i/10.0)));
userclienApp[i].Stop (Seconds (350));

safetServer[i] = SafetyAppServerHelper (100);


safetyserverApp[i] = safetServer[i].Install (cn.Get(0));
safetyserverApp[i].Start (Seconds (0.05*(i/10.0)));
safetyserverApp[i].Stop (Seconds (400));
safetapp[i] = SafetyAppHelper (outerIfs.GetAddress(1), 100);
safetapp[i].SetAttribute ("Interval", TimeValue (Seconds (0.5)));
safetapp[i].SetAttribute ("PacketSize", UintegerValue (20));
safetyclienApp[i]=safetapp[i].Install (stas.Get (i),mihUserwifi[i]);
safetyclienApp[i].Start (Seconds (0.15*(i/10.0)));
safetyclienApp[i].Stop (Seconds (350));

comfortServer[i] = ComfortAppServerHelper (300);


confortserverApp[i] = comfortServer[i].Install (cn.Get(0));
confortserverApp[i].Start(Seconds (0.02*(i/10.0)));
confortserverApp[i].Stop(Seconds (400));
comfortapp[i] = ComfortAppHelper (outerIfs.GetAddress(1), 300);
comfortapp[i].SetAttribute ("Interval", TimeValue (Seconds (0.7)));
comfortapp[i].SetAttribute ("PacketSize", UintegerValue (80));
confortclienApp[i]= comfortapp[i].Install
(stas.Get(i),mihUserwifi[i]);
confortclienApp[i].Start (Seconds (0.11*(i/10.0)));
confortclienApp[i].Stop (Seconds (350));
}

// Trace routing tables


Ipv4GlobalRoutingHelper g;
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("dynamic-global-routing.routes", std::ios::out);
g.PrintRoutingTableAllAt (Seconds (80), routingStream);

std::cout << "Starting simulation....." << std::endl;


Simulator::Stop (Seconds (duration));
Simulator::Run ();

Simulator::Destroy ();

std::cout << "Done." << std::endl;

return 0;

You might also like