blob: 7e0757a9d302db438e879f8825a1601c33c3ddf4 [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>
19 */
20
21#include "ccnx-producer.h"
22
23
24NS_LOG_COMPONENT_DEFINE ("CcnxProducer");
25
26namespace ns3
27{
28
29NS_OBJECT_ENSURE_REGISTERED (CcnxProducer);
30
31TypeId
32CcnxProducer::GetTypeId (void)
33{
34 static TypeId tid = TypeId ("ns3::CcnxProducer")
35 .SetParent<Application> ()
36 .AddConstructor<CcnxProducer> ()
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070037 // Alex: this is incorrect. SetNode call is not called if face is created using this accessor
38 // .AddAttribute ("Face","Local face to be used",
39 // PointerValue (CreateObject<CcnxLocalFace> ()),
40 // MakePointerAccessor (&CcnxProducer::m_face),
41 // MakePointerChecker<CcnxLocalFace> ())
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070042 .AddAttribute ("Ccnx","Ccnx is needed to access ContentStore",
43 PointerValue (NULL),
44 MakePointerAccessor (&CcnxProducer::m_ccnx),
45 MakePointerChecker<Ccnx> ())
46
47 /*.AddAttribute ("InterestName","CcnxName of the Interest (use CcnxNameComponents)",
48 PointerValue (CreateObject<CcnxNameComponents> ()),
49 MakePointerAccessor (&CcnxConsumer::m_interestName),
50 MakePointerChecker<CcnxNameComponents> ())
51 .AddAttribute ("LifeTime", "LifeTime fo interest packet",
52 TimeValue (Seconds (4.0)),
53 MakeTimeAccessor (&CcnxConsumer::m_interestLifeTime),
54 MakeTimeChecker ())
55 .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
56 IntegerValue(-1),
57 MakeIntegerAccessor(&CcnxConsumer::m_minSuffixComponents),
58 MakeIntegerChecker<int32_t>())
59 .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
60 IntegerValue(-1),
61 MakeIntegerAccessor(&CcnxConsumer::m_maxSuffixComponents),
62 MakeIntegerChecker<int32_t>())
63 .AddAttribute ("ChildSelector", "ChildSelector",
64 BooleanValue(false),
65 MakeBooleanAccessor(&CcnxConsumer::m_childSelector),
66 MakeBooleanChecker())
67 .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)",
68 PointerValue (CreateObject<CcnxNameComponents> ()),
69 MakePointerAccessor (&CcnxConsumer::m_exclude),
70 MakePointerChecker<CcnxNameComponents> ())*/
71 .AddAttribute ("Capacity", "Capacity of the ContentStore",
72 UintegerValue(100),
73 MakeUintegerAccessor(&CcnxProducer::m_storeCapacity),
74 MakeUintegerChecker<uint32_t>())
75 .AddTraceSource ("InterestTrace", "Interests that were received",
76 MakeTraceSourceAccessor (&CcnxProducer::m_interestsTrace))
77 .AddTraceSource ("ContentObjectTrace", "ContentObjects that were sent",
78 MakeTraceSourceAccessor (&CcnxProducer::m_contentObjectsTrace))
79 ;
80
81 return tid;
82}
83
84CcnxProducer::CcnxProducer ()
85{
86 NS_LOG_FUNCTION_NOARGS ();
87}
88
89CcnxProducer::~CcnxProducer()
90{
91 NS_LOG_FUNCTION_NOARGS ();
92}
93
94void
95CcnxProducer::DoDispose (void)
96{
97 NS_LOG_FUNCTION_NOARGS ();
98
99 Application::DoDispose ();
100}
101
102 // Application Methods
103void
104CcnxProducer::StartApplication () // Called at time specified by Start
105{
106 NS_LOG_FUNCTION_NOARGS ();
107// ScheduleNextTx();
108}
109
110void
111CcnxProducer::StopApplication () // Called at time specified by Stop
112{
113 NS_LOG_FUNCTION_NOARGS ();
114
115 CancelEvents ();
116}
117
118void
119CcnxProducer::CancelEvents ()
120{
121 NS_LOG_FUNCTION_NOARGS ();
122
Alexander Afanasyev152cf112011-08-29 17:58:32 -0700123 // Simulator::Cancel (m_sendEvent);
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700124}
125
126/*void
127CcnxProducer::ScheduleNextTx ()
128{
129 NS_LOG_FUNCTION_NOARGS ();
130
131 Time nextTime = Seconds(m_offTime);
132 m_sendEvent = Simulator::Schedule (nextTime, &CcnxConsumer::SendPacket, this);
133 }
134 */
135
136/*void
137CcnxConsumer::SendPacket ()
138 {
139 NS_LOG_FUNCTION_NOARGS ();
140 NS_LOG_INFO ("Sending Interest at " << Simulator::Now ());
141
142 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
143 CcnxInterestHeader interestHeader;
144 interestHeader.SetNonce(randomNonce);
145 interestHeader.SetName(m_interestName);
146 interestHeader.SetInterestLifetime(m_interestLifeTime);
147 interestHeader.SetChildSelector(m_childSelector);
148 interestHeader.SetExclude(m_exclude);
149 interestHeader.SetMaxSuffixComponents(m_maxSuffixComponents);
150 interestHeader.SetMinSuffixComponents(m_minSuffixComponents);
151
152 Ptr<Packet> packet = Create<Packet> ();
153 packet->AddHeader (interestHeader);
154
155 m_face->Receive(packet);
156
157 ScheduleNextTx();
158 }*/
159
160uint32_t
161CcnxProducer::GetStoreCapacity()
162{
163 return m_storeCapacity;
164}
165
166void
167CcnxProducer::HandlePacket(const Ptr<CcnxFace> &face, const Ptr<const Packet> &packet)
168{
169 uint8_t type[2];
170 uint32_t read = packet->CopyData (type,2);
171 if (read!=2)
172 {
173 NS_LOG_INFO ("Unknown CcnxPacket");
174 return;
175 }
176
177 if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
178 {
179 m_interestsTrace(face,packet);
180 }
181 else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
182 {
183 m_contentObjectsTrace(face,packet);
184 }
185}
186
187void
188CcnxProducer::AddContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
189{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700190 // m_ccnx->m_contentStore->Add (header, packet);
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700191}
192}