blob: eedd08ff128252954204e0816032837ce5102e38 [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 */
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080020// hijacker.cc
21
Alexander Afanasyev0c395372014-12-20 15:54:02 -080022#include "hijacker.hpp"
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080023
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080024#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
25
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080026NS_LOG_COMPONENT_DEFINE("Hijacker");
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080027
28namespace ns3 {
29
30// Necessary if you are planning to use ndn::AppHelper
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080031NS_OBJECT_ENSURE_REGISTERED(Hijacker);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080032
33TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034Hijacker::GetTypeId()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080035{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036 static TypeId tid = TypeId("Hijacker").SetParent<ndn::App>().AddConstructor<Hijacker>();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080037
38 return tid;
39}
40
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041Hijacker::Hijacker()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080042{
43}
44
45void
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080046Hijacker::OnInterest(shared_ptr<const ndn::Interest> interest)
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080047{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048 ndn::App::OnInterest(interest); // forward call to perform app-level tracing
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080049 // do nothing else (hijack interest)
50
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080051 NS_LOG_DEBUG("Do nothing for incoming interest for" << interest->getName());
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080052}
53
54void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055Hijacker::StartApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080056{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 App::StartApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080058
59 // equivalent to setting interest filter for "/" prefix
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080060 ndn::FibHelper::AddRoute(GetNode(), "/", m_face, 0);
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080061}
62
63void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064Hijacker::StopApplication()
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080065{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 App::StopApplication();
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -080067}
68
69} // namespace ns3