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-content-object-visitor.h" |
| 22 | #include "ccnb-parser-name-components-visitor.h" |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 23 | #include "ccnb-parser-non-negative-integer-visitor.h" |
| 24 | #include "ccnb-parser-timestamp-visitor.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 26 | #include "../syntax-tree/ccnb-parser-block.h" |
| 27 | #include "../syntax-tree/ccnb-parser-dtag.h" |
| 28 | |
Ilya Moiseenko | d26e682 | 2011-08-23 17:48:38 -0700 | [diff] [blame] | 29 | #include "ns3/ccnx-name-components.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 30 | #include "ns3/assert.h" |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 31 | #include "ns3/log.h" |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 33 | #include "ns3/ccnx-content-object-header.h" |
| 34 | |
| 35 | #include <boost/foreach.hpp> |
| 36 | |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 37 | NS_LOG_COMPONENT_DEFINE ("CcnbParserContentObjectVisitor"); |
| 38 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 39 | namespace ns3 { |
| 40 | namespace CcnbParser { |
| 41 | |
| 42 | // We don't really care about any other fields |
| 43 | void |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 44 | ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */) |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 45 | { |
| 46 | // uint32_t n.m_dtag; |
| 47 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 48 | static NameComponentsVisitor nameComponentsVisitor; |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 49 | static NonNegativeIntegerVisitor nonNegativeIntegerVisitor; |
| 50 | static TimestampVisitor timestampVisitor; |
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 | CcnxContentObjectHeader &contentObject = *(boost::any_cast<CcnxContentObjectHeader*> (param)); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 53 | |
| 54 | switch (n.m_dtag) |
| 55 | { |
| 56 | case CCN_DTAG_ContentObject: |
| 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 | contentObject.SetName (name); |
| 73 | break; |
| 74 | } |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 76 | case CCN_DTAG_Signature: // ignoring |
| 77 | break; |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 78 | |
| 79 | case CCN_DTAG_SignedInfo: |
| 80 | // process nested blocks |
| 81 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 82 | { |
| 83 | block->accept (*this, param); |
| 84 | } |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 85 | break; |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 86 | |
| 87 | case CCN_DTAG_Timestamp: |
| 88 | NS_LOG_DEBUG ("Timestamp"); |
| 89 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 90 | throw CcnbDecodingException (); |
| 91 | |
| 92 | contentObject.SetTimestamp ( |
| 93 | boost::any_cast<Time> ( |
| 94 | (*n.m_nestedTags.begin())->accept( |
| 95 | timestampVisitor |
| 96 | ))); |
| 97 | break; |
| 98 | |
| 99 | case CCN_DTAG_FreshnessSeconds: |
| 100 | NS_LOG_DEBUG ("FreshnessSeconds"); |
| 101 | |
| 102 | if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag |
| 103 | throw CcnbDecodingException (); |
| 104 | contentObject.SetFreshness ( |
| 105 | Seconds ( |
| 106 | boost::any_cast<uint32_t> ( |
| 107 | (*n.m_nestedTags.begin())->accept( |
| 108 | nonNegativeIntegerVisitor |
| 109 | )))); |
| 110 | |
| 111 | break; |
| 112 | |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 113 | case CCN_DTAG_Content: // !!! HACK |
| 114 | // This hack was necessary for memory optimizations (i.e., content is virtual payload) |
Alexander Afanasyev | e709f3d | 2011-08-21 17:55:45 -0700 | [diff] [blame] | 115 | NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag"); |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 116 | break; |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 117 | |
| 118 | default: // ignore all other stuff |
| 119 | break; |
Alexander Afanasyev | 8b37905 | 2011-08-21 16:58:20 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | } // namespace CcnbParser |
| 124 | } // namespace ns3 |