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 "jamming-mitigation.h" |
| 22 #include "ns3/simulator.h" |
| 23 #include "ns3/assert.h" |
| 24 #include "ns3/log.h" |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("JammingMitigation"); |
| 27 |
| 28 namespace ns3 { |
| 29 |
| 30 NS_OBJECT_ENSURE_REGISTERED (JammingMitigation); |
| 31 |
| 32 TypeId |
| 33 JammingMitigation::GetTypeId (void) |
| 34 { |
| 35 static TypeId tid = TypeId ("ns3::JammingMitigation") |
| 36 .SetParent<Object> () |
| 37 ; |
| 38 return tid; |
| 39 } |
| 40 |
| 41 JammingMitigation::JammingMitigation () |
| 42 : m_mitigationOn (false) // turn off mitigation by default |
| 43 { |
| 44 } |
| 45 |
| 46 JammingMitigation::~JammingMitigation () |
| 47 { |
| 48 } |
| 49 |
| 50 void |
| 51 JammingMitigation::SetId (uint32_t id) |
| 52 { |
| 53 NS_LOG_FUNCTION (this << id); |
| 54 m_id = id; |
| 55 } |
| 56 |
| 57 uint32_t |
| 58 JammingMitigation::GetId (void) const |
| 59 { |
| 60 NS_LOG_FUNCTION (this); |
| 61 return m_id; |
| 62 } |
| 63 |
| 64 void |
| 65 JammingMitigation::StartMitigation (void) |
| 66 { |
| 67 NS_LOG_FUNCTION (this); |
| 68 NS_LOG_DEBUG ("At Node #" << m_id << ", Mitigation of jamming started at " << |
| 69 Simulator::Now ().GetSeconds() << "s"); |
| 70 m_mitigationOn = true; // set flag |
| 71 DoMitigation (); |
| 72 } |
| 73 |
| 74 void |
| 75 JammingMitigation::StopMitigation (void) |
| 76 { |
| 77 NS_LOG_FUNCTION (this); |
| 78 NS_LOG_DEBUG ("At Node #" << m_id << ", Mitigation of jamming stopped at " << |
| 79 Simulator::Now ().GetSeconds() << "s"); |
| 80 m_mitigationOn = false; // set flag |
| 81 DoStopMitigation (); |
| 82 } |
| 83 |
| 84 bool |
| 85 JammingMitigation::StartRxHandler (Ptr<Packet> packet, double startRss) |
| 86 { |
| 87 NS_LOG_FUNCTION (this << packet << startRss); |
| 88 if (m_mitigationOn) |
| 89 { |
| 90 DoStartRxHandler (packet, startRss); |
| 91 } |
| 92 else |
| 93 { |
| 94 NS_LOG_DEBUG ("At Node #" << m_id << ", Mitigation of jamming is OFF!"); |
| 95 } |
| 96 return true; |
| 97 } |
| 98 |
| 99 bool |
| 100 JammingMitigation::EndRxHandler (Ptr<Packet> packet, double averageRss) |
| 101 { |
| 102 NS_LOG_FUNCTION (this << packet << averageRss); |
| 103 if (m_mitigationOn) |
| 104 { |
| 105 DoEndRxHandler (packet, averageRss); |
| 106 } |
| 107 else |
| 108 { |
| 109 NS_LOG_DEBUG ("At Node #" << m_id << ", Mitigation of jamming is OFF!"); |
| 110 } |
| 111 return true; |
| 112 } |
| 113 |
| 114 void |
| 115 JammingMitigation::EndTxHandler (Ptr<Packet> packet, double txPower) |
| 116 { |
| 117 NS_LOG_FUNCTION (this << packet << txPower); |
| 118 if (m_mitigationOn) |
| 119 { |
| 120 DoEndTxHandler (packet, txPower); |
| 121 } |
| 122 else |
| 123 { |
| 124 NS_LOG_DEBUG ("At Node #" << m_id << |
| 125 ", Mitigation of jamming is OFF, ignoring end TX event!"); |
| 126 } |
| 127 } |
| 128 |
| 129 /* |
| 130 * Protected functions start here. |
| 131 */ |
| 132 |
| 133 bool |
| 134 JammingMitigation::IsMitigationOn (void) const |
| 135 { |
| 136 NS_LOG_FUNCTION (this); |
| 137 return m_mitigationOn; |
| 138 } |
| 139 |
| 140 } // namespace ns3 |
LEFT | RIGHT |