IBR-DTN  1.0.0
BundleFilter.cpp
Go to the documentation of this file.
1 /*
2  * BundleFilter.cpp
3  *
4  * Copyright (C) 2014 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <jm@m-network.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "core/BundleFilter.h"
23 
24 namespace dtn
25 {
26  namespace core
27  {
29  : _metabundle(NULL), _bundle(NULL), _primaryblock(NULL), _block(NULL),
30  _block_length(0), _peer(NULL), _protocol(dtn::core::Node::CONN_UNDEFINED), _routing(NULL)
31  {
32 
33  }
34 
36  {
37 
38  }
39 
41  {
42  _metabundle = &data;
43  }
44 
46  {
47  if (_metabundle == NULL) throw FilterException("attribute not present in this context");
48  return *_metabundle;
49  }
50 
52  {
53  _bundle = &data;
54  _primaryblock = &data;
55  }
56 
58  {
59  if (_bundle == NULL) throw FilterException("attribute not present in this context");
60  return *_bundle;
61  }
62 
64  {
65  if (_metabundle != NULL) return *_metabundle;
66  if (_primaryblock != NULL) return *_primaryblock;
67  throw FilterException("attribute not present in this context");
68  }
69 
71  {
72  _primaryblock = &data;
73  }
74 
76  {
77  if (_primaryblock == NULL) throw FilterException("attribute not present in this context");
78  return *_primaryblock;
79  }
80 
82  {
83  _block = &block;
84  _block_length = size;
85  }
86 
88  {
89  if (_block == NULL) throw FilterException("attribute not present in this context");
90  return *_block;
91  }
92 
94  {
95  if (_block == NULL) throw FilterException("attribute not present in this context");
96  return _block_length;
97  }
98 
99  void FilterContext::setPeer(const dtn::data::EID &endpoint)
100  {
101  _peer = &endpoint;
102  }
103 
105  {
106  if (_peer == NULL) throw FilterException("attribute not present in this context");
107  return *_peer;
108  }
109 
111  {
112  _protocol = protocol;
113  }
114 
116  {
117  if (_protocol == dtn::core::Node::CONN_UNDEFINED) throw FilterException("attribute not present in this context");
118  return _protocol;
119  }
120 
122  {
123  _routing = &routing;
124  }
125 
126  const std::string FilterContext::getRoutingTag() const throw (FilterException)
127  {
128  if (_routing == NULL) throw FilterException("attribute not present in this context");
129  return _routing->getTag();
130  }
131 
133  : _next(NULL)
134  {
135  }
136 
138  {
139  if (_next != NULL) delete _next;
140  }
141 
143  {
144  if (_next != NULL) {
145  _next->append(filter);
146  return this;
147  }
148  _next = filter;
149  return this;
150  }
151 
153  {
154  return (_next == NULL) ? BundleFilter::PASS : _next->evaluate(context);
155  }
156 
158  {
159  return (_next == NULL) ? BundleFilter::PASS : _next->filter(context, bundle);
160  }
161  } /* namespace core */
162 } /* namespace dtn */
const dtn::data::Bundle & getBundle() const
virtual const std::string getTag() const
void setBundle(const dtn::data::Bundle &data)
dtn::core::Node::Protocol getProtocol() const
virtual ACTION evaluate(const FilterContext &context) const
virtual ACTION filter(const FilterContext &context, dtn::data::Bundle &bundle) const
const dtn::data::BundleID & getBundleID() const
void setProtocol(const dtn::core::Node::Protocol &protocol)
const dtn::data::PrimaryBlock & getPrimaryBlock() const
BundleFilter * append(BundleFilter *filter)
const dtn::data::MetaBundle & getMetaBundle() const
dtn::data::Number getBlockLength() const
void setMetaBundle(const dtn::data::MetaBundle &data)
const dtn::data::Block & getBlock() const
void setBlock(const dtn::data::Block &block, const dtn::data::Number &size)
const std::string getRoutingTag() const
void setRouting(const dtn::routing::RoutingExtension &routing)
const dtn::data::EID & setPeer() const
void setPrimaryBlock(const dtn::data::PrimaryBlock &data)