NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-interest.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2 /*
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  *
18  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19  */
20 
21 #include "ndn-interest.h"
22 
23 #include "ns3/log.h"
24 #include "ns3/unused.h"
25 #include "ns3/packet.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("ndn.Interest");
28 
29 namespace ns3 {
30 namespace ndn {
31 
32 Interest::Interest (Ptr<Packet> payload/* = Create<Packet> ()*/)
33  : m_name ()
34  , m_scope (0xFF)
35  , m_interestLifetime (Seconds (0))
36  , m_nonce (0)
37  , m_nackType (NORMAL_INTEREST)
38  , m_exclude (0)
39  , m_payload (payload)
40  , m_wire (0)
41 {
42  if (m_payload == 0) // just in case
43  {
44  m_payload = Create<Packet> ();
45  }
46 }
47 
48 Interest::Interest (const Interest &interest)
49  : 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)
54  , m_exclude (interest.m_exclude ? Create<Exclude> (*interest.GetExclude ()) : 0)
55  , m_payload (interest.GetPayload ()->Copy ())
56  , m_wire (0)
57 {
58  NS_LOG_FUNCTION ("correct copy constructor");
59 }
60 
61 void
62 Interest::SetName (Ptr<Name> name)
63 {
64  m_name = name;
65  m_wire = 0;
66 }
67 
68 void
69 Interest::SetName (const Name &name)
70 {
71  m_name = Create<Name> (name);
72  m_wire = 0;
73 }
74 
75 const Name&
77 {
78  if (m_name==0) throw InterestException();
79  return *m_name;
80 }
81 
82 Ptr<const Name>
84 {
85  return m_name;
86 }
87 
88 void
89 Interest::SetScope (int8_t scope)
90 {
91  m_scope = scope;
92  m_wire = 0;
93 }
94 
95 int8_t
97 {
98  return m_scope;
99 }
100 
101 void
103 {
104  m_interestLifetime = lifetime;
105  m_wire = 0;
106 }
107 
108 Time
110 {
111  return m_interestLifetime;
112 }
113 
114 void
115 Interest::SetNonce (uint32_t nonce)
116 {
117  m_nonce = nonce;
118  m_wire = 0;
119 }
120 
121 uint32_t
123 {
124  return m_nonce;
125 }
126 
127 void
128 Interest::SetNack (uint8_t nackType)
129 {
130  m_nackType = nackType;
131  m_wire = 0;
132 }
133 
134 uint8_t
136 {
137  return m_nackType;
138 }
139 
140 void
141 Interest::SetExclude (Ptr<Exclude> exclude)
142 {
143  m_exclude = exclude;
144  m_wire = 0;
145 }
146 
147 Ptr<const Exclude>
149 {
150  return m_exclude;
151 }
152 
153 void
154 Interest::SetPayload (Ptr<Packet> payload)
155 {
156  m_payload = payload;
157  m_wire = 0;
158 }
159 
160 Ptr<const Packet>
162 {
163  return m_payload;
164 }
165 
166 void
167 Interest::Print (std::ostream &os) const
168 {
169  os << "I: " << GetName ();
170 
171  return;
172  os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
173  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  }
190  os << " <Scope>" << GetScope () << "</Scope>\n";
191  if ( !GetInterestLifetime ().IsZero() )
192  os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
193  if (GetNonce ()>0)
194  os << " <Nonce>" << GetNonce () << "</Nonce>\n";
195  os << "</Interest>";
196 }
197 
198 } // namespace ndn
199 } // namespace ns3
200 
void SetScope(int8_t scope)
Set Scope Scope limits where the Interest may propagate.
Definition: ndn-interest.cc:89
Class for NDN Name.
Definition: name.h:29
Class to represent Exclude component in NDN interests.
Definition: exclude.h:25
const Name & GetName() const
Get interest name.
Definition: ndn-interest.cc:76
void SetNack(uint8_t nackType)
Mark the Interest as a Negative Acknowledgement Three types of NACKs are supported.
Ptr< const Name > GetNamePtr() const
Get smart pointer to the interest name (to avoid extra memory usage)
Definition: ndn-interest.cc:83
Class for Interest parsing exception.
Definition: ndn-interest.h:271
void SetInterestLifetime(Time time)
Set InterestLifetime InterestLifetime indicates the (approximate) time remaining before the interest ...
void Print(std::ostream &os) const
Print Interest in plain-text to the specified output stream.
uint32_t GetNonce() const
Get Nonce value Nonce carries a randomly-genenerated bytestring that is used to detect and discard du...
Ptr< const Packet > GetPayload() const
Get virtual "payload" to interest packet.
Time GetInterestLifetime() const
Get InterestLifetime value InterestLifetime indicates the (approximate) time remaining before the int...
void SetExclude(Ptr< Exclude > exclude)
Set exclude filter of interest packet.
Interest(Ptr< Packet > payload=Create< Packet >())
Constructor.
Definition: ndn-interest.cc:32
uint8_t GetNack() const
Get NACK type Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
NDN Interest (wire formats are defined in wire)
Definition: ndn-interest.h:43
void SetPayload(Ptr< Packet > payload)
Set virtual "payload" of interest packet.
int8_t GetScope() const
Get Scope value Scope limits where the Interest may propagate.
Definition: ndn-interest.cc:96
void SetName(Ptr< Name > name)
Set interest name.
Definition: ndn-interest.cc:62
void SetNonce(uint32_t nonce)
Set Nonce Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicat...
Ptr< const Exclude > GetExclude() const
Get exclude filter of interest packet.