author | Andrey Mazo <mazo@iitp.ru> |
Fri, 13 Mar 2009 17:51:04 +0300 | |
changeset 4811 | 080b8f23fa4a |
parent 4797 | 9902003078aa |
child 4812 | adcb26652e1d |
permissions | -rw-r--r-- |
4793 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2008,2009 IITP RAS |
|
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 |
* |
|
4811
080b8f23fa4a
Added license information to some files.
Andrey Mazo <mazo@iitp.ru>
parents:
4797
diff
changeset
|
18 |
* Author: Kirill Andreev <andreev@iitp.ru> |
4793 | 19 |
*/ |
20 |
||
21 |
||
22 |
#include "ns3/core-module.h" |
|
23 |
#include "ns3/simulator-module.h" |
|
24 |
#include "ns3/node-module.h" |
|
25 |
#include "ns3/helper-module.h" |
|
26 |
#include "ns3/global-routing-module.h" |
|
27 |
#include "ns3/wifi-module.h" |
|
28 |
#include "ns3/mobility-module.h" |
|
29 |
||
30 |
using namespace ns3; |
|
31 |
||
32 |
NS_LOG_COMPONENT_DEFINE ("TestMeshScript"); |
|
33 |
||
34 |
int |
|
35 |
main(int argc, char *argv[]) |
|
36 |
{ |
|
37 |
// Creating square topology with nNodes x nNodes grid: |
|
38 |
int xSize = 5; |
|
39 |
int ySize = 5; |
|
40 |
double step = 100.0; //Grid with one-hop edge |
|
41 |
double randomStart = 0.1; //One beacon interval |
|
42 |
NodeContainer nodes; |
|
43 |
CommandLine cmd; |
|
44 |
MobilityHelper mobility; |
|
45 |
MeshWifiHelper wifi; |
|
46 |
NetDeviceContainer meshDevices; |
|
47 |
// Defining a size of our network: |
|
48 |
cmd.AddValue("x-size", "Number of nodes in a row grid", xSize); |
|
49 |
cmd.AddValue("y-size", "Number of rows in a grid", ySize); |
|
50 |
cmd.AddValue("step", "Size of edge in our grid", step); |
|
51 |
cmd.AddValue("start", "Random start parameter", randomStart); |
|
52 |
cmd.Parse (argc, argv); |
|
53 |
NS_LOG_DEBUG("Grid:"<<xSize<<"*"<<ySize); |
|
54 |
// Creating nodes: |
|
55 |
nodes.Create (ySize*xSize); |
|
56 |
||
57 |
// Setting channel: |
|
58 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
|
59 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
|
60 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
|
61 |
// Setting Wifi: |
|
62 |
//wifi.SetPhy("ns3::WifiPhy"); |
|
63 |
wifi.SetRemoteStationManager("ns3::AarfWifiManager"); |
|
64 |
Ssid ssid = Ssid("MyMeSH"); |
|
65 |
wifi.SetMac ("ns3::MeshWifiMac", |
|
66 |
"Ssid", SsidValue (ssid), |
|
67 |
"RandomStart", TimeValue (Seconds (randomStart)) |
|
68 |
); |
|
69 |
wifi.SetPeerLinkManager ("ns3::WifiPeerManager"); |
|
70 |
wifi.SetL2RoutingProtocol ("ns3::Hwmp"); |
|
71 |
wifi.SetL2RoutingNetDevice ("ns3::L2RoutingNetDevice"); |
|
72 |
meshDevices = wifi.Install (wifiPhy,nodes,1); |
|
73 |
// Installing Mobility. |
|
74 |
mobility.SetPositionAllocator |
|
75 |
("ns3::GridPositionAllocator", |
|
76 |
"MinX", DoubleValue (0.0), |
|
77 |
"MinY", DoubleValue (0.0), |
|
78 |
"DeltaX", DoubleValue (step), |
|
79 |
"DeltaY", DoubleValue (step), |
|
80 |
"GridWidth", UintegerValue (xSize), |
|
81 |
"LayoutType", StringValue("RowFirst")); |
|
4797
9902003078aa
Removed unneeded word "struct", fixed mobility model, fixed random variable
Kirill Andreev <andreev@iitp.ru>
parents:
4793
diff
changeset
|
82 |
NS_LOG_UNCOND("Mobility"); |
9902003078aa
Removed unneeded word "struct", fixed mobility model, fixed random variable
Kirill Andreev <andreev@iitp.ru>
parents:
4793
diff
changeset
|
83 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
4793 | 84 |
mobility.Install (nodes); |
4797
9902003078aa
Removed unneeded word "struct", fixed mobility model, fixed random variable
Kirill Andreev <andreev@iitp.ru>
parents:
4793
diff
changeset
|
85 |
NS_LOG_UNCOND("Mobility installed"); |
4793 | 86 |
// Setting Internet Stack: |
87 |
InternetStackHelper stack; |
|
88 |
stack.Install(nodes); |
|
89 |
Ipv4AddressHelper address; |
|
90 |
address.SetBase ("10.1.1.0", "255.255.255.0"); |
|
91 |
Ipv4InterfaceContainer interfaces = address.Assign (meshDevices); |
|
92 |
UdpEchoServerHelper echoServer (9); |
|
93 |
ApplicationContainer serverApps = echoServer.Install (nodes.Get (0)); |
|
94 |
serverApps.Start (Seconds (1.0)); |
|
95 |
serverApps.Stop (Seconds (10.0)); |
|
96 |
UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9); |
|
97 |
echoClient.SetAttribute ("MaxPackets", UintegerValue (1000)); |
|
98 |
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.001))); |
|
99 |
echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); |
|
100 |
ApplicationContainer clientApps = echoClient.Install (nodes.Get (1)); |
|
101 |
clientApps.Start (Seconds (2.0)); |
|
102 |
clientApps.Stop (Seconds (10.0)); |
|
103 |
//end |
|
104 |
Simulator::Stop (Seconds (10.0)); |
|
105 |
Simulator::Run(); |
|
106 |
Simulator::Destroy(); |
|
107 |
return 0; |
|
108 |
} |