Advertisement
Guest User

mesh-multichannel

a guest
May 6th, 2010
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.57 KB | None | 0 0
  1. /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3.  * Copyright (c) 2010 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: Vitaly Balashov <vitaly.balashov@gmail.com>
  19.  */
  20.  
  21. /*
  22.  * This is a simplest example of multi-interface and multi-channel 802.11s mesh network
  23.  *
  24.  * Every mesh station has 2 interfaces configured on two different channels:
  25.  *
  26.  * channel:   i   j
  27.  *            |   |
  28.  * station:  [ STA ]  
  29.  *
  30.  * Chain topology is created:
  31.  *
  32.  *   1   2                   2   3                  3   1
  33.  *   |   |                   |   |                  |   |
  34.  *  [STA 1]   <-- 120 m --> [STA 2]  <-- 120 m --> [STA 3]
  35.  *  10.0.0.1                10.0.0.2               10.0.0.3
  36.  *  
  37.  *  Then STA1 ping STA3
  38.  *  
  39.  *  Parameters tuning and assertions are omitted for clarity.
  40.  */
  41.  
  42. #include "ns3/core-module.h"
  43. #include "ns3/simulator-module.h"
  44. #include "ns3/node-module.h"
  45. #include "ns3/helper-module.h"
  46. #include "ns3/global-routing-module.h"
  47. #include "ns3/wifi-module.h"
  48. #include "ns3/mesh-module.h"
  49. #include "ns3/mobility-module.h"
  50. #include "ns3/mesh-helper.h"
  51. #include <iostream>
  52.  
  53. using namespace ns3;
  54.  
  55. int main (int argc, char **argv)
  56. {
  57.   // Create nodes & devices
  58.   NodeContainer nodes;
  59.   nodes.Create (10);
  60.   YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
  61.   YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
  62.   wifiPhy.SetChannel (wifiChannel.Create ());
  63.   MeshHelper mesh = MeshHelper::Default ();    
  64.   mesh.SetStackInstaller ("ns3::Dot11sStack");  // use 802.11s mesh stack
  65.   mesh.SetNumberOfInterfaces (2);               // use 2-interface stations
  66.   NetDeviceContainer meshDevices = mesh.Install (wifiPhy, nodes);
  67.  
  68.   // Manually setup channel numbers for every mesh STA/interface
  69.   uint32_t channel[10 /*node id*/][2 /*interface id*/] = {{1, 0}, {0, 3}, {1, 2}, {1, 0}, {3, 0}, {2, 0}, {2, 4}, {1, 4}, {3, 1}, {4, 0}};
  70.   for (uint32_t i = 0; i < 10; ++i)
  71.     {
  72.       // access i-th mesh point, production code should add NS_ASSERT (mp != 0);
  73.       Ptr<MeshPointDevice> mp = DynamicCast<MeshPointDevice> (meshDevices.Get (i));  
  74.       // get list of MP interfaces, production code should add NS_ASSERT (ifaces.size() == 2)
  75.       std::vector< Ptr<NetDevice> > ifaces = mp->GetInterfaces ();
  76.       for (uint32_t j = 0; j < 2; ++j)
  77.         {
  78.           // access j-th interface, it's worth to add assertion again
  79.           Ptr<WifiNetDevice> iface = DynamicCast<WifiNetDevice> (ifaces [j]);
  80.           // finally set channel number
  81.           iface->GetPhy()->SetChannelNumber(channel[i][j]);
  82.         }
  83.     }
  84.  
  85.   // Place nodes
  86.  
  87.   MobilityHelper mobility;
  88.   Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  89.   positionAlloc->Add (Vector (0.0, 200.0, 0.0));
  90.   positionAlloc->Add (Vector (50.0, 150.0, 0.0));
  91.   positionAlloc->Add (Vector (50.0, 100.0, 0.0));
  92.   positionAlloc->Add (Vector (0.0, 25.0, 0.0));
  93.   positionAlloc->Add (Vector (125.0, 200.0, 0.0));
  94.   positionAlloc->Add (Vector (75.0, 100.0, 0.0));
  95.   positionAlloc->Add (Vector (100.0, 0.0, 0.0));
  96.   positionAlloc->Add (Vector (150.0, 150.0, 0.0));
  97.   positionAlloc->Add (Vector (160.0, 175.0, 0.0));
  98.   positionAlloc->Add (Vector (160.0, 0.0, 0.0));
  99.   mobility.SetPositionAllocator (positionAlloc);
  100.   mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  101.   mobility.Install (nodes);
  102.  
  103.   // Install Internet stack and ping
  104.   InternetStackHelper internetStack;
  105.   internetStack.Install (nodes);
  106.   Ipv4AddressHelper address;
  107.   address.SetBase ("10.0.0.0", "255.255.255.0");
  108.   address.Assign (meshDevices);
  109.   V4PingHelper ping (Ipv4Address ("10.0.0.4")); // ping target
  110.   ping.SetAttribute ("Verbose", BooleanValue (true));
  111.    
  112.   Time totalTime = Seconds(5);
  113.   ApplicationContainer p = ping.Install (nodes.Get (1));
  114.   p.Start (Seconds (0));
  115.   p.Stop (totalTime - Seconds(0.001));
  116.  
  117.   // Go!
  118.   Simulator::Stop (totalTime);
  119.   Simulator::Run ();
  120.   Simulator::Destroy ();
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement