blob: 7364701887c49ed049505a7b99de3559fd4771f1 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
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 *
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019 */
20
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080021#include "ndn-interest.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070023#include "ns3/log.h"
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070024#include "ns3/unused.h"
Alexander Afanasyev663d63f2012-09-09 11:55:36 -070025#include "ns3/packet.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070026
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070027NS_LOG_COMPONENT_DEFINE ("ndn.Interest");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029namespace ns3 {
30namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070032Interest::Interest (Ptr<Packet> payload/* = Create<Packet> ()*/)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070033 : m_name ()
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080034 , m_scope (0xFF)
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070035 , m_interestLifetime (Seconds (0))
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070036 , m_nonce (0)
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080037 , m_nackType (NORMAL_INTEREST)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070038 , m_payload (payload)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070039 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070040{
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070041 if (m_payload == 0) // just in case
42 {
43 m_payload = Create<Packet> ();
44 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070045}
46
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070047Interest::Interest (const Interest &interest)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070048 : m_name (Create<Name> (interest.GetName ()))
49 , m_scope (interest.m_scope)
50 , m_interestLifetime (interest.m_interestLifetime)
51 , m_nonce (interest.m_nonce)
52 , m_nackType (interest.m_nackType)
53 , m_payload (interest.GetPayload ()->Copy ())
54 , m_wire (0)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070055{
56}
57
Alexander Afanasyeva89bc102013-07-16 10:17:31 -070058Interest::Interest (Ptr<const Interest> interest)
59 : m_name (Create<Name> (interest->GetName ()))
60 , m_scope (interest->m_scope)
61 , m_interestLifetime (interest->m_interestLifetime)
62 , m_nonce (interest->m_nonce)
63 , m_nackType (interest->m_nackType)
64 , m_payload (interest->GetPayload ()->Copy ())
65 , m_wire (0)
66{
67}
68
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070070Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
72 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070073 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074}
75
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070076void
77Interest::SetName (const Name &name)
78{
79 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070080 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070081}
82
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070083const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070084Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070086 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087 return *m_name;
88}
89
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070090Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070091Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070092{
93 return m_name;
94}
95
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070096void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070097Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070098{
99 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700100 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101}
102
103int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700104Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105{
106 return m_scope;
107}
108
109void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700110Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700111{
112 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700113 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114}
115
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700116Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700117Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700118{
119 return m_interestLifetime;
120}
121
122void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700123Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124{
125 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700126 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127}
128
129uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700130Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700131{
132 return m_nonce;
133}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700134
135void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700136Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700137{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800138 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700139 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700140}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800141
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800142uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700143Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700144{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800145 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700146}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700147
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700149Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700151 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700152 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700153}
154
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700155Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700156Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700157{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700158 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159}
160
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700161void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700162Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700164 os << "I: " << GetName ();
165
166 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700167 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800168 if (GetNack ()>0)
169 {
170 os << " <NACK>";
171 switch (GetNack ())
172 {
173 case NACK_LOOP:
174 os << "loop";
175 break;
176 case NACK_CONGESTION:
177 os << "congestion";
178 break;
179 default:
180 os << "unknown";
181 break;
182 }
183 os << "</NACK>\n";
184 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800185 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700186 if ( !GetInterestLifetime ().IsZero() )
187 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
188 if (GetNonce ()>0)
189 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
190 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191}
192
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700193} // namespace ndn
194} // namespace ns3
195