blob: d33b2b03f219dc4f264c1a3ceaa53f3154e1725e [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
23namespace ns3 {
24namespace CcnbParser {
25
26// We don't care about any other fields
27void
28InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
29{
30 // uint32_t n.m_dtag;
31 // std::list<Ptr<Block> > n.m_nestedBlocks;
32
33 static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
34 static NameComponentsVisitor m_nameComponentsVisitor;
35
36 CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
37
38 switch (n.m_dtag)
39 {
40 case CCN_DTAG_Interest:
41 // process nested blocks
42 BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
43 {
44 block->accept (*this, param);
45 }
46 break;
47 case CCN_DTAG_Name:
48 {
49 // process name components
50 Ptr<Name::Components> name = Create<Name::Components> ();
51
52 BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
53 {
54 block->accept (nameComponentsVisitor, *name);
55 }
56 interest.SetName (name);
57 break;
58 }
59 case CCN_DTAG_MinSuffixComponents:
60 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
61 throw CcnxDecodingException ();
62 interest.SetMinSuffixComponents (
63 boost::any_cast<uint32_t> (
64 (*n.m_nestedBlocks.begin())->accept(
65 nonNegativeIntegerVisitor
66 )));
67 break;
68 case CCN_DTAG_MaxSuffixComponents:
69 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
70 throw CcnxDecodingException ();
71 interest.SetMaxSuffixComponents (
72 boost::any_cast<uint32_t> (
73 (*n.m_nestedBlocks.begin())->accept(
74 nonNegativeIntegerVisitor
75 )));
76 break;
77 case CCN_DTAG_Exclude:
78 {
79 // process exclude components
80 Ptr<Name::Components> exclude = Create<Name::Components> ();
81
82 BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
83 {
84 block->accept (nameComponentsVisitor, *exclude);
85 }
86 interest.SetExclude (exclude);
87 break;
88 }
89 case CCN_DTAG_ChildSelector:
90 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
91 throw CcnxDecodingException ();
92
93 interest.SetChildSelector (
94 1 == boost::any_cast<uint32_t> (
95 (*n.m_nestedBlocks.begin())->accept(
96 nonNegativeIntegerVisitor
97 )));
98 break;
99 case CCN_DTAG_AnswerOriginKind:
100 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
101 throw CcnxDecodingException ();
102 interest.SetAnswerOriginKind (
103 1 == boost::any_cast<uint32_t> (
104 (*n.m_nestedBlocks.begin())->accept(
105 nonNegativeIntegerVisitor
106 )));
107 break;
108 case CCN_DTAG_Scope:
109 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
110 throw CcnxDecodingException ();
111 interest.SetScope (
112 boost::any_cast<uint32_t> (
113 (*n.m_nestedBlocks.begin())->accept(
114 nonNegativeIntegerVisitor
115 )));
116 break;
117 case CCN_DTAG_InterestLifetime:
118 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
119 throw CcnxDecodingException ();
120
121 /// \todo Decode InterestLifetime
122 break;
123 case CCN_DTAG_Nonce:
124 if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
125 throw CcnxDecodingException ();
126
127 /// \todo Decode Nonce
128 break;
129 }
130}
131
132} // namespace CcnbParser
133} // namespace ns3