blob: 2a13885f6b90ec8c983051e453e979bbba48adc7 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20// hijacker.cpp
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080021
Alexander Afanasyev0c395372014-12-20 15:54:02 -080022#include "hijacker.hpp"
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080023
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080024#include "ns3/log.h"
25
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080026#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
27
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080028NS_LOG_COMPONENT_DEFINE("Hijacker");
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080029
30namespace ns3 {
31
32// Necessary if you are planning to use ndn::AppHelper
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033NS_OBJECT_ENSURE_REGISTERED(Hijacker);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080034
35TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036Hijacker::GetTypeId()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080037{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 static TypeId tid = TypeId("Hijacker").SetParent<ndn::App>().AddConstructor<Hijacker>();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080039
40 return tid;
41}
42
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043Hijacker::Hijacker()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080044{
45}
46
47void
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080048Hijacker::OnInterest(std::shared_ptr<const ndn::Interest> interest)
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080049{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 ndn::App::OnInterest(interest); // forward call to perform app-level tracing
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080051 // do nothing else (hijack interest)
52
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080053 NS_LOG_DEBUG("Do nothing for incoming interest for" << interest->getName());
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080054}
55
56void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057Hijacker::StartApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080058{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 App::StartApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080060
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080061 // equivalent to setting interest filter for "/prefix" prefix
62 ndn::FibHelper::AddRoute(GetNode(), "/prefix/sub", m_face, 0);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080063}
64
65void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066Hijacker::StopApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080067{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 App::StopApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080069}
70
71} // namespace ns3