|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2006,2007 INRIA |
|
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: Mathieu Lacage, <mathieu.lacage@sophia.inria.fr> |
|
19 */ |
|
20 #include "ns3/packet.h" |
|
21 #include "ns3/simulator.h" |
|
22 #include "ns3/mobility-model.h" |
|
23 #include "ns3/net-device.h" |
|
24 #include "ns3/node.h" |
|
25 #include "wifi-channel.h" |
|
26 #include "propagation-loss-model.h" |
|
27 #include "propagation-delay-model.h" |
|
28 |
|
29 |
|
30 namespace ns3 { |
|
31 |
|
32 WifiChannel::WifiChannel () |
|
33 {} |
|
34 WifiChannel::~WifiChannel () |
|
35 {} |
|
36 |
|
37 void |
|
38 WifiChannel::Add (Ptr<NetDevice> device, ReceiveCallback callback) |
|
39 { |
|
40 m_deviceList.push_back (std::make_pair (device, callback)); |
|
41 } |
|
42 void |
|
43 WifiChannel::Send (Ptr<NetDevice> sender, const Packet &packet, double txPowerDbm, |
|
44 uint64_t wifiMode) const |
|
45 { |
|
46 Ptr<MobilityModel> senderMobility = sender->GetNode ()->QueryInterface<MobilityModel> (MobilityModel::iid); |
|
47 uint32_t j = 0; |
|
48 for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++) |
|
49 { |
|
50 if (sender != i->first) |
|
51 { |
|
52 Ptr<MobilityModel> receiverMobility = i->first->GetNode ()->QueryInterface<MobilityModel> (MobilityModel::iid); |
|
53 double distance = senderMobility->GetDistanceFrom (receiverMobility); |
|
54 Time delay = m_delay->GetDelay (distance); |
|
55 double rxPowerDbm = m_loss->GetRxPower (txPowerDbm, distance); |
|
56 Simulator::Schedule (delay, &WifiChannel::Receive, this, |
|
57 j, packet, rxPowerDbm, wifiMode); |
|
58 } |
|
59 j++; |
|
60 } |
|
61 } |
|
62 |
|
63 void |
|
64 WifiChannel::Receive (uint32_t i, |
|
65 const Packet &packet, double rxPowerDbm, |
|
66 uint64_t wifiMode) const |
|
67 { |
|
68 m_deviceList[i].second (packet, rxPowerDbm, wifiMode); |
|
69 } |
|
70 |
|
71 uint32_t |
|
72 WifiChannel::GetNDevices (void) const |
|
73 { |
|
74 return m_deviceList.size (); |
|
75 } |
|
76 Ptr<NetDevice> |
|
77 WifiChannel::GetDevice (uint32_t i) const |
|
78 { |
|
79 return m_deviceList[i].first; |
|
80 } |
|
81 |
|
82 } // namespace ns3 |