blob: 1cec691f86bad37fe69320f83955b7d9a248e85f [file] [log] [blame]
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -07001/* -*- 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 Afanasyev09c7deb2011-11-23 14:50:10 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070020 */
21
22#include "ccnx-producer.h"
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080023#include "ns3/ccnx-interest-header.h"
24#include "ns3/string.h"
25#include "ns3/integer.h"
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070026
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080027#include "ns3/ccnx-local-face.h"
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070028
29NS_LOG_COMPONENT_DEFINE ("CcnxProducer");
30
31namespace ns3
32{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080033
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070034NS_OBJECT_ENSURE_REGISTERED (CcnxProducer);
35
36TypeId
37CcnxProducer::GetTypeId (void)
38{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080039 static TypeId tid = TypeId ("ns3::CcnxProducer")
40 .SetParent<CcnxApp> ()
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070041 .AddConstructor<CcnxProducer> ()
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070042 .AddAttribute ("Prefix","Prefix, for which producer has the data",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043 StringValue ("/"),
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070044 MakeCcnxNameComponentsAccessor (&CcnxProducer::m_prefix),
45 MakeCcnxNameComponentsChecker ())
46 .AddAttribute ("PayloadSize", "Virtual payload size for Content packets",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080047 UintegerValue (100),
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070048 MakeUintegerAccessor(&CcnxProducer::m_virtualPayloadSize),
49 MakeUintegerChecker<uint32_t>())
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080050 // .AddTraceSource ("InterestTrace", "Interests that were received",
51 // MakeTraceSourceAccessor (&CcnxProducer::m_interestsTrace))
52 // .AddTraceSource ("ContentObjectTrace", "ContentObjects that were sent",
53 // MakeTraceSourceAccessor (&CcnxProducer::m_contentObjectsTrace))
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070054 ;
55
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056 return tid;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070057}
58
59CcnxProducer::CcnxProducer ()
60{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080061 // NS_LOG_FUNCTION_NOARGS ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070062}
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080063
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070064void
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080065CcnxProducer::OnInterest (const Ptr<const CcnxInterestHeader> &interest)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070066{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080067 NS_LOG_FUNCTION (this << interest);
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070068
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080069 if (!m_active) return;
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070070
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080071 static CcnxContentObjectTail tail;
72 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
73 header->SetName (Create<CcnxNameComponents> (interest->GetName ()));
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070074
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080075 Ptr<Packet> packet = Create<Packet> (m_virtualPayloadSize);
76 outgoingPacket->AddHeader (*header);
77 outgoingPacket->AddTrailer (tail);
78
79 m_protocolHandler (outgoingPacket);
Ilya Moiseenkob62c7402011-10-28 13:02:18 -070080}
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080081
82} // namespace ns3