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 | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 23 | #include "ns3/ccnx-interest-header.h" |
| 24 | #include "ns3/string.h" |
| 25 | #include "ns3/integer.h" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 27 | #include "ns3/ccnx-local-face.h" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 28 | |
| 29 | NS_LOG_COMPONENT_DEFINE ("CcnxProducer"); |
| 30 | |
| 31 | namespace ns3 |
| 32 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 33 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 34 | NS_OBJECT_ENSURE_REGISTERED (CcnxProducer); |
| 35 | |
| 36 | TypeId |
| 37 | CcnxProducer::GetTypeId (void) |
| 38 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 39 | static TypeId tid = TypeId ("ns3::CcnxProducer") |
| 40 | .SetParent<CcnxApp> () |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 41 | .AddConstructor<CcnxProducer> () |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 42 | .AddAttribute ("Prefix","Prefix, for which producer has the data", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 43 | StringValue ("/"), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 44 | MakeCcnxNameComponentsAccessor (&CcnxProducer::m_prefix), |
| 45 | MakeCcnxNameComponentsChecker ()) |
| 46 | .AddAttribute ("PayloadSize", "Virtual payload size for Content packets", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 47 | UintegerValue (100), |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 48 | MakeUintegerAccessor(&CcnxProducer::m_virtualPayloadSize), |
| 49 | MakeUintegerChecker<uint32_t>()) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 50 | // .AddTraceSource ("InterestTrace", "Interests that were received", |
| 51 | // MakeTraceSourceAccessor (&CcnxProducer::m_interestsTrace)) |
| 52 | // .AddTraceSource ("ContentObjectTrace", "ContentObjects that were sent", |
| 53 | // MakeTraceSourceAccessor (&CcnxProducer::m_contentObjectsTrace)) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 54 | ; |
| 55 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 56 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | CcnxProducer::CcnxProducer () |
| 60 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 61 | // NS_LOG_FUNCTION_NOARGS (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 62 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 63 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 64 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 65 | CcnxProducer::OnInterest (const Ptr<const CcnxInterestHeader> &interest) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 66 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 67 | NS_LOG_FUNCTION (this << interest); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 69 | if (!m_active) return; |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 71 | static CcnxContentObjectTail tail; |
| 72 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 73 | header->SetName (Create<CcnxNameComponents> (interest->GetName ())); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 75 | Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize); |
| 76 | outgoingPacket->AddHeader (*header); |
| 77 | outgoingPacket->AddTrailer (tail); |
| 78 | |
| 79 | m_protocolHandler (outgoingPacket); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 80 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame^] | 81 | |
| 82 | } // namespace ns3 |