blob: 70e2d9e12911cb4d33caf077de68e3f8483db04c [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"
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080024
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080025NS_LOG_COMPONENT_DEFINE("Hijacker");
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080026
27namespace ns3 {
28
29// Necessary if you are planning to use ndn::AppHelper
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080030NS_OBJECT_ENSURE_REGISTERED(Hijacker);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080031
32TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033Hijacker::GetTypeId()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080034{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035 static TypeId tid = TypeId("Hijacker").SetParent<ndn::App>().AddConstructor<Hijacker>();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080036
37 return tid;
38}
39
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040Hijacker::Hijacker()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080041{
42}
43
44void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045Hijacker::OnInterest(Ptr<const ndn::Interest> interest)
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080046{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 ndn::App::OnInterest(interest); // forward call to perform app-level tracing
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080048 // do nothing else (hijack interest)
49
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 NS_LOG_DEBUG("Do nothing for incoming interest for" << interest->GetName());
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080051}
52
53void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054Hijacker::StartApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080055{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 App::StartApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080057
58 // equivalent to setting interest filter for "/" prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 Ptr<ndn::Fib> fib = GetNode()->GetObject<ndn::Fib>();
60 Ptr<ndn::fib::Entry> fibEntry = fib->Add(ndn::Name("/"), m_face, 0);
61 fibEntry->UpdateStatus(m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080062}
63
64void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065Hijacker::StopApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080066{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 App::StopApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080068}
69
70} // namespace ns3