|
|
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
3 |
* Copyright (c) 2015 Universidad de la República - Uruguay |
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: Matias Richart <mrichart@fing.edu.uy> |
19 |
*/ |
20 |
|
21 |
#include <sstream> |
22 |
#include <fstream> |
23 |
|
24 |
#include "ns3/core-module.h" |
25 |
#include "ns3/network-module.h" |
26 |
#include "ns3/dce-module.h" |
27 |
#include "ns3/internet-module.h" |
28 |
#include "ns3/mobility-module.h" |
29 |
#include "ns3/wifi-module.h" |
30 |
|
31 |
using namespace ns3; |
32 |
using namespace std; |
33 |
|
34 |
NS_LOG_COMPONENT_DEFINE ("DceWireless"); |
35 |
|
36 |
static void |
37 |
SetPosition (Ptr<Node> node, Vector position) |
38 |
{ |
39 |
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); |
40 |
mobility->SetPosition (position); |
41 |
} |
42 |
|
43 |
static Vector |
44 |
GetPosition (Ptr<Node> node) |
45 |
{ |
46 |
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); |
47 |
return mobility->GetPosition (); |
48 |
} |
49 |
|
50 |
static void |
51 |
AdvancePosition (Ptr<Node> node, int stepsSize) |
52 |
{ |
53 |
Vector pos = GetPosition (node); |
54 |
pos.x += stepsSize; |
55 |
SetPosition (node, pos); |
56 |
NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << " sec; setting new position to " << pos); |
57 |
} |
58 |
|
59 |
int main (int argc, char *argv[]) |
60 |
{ |
61 |
uint32_t rtsThreshold = 2346; |
62 |
int ap1_x = 0; |
63 |
int ap1_y = 0; |
64 |
int sta1_x = 10; |
65 |
int sta1_y = 0; |
66 |
uint32_t simuTime = 300; |
67 |
|
68 |
CommandLine cmd; |
69 |
cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime); |
70 |
cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x); |
71 |
cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y); |
72 |
cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x); |
73 |
cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y); |
74 |
cmd.Parse (argc, argv); |
75 |
|
76 |
// Define the AP |
77 |
NodeContainer wifiApNodes; |
78 |
wifiApNodes.Create (1); |
79 |
|
80 |
//Define the STA |
81 |
NodeContainer wifiStaNodes; |
82 |
wifiStaNodes.Create (1); |
83 |
|
84 |
WifiHelper wifi = WifiHelper::Default (); |
85 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211a); |
86 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
87 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
88 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
89 |
|
90 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
91 |
|
92 |
NetDeviceContainer wifiApDevices; |
93 |
NetDeviceContainer wifiStaDevices; |
94 |
NetDeviceContainer wifiDevices; |
95 |
|
96 |
//Configure the STA node |
97 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "ControlMode", StringValue ("ErpOfdmRate6Mbps")); |
98 |
|
99 |
Ssid ssid = Ssid ("AP0"); |
100 |
wifiMac.SetType ("ns3::StaWifiMac", |
101 |
"Ssid", SsidValue (ssid), |
102 |
"ActiveProbing", BooleanValue (false), |
103 |
"MaxMissedBeacons", UintegerValue (1000)); |
104 |
wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0))); |
105 |
|
106 |
//Configure the AP node |
107 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate54Mbps"),"ControlMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (rtsThreshold)); |
108 |
|
109 |
ssid = Ssid ("AP0"); |
110 |
wifiMac.SetType ("ns3::ApWifiMac", |
111 |
"Ssid", SsidValue (ssid)); |
112 |
wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0))); |
113 |
|
114 |
wifiDevices.Add (wifiStaDevices); |
115 |
wifiDevices.Add (wifiApDevices); |
116 |
|
117 |
// Configure the mobility. |
118 |
MobilityHelper mobility; |
119 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
120 |
positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0)); |
121 |
positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0)); |
122 |
mobility.SetPositionAllocator (positionAlloc); |
123 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
124 |
mobility.Install (wifiApNodes.Get (0)); |
125 |
mobility.Install (wifiStaNodes.Get (0)); |
126 |
|
127 |
|
128 |
//Configure the IP stack |
129 |
InternetStackHelper stack; |
130 |
stack.Install (wifiApNodes); |
131 |
stack.Install (wifiStaNodes); |
132 |
Ipv4AddressHelper address; |
133 |
address.SetBase ("10.1.1.0", "255.255.255.0"); |
134 |
Ipv4InterfaceContainer i = address.Assign (wifiDevices); |
135 |
Ipv4Address sinkAddress = i.GetAddress (0); |
136 |
uint16_t port = 9; |
137 |
|
138 |
DceManagerHelper dceManager; |
139 |
dceManager.Install (wifiApNodes); |
140 |
dceManager.Install (wifiStaNodes); |
141 |
|
142 |
DceApplicationHelper dce; |
143 |
ApplicationContainer apps; |
144 |
|
145 |
dce.SetBinary ("tcp-server-3"); |
146 |
dce.ResetArguments (); |
147 |
dce.SetStackSize (1 << 16); |
148 |
apps = dce.Install (wifiStaNodes.Get (0)); |
149 |
apps.Start (Seconds (2.0)); |
150 |
|
151 |
dce.SetBinary ("tcp-client-3"); |
152 |
dce.ResetArguments (); |
153 |
dce.ParseArguments ("10.1.1.1"); |
154 |
apps = dce.Install (wifiApNodes.Get (0)); |
155 |
apps.Start (Seconds (2.5)); |
156 |
|
157 |
Simulator::Schedule (Seconds (2.5154), &AdvancePosition, wifiApNodes.Get (0), -50); |
158 |
Simulator::Schedule (Seconds (8.5154), &AdvancePosition, wifiApNodes.Get (0), 50); |
159 |
|
160 |
Simulator::Stop (Seconds (simuTime)); |
161 |
Simulator::Run (); |
162 |
|
163 |
Simulator::Destroy (); |
164 |
|
165 |
return 0; |
166 |
} |