blob: f1852d45437df0f2a15061a9ed9c4c08023ccac9 [file] [log] [blame]
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -08001/* -*- 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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080023#include "hijacker.hpp"
24#include "ns3/ndn-name.hpp"
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080025
26NS_LOG_COMPONENT_DEFINE ("Hijacker");
27
28namespace ns3 {
29
30// Necessary if you are planning to use ndn::AppHelper
31NS_OBJECT_ENSURE_REGISTERED (Hijacker);
32
33TypeId
34Hijacker::GetTypeId ()
35{
36 static TypeId tid = TypeId ("Hijacker")
37 .SetParent<ndn::App> ()
38 .AddConstructor<Hijacker> ()
39 ;
40
41 return tid;
42}
43
44Hijacker::Hijacker ()
45{
46}
47
48void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070049Hijacker::OnInterest (Ptr<const ndn::Interest> interest)
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080050{
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070051 ndn::App::OnInterest (interest); // forward call to perform app-level tracing
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080052 // do nothing else (hijack interest)
53
54 NS_LOG_DEBUG ("Do nothing for incoming interest for" << interest->GetName ());
55}
56
57void
58Hijacker::StartApplication ()
59{
60 App::StartApplication ();
61
62 // equivalent to setting interest filter for "/" prefix
63 Ptr<ndn::Fib> fib = GetNode ()->GetObject<ndn::Fib> ();
Alexander Afanasyev92136012013-07-16 20:36:30 -070064 Ptr<ndn::fib::Entry> fibEntry = fib->Add (ndn::Name ("/"), m_face, 0);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080065 fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
66}
67
68void
69Hijacker::StopApplication ()
70{
71 App::StopApplication ();
72}
73
74} // namespace ns3
75