blob: ccb40b2cb508ae23efb8fdbd03229aed15e98c1f [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"
25#include "ns3/name-components.h"
26#include "ns3/assert.h"
27
28#include "ns3/ccnx-interest-header.h"
29
30#include <boost/foreach.hpp>
31
Alexander Afanasyev8b379052011-08-21 16:58:20 -070032namespace ns3 {
33namespace CcnbParser {
34
35// We don't care about any other fields
36void
37InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
38{
39 // uint32_t n.m_dtag;
40 // std::list<Ptr<Block> > n.m_nestedBlocks;
41
42 static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070043 static NameComponentsVisitor nameComponentsVisitor;
Alexander Afanasyev8b379052011-08-21 16:58:20 -070044
45 CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
46
47 switch (n.m_dtag)
48 {
49 case CCN_DTAG_Interest:
50 // process nested blocks
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070051 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070052 {
53 block->accept (*this, param);
54 }
55 break;
56 case CCN_DTAG_Name:
57 {
58 // process name components
59 Ptr<Name::Components> name = Create<Name::Components> ();
60
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070061 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070062 {
63 block->accept (nameComponentsVisitor, *name);
64 }
65 interest.SetName (name);
66 break;
67 }
68 case CCN_DTAG_MinSuffixComponents:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070069 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
70 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070071 interest.SetMinSuffixComponents (
72 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070073 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -070074 nonNegativeIntegerVisitor
75 )));
76 break;
77 case CCN_DTAG_MaxSuffixComponents:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070078 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
79 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -070080 interest.SetMaxSuffixComponents (
81 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070082 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -070083 nonNegativeIntegerVisitor
84 )));
85 break;
86 case CCN_DTAG_Exclude:
87 {
88 // process exclude components
89 Ptr<Name::Components> exclude = Create<Name::Components> ();
90
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070091 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
Alexander Afanasyev8b379052011-08-21 16:58:20 -070092 {
93 block->accept (nameComponentsVisitor, *exclude);
94 }
95 interest.SetExclude (exclude);
96 break;
97 }
98 case CCN_DTAG_ChildSelector:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -070099 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
100 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700101
102 interest.SetChildSelector (
103 1 == boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700104 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700105 nonNegativeIntegerVisitor
106 )));
107 break;
108 case CCN_DTAG_AnswerOriginKind:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700109 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
110 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700111 interest.SetAnswerOriginKind (
112 1 == boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700113 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700114 nonNegativeIntegerVisitor
115 )));
116 break;
117 case CCN_DTAG_Scope:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700118 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
119 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700120 interest.SetScope (
121 boost::any_cast<uint32_t> (
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700122 (*n.m_nestedTags.begin())->accept(
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700123 nonNegativeIntegerVisitor
124 )));
125 break;
126 case CCN_DTAG_InterestLifetime:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700127 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
128 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700129
130 /// \todo Decode InterestLifetime
131 break;
132 case CCN_DTAG_Nonce:
Alexander Afanasyeve709f3d2011-08-21 17:55:45 -0700133 if (n.m_nestedTags.size()!=1) // should be exactly one UDATA inside this tag
134 throw CcnbDecodingException ();
Alexander Afanasyev8b379052011-08-21 16:58:20 -0700135
136 /// \todo Decode Nonce
137 break;
138 }
139}
140
141} // namespace CcnbParser
142} // namespace ns3