Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011-2012 University of California, Los Angeles |
| 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | // hijacker.cc |
| 22 | |
| 23 | #include "hijacker.h" |
| 24 | |
| 25 | NS_LOG_COMPONENT_DEFINE ("Hijacker"); |
| 26 | |
| 27 | namespace ns3 { |
| 28 | |
| 29 | // Necessary if you are planning to use ndn::AppHelper |
| 30 | NS_OBJECT_ENSURE_REGISTERED (Hijacker); |
| 31 | |
| 32 | TypeId |
| 33 | Hijacker::GetTypeId () |
| 34 | { |
| 35 | static TypeId tid = TypeId ("Hijacker") |
| 36 | .SetParent<ndn::App> () |
| 37 | .AddConstructor<Hijacker> () |
| 38 | ; |
| 39 | |
| 40 | return tid; |
| 41 | } |
| 42 | |
| 43 | Hijacker::Hijacker () |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 48 | Hijacker::OnInterest (const Ptr<const ndn::Interest> &interest, Ptr<Packet> packet) |
Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 49 | { |
| 50 | ndn::App::OnInterest (interest, packet); // forward call to perform app-level tracing |
| 51 | // do nothing else (hijack interest) |
| 52 | |
| 53 | NS_LOG_DEBUG ("Do nothing for incoming interest for" << interest->GetName ()); |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | Hijacker::StartApplication () |
| 58 | { |
| 59 | App::StartApplication (); |
| 60 | |
| 61 | // equivalent to setting interest filter for "/" prefix |
| 62 | Ptr<ndn::Fib> fib = GetNode ()->GetObject<ndn::Fib> (); |
| 63 | Ptr<ndn::fib::Entry> fibEntry = fib->Add ("/", m_face, 0); |
| 64 | fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | Hijacker::StopApplication () |
| 69 | { |
| 70 | App::StopApplication (); |
| 71 | } |
| 72 | |
| 73 | } // namespace ns3 |
| 74 | |