1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#include "modules.hpp"
#include "ns3/pointer.h"
/**
* Create a sensors cell base on
* nbSensors Number of temperature sensors in the cell
* ap the Access Point (usually linked to the cloud)
*/
Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap,int positionSeed){
// Create sensors
NodeContainer sensors;
sensors.Create(nbSensors);
// Define sensors position/mobility
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); // Sensors are fixed
Ptr<UniformRandomVariable> X = CreateObject<UniformRandomVariable> ();
X->SetAttribute ("Min", DoubleValue (0));
X->SetAttribute ("Max", DoubleValue (RECT_SIZE));
X->SetAttribute("Stream",IntegerValue(positionSeed));
Ptr<UniformRandomVariable> Y = CreateObject<UniformRandomVariable> ();
Y->SetAttribute ("Min", DoubleValue (0));
Y->SetAttribute ("Max", DoubleValue (RECT_SIZE));
Y->SetAttribute("Stream",IntegerValue(positionSeed+1));
mobility.SetPositionAllocator("ns3::RandomRectanglePositionAllocator",
"X",PointerValue(X),
"Y",PointerValue(Y));
mobility.Install(NodeContainer(ap,sensors));
// To apply XXWifiPhy and WifiMac on sensors
WifiHelper wifiHelper;
wifiHelper.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
/* Set up Legacy Channel */
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency", DoubleValue (5e9));
/* Setup Physical Layer */
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
wifiPhy.Set ("TxPowerStart", DoubleValue (10.0));
wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0));
wifiPhy.Set ("TxPowerLevels", UintegerValue (1));
wifiPhy.Set ("TxGain", DoubleValue (0));
wifiPhy.Set ("RxGain", DoubleValue (0));
wifiPhy.Set ("RxNoiseFigure", DoubleValue (10));
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79));
wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3));
// wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("HtMcs7"),
"ControlMode", StringValue ("HtMcs0"));
/* Configure AP */
Ssid ssid = Ssid ("network");
WifiMacHelper wifiMac;
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));
NetDeviceContainer apNetDevice;
apNetDevice = wifiHelper.Install (wifiPhy, wifiMac, ap);
/* Configure STA */
wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid));
NetDeviceContainer sensorsNetDevices;
sensorsNetDevices = wifiHelper.Install (wifiPhy, wifiMac, sensors);
return(std::make_pair(std::make_pair(ap,sensors),std::make_pair(apNetDevice,sensorsNetDevices)));
}
/**
* Install network stack and applications
*/
void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval){
NodeContainer ap=cell.first.first;
NodeContainer sensors=cell.first.second;
NetDeviceContainer apNetDev= cell.second.first;
NetDeviceContainer sensorsNetDev= cell.second.second;
// 6. Install TCP/IP stack & assign IP addresses
InternetStackHelper internet;
// internet.Install (ap);
internet.Install (sensors);
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.0.0.0", "255.255.0.0");
Ipv4InterfaceContainer apInt,sensorsInt;
apInt=ipv4.Assign(apNetDev);
sensorsInt=ipv4.Assign(sensorsNetDev);
UdpEchoClientHelper echoClientHelper (InetSocketAddress (cloudInfos.second.first, cloudInfos.second.second));
echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (sensorsSendInterval)));
echoClientHelper.SetAttribute ("PacketSize", UintegerValue (sensorsPktSize));
echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (MAX_PACKET_BY_SENSOR));
ApplicationContainer pingApps;
// again using different start times to workaround Bug 388 and Bug 912
for(int i=0;i<sensors.GetN();i++){
echoClientHelper.SetAttribute ("StartTime", TimeValue (MilliSeconds (1+i)));
echoClientHelper.Install (sensors.Get(i));
}
}
CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){
NodeContainer HopNodes;
HopNodes.Create(nbHop);
InternetStackHelper stack;
stack.Install(HopNodes);
Ipv4Address cloudIP; // Will be fill in the following for loop
int cloudPort=80;
for(int i=0;i<nbHop-1;i++){
NodeContainer curNodes(HopNodes.Get(i),HopNodes.Get(i+1));
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ((std::to_string(bandwidth)+"Mbps").c_str()));
pointToPoint.SetChannelAttribute ("Delay", StringValue ((std::to_string(latency)+"ms").c_str()));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (curNodes);
Ipv4AddressHelper address;
address.SetBase (("10."+std::to_string(i+1)+".0.0").c_str(), "255.255.0.0"); // Remember: 10.0.0.0 is used by WIFI
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
if(i==nbHop-2){ // If we are on the last for loop (before last node)
cloudIP=p2pInterfaces.GetAddress (1); // Get Last node interface
PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), cloudPort));
ApplicationContainer sinkApp=apSink.Install(curNodes.Get(1)); // Instal sink on last node
sinkApp.Get(0)->TraceConnect("Rx","CloudSwitch",MakeCallback(&PktReceived));
sinkApp.Start (Seconds (0));
}
}
return(std::make_pair(HopNodes,std::make_pair(cloudIP,cloudPort)));
}
|