blob: 0bd0e4671da7ec0609d7aaaa9d8e5e432e091142 [file] [log] [blame]
Alexander Afanasyev8b379052011-08-21 16:58:20 -07001/* -*- 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 Afanasyeve709f3d2011-08-21 17:55:45 -070023#include "ns3/ccnb-parser-block.h"
24#include "ns3/ccnb-parser-dtag.h"
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070025#include "ns3/ccnx-name-components.h"
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070026#include "ns3/assert.h"
Alexander Afanasyevf21c5be2011-08-22 00:35:54 -070027#include "ns3/nstime.h"
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070028
29#include "ns3/ccnx-interest-header.h"
Alexander Afanasyevf21c5be2011-08-22 00:35:54 -070030#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 Afanasyeve709f3d2011-08-21 17:55:45 -070034
35#include <boost/foreach.hpp>
36
Alexander Afanasyev8b379052011-08-21 16:58:20 -070037namespace ns3 {
38namespace CcnbParser {
39
40// We don't care about any other fields
41void
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070042InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader* */)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070043{
44 // uint32_t n.m_dtag;
45 // std::list<Ptr<Block> > n.m_nestedBlocks;
46
47 static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070048 static NameComponentsVisitor nameComponentsVisitor;
Alexander Afanasyevf21c5be2011-08-22 00:35:54 -070049 static TimestampVisitor timestampVisitor;
50 static NonceVisitor nonceVisitor;
Alexander Afanasyev8b379052011-08-21 16:58:20 -070051
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070052 CcnxInterestHeader &interest = *(boost::any_cast<CcnxInterestHeader*> (param));
Alexander Afanasyev8b379052011-08-21 16:58:20 -070053
54 switch (n.m_dtag)
55 {
56 case CCN_DTAG_Interest:
57 // process nested blocks
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070058 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070059 {
60 block->accept (*this, param);
61 }
62 break;
63 case CCN_DTAG_Name:
64 {
65 // process name components
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070066 Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070067
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070068 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070069 {
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070070 block->accept (nameComponentsVisitor, &(*name));
Alexander Afanasyev8b379052011-08-21 16:58:20 -070071 }
72 interest.SetName (name);
73 break;
74 }
75 case CCN_DTAG_MinSuffixComponents:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070076 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
77 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070078 interest.SetMinSuffixComponents (
79 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070080 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -070081 nonNegativeIntegerVisitor
82 )));
83 break;
84 case CCN_DTAG_MaxSuffixComponents:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070085 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
86 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070087 interest.SetMaxSuffixComponents (
88 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070089 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -070090 nonNegativeIntegerVisitor
91 )));
92 break;
93 case CCN_DTAG_Exclude:
94 {
95 // process exclude components
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070096 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070097
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070098 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070099 {
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700100 block->accept (nameComponentsVisitor, &(*exclude));
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700101 }
102 interest.SetExclude (exclude);
103 break;
104 }
105 case CCN_DTAG_ChildSelector:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700106 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
107 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700108
109 interest.SetChildSelector (
110 1 == boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700111 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700112 nonNegativeIntegerVisitor
113 )));
114 break;
115 case CCN_DTAG_AnswerOriginKind:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700116 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
117 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700118 interest.SetAnswerOriginKind (
119 1 == boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700120 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700121 nonNegativeIntegerVisitor
122 )));
123 break;
124 case CCN_DTAG_Scope:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700125 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
126 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700127 interest.SetScope (
128 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700129 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700130 nonNegativeIntegerVisitor
131 )));
132 break;
133 case CCN_DTAG_InterestLifetime:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700134 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
135 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700136
Alexander Afanasyevf21c5be2011-08-22 00:35:54 -0700137 interest.SetInterestLifetime (
138 boost::any_cast<Time> (
139 (*n.m_nestedTags.begin())->accept(
140 timestampVisitor
141 )));
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700142 break;
143 case CCN_DTAG_Nonce:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700144 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
145 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700146
Alexander Afanasyevf21c5be2011-08-22 00:35:54 -0700147 interest.SetNonce (
148 boost::any_cast<uint32_t> (
149 (*n.m_nestedTags.begin())->accept(
150 nonceVisitor
151 )));
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700152 break;
153 }
154}
155
156} // namespace CcnbParser
157} // namespace ns3