blob: 5d7636269ebd9f92d2b5916b679ed0a41741f2f4 [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{
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070056 NS_LOG_FUNCTION ("correct copy constructor");
Alexander Afanasyeva89bc102013-07-16 10:17:31 -070057}
58
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070060Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061{
62 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070063 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070064}
65
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070066void
67Interest::SetName (const Name &name)
68{
69 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070070 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070071}
72
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070073const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070074Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070076 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077 return *m_name;
78}
79
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070080Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070081Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070082{
83 return m_name;
84}
85
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070087Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088{
89 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070090 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070091}
92
93int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070094Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095{
96 return m_scope;
97}
98
99void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700100Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101{
102 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700103 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700104}
105
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700106Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700107Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108{
109 return m_interestLifetime;
110}
111
112void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700113Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114{
115 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700116 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117}
118
119uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700120Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121{
122 return m_nonce;
123}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700124
125void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700126Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700127{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800128 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700129 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700130}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800131
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800132uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700133Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700134{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800135 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700136}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700137
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700139Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700141 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700142 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700143}
144
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700145Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700146Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700147{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700148 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149}
150
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700151void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700152Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700153{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700154 os << "I: " << GetName ();
155
156 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700157 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800158 if (GetNack ()>0)
159 {
160 os << " <NACK>";
161 switch (GetNack ())
162 {
163 case NACK_LOOP:
164 os << "loop";
165 break;
166 case NACK_CONGESTION:
167 os << "congestion";
168 break;
169 default:
170 os << "unknown";
171 break;
172 }
173 os << "</NACK>\n";
174 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800175 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700176 if ( !GetInterestLifetime ().IsZero() )
177 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
178 if (GetNonce ()>0)
179 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
180 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700181}
182
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700183} // namespace ndn
184} // namespace ns3
185