blob: 3b09fde622a0624f2dd971d7f28bdc9551d1b21e [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 Afanasyevabb493a2013-07-19 15:31:33 -070038 , m_exclude (0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070039 , m_payload (payload)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070040 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041{
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070042 if (m_payload == 0) // just in case
43 {
44 m_payload = Create<Packet> ();
45 }
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070046}
47
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070048Interest::Interest (const Interest &interest)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070049 : m_name (Create<Name> (interest.GetName ()))
50 , m_scope (interest.m_scope)
51 , m_interestLifetime (interest.m_interestLifetime)
52 , m_nonce (interest.m_nonce)
53 , m_nackType (interest.m_nackType)
Alexander Afanasyevabb493a2013-07-19 15:31:33 -070054 , m_exclude (interest.m_exclude ? Create<Exclude> (*interest.GetExclude ()) : 0)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070055 , m_payload (interest.GetPayload ()->Copy ())
56 , m_wire (0)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070057{
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070058 NS_LOG_FUNCTION ("correct copy constructor");
Alexander Afanasyeva89bc102013-07-16 10:17:31 -070059}
60
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070062Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070063{
64 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070065 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066}
67
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070068void
69Interest::SetName (const Name &name)
70{
71 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070072 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070073}
74
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070075const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070076Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070078 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079 return *m_name;
80}
81
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070082Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070083Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070084{
85 return m_name;
86}
87
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070089Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090{
91 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070092 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070093}
94
95int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070096Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070097{
98 return m_scope;
99}
100
101void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700102Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103{
104 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700105 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106}
107
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700108Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700109Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700110{
111 return m_interestLifetime;
112}
113
114void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700115Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116{
117 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700118 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119}
120
121uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700122Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123{
124 return m_nonce;
125}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700126
127void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700128Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700129{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800130 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700131 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700132}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800133
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800134uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700135Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700136{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800137 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700138}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700139
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140void
Alexander Afanasyevabb493a2013-07-19 15:31:33 -0700141Interest::SetExclude (Ptr<Exclude> exclude)
142{
143 m_exclude = exclude;
144 m_wire = 0;
145}
146
147Ptr<const Exclude>
148Interest::GetExclude () const
149{
150 return m_exclude;
151}
152
153void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700154Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700156 m_payload = payload;
Alexander Afanasyevee762552013-07-10 22:29:22 -0700157 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158}
159
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700160Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700161Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700163 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700164}
165
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700166void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700167Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700168{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700169 os << "I: " << GetName ();
170
171 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700172 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800173 if (GetNack ()>0)
174 {
175 os << " <NACK>";
176 switch (GetNack ())
177 {
178 case NACK_LOOP:
179 os << "loop";
180 break;
181 case NACK_CONGESTION:
182 os << "congestion";
183 break;
184 default:
185 os << "unknown";
186 break;
187 }
188 os << "</NACK>\n";
189 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800190 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700191 if ( !GetInterestLifetime ().IsZero() )
192 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
193 if (GetNonce ()>0)
194 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
195 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700196}
197
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700198} // namespace ndn
199} // namespace ns3
200