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: Denis Fakhriev <fakhriev@telum.ru> |
| 19 * Kirill Andreev <andreev@telum.ru> |
| 20 */ |
| 21 |
| 22 #include "ns3/mac48-address.h" |
| 23 #include "lrr-mac-impl.h" |
| 24 |
| 25 #include "lrr-mac-access-manager.h" |
| 26 #include "lrr-mac-header.h" |
| 27 #include "lrr-device.h" |
| 28 |
| 29 namespace ns3 { |
| 30 namespace lrr { |
| 31 |
| 32 NS_OBJECT_ENSURE_REGISTERED (CollisionFreeMacImpl); |
| 33 |
| 34 TypeId· |
| 35 CollisionFreeMacImpl::GetTypeId () |
| 36 { |
| 37 static TypeId tid = TypeId ("ns3::lrr::CollisionFreeMacImpl") |
| 38 .SetParent<Mac> () |
| 39 .AddConstructor<CollisionFreeMacImpl> () |
| 40 .AddTraceSource ("RxError", "Error when receiving a packet", |
| 41 MakeTraceSourceAccessor (&CollisionFreeMacImpl::m_rxErrorTr
ace)) |
| 42 ; |
| 43 return tid; |
| 44 } |
| 45 |
| 46 CollisionFreeMacImpl::CollisionFreeMacImpl () : |
| 47 Mac (), |
| 48 m_address (Address ()), |
| 49 m_accessManager (CreateObject<AccessManager> ()) |
| 50 { |
| 51 m_accessManager->SetMac (this); |
| 52 } |
| 53 |
| 54 void |
| 55 CollisionFreeMacImpl::DoStart () |
| 56 { |
| 57 /// Works with lrr::Phy |
| 58 GetPhy ()->TraceConnectWithoutContext ("RxEndError", MakeCallback (&CollisionF
reeMacImpl::ReceiveError, this)); |
| 59 } |
| 60 |
| 61 CollisionFreeMacImpl::~CollisionFreeMacImpl () |
| 62 {} |
| 63 |
| 64 void |
| 65 CollisionFreeMacImpl::DoDispose () |
| 66 { |
| 67 m_accessManager->SetMac (0); |
| 68 m_accessManager = 0; |
| 69 Mac::DoDispose (); |
| 70 } |
| 71 |
| 72 void |
| 73 CollisionFreeMacImpl::SetAddress (Address address) |
| 74 { |
| 75 m_address = address; |
| 76 } |
| 77 |
| 78 Address |
| 79 CollisionFreeMacImpl::GetAddress () const |
| 80 { |
| 81 return m_address; |
| 82 } |
| 83 // Ideal MAC layer functionality: obtain reservations from neighbors |
| 84 Ptr<AccessManager> |
| 85 CollisionFreeMacImpl::GetAccessManager () const |
| 86 { |
| 87 return m_accessManager; |
| 88 } |
| 89 |
| 90 void |
| 91 CollisionFreeMacImpl::Enqueue (Ptr<Packet> packet, Address to, Address from, uin
t16_t type) |
| 92 { |
| 93 MacHeader header; |
| 94 header.SetType (type); |
| 95 header.SetSource (from); |
| 96 header.SetDestination (to); |
| 97 packet->AddHeader (header); |
| 98 m_accessManager->Enqueue (packet); |
| 99 } |
| 100 |
| 101 void |
| 102 CollisionFreeMacImpl::Receive (Ptr<Packet> packet) |
| 103 { |
| 104 MacHeader header; |
| 105 packet->RemoveHeader (header); |
| 106 Address from = header.GetSource (); |
| 107 Address to = header.GetDestination (); |
| 108 uint16_t protocolNumber = header.GetType (); |
| 109 |
| 110 if (IsGroupAddress (to) || IsMyAddress (to)) |
| 111 { |
| 112 ForwardUp (packet, from, to, protocolNumber); |
| 113 } |
| 114 } |
| 115 |
| 116 void |
| 117 CollisionFreeMacImpl::SetQueue (Ptr<Queue> queue) |
| 118 { |
| 119 m_accessManager->SetQueue (queue); |
| 120 } |
| 121 |
| 122 void |
| 123 CollisionFreeMacImpl::ReceiveError (Ptr<const Packet> errorPacket) |
| 124 { |
| 125 MacHeader header; |
| 126 if (!errorPacket->PeekHeader (header)) |
| 127 { |
| 128 return; |
| 129 } |
| 130 Address destination = header.GetDestination (); |
| 131 Address source = header.GetSource (); |
| 132 if (IsMyAddress (destination)) |
| 133 { |
| 134 m_rxErrorTrace (destination, source); |
| 135 } |
| 136 } |
| 137 |
| 138 Address |
| 139 CollisionFreeMacImpl::GetBroadcast () const |
| 140 { |
| 141 return Mac48Address::GetBroadcast (); |
| 142 } |
| 143 |
| 144 Address |
| 145 CollisionFreeMacImpl::GetMulticast (Ipv4Address group) const |
| 146 { |
| 147 return Mac48Address::GetMulticast (group); |
| 148 } |
| 149 |
| 150 Address |
| 151 CollisionFreeMacImpl::GetMulticast (Ipv6Address group) const |
| 152 { |
| 153 return Mac48Address::GetMulticast (group); |
| 154 } |
| 155 |
| 156 bool |
| 157 CollisionFreeMacImpl::IsMyAddress (const Address & a) const |
| 158 { |
| 159 return Mac48Address::ConvertFrom (a) == Mac48Address::ConvertFrom (m_address); |
| 160 } |
| 161 |
| 162 bool |
| 163 CollisionFreeMacImpl::IsGroupAddress (const Address & a) const |
| 164 { |
| 165 return Mac48Address::ConvertFrom (a).IsGroup (); |
| 166 } |
| 167 } // namespace lrr |
| 168 } // namespace ns3 |
OLD | NEW |