LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2006,2007 INRIA |
| 4 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
| 5 * |
| 6 * This program is free software; you can redistribute it and/or modify |
| 7 * it under the terms of the GNU General Public License version 2 as |
| 8 * published by the Free Software Foundation; |
| 9 * |
| 10 * This program is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 * GNU General Public License for more details. |
| 14 * |
| 15 * You should have received a copy of the GNU General Public License |
| 16 * along with this program; if not, write to the Free Software |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 * |
| 19 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
| 20 * Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 21 */ |
| 22 |
| 23 #include "ns3/packet.h" |
| 24 #include "ns3/simulator.h" |
| 25 #include "ns3/mobility-model.h" |
| 26 #include "ns3/net-device.h" |
| 27 #include "ns3/node.h" |
| 28 #include "ns3/log.h" |
| 29 #include "ns3/pointer.h" |
| 30 #include "ns3/object-factory.h" |
| 31 #include "ns3/propagation-loss-model.h" |
| 32 #include "ns3/propagation-delay-model.h" |
| 33 #include "nsl-wifi-channel.h" |
| 34 #include "nsl-wifi-phy.h" |
| 35 |
| 36 NS_LOG_COMPONENT_DEFINE ("NslWifiChannel"); |
| 37 |
| 38 namespace ns3 { |
| 39 |
| 40 TypeId |
| 41 NslWifiChannel::GetTypeId (void) |
| 42 { |
| 43 static TypeId tid = TypeId ("ns3::NslWifiChannel") |
| 44 .SetParent<WifiChannel> () |
| 45 .AddConstructor<NslWifiChannel> () |
| 46 .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss mo
del attached to this channel.", |
| 47 PointerValue (), |
| 48 MakePointerAccessor (&NslWifiChannel::m_loss), |
| 49 MakePointerChecker<PropagationLossModel> ()) |
| 50 .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay
model attached to this channel.", |
| 51 PointerValue (), |
| 52 MakePointerAccessor (&NslWifiChannel::m_delay), |
| 53 MakePointerChecker<PropagationDelayModel> ()) |
| 54 ; |
| 55 return tid; |
| 56 } |
| 57 |
| 58 NslWifiChannel::NslWifiChannel () |
| 59 {} |
| 60 NslWifiChannel::~NslWifiChannel () |
| 61 { |
| 62 NS_LOG_FUNCTION_NOARGS (); |
| 63 m_phyList.clear (); |
| 64 } |
| 65 |
| 66 void |
| 67 NslWifiChannel::SetPropagationLossModel (Ptr<PropagationLossModel> loss) |
| 68 { |
| 69 m_loss = loss; |
| 70 } |
| 71 |
| 72 void |
| 73 NslWifiChannel::SetPropagationDelayModel (Ptr<PropagationDelayModel> delay) |
| 74 { |
| 75 m_delay = delay; |
| 76 } |
| 77 |
| 78 void |
| 79 NslWifiChannel::Send (Ptr<NslWifiPhy> sender, Ptr<const Packet> packet, double t
xPowerDbm, |
| 80 WifiMode wifiMode, WifiPreamble preamble) const |
| 81 { |
| 82 Ptr<MobilityModel> senderMobility = sender->GetMobility ()->GetObject<Mobility
Model> (); |
| 83 NS_ASSERT (senderMobility != 0); |
| 84 uint32_t j = 0; |
| 85 for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i+
+, j++) |
| 86 { |
| 87 if (sender != (*i)) |
| 88 { |
| 89 // For now don't account for inter channel interference |
| 90 if ((*i)->GetChannelNumber() != sender->GetChannelNumber()) |
| 91 continue; |
| 92 |
| 93 Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<
MobilityModel> (); |
| 94 Time delay = m_delay->GetDelay (senderMobility, receiverMobility); |
| 95 double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, r
eceiverMobility); |
| 96 NS_LOG_DEBUG ("propagation: txPower="<<txPowerDbm<<"dbm, rxPower="<<rx
PowerDbm<<"dbm, "<< |
| 97 "distance="<<senderMobility->GetDistanceFrom (receiverMo
bility)<<"m, delay="<<delay); |
| 98 Ptr<Packet> copy = packet->Copy (); |
| 99 Ptr<Object> dstNetDevice = m_phyList[j]->GetDevice (); |
| 100 uint32_t dstNode; |
| 101 if (dstNetDevice == 0) |
| 102 { |
| 103 dstNode = 0xffffffff; |
| 104 } |
| 105 else |
| 106 { |
| 107 dstNode = dstNetDevice->GetObject<NetDevice> ()->GetNode ()->GetId
(); |
| 108 } |
| 109 Simulator::ScheduleWithContext (dstNode, |
| 110 delay, &NslWifiChannel::Receive, this, |
| 111 j, copy, rxPowerDbm, wifiMode, preambl
e); |
| 112 } |
| 113 } |
| 114 } |
| 115 |
| 116 void |
| 117 NslWifiChannel::Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm, |
| 118 WifiMode txMode, WifiPreamble preamble) const |
| 119 { |
| 120 m_phyList[i]->StartReceivePacket (packet, rxPowerDbm, txMode, preamble); |
| 121 } |
| 122 |
| 123 uint32_t |
| 124 NslWifiChannel::GetNDevices (void) const |
| 125 { |
| 126 return m_phyList.size (); |
| 127 } |
| 128 Ptr<NetDevice> |
| 129 NslWifiChannel::GetDevice (uint32_t i) const |
| 130 { |
| 131 return m_phyList[i]->GetDevice ()->GetObject<NetDevice> (); |
| 132 } |
| 133 |
| 134 void |
| 135 NslWifiChannel::Add (Ptr<NslWifiPhy> phy) |
| 136 { |
| 137 m_phyList.push_back (phy); |
| 138 } |
| 139 |
| 140 } // namespace ns3 |
LEFT | RIGHT |