IBR-DTN  1.0.0
FragmentManager.h
Go to the documentation of this file.
1 /*
2  * FragmentManager.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.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 #ifndef FRAGMENTMANAGER_H_
23 #define FRAGMENTMANAGER_H_
24 
25 #include "Component.h"
26 #include "core/EventReceiver.h"
27 #include "storage/BundleResult.h"
29 #include <ibrdtn/data/MetaBundle.h>
30 #include <ibrcommon/thread/Queue.h>
31 #include <ibrcommon/thread/Mutex.h>
32 #include <list>
33 #include <set>
34 
35 namespace dtn
36 {
37  namespace core
38  {
39  class FragmentationAbortedException : public ibrcommon::Exception
40  {
41  public:
42  FragmentationAbortedException(string what = "Fragmentation aborted.") throw() : ibrcommon::Exception(what)
43  {
44  }
45  };
46 
48  {
49  public:
50  FragmentationProhibitedException(string what = "Fragmentation is prohibited.") throw() : FragmentationAbortedException(what)
51  {
52  }
53  };
54 
56  {
57  public:
58  FragmentationNotNecessaryException(string what = "Fragmentation is not necessary.") throw() : FragmentationAbortedException(what)
59  {
60  }
61  };
62 
63  class FragmentManager : public dtn::daemon::IndependentComponent, public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>
64  {
65  static const std::string TAG;
66 
67  public:
69  virtual ~FragmentManager();
70 
71  void __cancellation() throw ();
72 
73  void componentUp() throw ();
74  void componentRun() throw ();
75  void componentDown() throw ();
76 
77  void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
78 
79  const std::string getName() const;
80 
87  static void setOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id, const dtn::data::Length &abs_offset, const dtn::data::Length &frag_offset) throw ();
88 
95  static dtn::data::Length getOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id) throw ();
96 
103  static void split(const dtn::data::Bundle &bundle, const dtn::data::Length &maxPayloadLength, std::list<dtn::data::Bundle> &fragments) throw (FragmentationAbortedException);
104 
105  private:
106  class Transmission
107  {
108  public:
109  Transmission();
110  virtual ~Transmission();
111 
112  bool operator<(const Transmission &other) const;
113  bool operator==(const Transmission &other) const;
114 
115  dtn::data::EID peer;
117  dtn::data::Length offset;
118  dtn::data::Timestamp expires;
119  };
120 
121  static void expire_offsets(const dtn::data::Timestamp &timestamp);
122  static dtn::data::Length get_payload_offset(const dtn::data::Bundle &bundle, const dtn::data::Length &abs_offset, const dtn::data::Length &frag_offset) throw ();
123 
132  static void addBlocksFromBundleToFragment(const dtn::data::Bundle &bundle, dtn::data::Bundle &fragment, dtn::data::PayloadBlock &fragment_payloadBlock, bool isFirstFragment, bool isLastFragment);
133 
134  // search for similar bundles in the storage
135  void search(const dtn::data::MetaBundle &meta, dtn::storage::BundleResult &list);
136 
137  ibrcommon::Queue<dtn::data::MetaBundle> _incoming;
138  bool _running;
139 
140  static ibrcommon::Mutex _offsets_mutex;
141  static std::set<Transmission> _offsets;
142  };
143  } /* namespace core */
144 } /* namespace dtn */
145 #endif /* FRAGMENTMANAGER_H_ */
static void split(const dtn::data::Bundle &bundle, const dtn::data::Length &maxPayloadLength, std::list< dtn::data::Bundle > &fragments)
size_t Length
Definition: Number.h:33
FragmentationProhibitedException(string what="Fragmentation is prohibited.")
static void setOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id, const dtn::data::Length &abs_offset, const dtn::data::Length &frag_offset)
const std::string getName() const
FragmentationAbortedException(string what="Fragmentation aborted.")
FragmentationNotNecessaryException(string what="Fragmentation is not necessary.")
void raiseEvent(const dtn::routing::QueueBundleEvent &evt)
static dtn::data::Length getOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id)