-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp-udp.cc
187 lines (152 loc) · 6.21 KB
/
ftp-udp.cc
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "ns3/core-module.h"
#include "ns3/csma-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/application-container.h"
#include "ns3/packet-sink-helper.h"
#include "ns3/on-off-helper.h"
#include "ns3/random-variable-stream.h"
#include "ns3/netanim-module.h"
#include "iostream"
#include "string"
using namespace ns3;
using namespace std;
NS_LOG_COMPONENT_DEFINE ("Test1");
int main (int argc,char *argv[])
{
Packet::EnableChecking();
Packet::EnablePrinting();
uint32_t nVoipSta = 1;
uint32_t nFtpSta = 1;
uint32_t nSta = nVoipSta + nFtpSta;
uint32_t nVoipSer = 1;
uint32_t nFtpSer = 1;
uint32_t nCsma = nVoipSer + nFtpSer;
bool verbose = true;
if(verbose)
{
LogComponentEnable("ApWifiMac", LOG_LEVEL_ALL);
LogComponentEnable("OnOffApplication", LOG_LEVEL_INFO);
}
std::string animFile = "ftp-udp-animation.xml";
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (2200));
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
//create nodes
NodeContainer p2pNode;
p2pNode.Create (2);
NodeContainer wifiApNode;
wifiApNode.Add (p2pNode.Get(0));
NodeContainer wifiStaNode;
wifiStaNode.Create (nSta);
NodeContainer csmaNode;
csmaNode.Add(p2pNode.Get(1));
csmaNode.Create (nCsma);
//create & setup wifi channel
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetChannel(channel.Create());
//install wire devices
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue("100Mbps"));
pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
NetDeviceContainer p2pDevice;
p2pDevice = pointToPoint.Install (p2pNode);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue(NanoSeconds (6560)));
csma.SetDeviceAttribute ("Mtu", UintegerValue(1508));
NetDeviceContainer csmaDevice;
csmaDevice = csma.Install (csmaNode);
//install wireless devices
WifiHelper wifi = WifiHelper::Default();
wifi.SetRemoteStationManager("ns3::AarfWifiManager");
QosWifiMacHelper mac = QosWifiMacHelper::Default();
Ssid ssid = Ssid("ns-3-ssid");
mac.SetType("ns3::StaWifiMac","Ssid",SsidValue(ssid),"ActiveProbing",BooleanValue(true));
NetDeviceContainer staDevices;
staDevices = wifi.Install(phy, mac, wifiStaNode);
mac.SetType("ns3::ApWifiMac","Ssid",SsidValue(ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install(phy, mac , wifiApNode);
//setting mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install(wifiStaNode);
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add(Vector(0, 0, 0));
positionAlloc->Add(Vector(0, 100, 0));
positionAlloc->Add(Vector(-500, 200, 0));
positionAlloc->Add(Vector(500, 200, 0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(wifiApNode);
mobility.Install(csmaNode);
InternetStackHelper stack;
stack.Install(csmaNode);
stack.Install(wifiApNode);
stack.Install(wifiStaNode);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer p2pInterface;
p2pInterface = address.Assign (p2pDevice);
address.SetBase("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces = address.Assign(staDevices);
Ipv4InterfaceContainer wifiApInterfaces;
wifiApInterfaces = address.Assign(apDevices);
address.SetBase("10.1.3.0","255.255.255.0");
Ipv4InterfaceContainer csmaInterface;
csmaInterface = address.Assign (csmaDevice);
//tcp receiver
Address remoteAddress1 = InetSocketAddress(wifiInterfaces.GetAddress(1),2000);
PacketSinkHelper receiver1("ns3::TcpSocketFactory", remoteAddress1);
ApplicationContainer receiverapp1 = receiver1.Install(wifiStaNode.Get(1));
receiverapp1.Start(Seconds(1.0));
receiverapp1.Stop(Seconds(1.2));
//tcp sender
OnOffHelper sender1("ns3::TcpSocketFactory", remoteAddress1);
sender1.SetConstantRate(DataRate("1Mb/s"), 1024);
//DataRate dataRate ("10Mb/s");
//sender1.SetAttribute ("DataRate", DataRateValue (dataRate));
//sender1.SetAttribute ("PacketSize", UintegerValue (1508));
//sender1.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"));
//sender1.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
ApplicationContainer senderapp1 = sender1.Install(csmaNode.Get(1));
senderapp1.Start(Seconds(1.0));
senderapp1.Stop(Seconds(1.2));
//voip receiver
Address remoteAddress2 = InetSocketAddress(wifiInterfaces.GetAddress(0), 4000);
PacketSinkHelper receiver2("ns3::UdpSocketFactory", remoteAddress2);
ApplicationContainer receiverapp2 = receiver2.Install(wifiStaNode.Get(0));
receiverapp2.Start(Seconds(2.0));
receiverapp2.Stop(Seconds(2.4));
//voip sender
OnOffHelper sender2("ns3::UdpSocketFactory", remoteAddress2);
sender2.SetConstantRate(DataRate("65.625Kbps"), 1024);
//sender2.SetAttribute ("DataRate", StringValue ("10Mb/s"));
//sender2.SetAttribute ("PacketSize", UintegerValue (1508));
//sender2.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"));
//sender2.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVarialbe[Constant=0.0]"));
ApplicationContainer senderapp2 = sender2.Install(csmaNode.Get(2));
senderapp2.Start(Seconds(2.0));
senderapp2.Stop(Seconds(2.4));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
AnimationInterface anim (animFile);
Simulator::Stop(Seconds(3.0));
pointToPoint.EnablePcapAll("P2p_mytest1");
csma.EnablePcapAll("Csma_mytest1");
Simulator::Run();
Simulator::Destroy();
return 0;
}