Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(719)

Unified Diff: src/jamming/model/jammer.cc

Issue 1055041: ns-3: Wireless Interference (Jamming) Framework
Patch Set: Add python bindings. Update to latest dev tree (3.11). Created 12 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/jamming/model/jammer.h ('k') | src/jamming/model/jamming-mitigation.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/jamming/model/jammer.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/jamming/model/jammer.cc
@@ -0,0 +1,136 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
+ */
+
+#include "jammer.h"
+#include "ns3/simulator.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("Jammer");
+
+/*
+ * Jammer base class.
+ */
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (Jammer);
+
+TypeId
+Jammer::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::Jammer")
+ .SetParent<Object> ()
+ ;
+ return tid;
+}
+
+Jammer::Jammer (void)
+ : m_jammerOn (false) // jammer off by default
+{
+}
+
+Jammer::~Jammer (void)
+{
+}
+
+void
+Jammer::SetId (uint32_t id)
+{
+ NS_LOG_FUNCTION (this << id);
+ m_id = id;
+}
+
+uint32_t
+Jammer::GetId (void) const
+{
+ NS_LOG_FUNCTION (this);
+ return m_id;
+}
+
+void
+Jammer::StartJammer (void)
+{
+ NS_LOG_FUNCTION (this);
+ m_jammerOn = true; // turn jammer on
+ DoJamming (); // call jamming function
+}
+
+void
+Jammer::StopJammer (void)
+{
+ NS_LOG_FUNCTION (this);
+ m_jammerOn = false; // turn jammer off
+ DoStopJammer (); // stop jammer
+}
+
+bool
+Jammer::StartRxHandler (Ptr<Packet> packet, double startRss)
+{
+ NS_LOG_FUNCTION (this << packet << startRss);
+ if (m_jammerOn)
+ {
+ return DoStartRxHandler (packet, startRss);
+ }
+ else
+ {
+ NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring StartRx!");
+ return false; // when jammer is off, all incoming packets are ignored.
+ }
+}
+
+bool
+Jammer::EndRxHandler (Ptr<Packet> packet, double averageRss)
+{
+ NS_LOG_FUNCTION (this << packet << averageRss);
+ if (m_jammerOn)
+ {
+ return DoEndRxHandler (packet, averageRss);
+ }
+ else
+ {
+ NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring EndRx!");
+ return false;
+ }
+}
+
+void
+Jammer::EndTxHandler (Ptr<Packet> packet, double txPower)
+{
+ NS_LOG_FUNCTION (this << packet << txPower);
+ if (m_jammerOn)
+ {
+ DoEndTxHandler (packet, txPower);
+ }
+ else
+ {
+ NS_LOG_DEBUG ("At Node #" << m_id << ", Jammer is OFF, ignoring EndTx!");
+ }
+}
+
+/*
+ * Protected functions start here.
+ */
+
+bool
+Jammer::IsJammerOn (void) const
+{
+ return m_jammerOn;
+}
+
+} // namespace ns3
« no previous file with comments | « src/jamming/model/jammer.h ('k') | src/jamming/model/jamming-mitigation.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b