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> |
| 34 | |
| 35 | NS_LOG_COMPONENT_DEFINE ("CcnxHijacker"); |
| 36 | |
| 37 | namespace ns3 |
| 38 | { |
| 39 | |
| 40 | NS_OBJECT_ENSURE_REGISTERED (CcnxHijacker); |
| 41 | |
| 42 | TypeId |
| 43 | CcnxHijacker::GetTypeId (void) |
| 44 | { |
| 45 | static TypeId tid = TypeId ("ns3::CcnxHijacker") |
| 46 | .SetParent<CcnxApp> () |
| 47 | .AddConstructor<CcnxHijacker> () |
| 48 | .AddAttribute ("Prefix","Prefix, which hijacker wants to attack", |
| 49 | StringValue ("/"), |
| 50 | MakeCcnxNameComponentsAccessor (&CcnxHijacker::m_prefix), |
| 51 | MakeCcnxNameComponentsChecker ()) |
| 52 | .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", |
| 53 | UintegerValue (1024), |
| 54 | MakeUintegerAccessor(&CcnxHijacker::m_virtualPayloadSize), |
| 55 | MakeUintegerChecker<uint32_t>()) |
| 56 | |
| 57 | .AddTraceSource ("TransmittedContentObjects", "TransmittedContentObjects", |
| 58 | MakeTraceSourceAccessor (&CcnxHijacker::m_transmittedContentObjects)) |
| 59 | ; |
| 60 | |
| 61 | return tid; |
| 62 | } |
| 63 | |
| 64 | CcnxHijacker::CcnxHijacker () |
| 65 | { |
| 66 | // NS_LOG_FUNCTION_NOARGS (); |
| 67 | } |
| 68 | |
| 69 | // inherited from Application base class. |
| 70 | void |
| 71 | CcnxHijacker::StartApplication () |
| 72 | { |
| 73 | NS_LOG_FUNCTION_NOARGS (); |
| 74 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 75 | |
| 76 | CcnxApp::StartApplication (); |
| 77 | |
| 78 | GetNode ()->GetObject<CcnxFib> ()->Add (m_prefix, m_face, 0); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | CcnxHijacker::StopApplication () |
| 83 | { |
| 84 | NS_LOG_FUNCTION_NOARGS (); |
| 85 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 86 | |
| 87 | CcnxApp::StopApplication (); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | void |
| 92 | CcnxHijacker::OnInterest (const Ptr<const CcnxInterestHeader> &interest) |
| 93 | { |
| 94 | CcnxApp::OnInterest (interest); // tracing inside |
| 95 | |
| 96 | NS_LOG_FUNCTION (this << interest); |
| 97 | |
| 98 | /* |
| 99 | if (!m_active) return; |
| 100 | |
| 101 | static CcnxContentObjectTail tail; |
| 102 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 103 | header->SetName (Create<CcnxNameComponents> (interest->GetName ())); |
| 104 | |
| 105 | NS_LOG_INFO ("Respodning with ContentObject:\n" << boost::cref(*header)); |
| 106 | |
| 107 | Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize); |
| 108 | |
| 109 | m_transmittedContentObjects (header, packet, this, m_face); |
| 110 | |
| 111 | packet->AddHeader (*header); |
| 112 | packet->AddTrailer (tail); |
| 113 | |
| 114 | m_protocolHandler (packet);*/ |
| 115 | } |
| 116 | |
| 117 | } // namespace ns3 |