src/devices/mesh/dot11s/dot11s-helper.cc
changeset 4929 1689c94d7442
parent 4919 b8a0476c7e06
child 4930 fa5e570d56fa
equal deleted inserted replaced
4928:825037c2d7ab 4929:1689c94d7442
    26 #include "ns3/wifi-net-device.h"
    26 #include "ns3/wifi-net-device.h"
    27 #include "ns3/wifi-phy.h"
    27 #include "ns3/wifi-phy.h"
    28 #include "ns3/wifi-channel.h"
    28 #include "ns3/wifi-channel.h"
    29 #include "ns3/wifi-remote-station-manager.h"
    29 #include "ns3/wifi-remote-station-manager.h"
    30 #include "ns3/mesh-wifi-interface-mac.h"
    30 #include "ns3/mesh-wifi-interface-mac.h"
       
    31 #include "ns3/aarf-wifi-manager.h"
    31 
    32 
    32 namespace ns3 {
    33 namespace ns3 {
    33 namespace dot11s {
    34 namespace dot11s {
    34 
    35 
    35 MeshWifiHelper::MeshWifiHelper ()
    36 MeshWifiHelper::MeshWifiHelper () : m_ssid("Mesh"), m_randomStartDelay (Seconds (0))
    36 {
    37 {
    37 }
    38 }
    38 
    39   
    39 MeshWifiHelper::~MeshWifiHelper ()
    40 void MeshWifiHelper::SetSsid (Ssid const & s)
    40 {
    41 {
       
    42   m_ssid = s;
    41 }
    43 }
    42 
    44 
    43   void
    45 void MeshWifiHelper::SetRandomStartDelay (Time t)
    44 MeshWifiHelper::SetRemoteStationManager (std::string type,
       
    45     std::string n0, const AttributeValue &v0,
       
    46     std::string n1, const AttributeValue &v1,
       
    47     std::string n2, const AttributeValue &v2,
       
    48     std::string n3, const AttributeValue &v3,
       
    49     std::string n4, const AttributeValue &v4,
       
    50     std::string n5, const AttributeValue &v5,
       
    51     std::string n6, const AttributeValue &v6,
       
    52     std::string n7, const AttributeValue &v7)
       
    53 {
    46 {
    54   m_stationManager = ObjectFactory ();
    47   m_randomStartDelay = t;
    55   m_stationManager.SetTypeId (type);
       
    56   m_stationManager.Set (n0, v0);
       
    57   m_stationManager.Set (n1, v1);
       
    58   m_stationManager.Set (n2, v2);
       
    59   m_stationManager.Set (n3, v3);
       
    60   m_stationManager.Set (n4, v4);
       
    61   m_stationManager.Set (n5, v5);
       
    62   m_stationManager.Set (n6, v6);
       
    63   m_stationManager.Set (n7, v7);
       
    64 }
    48 }
    65 
    49 
    66   void
    50 Ptr<WifiNetDevice> MeshWifiHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr<Node> node) const
    67 MeshWifiHelper::SetMac (std::string type,
       
    68     std::string n0, const AttributeValue &v0,
       
    69     std::string n1, const AttributeValue &v1,
       
    70     std::string n2, const AttributeValue &v2,
       
    71     std::string n3, const AttributeValue &v3,
       
    72     std::string n4, const AttributeValue &v4,
       
    73     std::string n5, const AttributeValue &v5,
       
    74     std::string n6, const AttributeValue &v6,
       
    75     std::string n7, const AttributeValue &v7)
       
    76 {
    51 {
    77   m_meshMac = ObjectFactory ();
    52   Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
    78   m_meshMac.SetTypeId (type);
    53   
    79   m_meshMac.Set (n0, v0);
    54   // Creating MAC for this interface
    80   m_meshMac.Set (n1, v1);
    55   Ptr<MeshWifiInterfaceMac> mac = CreateObject<MeshWifiInterfaceMac> ();
    81   m_meshMac.Set (n2, v2);
    56   mac->SetSsid (m_ssid);
    82   m_meshMac.Set (n3, v3);
    57   if (m_randomStartDelay > Seconds (0))
    83   m_meshMac.Set (n4, v4);
    58     mac->SetRandomStartDelay (m_randomStartDelay);
    84   m_meshMac.Set (n5, v5);
    59   Ptr<WifiRemoteStationManager> manager = CreateObject<AarfWifiManager> ();
    85   m_meshMac.Set (n6, v6);
    60   Ptr<WifiPhy> phy = phyHelper.Create (node, device);
    86   m_meshMac.Set (n7, v7);
    61   mac->SetAddress (Mac48Address::Allocate ());
       
    62   device->SetMac (mac);
       
    63   device->SetPhy (phy);
       
    64   device->SetRemoteStationManager (manager);
       
    65   
       
    66   return device;
    87 }
    67 }
    88 void
    68   
    89 MeshWifiHelper::SetPeerManager (std::string type,
       
    90     std::string n0, const AttributeValue &v0,
       
    91     std::string n1, const AttributeValue &v1,
       
    92     std::string n2, const AttributeValue &v2,
       
    93     std::string n3, const AttributeValue &v3,
       
    94     std::string n4, const AttributeValue &v4,
       
    95     std::string n5, const AttributeValue &v5,
       
    96     std::string n6, const AttributeValue &v6,
       
    97     std::string n7, const AttributeValue &v7)
       
    98 {
       
    99   m_peerMan = ObjectFactory ();
       
   100   m_peerMan.SetTypeId (type);
       
   101   m_peerMan.Set (n0, v0);
       
   102   m_peerMan.Set (n1, v1);
       
   103   m_peerMan.Set (n2, v2);
       
   104   m_peerMan.Set (n3, v3);
       
   105   m_peerMan.Set (n4, v4);
       
   106   m_peerMan.Set (n5, v5);
       
   107   m_peerMan.Set (n6, v6);
       
   108   m_peerMan.Set (n7, v7);
       
   109 }
       
   110 void
       
   111 MeshWifiHelper::SetRouting (std::string type,
       
   112     std::string n0, const AttributeValue &v0,
       
   113     std::string n1, const AttributeValue &v1,
       
   114     std::string n2, const AttributeValue &v2,
       
   115     std::string n3, const AttributeValue &v3,
       
   116     std::string n4, const AttributeValue &v4,
       
   117     std::string n5, const AttributeValue &v5,
       
   118     std::string n6, const AttributeValue &v6,
       
   119     std::string n7, const AttributeValue &v7)
       
   120 {
       
   121   m_routing = ObjectFactory ();
       
   122   m_routing.SetTypeId (type);
       
   123   m_routing.Set (n0, v0);
       
   124   m_routing.Set (n1, v1);
       
   125   m_routing.Set (n2, v2);
       
   126   m_routing.Set (n3, v3);
       
   127   m_routing.Set (n4, v4);
       
   128   m_routing.Set (n5, v5);
       
   129   m_routing.Set (n6, v6);
       
   130   m_routing.Set (n7, v7);
       
   131 }
       
   132 void
       
   133 MeshWifiHelper::SetL2RoutingNetDevice (std::string type,
       
   134     std::string n0, const AttributeValue &v0,
       
   135     std::string n1, const AttributeValue &v1,
       
   136     std::string n2, const AttributeValue &v2,
       
   137     std::string n3, const AttributeValue &v3,
       
   138     std::string n4, const AttributeValue &v4,
       
   139     std::string n5, const AttributeValue &v5,
       
   140     std::string n6, const AttributeValue &v6,
       
   141     std::string n7, const AttributeValue &v7
       
   142     )
       
   143 {
       
   144   m_deviceFactory = ObjectFactory ();
       
   145   m_deviceFactory.SetTypeId (type);
       
   146   m_deviceFactory.Set (n0, v0);
       
   147   m_deviceFactory.Set (n1, v1);
       
   148   m_deviceFactory.Set (n2, v2);
       
   149   m_deviceFactory.Set (n3, v3);
       
   150   m_deviceFactory.Set (n4, v4);
       
   151   m_deviceFactory.Set (n5, v5);
       
   152   m_deviceFactory.Set (n6, v6);
       
   153   m_deviceFactory.Set (n7, v7);
       
   154 }
       
   155 NetDeviceContainer
    69 NetDeviceContainer
   156 MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
    70 MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c, uint32_t nInterfaces) const
   157 {
    71 {
   158   NetDeviceContainer devices;
    72   NetDeviceContainer devices;
       
    73   
   159   for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
    74   for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
   160   {
    75   {
   161     Ptr<Node> node = *i;
    76     Ptr<Node> node = *i;
   162     // Create a mesh point device:
    77     
   163     Ptr<MeshPointDevice> mp = m_deviceFactory.Create<MeshPointDevice> ();
    78     // Create a mesh point device
   164     std::vector<Ptr<NetDevice> > mpInterfacess;
    79     Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
   165     // Creating interface:
    80     node->AddDevice (mp);
   166     {
    81     
   167       Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
    82     // Create wifi interfaces (single interface by default)
   168       //Creating MAC for this interface
    83     for (uint32_t i = 0; i < nInterfaces; ++i)
   169       Ptr<MeshWifiInterfaceMac> mac = m_meshMac.Create<MeshWifiInterfaceMac> ();
    84       {
   170       Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
    85         Ptr<WifiNetDevice> iface = CreateInterface (phyHelper, node);
   171       Ptr<WifiPhy> phy = phyHelper.Create (node, device);
    86         
   172       mac->SetAddress (Mac48Address::Allocate ());
    87         node->AddDevice (iface);
   173       device->SetMac (mac);
    88         mp->AddInterface (iface);
   174       device->SetPhy (phy);
    89       }
   175       device->SetRemoteStationManager (manager);
    90     
   176       node->AddDevice (device);
    91     // Install 802.11s protocols
   177       mpInterfacess.push_back (device);
    92     Ptr<PeerManagementProtocol> pmp = CreateObject<PeerManagementProtocol> ();
   178     }
    93     bool pmp_ok = pmp->Install (mp);
   179     node -> AddDevice (mp);
    94     NS_ASSERT (pmp_ok);
   180     for (std::vector<Ptr<NetDevice> > ::iterator iter=mpInterfacess.begin ();iter != mpInterfacess.end(); ++iter)
    95     
   181       mp->AddInterface (*iter);
    96     Ptr<HwmpProtocol> hwmp = CreateObject<HwmpProtocol> ();
   182     mpInterfacess.clear ();
    97     bool hwmp_ok = hwmp->Install (mp);
   183     //Install protocols:
    98     NS_ASSERT (hwmp_ok);
   184     Ptr<PeerManagementProtocol> peer = m_peerMan.Create<PeerManagementProtocol> ();
    99     
   185     NS_ASSERT(peer->Install(mp));
   100     pmp->SetPeerLinkStatusCallback(MakeCallback(&HwmpProtocol::PeerLinkStatus, hwmp));
   186     Ptr<HwmpProtocol> hwmp = m_routing.Create<HwmpProtocol> ();
   101     hwmp->SetNeighboursCallback(MakeCallback(&PeerManagementProtocol::GetActiveLinks, pmp));
   187     peer->SetPeerLinkStatusCallback(MakeCallback(&HwmpProtocol::PeerLinkStatus, hwmp));
   102     
   188     hwmp->SetNeighboursCallback(MakeCallback(&PeerManagementProtocol::GetActiveLinks, peer));
   103     mp->SetRoutingProtocol (hwmp);
   189     NS_ASSERT(hwmp->Install(mp));
   104     
   190     devices.Add (mp);
   105     devices.Add (mp);
   191   }
   106   }
   192   return devices;
   107   return devices;
   193 }
   108 }
   194 
   109 
   195 NetDeviceContainer
   110 NetDeviceContainer
   196 MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node) const
   111 MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node, uint32_t nInterfaces) const
   197 {
   112 {
   198   return Install (phy, NodeContainer (node));
   113   return Install (phy, NodeContainer (node));
   199 }
   114 }
   200   
   115   
   201 } // namespace dot11s
   116 } // namespace dot11s