blob: bd8784ef3cdea2743b0ee5f7dce8f0e55f0a9996 [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{
41}
42
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070043Interest::Interest (const Interest &interest)
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070044 : m_name (Create<Name> (interest.GetName ()))
45 , m_scope (interest.m_scope)
46 , m_interestLifetime (interest.m_interestLifetime)
47 , m_nonce (interest.m_nonce)
48 , m_nackType (interest.m_nackType)
49 , m_payload (interest.GetPayload ()->Copy ())
50 , m_wire (0)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070051{
52}
53
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070055Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056{
57 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070058 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059}
60
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070061void
62Interest::SetName (const Name &name)
63{
64 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070065 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070066}
67
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070068const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070069Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070070{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070071 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072 return *m_name;
73}
74
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070075Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070076Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070077{
78 return m_name;
79}
80
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070082Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083{
84 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070085 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086}
87
88int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070089Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090{
91 return m_scope;
92}
93
94void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070095Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070096{
97 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070098 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070099}
100
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700101Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700102Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103{
104 return m_interestLifetime;
105}
106
107void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700108Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109{
110 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700111 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112}
113
114uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700115Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116{
117 return m_nonce;
118}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700119
120void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700121Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700122{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800123 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700124 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700125}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800126
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800127uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700128Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700129{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800130 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700131}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700132
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700133void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700134Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700136 m_payload = payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137}
138
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700139Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700140Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700141{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700142 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700143}
144
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700146Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700147{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700148 os << "I: " << GetName ();
149
150 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700151 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800152 if (GetNack ()>0)
153 {
154 os << " <NACK>";
155 switch (GetNack ())
156 {
157 case NACK_LOOP:
158 os << "loop";
159 break;
160 case NACK_CONGESTION:
161 os << "congestion";
162 break;
163 default:
164 os << "unknown";
165 break;
166 }
167 os << "</NACK>\n";
168 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800169 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700170 if ( !GetInterestLifetime ().IsZero() )
171 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
172 if (GetNonce ()>0)
173 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
174 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700175}
176
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700177} // namespace ndn
178} // namespace ns3
179