OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 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/pointer.h" |
| 22 #include "ns3/uinteger.h" |
| 23 #include "ns3/log.h" |
| 24 #include "lrr-device.h" |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("LrrNeighborAwareDevice"); |
| 27 |
| 28 namespace ns3 { |
| 29 namespace lrr { |
| 30 |
| 31 NS_OBJECT_ENSURE_REGISTERED (NeighborAwareDevice); |
| 32 |
| 33 TypeId |
| 34 NeighborAwareDevice::GetTypeId () |
| 35 { |
| 36 static TypeId tid = TypeId ("ns3::lrr::NeighborAwareDevice") |
| 37 .SetParent<NetDevice> () |
| 38 .AddConstructor<NeighborAwareDevice> () |
| 39 .AddAttribute ("Mac", "The MAC layer attached to this device.", |
| 40 PointerValue (), |
| 41 MakePointerAccessor (&NeighborAwareDevice::GetMac, |
| 42 &NeighborAwareDevice::SetMac), |
| 43 MakePointerChecker<Mac> ()) |
| 44 ; |
| 45 return tid; |
| 46 } |
| 47 |
| 48 NeighborAwareDevice::NeighborAwareDevice () : |
| 49 m_mac (0), m_node (0), m_ifIndex (0), m_mtu (0) |
| 50 {} |
| 51 |
| 52 void |
| 53 NeighborAwareDevice::DoStart () |
| 54 { |
| 55 m_mac->Start (); |
| 56 NetDevice::DoStart (); |
| 57 } |
| 58 |
| 59 NeighborAwareDevice::~NeighborAwareDevice () |
| 60 { |
| 61 NS_LOG_FUNCTION (this); |
| 62 } |
| 63 |
| 64 void |
| 65 NeighborAwareDevice::DoDispose () |
| 66 { |
| 67 NS_LOG_FUNCTION (this); |
| 68 m_node = 0; |
| 69 m_mac = 0; |
| 70 m_forwardUp = MakeNullCallback <bool,Ptr<NetDevice>,Ptr<const Packet>,uint16_t
,const Address &> (); |
| 71 m_promiscRx = MakeNullCallback<bool, Ptr<NetDevice>, Ptr<const Packet>, uint16
_t, const Address &, const Address &, enum PacketType> (); |
| 72 // chain up. |
| 73 NetDevice::DoDispose (); |
| 74 } |
| 75 // MAC { |
| 76 void |
| 77 NeighborAwareDevice::SetMac (Ptr<Mac> mac) |
| 78 { |
| 79 m_mac = mac; |
| 80 m_mac->SetForwardUpCallback (MakeCallback (&NeighborAwareDevice::ForwardUp, th
is)); |
| 81 } |
| 82 |
| 83 Ptr<Mac> |
| 84 NeighborAwareDevice::GetMac () const |
| 85 { |
| 86 return m_mac; |
| 87 } |
| 88 // } |
| 89 // Inherited from NetDevice base class { |
| 90 void |
| 91 NeighborAwareDevice::SetIfIndex (const uint32_t index) |
| 92 { |
| 93 m_ifIndex = index; |
| 94 } |
| 95 |
| 96 uint32_t |
| 97 NeighborAwareDevice::GetIfIndex () const |
| 98 { |
| 99 return m_ifIndex; |
| 100 } |
| 101 |
| 102 Ptr<Channel> |
| 103 NeighborAwareDevice::GetChannel () const |
| 104 { |
| 105 return 0; |
| 106 } |
| 107 |
| 108 void |
| 109 NeighborAwareDevice::SetAddress (Address address) |
| 110 { |
| 111 m_mac->SetAddress (address); |
| 112 } |
| 113 |
| 114 Address |
| 115 NeighborAwareDevice::GetAddress () const |
| 116 { |
| 117 NS_ASSERT (m_mac != 0); |
| 118 return m_mac->GetAddress (); |
| 119 } |
| 120 |
| 121 bool |
| 122 NeighborAwareDevice::SetMtu (const uint16_t mtu) |
| 123 { |
| 124 UintegerValue maxMsduSize; |
| 125 m_mac->GetAttribute ("MaxMsduSize", maxMsduSize); |
| 126 if (mtu > maxMsduSize.Get () || mtu == 0) |
| 127 { |
| 128 return false; |
| 129 } |
| 130 m_mtu = mtu; |
| 131 return true; |
| 132 } |
| 133 |
| 134 uint16_t |
| 135 NeighborAwareDevice::GetMtu () const |
| 136 { |
| 137 if (m_mtu == 0) |
| 138 { |
| 139 UintegerValue maxMsduSize; |
| 140 m_mac->GetAttribute ("MaxMsduSize", maxMsduSize); |
| 141 m_mtu = maxMsduSize.Get (); |
| 142 } |
| 143 return m_mtu; |
| 144 } |
| 145 |
| 146 bool |
| 147 NeighborAwareDevice::IsLinkUp () const |
| 148 { |
| 149 return true; |
| 150 } |
| 151 |
| 152 void |
| 153 NeighborAwareDevice::AddLinkChangeCallback (Callback<void> callback) |
| 154 {} |
| 155 |
| 156 bool |
| 157 NeighborAwareDevice::IsBroadcast () const |
| 158 { |
| 159 return true; |
| 160 } |
| 161 |
| 162 Address |
| 163 NeighborAwareDevice::GetBroadcast () const |
| 164 { |
| 165 return m_mac->GetBroadcast (); |
| 166 } |
| 167 |
| 168 bool |
| 169 NeighborAwareDevice::IsMulticast () const |
| 170 { |
| 171 return true; |
| 172 } |
| 173 |
| 174 Address |
| 175 NeighborAwareDevice::GetMulticast (Ipv4Address multicastGroup) const |
| 176 { |
| 177 return m_mac->GetMulticast (multicastGroup); |
| 178 } |
| 179 |
| 180 Address |
| 181 NeighborAwareDevice::GetMulticast (Ipv6Address multicastGroup) const |
| 182 { |
| 183 return m_mac->GetMulticast (multicastGroup); |
| 184 } |
| 185 |
| 186 bool |
| 187 NeighborAwareDevice::IsPointToPoint () const |
| 188 { |
| 189 return false; |
| 190 } |
| 191 |
| 192 bool |
| 193 NeighborAwareDevice::IsBridge () const |
| 194 { |
| 195 return false; |
| 196 } |
| 197 |
| 198 bool |
| 199 NeighborAwareDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t pro
tocolNumber) |
| 200 { |
| 201 m_mac->Enqueue (packet, dest, m_mac->GetAddress (), protocolNumber); |
| 202 return true; |
| 203 } |
| 204 |
| 205 bool |
| 206 NeighborAwareDevice::SendFrom (Ptr<Packet> packet, const Address& source, const
Address& dest, uint16_t protocolNumber) |
| 207 { |
| 208 NS_FATAL_ERROR ("Radio does not support SendFrom"); |
| 209 return false; |
| 210 } |
| 211 |
| 212 Ptr<Node> |
| 213 NeighborAwareDevice::GetNode () const |
| 214 { |
| 215 return m_node; |
| 216 } |
| 217 |
| 218 void |
| 219 NeighborAwareDevice::SetNode (Ptr<Node> node) |
| 220 { |
| 221 m_node = node; |
| 222 } |
| 223 |
| 224 bool |
| 225 NeighborAwareDevice::NeedsArp () const |
| 226 { |
| 227 return true; |
| 228 } |
| 229 |
| 230 void |
| 231 NeighborAwareDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) |
| 232 { |
| 233 m_forwardUp = cb; |
| 234 } |
| 235 |
| 236 void |
| 237 NeighborAwareDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) |
| 238 { |
| 239 m_promiscRx = cb; |
| 240 } |
| 241 |
| 242 bool |
| 243 NeighborAwareDevice::SupportsSendFrom () const |
| 244 { |
| 245 return false; |
| 246 } |
| 247 // } |
| 248 std::vector<Ptr<NetDevice> > |
| 249 NeighborAwareDevice::GetCommunicationNeighbors () const |
| 250 { |
| 251 NS_ASSERT (m_mac != 0); |
| 252 return GetMac ()->GetCommunicationNeighbors (); |
| 253 } |
| 254 |
| 255 void |
| 256 NeighborAwareDevice::ForwardUp (Ptr<Packet> packet, Address from, Address to, ui
nt16_t protocolN) |
| 257 { |
| 258 m_forwardUp (this, packet, protocolN, from); |
| 259 } |
| 260 } |
| 261 } |
OLD | NEW |