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 | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 37 | namespace ns3 { |
| 38 | namespace CcnbParser { |
| 39 | |
| 40 | // We don't care about any other fields |
| 41 | void |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 42 | InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader* */) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 43 | { |
| 44 | // uint32_t n.m_dtag; |
| 45 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
| 46 | |
| 47 | static NonNegativeIntegerVisitor nonNegativeIntegerVisitor; |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 48 | static NameComponentsVisitor nameComponentsVisitor; |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 49 | static TimestampVisitor timestampVisitor; |
| 50 | static NonceVisitor nonceVisitor; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 52 | CcnxInterestHeader &interest = *(boost::any_cast<CcnxInterestHeader*> (param)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 53 | |
| 54 | switch (n.m_dtag) |
| 55 | { |
| 56 | case CCN_DTAG_Interest: |
| 57 | // process nested blocks |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 58 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 59 | { |
| 60 | block->accept (*this, param); |
| 61 | } |
| 62 | break; |
| 63 | case CCN_DTAG_Name: |
| 64 | { |
| 65 | // process name components |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 66 | Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 68 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 69 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 70 | block->accept (nameComponentsVisitor, &(*name)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 71 | } |
| 72 | interest.SetName (name); |
| 73 | break; |
| 74 | } |
| 75 | case CCN_DTAG_MinSuffixComponents: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 76 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 77 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 78 | interest.SetMinSuffixComponents ( |
| 79 | boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 80 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 81 | nonNegativeIntegerVisitor |
| 82 | ))); |
| 83 | break; |
| 84 | case CCN_DTAG_MaxSuffixComponents: |
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.SetMaxSuffixComponents ( |
| 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_Exclude: |
| 94 | { |
| 95 | // process exclude components |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 96 | Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 97 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 98 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 99 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 100 | block->accept (nameComponentsVisitor, &(*exclude)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 101 | } |
| 102 | interest.SetExclude (exclude); |
| 103 | break; |
| 104 | } |
| 105 | case CCN_DTAG_ChildSelector: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 106 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 107 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 108 | |
| 109 | interest.SetChildSelector ( |
| 110 | 1 == boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 111 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 112 | nonNegativeIntegerVisitor |
| 113 | ))); |
| 114 | break; |
| 115 | case CCN_DTAG_AnswerOriginKind: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 116 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 117 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 118 | interest.SetAnswerOriginKind ( |
| 119 | 1 == boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 120 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 121 | nonNegativeIntegerVisitor |
| 122 | ))); |
| 123 | break; |
| 124 | case CCN_DTAG_Scope: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 125 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 126 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 127 | interest.SetScope ( |
| 128 | boost::any_cast<uint32_t> ( |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 129 | (*n.m_nestedTags.begin())->accept( |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 130 | nonNegativeIntegerVisitor |
| 131 | ))); |
| 132 | break; |
| 133 | case CCN_DTAG_InterestLifetime: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 134 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 135 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 137 | interest.SetInterestLifetime ( |
| 138 | boost::any_cast<Time> ( |
| 139 | (*n.m_nestedTags.begin())->accept( |
| 140 | timestampVisitor |
| 141 | ))); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 142 | break; |
| 143 | case CCN_DTAG_Nonce: |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 144 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 145 | throw CcnbDecodingException (); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | f21c5be | 2011-08-22 00:35:54 -0700 | [diff] [blame] | 147 | interest.SetNonce ( |
| 148 | boost::any_cast<uint32_t> ( |
| 149 | (*n.m_nestedTags.begin())->accept( |
| 150 | nonceVisitor |
| 151 | ))); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | } // namespace CcnbParser |
| 157 | } // namespace ns3 |