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 */ |
|
20 #include "ns3/dot11s-installer.h" |
|
21 #include "ns3/peer-management-protocol.h" |
|
22 #include "ns3/hwmp-protocol.h" |
|
23 #include "ns3/wifi-net-device.h" |
|
24 #include "ns3/mesh-wifi-interface-mac.h" |
|
25 |
|
26 namespace ns3 { |
|
27 using namespace dot11s; |
|
28 NS_OBJECT_ENSURE_REGISTERED (Dot11sStack); |
|
29 TypeId |
|
30 Dot11sStack::GetTypeId () |
|
31 { |
|
32 static TypeId tid = TypeId ("ns3::Dot11sStack") |
|
33 .SetParent<Object> () |
|
34 .AddConstructor<Dot11sStack> () |
|
35 .AddAttribute ("Root", |
|
36 "The MAC address of root mesh point.", |
|
37 Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
|
38 MakeMac48AddressAccessor (&Dot11sStack::m_root), |
|
39 MakeMac48AddressChecker ()); |
|
40 return tid; |
|
41 } |
|
42 Dot11sStack::Dot11sStack () : |
|
43 m_root (Mac48Address ("ff:ff:ff:ff:ff:ff")) |
|
44 { |
|
45 } |
|
46 Dot11sStack::~Dot11sStack () |
|
47 { |
|
48 } |
|
49 void |
|
50 Dot11sStack::DoDispose () |
|
51 { |
|
52 } |
|
53 bool |
|
54 Dot11sStack::InstallStack (Ptr<MeshPointDevice> mp) |
|
55 { |
|
56 //Install Peer management protocol: |
|
57 Ptr<PeerManagementProtocol> pmp = CreateObject<PeerManagementProtocol> (); |
|
58 pmp->SetMeshId ("mesh"); |
|
59 bool install_ok = pmp->Install (mp); |
|
60 if (!install_ok) |
|
61 { |
|
62 return false; |
|
63 } |
|
64 //Install HWMP: |
|
65 Ptr<HwmpProtocol> hwmp = CreateObject<HwmpProtocol> (); |
|
66 install_ok = hwmp->Install (mp); |
|
67 if (!install_ok) |
|
68 { |
|
69 return false; |
|
70 } |
|
71 if (mp->GetAddress() == m_root) |
|
72 { |
|
73 hwmp->SetRoot (); |
|
74 } |
|
75 //Install interaction between HWMP and Peer management protocol: |
|
76 //PeekPointer()'s to avoid circular Ptr references |
|
77 pmp->SetPeerLinkStatusCallback (MakeCallback (&HwmpProtocol::PeerLinkStatus, PeekPointer (hwmp))); |
|
78 hwmp->SetNeighboursCallback (MakeCallback (&PeerManagementProtocol::GetPeers, PeekPointer (pmp))); |
|
79 return true; |
|
80 } |
|
81 void |
|
82 Dot11sStack::Report (const Ptr<MeshPointDevice> mp, std::ostream& os) |
|
83 { |
|
84 mp->Report (os); |
|
85 |
|
86 std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces (); |
|
87 for (std::vector<Ptr<NetDevice> >::const_iterator i = ifaces.begin (); i != ifaces.end (); ++i) |
|
88 { |
|
89 Ptr<WifiNetDevice> device = (*i)->GetObject<WifiNetDevice> (); |
|
90 NS_ASSERT (device != 0); |
|
91 Ptr<MeshWifiInterfaceMac> mac = device->GetMac ()->GetObject<MeshWifiInterfaceMac> (); |
|
92 NS_ASSERT (mac != 0); |
|
93 mac->Report (os); |
|
94 } |
|
95 Ptr<HwmpProtocol> hwmp = mp->GetObject<HwmpProtocol> (); |
|
96 NS_ASSERT (hwmp != 0); |
|
97 hwmp->Report (os); |
|
98 |
|
99 Ptr<PeerManagementProtocol> pmp = mp->GetObject<PeerManagementProtocol> (); |
|
100 NS_ASSERT (pmp != 0); |
|
101 pmp->Report (os); |
|
102 } |
|
103 void |
|
104 Dot11sStack::ResetStats (const Ptr<MeshPointDevice> mp) |
|
105 { |
|
106 mp->ResetStats (); |
|
107 |
|
108 std::vector<Ptr<NetDevice> > ifaces = mp->GetInterfaces (); |
|
109 for (std::vector<Ptr<NetDevice> >::const_iterator i = ifaces.begin (); i != ifaces.end (); ++i) |
|
110 { |
|
111 Ptr<WifiNetDevice> device = (*i)->GetObject<WifiNetDevice> (); |
|
112 NS_ASSERT (device != 0); |
|
113 Ptr<MeshWifiInterfaceMac> mac = device->GetMac ()->GetObject<MeshWifiInterfaceMac> (); |
|
114 NS_ASSERT (mac != 0); |
|
115 mac->ResetStats (); |
|
116 } |
|
117 Ptr<HwmpProtocol> hwmp = mp->GetObject<HwmpProtocol> (); |
|
118 NS_ASSERT (hwmp != 0); |
|
119 hwmp->ResetStats (); |
|
120 |
|
121 Ptr<PeerManagementProtocol> pmp = mp->GetObject<PeerManagementProtocol> (); |
|
122 NS_ASSERT (pmp != 0); |
|
123 pmp->ResetStats (); |
|
124 } |
|
125 } //namespace ns3 |
|