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" |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame^] | 24 | #include "ns3/ndn-name.h" |
Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 25 | |
| 26 | NS_LOG_COMPONENT_DEFINE ("Hijacker"); |
| 27 | |
| 28 | namespace ns3 { |
| 29 | |
| 30 | // Necessary if you are planning to use ndn::AppHelper |
| 31 | NS_OBJECT_ENSURE_REGISTERED (Hijacker); |
| 32 | |
| 33 | TypeId |
| 34 | Hijacker::GetTypeId () |
| 35 | { |
| 36 | static TypeId tid = TypeId ("Hijacker") |
| 37 | .SetParent<ndn::App> () |
| 38 | .AddConstructor<Hijacker> () |
| 39 | ; |
| 40 | |
| 41 | return tid; |
| 42 | } |
| 43 | |
| 44 | Hijacker::Hijacker () |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | void |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 49 | Hijacker::OnInterest (Ptr<const ndn::Interest> interest) |
Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 50 | { |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 51 | ndn::App::OnInterest (interest); // forward call to perform app-level tracing |
Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 52 | // do nothing else (hijack interest) |
| 53 | |
| 54 | NS_LOG_DEBUG ("Do nothing for incoming interest for" << interest->GetName ()); |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | Hijacker::StartApplication () |
| 59 | { |
| 60 | App::StartApplication (); |
| 61 | |
| 62 | // equivalent to setting interest filter for "/" prefix |
| 63 | Ptr<ndn::Fib> fib = GetNode ()->GetObject<ndn::Fib> (); |
Alexander Afanasyev | 9213601 | 2013-07-16 20:36:30 -0700 | [diff] [blame^] | 64 | Ptr<ndn::fib::Entry> fibEntry = fib->Add (ndn::Name ("/"), m_face, 0); |
Alexander Afanasyev | c3cc0b3 | 2012-12-12 18:41:20 -0800 | [diff] [blame] | 65 | fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | Hijacker::StopApplication () |
| 70 | { |
| 71 | App::StopApplication (); |
| 72 | } |
| 73 | |
| 74 | } // namespace ns3 |
| 75 | |