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