blob: 195c4f90e981e932b71d76578da8bbd418954d36 [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 Afanasyeveae83ee2013-03-15 15:01:10 -070032NS_OBJECT_ENSURE_REGISTERED (Interest);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070034Interest::Interest ()
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070035 : m_name ()
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080036 , m_scope (0xFF)
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070037 , m_interestLifetime (Seconds (0))
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038 , m_nonce (0)
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080039 , m_nackType (NORMAL_INTEREST)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070040 , m_payload (0)
41 , m_wire (0)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042{
43}
44
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070045Interest::Interest (const Interest &interest)
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070046 : m_name (Create<Name> (interest.GetName ()))
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070047 , m_scope (interest.m_scope)
48 , m_interestLifetime (interest.m_interestLifetime)
49 , m_nonce (interest.m_nonce)
50 , m_nackType (interest.m_nackType)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070051 , m_payload (interest.GetPayload ()->Copy ())
52 , m_wire (0)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070053{
54}
55
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070057Interest::SetName (Ptr<Name> name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058{
59 m_name = name;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070060 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061}
62
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070063void
64Interest::SetName (const Name &name)
65{
66 m_name = Create<Name> (name);
Alexander Afanasyevb989b122013-07-10 17:15:46 -070067 m_wire = 0;
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070068}
69
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070070const Name&
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070071Interest::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072{
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070073 if (m_name==0) throw InterestException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074 return *m_name;
75}
76
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070077Ptr<const Name>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070078Interest::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070079{
80 return m_name;
81}
82
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070084Interest::SetScope (int8_t scope)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085{
86 m_scope = scope;
Alexander Afanasyevb989b122013-07-10 17:15:46 -070087 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070088}
89
90int8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070091Interest::GetScope () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092{
93 return m_scope;
94}
95
96void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070097Interest::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070098{
99 m_interestLifetime = lifetime;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700100 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101}
102
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700103Time
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700104Interest::GetInterestLifetime () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105{
106 return m_interestLifetime;
107}
108
109void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700110Interest::SetNonce (uint32_t nonce)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700111{
112 m_nonce = nonce;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700113 m_wire = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114}
115
116uint32_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700117Interest::GetNonce () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700118{
119 return m_nonce;
120}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700121
122void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700123Interest::SetNack (uint8_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700124{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800125 m_nackType = nackType;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700126 m_wire = 0;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700127}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800128
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800129uint8_t
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700130Interest::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700131{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800132 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700133}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700134
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135void
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700136Interest::SetPayload (Ptr<Packet> payload)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700138 m_payload = payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700139}
140
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700141Ptr<const Payload>
142Interest::GetPayload () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700143{
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700144 return m_payload;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700145}
146
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700147void
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700148Interest::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700150 os << "I: " << GetName ();
151
152 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700153 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800154 if (GetNack ()>0)
155 {
156 os << " <NACK>";
157 switch (GetNack ())
158 {
159 case NACK_LOOP:
160 os << "loop";
161 break;
162 case NACK_CONGESTION:
163 os << "congestion";
164 break;
165 default:
166 os << "unknown";
167 break;
168 }
169 os << "</NACK>\n";
170 }
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800171 os << " <Scope>" << GetScope () << "</Scope>\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700172 if ( !GetInterestLifetime ().IsZero() )
173 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
174 if (GetNonce ()>0)
175 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
176 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700177}
178
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700179} // namespace ndn
180} // namespace ns3
181