Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 21 | #include "interest-visitor.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 22 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 23 | #include "../syntax-tree/block.h" |
| 24 | #include "../syntax-tree/dtag.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame^] | 26 | #include "ns3/ndn-name.h" |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 27 | #include "ns3/ndn-interest-header.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 29 | #include "ns3/assert.h" |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 30 | #include "ns3/nstime.h" |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | #include "name-components-visitor.h" |
| 33 | #include "non-negative-integer-visitor.h" |
| 34 | #include "timestamp-visitor.h" |
| 35 | #include "uint32t-blob-visitor.h" |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 36 | |
| 37 | #include <boost/foreach.hpp> |
| 38 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 39 | #include "ns3/log.h" |
| 40 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | NS_LOG_COMPONENT_DEFINE ("ndn.CcnbParser.InterestVisitor"); |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 43 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 44 | namespace ndn { |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 45 | namespace CcnbParser { |
| 46 | |
| 47 | // We don't care about any other fields |
| 48 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 49 | InterestVisitor::visit (Dtag &n, boost::any param/*should be InterestHeader* */) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 50 | { |
| 51 | // uint32_t n.m_dtag; |
| 52 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
| 53 | |
| 54 | static NonNegativeIntegerVisitor nonNegativeIntegerVisitor; |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame^] | 55 | static NameVisitor nameComponentsVisitor; |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 56 | static TimestampVisitor timestampVisitor; |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 57 | static Uint32tBlobVisitor nonceVisitor; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 59 | InterestHeader &interest = *(boost::any_cast<InterestHeader*> (param)); |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 61 | switch (n.m_dtag) |
| 62 | { |
| 63 | case CCN_DTAG_Interest: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 64 | NS_LOG_DEBUG ("Interest"); |
| 65 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 66 | // process nested blocks |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 67 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 68 | { |
| 69 | block->accept (*this, param); |
| 70 | } |
| 71 | break; |
| 72 | case CCN_DTAG_Name: |
| 73 | { |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 74 | NS_LOG_DEBUG ("Name"); |
| 75 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 76 | // process name components |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame^] | 77 | Ptr<Name> name = Create<Name> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 79 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 80 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 81 | block->accept (nameComponentsVisitor, &(*name)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 82 | } |
| 83 | interest.SetName (name); |
| 84 | break; |
| 85 | } |
| 86 | case CCN_DTAG_MinSuffixComponents: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 87 | NS_LOG_DEBUG ("MinSuffixComponents"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 88 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 89 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 90 | interest.SetMinSuffixComponents ( |
| 91 | boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 92 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 93 | nonNegativeIntegerVisitor |
| 94 | ))); |
| 95 | break; |
| 96 | case CCN_DTAG_MaxSuffixComponents: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 97 | NS_LOG_DEBUG ("MaxSuffixComponents"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 98 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 99 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 100 | interest.SetMaxSuffixComponents ( |
| 101 | boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 102 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 103 | nonNegativeIntegerVisitor |
| 104 | ))); |
| 105 | break; |
| 106 | case CCN_DTAG_Exclude: |
| 107 | { |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 108 | NS_LOG_DEBUG ("Exclude"); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 109 | // process exclude components |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame^] | 110 | Ptr<Name> exclude = Create<Name> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 112 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 113 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 114 | block->accept (nameComponentsVisitor, &(*exclude)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 115 | } |
| 116 | interest.SetExclude (exclude); |
| 117 | break; |
| 118 | } |
| 119 | case CCN_DTAG_ChildSelector: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 120 | NS_LOG_DEBUG ("ChildSelector"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 121 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 122 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 123 | |
| 124 | interest.SetChildSelector ( |
| 125 | 1 == boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 126 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 127 | nonNegativeIntegerVisitor |
| 128 | ))); |
| 129 | break; |
| 130 | case CCN_DTAG_AnswerOriginKind: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 131 | NS_LOG_DEBUG ("AnswerOriginKind"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 132 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 133 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 134 | interest.SetAnswerOriginKind ( |
| 135 | 1 == boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 136 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 137 | nonNegativeIntegerVisitor |
| 138 | ))); |
| 139 | break; |
| 140 | case CCN_DTAG_Scope: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 141 | NS_LOG_DEBUG ("Scope"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 142 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 143 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 144 | interest.SetScope ( |
| 145 | boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 146 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 147 | nonNegativeIntegerVisitor |
| 148 | ))); |
| 149 | break; |
| 150 | case CCN_DTAG_InterestLifetime: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 151 | NS_LOG_DEBUG ("InterestLifetime"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 152 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 153 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 154 | |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 155 | interest.SetInterestLifetime ( |
| 156 | boost::any_cast<Time> ( |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 157 | (*n.m_nestedTags.begin())->accept( |
| 158 | timestampVisitor |
| 159 | ))); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 160 | break; |
| 161 | case CCN_DTAG_Nonce: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 162 | NS_LOG_DEBUG ("Nonce"); |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 163 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 164 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 166 | interest.SetNonce ( |
| 167 | boost::any_cast<uint32_t> ( |
| 168 | (*n.m_nestedTags.begin())->accept( |
| 169 | nonceVisitor |
| 170 | ))); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 171 | break; |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 172 | |
| 173 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 174 | case CCN_DTAG_Nack: |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 175 | NS_LOG_DEBUG ("Nack"); |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 176 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 177 | throw CcnbDecodingException (); |
| 178 | |
| 179 | interest.SetNack ( |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 180 | boost::any_cast<uint32_t> ( |
| 181 | (*n.m_nestedTags.begin())->accept(nonNegativeIntegerVisitor))); |
Ilya Moiseenko | d1f1951 | 2011-11-16 14:31:19 -0800 | [diff] [blame] | 182 | break; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 183 | } |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | } // namespace CcnbParser |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 187 | } // namespace ndn |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 188 | } // namespace ns3 |