blob: 134cd01f0f345cfba2dceb39f75ace917892e57f [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 Afanasyev08d984e2011-08-13 19:20:22 -070058void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070059Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060{
61 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070062 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070063}
64
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070065void
66Interest::SetName (const Name &name)
67{
68 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070069 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070070}
71
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070072const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070073Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070075 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076 return *m_name;
77}
78
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070079Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070080Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070081{
82 return m_name;
83}
84
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070086Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087{
88 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070089 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090}
91
92int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070093Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094{
95 return m_scope;
96}
97
98void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070099Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100{
101 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700102 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103}
104
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700105Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700106Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700107{
108 return m_interestLifetime;
109}
110
111void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700112Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700113{
114 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700115 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116}
117
118uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700119Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120{
121 return m_nonce;
122}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700123
124void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700125Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700126{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800127 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700128 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700129}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800130
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800131uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700132Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700133{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800134 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700135}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700136
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700138Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700139{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700140 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700141 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142}
143
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700144Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700145Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700147 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148}
149
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700151Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700152{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700153 os << "I: " << GetName ();
154
155 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700156 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800157 if (GetNack ()>0)
158 {
159 os << " <NACK>";
160 switch (GetNack ())
161 {
162 case NACK_LOOP:
163 os << "loop";
164 break;
165 case NACK_CONGESTION:
166 os << "congestion";
167 break;
168 default:
169 os << "unknown";
170 break;
171 }
172 os << "</NACK>\n";
173 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800174 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700175 if ( !GetInterestLifetime ().IsZero() )
176 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
177 if (GetNonce ()>0)
178 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
179 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180}
181
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700182} // namespace ndn
183} // namespace ns3
184