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