00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ns3/packet.h"
00021 #include "ns3/simulator.h"
00022 #include "ns3/mobility-model.h"
00023 #include "ns3/net-device.h"
00024 #include "ns3/node.h"
00025 #include "ns3/log.h"
00026 #include "ns3/pointer.h"
00027 #include "ns3/object-factory.h"
00028 #include "yans-wifi-channel.h"
00029 #include "yans-wifi-phy.h"
00030 #include "propagation-loss-model.h"
00031 #include "propagation-delay-model.h"
00032
00033 NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");
00034
00035 namespace ns3 {
00036
00037 TypeId
00038 YansWifiChannel::GetTypeId (void)
00039 {
00040 static TypeId tid = TypeId ("ns3::YansWifiChannel")
00041 .SetParent<WifiChannel> ()
00042 .AddConstructor<YansWifiChannel> ()
00043 .AddAttribute ("PropagationLossModel", "A pointer to the propagation loss model attached to this channel.",
00044 PointerValue (),
00045 MakePointerAccessor (&YansWifiChannel::m_loss),
00046 MakePointerChecker<PropagationLossModel> ())
00047 .AddAttribute ("PropagationDelayModel", "A pointer to the propagation delay model attached to this channel.",
00048 PointerValue (),
00049 MakePointerAccessor (&YansWifiChannel::m_delay),
00050 MakePointerChecker<PropagationDelayModel> ())
00051 ;
00052 return tid;
00053 }
00054
00055 YansWifiChannel::YansWifiChannel ()
00056 {}
00057 YansWifiChannel::~YansWifiChannel ()
00058 {
00059 m_phyList.clear ();
00060 }
00061
00062 void
00063 YansWifiChannel::SetPropagationLossModel (Ptr<PropagationLossModel> loss)
00064 {
00065 m_loss = loss;
00066 }
00067 void
00068 YansWifiChannel::SetPropagationDelayModel (Ptr<PropagationDelayModel> delay)
00069 {
00070 m_delay = delay;
00071 }
00072
00073 void
00074 YansWifiChannel::Send (Ptr<YansWifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm,
00075 WifiMode wifiMode, WifiPreamble preamble) const
00076 {
00077 Ptr<MobilityModel> senderMobility = sender->GetMobility ()->GetObject<MobilityModel> ();
00078 NS_ASSERT (senderMobility != 0);
00079 uint32_t j = 0;
00080 for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++)
00081 {
00082 if (sender != (*i))
00083 {
00084 Ptr<MobilityModel> receiverMobility = (*i)->GetMobility ()->GetObject<MobilityModel> ();
00085 Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
00086 double rxPowerDbm = m_loss->CalcRxPower (txPowerDbm, senderMobility, receiverMobility);
00087 NS_LOG_DEBUG ("propagation: txPower="<<txPowerDbm<<"dbm, rxPower="<<rxPowerDbm<<"dbm, "<<
00088 "distance="<<senderMobility->GetDistanceFrom (receiverMobility)<<"m, delay="<<delay);
00089 Ptr<Packet> copy = packet->Copy ();
00090 Simulator::Schedule (delay, &YansWifiChannel::Receive, this,
00091 j, copy, rxPowerDbm, wifiMode, preamble);
00092 }
00093 j++;
00094 }
00095 }
00096
00097 void
00098 YansWifiChannel::Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm,
00099 WifiMode txMode, WifiPreamble preamble) const
00100 {
00101 m_phyList[i]->StartReceivePacket (packet, rxPowerDbm, txMode, preamble);
00102 }
00103
00104 uint32_t
00105 YansWifiChannel::GetNDevices (void) const
00106 {
00107 return m_phyList.size ();
00108 }
00109 Ptr<NetDevice>
00110 YansWifiChannel::GetDevice (uint32_t i) const
00111 {
00112 return m_phyList[i]->GetDevice ()->GetObject<NetDevice> ();
00113 }
00114
00115 void
00116 YansWifiChannel::Add (Ptr<YansWifiPhy> phy)
00117 {
00118 m_phyList.push_back (phy);
00119 }
00120
00121 }