blob: 252cf92002f3e76636413e6bd457a024e66c10c9 [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
23#include "hijacker.h"
24
25NS_LOG_COMPONENT_DEFINE ("Hijacker");
26
27namespace ns3 {
28
29// Necessary if you are planning to use ndn::AppHelper
30NS_OBJECT_ENSURE_REGISTERED (Hijacker);
31
32TypeId
33Hijacker::GetTypeId ()
34{
35 static TypeId tid = TypeId ("Hijacker")
36 .SetParent<ndn::App> ()
37 .AddConstructor<Hijacker> ()
38 ;
39
40 return tid;
41}
42
43Hijacker::Hijacker ()
44{
45}
46
47void
48Hijacker::OnInterest (const Ptr<const ndn::InterestHeader> &interest, Ptr<Packet> packet)
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
56void
57Hijacker::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
67void
68Hijacker::StopApplication ()
69{
70 App::StopApplication ();
71}
72
73} // namespace ns3
74