OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2011 Telum (www.telum.ru) |
| 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: Kirill Andreev <andreev@telum.ru> |
| 19 */ |
| 20 |
| 21 #include "ns3/low-resolution-radio-module.h" |
| 22 |
| 23 #include "ns3/mac48-address.h" |
| 24 #include "ns3/wifi-spectrum-value-helper.h" |
| 25 /// Mobility: |
| 26 #include "ns3/constant-position-mobility-model.h" |
| 27 /// Propagation: |
| 28 #include "ns3/propagation-loss-model.h" |
| 29 #include "ns3/propagation-delay-model.h" |
| 30 #include "ns3/double.h" |
| 31 /// Headers needed to install internet: |
| 32 #include "ns3/internet-stack-helper.h" |
| 33 #include "ns3/ipv4-address-helper.h" |
| 34 /// Applications: |
| 35 #include "ns3/v4ping-helper.h" |
| 36 #include "ns3/application-container.h" |
| 37 #include "ns3/boolean.h" |
| 38 |
| 39 #include "ns3/simulator.h" |
| 40 |
| 41 using namespace ns3; |
| 42 |
| 43 int main () |
| 44 { |
| 45 /* |
| 46 * This example creates two nodes @step meters apart from each other, installs
one radio-interface |
| 47 * on each node and tests ping between them. |
| 48 * Internet stack with global routing are installed above radio stack. |
| 49 */ |
| 50 ///\name Model Parameters: |
| 51 ///\{ |
| 52 double step = 500; |
| 53 uint32_t nodeCount = 10; |
| 54 double totalTime = 15; |
| 55 ///\} |
| 56 // 1. Create and place nodes: |
| 57 NodeContainer nodes; |
| 58 nodes.Create (nodeCount); |
| 59 /// Set position for each node: chain topology |
| 60 for (unsigned int i = 0; i < nodeCount; i++) |
| 61 { |
| 62 Ptr<Node> node = nodes.Get (i); |
| 63 Ptr<ConstantPositionMobilityModel> model = CreateObject<ConstantPositionMo
bilityModel> (); |
| 64 node->AggregateObject (model); |
| 65 model->SetPosition (Vector (0, step * i, 0)); |
| 66 } |
| 67 // 2. Create channel: |
| 68 Ptr<lrr::NeighborAwareSpectrumChannel> channel = LrrChannelHelper::Default ().
Create (); |
| 69 |
| 70 NeighborAwareDeviceHelper deviceHelper; |
| 71 deviceHelper.SetChannel (channel); |
| 72 |
| 73 //3. Crete TX power spectral density and noise power spectral densityL |
| 74 WifiSpectrumValue5MhzFactory sf; |
| 75 |
| 76 double txPower = 0.1; // Watts |
| 77 uint32_t channelNumber = 1; |
| 78 Ptr<SpectrumValue> txPsd = sf.CreateTxPowerSpectralDensity (txPower, channelNu
mber); |
| 79 |
| 80 const double k = 1.381e-23; //Boltzmann's constant |
| 81 const double T = 290; // temperature in Kelvin |
| 82 double noisePsdValue = k * T; // watts per hertz |
| 83 Ptr<SpectrumValue> noisePsd = sf.CreateConstant (noisePsdValue); |
| 84 Ptr<SpectrumValue> rxfilter = sf.CreateRfFilter (channelNumber+4); |
| 85 |
| 86 deviceHelper.SetTxPowerSpectralDensity (txPsd); |
| 87 deviceHelper.SetNoisePowerSpectralDensity (noisePsd); |
| 88 deviceHelper.SetRxFilter (rxfilter); |
| 89 |
| 90 //4. Install devices on nodes: |
| 91 NetDeviceContainer devices = deviceHelper.Install (nodes); |
| 92 //5. Install internet stack and routing: |
| 93 InternetStackHelper internet; |
| 94 LrrRoutingHelper lrrRouting; |
| 95 internet.SetRoutingHelper (lrrRouting); |
| 96 internet.Install (nodes); |
| 97 Ipv4AddressHelper ipAddrs; |
| 98 ipAddrs.SetBase ("10.0.0.0", "255.255.255.0"); |
| 99 Ipv4InterfaceContainer interfaces = ipAddrs.Assign (devices); |
| 100 //6. Install applications (ping) |
| 101 V4PingHelper ping (interfaces.GetAddress (nodeCount - 1)); |
| 102 ping.SetAttribute ("Verbose", BooleanValue (true)); |
| 103 ApplicationContainer p = ping.Install (nodes.Get (0)); |
| 104 p.Start (Seconds (0)); |
| 105 p.Stop (Seconds (totalTime) - Seconds (0.001)); |
| 106 //7. GO! |
| 107 lrr::GlobalGraph::Instance ()->Start (); |
| 108 Simulator::Stop (Seconds (totalTime)); |
| 109 Simulator::Run (); |
| 110 lrr::GlobalGraph::Instance ()->Stop (); |
| 111 Simulator::Destroy (); |
| 112 |
| 113 return 0; |
| 114 } |
OLD | NEW |