Ilya Moiseenko | 098dd76 | 2012-01-11 19:57:48 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #include "ccnx-hijacker.h" |
| 23 | #include "ns3/log.h" |
| 24 | #include "ns3/ccnx-interest-header.h" |
| 25 | #include "ns3/ccnx-content-object-header.h" |
| 26 | #include "ns3/string.h" |
| 27 | #include "ns3/uinteger.h" |
| 28 | #include "ns3/packet.h" |
| 29 | |
| 30 | #include "../model/ccnx-local-face.h" |
| 31 | #include "ns3/ccnx-fib.h" |
| 32 | |
| 33 | #include <boost/ref.hpp> |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame^] | 34 | #include <boost/lambda/lambda.hpp> |
| 35 | #include <boost/lambda/bind.hpp> |
| 36 | namespace ll = boost::lambda; |
Ilya Moiseenko | 098dd76 | 2012-01-11 19:57:48 -0800 | [diff] [blame] | 37 | |
| 38 | NS_LOG_COMPONENT_DEFINE ("CcnxHijacker"); |
| 39 | |
| 40 | namespace ns3 |
| 41 | { |
| 42 | |
| 43 | NS_OBJECT_ENSURE_REGISTERED (CcnxHijacker); |
| 44 | |
| 45 | TypeId |
| 46 | CcnxHijacker::GetTypeId (void) |
| 47 | { |
| 48 | static TypeId tid = TypeId ("ns3::CcnxHijacker") |
| 49 | .SetParent<CcnxApp> () |
| 50 | .AddConstructor<CcnxHijacker> () |
| 51 | .AddAttribute ("Prefix","Prefix, which hijacker wants to attack", |
| 52 | StringValue ("/"), |
| 53 | MakeCcnxNameComponentsAccessor (&CcnxHijacker::m_prefix), |
| 54 | MakeCcnxNameComponentsChecker ()) |
| 55 | .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", |
| 56 | UintegerValue (1024), |
| 57 | MakeUintegerAccessor(&CcnxHijacker::m_virtualPayloadSize), |
| 58 | MakeUintegerChecker<uint32_t>()) |
| 59 | |
| 60 | .AddTraceSource ("TransmittedContentObjects", "TransmittedContentObjects", |
| 61 | MakeTraceSourceAccessor (&CcnxHijacker::m_transmittedContentObjects)) |
| 62 | ; |
| 63 | |
| 64 | return tid; |
| 65 | } |
| 66 | |
| 67 | CcnxHijacker::CcnxHijacker () |
| 68 | { |
| 69 | // NS_LOG_FUNCTION_NOARGS (); |
| 70 | } |
| 71 | |
| 72 | // inherited from Application base class. |
| 73 | void |
| 74 | CcnxHijacker::StartApplication () |
| 75 | { |
| 76 | NS_LOG_FUNCTION_NOARGS (); |
| 77 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 78 | |
| 79 | CcnxApp::StartApplication (); |
| 80 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame^] | 81 | Ptr<CcnxFib> fib = GetNode ()->GetObject<CcnxFib> (); |
| 82 | CcnxFibEntryContainer::type::iterator fibEntry = fib->Add (m_prefix, m_face, 0); |
| 83 | |
| 84 | // make face green, so it will be used primarily |
| 85 | fib->m_fib.modify (fibEntry, |
| 86 | ll::bind (&CcnxFibEntry::UpdateStatus, |
| 87 | ll::_1, m_face, CcnxFibFaceMetric::NDN_FIB_GREEN)); |
Ilya Moiseenko | 098dd76 | 2012-01-11 19:57:48 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void |
| 91 | CcnxHijacker::StopApplication () |
| 92 | { |
| 93 | NS_LOG_FUNCTION_NOARGS (); |
| 94 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 95 | |
| 96 | CcnxApp::StopApplication (); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void |
| 101 | CcnxHijacker::OnInterest (const Ptr<const CcnxInterestHeader> &interest) |
| 102 | { |
| 103 | CcnxApp::OnInterest (interest); // tracing inside |
| 104 | |
| 105 | NS_LOG_FUNCTION (this << interest); |
| 106 | |
| 107 | /* |
| 108 | if (!m_active) return; |
| 109 | |
| 110 | static CcnxContentObjectTail tail; |
| 111 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 112 | header->SetName (Create<CcnxNameComponents> (interest->GetName ())); |
| 113 | |
| 114 | NS_LOG_INFO ("Respodning with ContentObject:\n" << boost::cref(*header)); |
| 115 | |
| 116 | Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize); |
| 117 | |
| 118 | m_transmittedContentObjects (header, packet, this, m_face); |
| 119 | |
| 120 | packet->AddHeader (*header); |
| 121 | packet->AddTrailer (tail); |
| 122 | |
| 123 | m_protocolHandler (packet);*/ |
| 124 | } |
| 125 | |
| 126 | } // namespace ns3 |