OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 University of Washington |
| 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 * Modified by Hemanth Narra <hemanthnarra222@gmail.com> to suit the |
| 19 * TDMA implementation. |
| 20 */ |
| 21 #include "simple-wireless-channel.h" |
| 22 #include "ns3/simulator.h" |
| 23 #include "ns3/packet.h" |
| 24 #include "ns3/node.h" |
| 25 #include "ns3/log.h" |
| 26 #include "ns3/double.h" |
| 27 #include "ns3/uinteger.h" |
| 28 #include "ns3/ptr.h" |
| 29 #include "ns3/net-device.h" |
| 30 #include "ns3/mobility-model.h" |
| 31 |
| 32 NS_LOG_COMPONENT_DEFINE ("SimpleWirelessChannel"); |
| 33 |
| 34 namespace ns3 { |
| 35 |
| 36 NS_OBJECT_ENSURE_REGISTERED (SimpleWirelessChannel); |
| 37 |
| 38 TypeId |
| 39 SimpleWirelessChannel::GetTypeId (void) |
| 40 { |
| 41 static TypeId tid = TypeId ("ns3::SimpleWirelessChannel") |
| 42 .SetParent<Channel> () |
| 43 .AddConstructor<SimpleWirelessChannel> () |
| 44 .AddAttribute ("MaxRange", |
| 45 "Maximum Transmission Range (meters)", |
| 46 DoubleValue (250), |
| 47 MakeDoubleAccessor (&SimpleWirelessChannel::m_range), |
| 48 MakeDoubleChecker<double> ()) |
| 49 ; |
| 50 return tid; |
| 51 } |
| 52 |
| 53 SimpleWirelessChannel::SimpleWirelessChannel () |
| 54 { |
| 55 } |
| 56 |
| 57 void |
| 58 SimpleWirelessChannel::Send (Ptr<const Packet> p, Ptr<TdmaMacLow> sender) |
| 59 { |
| 60 NS_LOG_FUNCTION (p << sender); |
| 61 for (TdmaMacLowList::const_iterator i = m_tdmaMacLowList.begin (); i != m_tdma
MacLowList.end (); ++i) |
| 62 { |
| 63 Ptr<TdmaMacLow> tmp = *i; |
| 64 if (tmp->GetDevice () == sender->GetDevice ()) |
| 65 { |
| 66 continue; |
| 67 } |
| 68 Ptr<MobilityModel> a = sender->GetDevice ()->GetNode ()->GetObject<Mobilit
yModel> (); |
| 69 Ptr<MobilityModel> b = tmp->GetDevice ()->GetNode ()->GetObject<MobilityMo
del> (); |
| 70 NS_ASSERT_MSG (a && b, "Error: nodes must have mobility models"); |
| 71 double distance = a->GetDistanceFrom (b); |
| 72 NS_LOG_DEBUG ("Distance: " << distance << " Max Range: " << m_range); |
| 73 if (distance > m_range) |
| 74 { |
| 75 continue; |
| 76 } |
| 77 // speed of light is 3.3 ns/meter |
| 78 Time propagationTime = NanoSeconds (uint64_t (3.3 * distance)); |
| 79 NS_LOG_DEBUG ("Node " << sender->GetDevice ()->GetNode ()->GetId () << " s
ending to node " << |
| 80 tmp->GetDevice ()->GetNode ()->GetId () << " at distance " <
< distance << |
| 81 " meters; arriving time (ns): " << propagationTime); |
| 82 Simulator::ScheduleWithContext (tmp->GetDevice ()->GetNode ()->GetId (),(p
ropagationTime), |
| 83 &TdmaMacLow::Receive, tmp, p->Copy ()); |
| 84 } |
| 85 } |
| 86 |
| 87 void |
| 88 SimpleWirelessChannel::Add (Ptr<TdmaMacLow> tdmaMacLow) |
| 89 { |
| 90 NS_LOG_DEBUG (this << " " << tdmaMacLow); |
| 91 m_tdmaMacLowList.push_back (tdmaMacLow); |
| 92 NS_LOG_DEBUG ("current m_tdmaMacLowList size: " << m_tdmaMacLowList.size ()); |
| 93 } |
| 94 |
| 95 uint32_t |
| 96 SimpleWirelessChannel::GetNDevices (void) const |
| 97 { |
| 98 return m_tdmaMacLowList.size (); |
| 99 } |
| 100 Ptr<NetDevice> |
| 101 SimpleWirelessChannel::GetDevice (uint32_t i) const |
| 102 { |
| 103 return m_tdmaMacLowList[i]->GetDevice (); |
| 104 } |
| 105 |
| 106 double |
| 107 SimpleWirelessChannel::GetMaxRange (void) const |
| 108 { |
| 109 return m_range; |
| 110 } |
| 111 |
| 112 } // namespace ns3 |
OLD | NEW |