Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 21 | #include "ndn-interest.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 23 | #include "ns3/log.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 24 | #include "ns3/unused.h" |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 25 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 27 | NS_LOG_COMPONENT_DEFINE ("ndn.Interest"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 29 | namespace ns3 { |
| 30 | namespace ndn { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 32 | Interest::Interest (Ptr<Packet> payload/* = Create<Packet> ()*/) |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 33 | : m_name () |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 34 | , m_scope (0xFF) |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 35 | , m_interestLifetime (Seconds (0)) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 36 | , m_nonce (0) |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 37 | , m_nackType (NORMAL_INTEREST) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 38 | , m_payload (payload) |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 39 | , m_wire (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 40 | { |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 41 | if (m_payload == 0) // just in case |
| 42 | { |
| 43 | m_payload = Create<Packet> (); |
| 44 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 47 | Interest::Interest (const Interest &interest) |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 48 | : 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 Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 56 | NS_LOG_FUNCTION ("correct copy constructor"); |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 59 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 60 | Interest::SetName (Ptr<Name> name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | { |
| 62 | m_name = name; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 63 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 66 | void |
| 67 | Interest::SetName (const Name &name) |
| 68 | { |
| 69 | m_name = Create<Name> (name); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 70 | m_wire = 0; |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 73 | const Name& |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 74 | Interest::GetName () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 75 | { |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 76 | if (m_name==0) throw InterestException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | return *m_name; |
| 78 | } |
| 79 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 80 | Ptr<const Name> |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 81 | Interest::GetNamePtr () const |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 82 | { |
| 83 | return m_name; |
| 84 | } |
| 85 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 86 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 87 | Interest::SetScope (int8_t scope) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 88 | { |
| 89 | m_scope = scope; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 90 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int8_t |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 94 | Interest::GetScope () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 95 | { |
| 96 | return m_scope; |
| 97 | } |
| 98 | |
| 99 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 100 | Interest::SetInterestLifetime (Time lifetime) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | { |
| 102 | m_interestLifetime = lifetime; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 103 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 106 | Time |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 107 | Interest::GetInterestLifetime () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 108 | { |
| 109 | return m_interestLifetime; |
| 110 | } |
| 111 | |
| 112 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 113 | Interest::SetNonce (uint32_t nonce) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 114 | { |
| 115 | m_nonce = nonce; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 116 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | uint32_t |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 120 | Interest::GetNonce () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | { |
| 122 | return m_nonce; |
| 123 | } |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 124 | |
| 125 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 126 | Interest::SetNack (uint8_t nackType) |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 127 | { |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 128 | m_nackType = nackType; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 129 | m_wire = 0; |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 130 | } |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 132 | uint8_t |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 133 | Interest::GetNack () const |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 134 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 135 | return m_nackType; |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 136 | } |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 137 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 138 | void |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 139 | Interest::SetPayload (Ptr<Packet> payload) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 140 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 141 | m_payload = payload; |
Alexander Afanasyev | ee76255 | 2013-07-10 22:29:22 -0700 | [diff] [blame] | 142 | m_wire = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 145 | Ptr<const Packet> |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 146 | Interest::GetPayload () const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 147 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 148 | return m_payload; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 151 | void |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 152 | Interest::Print (std::ostream &os) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 154 | os << "I: " << GetName (); |
| 155 | |
| 156 | return; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 157 | os << "<Interest>\n <Name>" << GetName () << "</Name>\n"; |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 158 | if (GetNack ()>0) |
| 159 | { |
| 160 | os << " <NACK>"; |
| 161 | switch (GetNack ()) |
| 162 | { |
| 163 | case NACK_LOOP: |
| 164 | os << "loop"; |
| 165 | break; |
| 166 | case NACK_CONGESTION: |
| 167 | os << "congestion"; |
| 168 | break; |
| 169 | default: |
| 170 | os << "unknown"; |
| 171 | break; |
| 172 | } |
| 173 | os << "</NACK>\n"; |
| 174 | } |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 175 | os << " <Scope>" << GetScope () << "</Scope>\n"; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 176 | if ( !GetInterestLifetime ().IsZero() ) |
| 177 | os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n"; |
| 178 | if (GetNonce ()>0) |
| 179 | os << " <Nonce>" << GetNonce () << "</Nonce>\n"; |
| 180 | os << "</Interest>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 183 | } // namespace ndn |
| 184 | } // namespace ns3 |
| 185 | |