Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [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> |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "ccnx-producer.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 23 | #include "ns3/log.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 24 | #include "ns3/ccnx-interest-header.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 25 | #include "ns3/ccnx-content-object-header.h" |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 26 | #include "ns3/string.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 27 | #include "ns3/uinteger.h" |
| 28 | #include "ns3/packet.h" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 30 | #include "ns3/ccnx-local-face.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 31 | #include "ns3/ccnx-fib.h" |
| 32 | |
| 33 | #include <boost/ref.hpp> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 34 | |
| 35 | NS_LOG_COMPONENT_DEFINE ("CcnxProducer"); |
| 36 | |
| 37 | namespace ns3 |
| 38 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 39 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 40 | NS_OBJECT_ENSURE_REGISTERED (CcnxProducer); |
| 41 | |
| 42 | TypeId |
| 43 | CcnxProducer::GetTypeId (void) |
| 44 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 45 | static TypeId tid = TypeId ("ns3::CcnxProducer") |
| 46 | .SetParent<CcnxApp> () |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 47 | .AddConstructor<CcnxProducer> () |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 48 | .AddAttribute ("Prefix","Prefix, for which producer has the data", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 49 | StringValue ("/"), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 50 | MakeCcnxNameComponentsAccessor (&CcnxProducer::m_prefix), |
| 51 | MakeCcnxNameComponentsChecker ()) |
| 52 | .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 53 | UintegerValue (1024), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 54 | MakeUintegerAccessor(&CcnxProducer::m_virtualPayloadSize), |
| 55 | MakeUintegerChecker<uint32_t>()) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 56 | // .AddTraceSource ("InterestTrace", "Interests that were received", |
| 57 | // MakeTraceSourceAccessor (&CcnxProducer::m_interestsTrace)) |
| 58 | // .AddTraceSource ("ContentObjectTrace", "ContentObjects that were sent", |
| 59 | // MakeTraceSourceAccessor (&CcnxProducer::m_contentObjectsTrace)) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 60 | ; |
| 61 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 62 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | CcnxProducer::CcnxProducer () |
| 66 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 67 | // NS_LOG_FUNCTION_NOARGS (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 68 | } |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 69 | |
| 70 | // inherited from Application base class. |
| 71 | void |
| 72 | CcnxProducer::StartApplication () |
| 73 | { |
| 74 | NS_LOG_FUNCTION_NOARGS (); |
| 75 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 76 | |
| 77 | CcnxApp::StartApplication (); |
| 78 | |
| 79 | GetNode ()->GetObject<CcnxFib> ()->Add (m_prefix, m_face, 0); |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | CcnxProducer::StopApplication () |
| 84 | { |
| 85 | NS_LOG_FUNCTION_NOARGS (); |
| 86 | NS_ASSERT (GetNode ()->GetObject<CcnxFib> () != 0); |
| 87 | |
| 88 | CcnxApp::StopApplication (); |
| 89 | } |
| 90 | |
| 91 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 92 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 93 | CcnxProducer::OnInterest (const Ptr<const CcnxInterestHeader> &interest) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 94 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 95 | NS_LOG_FUNCTION (this << interest); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 97 | if (!m_active) return; |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 99 | static CcnxContentObjectTail tail; |
| 100 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 101 | header->SetName (Create<CcnxNameComponents> (interest->GetName ())); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 102 | |
| 103 | NS_LOG_INFO ("Respodning with ContentObject:\n" << boost::cref(*header)); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 105 | Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 106 | packet->AddHeader (*header); |
| 107 | packet->AddTrailer (tail); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 109 | m_protocolHandler (packet); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 110 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 111 | |
| 112 | } // namespace ns3 |