LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
| 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: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 19 */ |
| 20 |
| 21 #include "jammer.h" |
| 22 #include "ns3/simulator.h" |
| 23 #include "ns3/log.h" |
| 24 |
| 25 NS_LOG_COMPONENT_DEFINE ("Jammer"); |
| 26 |
| 27 /* |
| 28 * Jammer base class. |
| 29 */ |
| 30 namespace ns3 { |
| 31 |
| 32 NS_OBJECT_ENSURE_REGISTERED (Jammer); |
| 33 |
| 34 TypeId |
| 35 Jammer::GetTypeId (void) |
| 36 { |
| 37 static TypeId tid = TypeId ("ns3::Jammer") |
| 38 .SetParent<Object> () |
| 39 ; |
| 40 return tid; |
| 41 } |
| 42 |
| 43 Jammer::Jammer (void) |
| 44 : m_jammerOn (false) // jammer off by default |
| 45 { |
| 46 } |
| 47 |
| 48 Jammer::~Jammer (void) |
| 49 { |
| 50 } |
| 51 |
| 52 void |
| 53 Jammer::SetId (uint32_t id) |
| 54 { |
| 55 NS_LOG_FUNCTION (this << id); |
| 56 m_id = id; |
| 57 } |
| 58 |
| 59 uint32_t |
| 60 Jammer::GetId (void) const |
| 61 { |
| 62 NS_LOG_FUNCTION (this); |
| 63 return m_id; |
| 64 } |
| 65 |
| 66 void |
| 67 Jammer::StartJammer (void) |
| 68 { |
| 69 NS_LOG_FUNCTION (this); |
| 70 m_jammerOn = true; // turn jammer on |
| 71 DoJamming (); // call jamming function |
| 72 } |
| 73 |
| 74 void |
| 75 Jammer::StopJammer (void) |
| 76 { |
| 77 NS_LOG_FUNCTION (this); |
| 78 m_jammerOn = false; // turn jammer off |
| 79 DoStopJammer (); // stop jammer |
| 80 } |
| 81 |
| 82 bool |
| 83 Jammer::StartRxHandler (Ptr<Packet> packet, double startRss) |
| 84 { |
| 85 NS_LOG_FUNCTION (this << packet << startRss); |
| 86 if (m_jammerOn) |
| 87 { |
| 88 return DoStartRxHandler (packet, startRss); |
| 89 } |
| 90 else |
| 91 { |
| 92 NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring StartRx!")
; |
| 93 return false; // when jammer is off, all incoming packets are ignored. |
| 94 } |
| 95 } |
| 96 |
| 97 bool |
| 98 Jammer::EndRxHandler (Ptr<Packet> packet, double averageRss) |
| 99 { |
| 100 NS_LOG_FUNCTION (this << packet << averageRss); |
| 101 if (m_jammerOn) |
| 102 { |
| 103 return DoEndRxHandler (packet, averageRss); |
| 104 } |
| 105 else |
| 106 { |
| 107 NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring EndRx!"); |
| 108 return false; |
| 109 } |
| 110 } |
| 111 |
| 112 void |
| 113 Jammer::EndTxHandler (Ptr<Packet> packet, double txPower) |
| 114 { |
| 115 NS_LOG_FUNCTION (this << packet << txPower); |
| 116 if (m_jammerOn) |
| 117 { |
| 118 DoEndTxHandler (packet, txPower); |
| 119 } |
| 120 else |
| 121 { |
| 122 NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring EndTx!"); |
| 123 } |
| 124 } |
| 125 |
| 126 /* |
| 127 * Protected functions start here. |
| 128 */ |
| 129 |
| 130 bool |
| 131 Jammer::IsJammerOn (void) const |
| 132 { |
| 133 return m_jammerOn; |
| 134 } |
| 135 |
| 136 } // namespace ns3 |
LEFT | RIGHT |