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