|
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 * |
|
18 * Authors: Kirill Andreev <andreev@iitp.ru> |
|
19 * Evgeny Khorov <horov@frtk.ru> |
|
20 */ |
|
21 |
|
22 |
|
23 #include "ns3/core-module.h" |
|
24 #include "ns3/simulator-module.h" |
|
25 #include "ns3/node-module.h" |
|
26 #include "ns3/helper-module.h" |
|
27 #include "ns3/global-routing-module.h" |
|
28 #include "ns3/wifi-module.h" |
|
29 #include "ns3/mobility-module.h" |
|
30 |
|
31 using namespace ns3; |
|
32 |
|
33 NS_LOG_COMPONENT_DEFINE ("TestMeshScript"); |
|
34 |
|
35 int |
|
36 main(int argc, char *argv[]) |
|
37 { |
|
38 // Creating square topology with nNodes x nNodes grid: |
|
39 int xSize = 5; |
|
40 int ySize = 5; |
|
41 double step = 100.0; //Grid with one-hop edge |
|
42 double randomStart = 0.1; //One beacon interval |
|
43 NodeContainer nodes; |
|
44 CommandLine cmd; |
|
45 MobilityHelper mobility; |
|
46 MeshWifiHelper wifi; |
|
47 NetDeviceContainer meshDevices; |
|
48 // Defining a size of our network: |
|
49 cmd.AddValue("x-size", "Number of nodes in a row grid", xSize); |
|
50 cmd.AddValue("y-size", "Number of rows in a grid", ySize); |
|
51 cmd.AddValue("step", "Size of edge in our grid", step); |
|
52 cmd.AddValue("start", "Random start parameter", randomStart); |
|
53 cmd.Parse (argc, argv); |
|
54 NS_LOG_DEBUG("Grid:"<<xSize<<"*"<<ySize); |
|
55 // Creating nodes: |
|
56 nodes.Create (ySize*xSize); |
|
57 |
|
58 // Setting channel: |
|
59 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
|
60 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
|
61 wifiPhy.SetChannel (wifiChannel.Create ()); |
|
62 // Setting Wifi: |
|
63 //wifi.SetPhy("ns3::WifiPhy"); |
|
64 wifi.SetRemoteStationManager("ns3::AarfWifiManager"); |
|
65 Ssid ssid = Ssid("MyMeSH"); |
|
66 wifi.SetMac ("ns3::MeshWifiMac", |
|
67 "Ssid", SsidValue (ssid), |
|
68 "RandomStart", TimeValue (Seconds (randomStart)) |
|
69 ); |
|
70 wifi.SetPeerLinkManager ("ns3::WifiPeerManager"); |
|
71 wifi.SetL2RoutingProtocol ("ns3::Hwmp"); |
|
72 wifi.SetL2RoutingNetDevice ("ns3::L2RoutingNetDevice"); |
|
73 meshDevices = wifi.Install (wifiPhy,nodes,1); |
|
74 // Installing Mobility. |
|
75 mobility.SetPositionAllocator |
|
76 ("ns3::GridPositionAllocator", |
|
77 "MinX", DoubleValue (0.0), |
|
78 "MinY", DoubleValue (0.0), |
|
79 "DeltaX", DoubleValue (step), |
|
80 "DeltaY", DoubleValue (step), |
|
81 "GridWidth", UintegerValue (xSize), |
|
82 "LayoutType", StringValue("RowFirst")); |
|
83 mobility.SetMobilityModel ("ns3::StaticMobilityModel"); |
|
84 mobility.Install (nodes); |
|
85 |
|
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 } |