IBR-DTNSuite  0.10
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"
28 #include <ibrdtn/data/MetaBundle.h>
29 #include <ibrcommon/thread/Queue.h>
30 #include <ibrcommon/thread/Mutex.h>
31 #include <list>
32 #include <set>
33 
34 namespace dtn
35 {
36  namespace core
37  {
39  {
40  public:
41  FragmentationAbortedException(string what = "Fragmentation aborted.") throw() : ibrcommon::Exception(what)
42  {
43  }
44  };
45 
47  {
48  public:
49  FragmentationProhibitedException(string what = "Fragmentation is prohibited.") throw() : FragmentationAbortedException(what)
50  {
51  }
52  };
53 
55  {
56  public:
57  FragmentationNotNecessaryException(string what = "Fragmentation is not necessary.") throw() : FragmentationAbortedException(what)
58  {
59  }
60  };
61 
63  {
64  static const std::string TAG;
65 
66  public:
68  virtual ~FragmentManager();
69 
70  void signal(const dtn::data::MetaBundle &meta);
71 
72  void __cancellation() throw ();
73 
74  void componentUp() throw ();
75  void componentRun() throw ();
76  void componentDown() throw ();
77 
78  void raiseEvent(const Event *evt) throw ();
79 
80  const std::string getName() const;
81 
88  static void setOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id, const dtn::data::Length &abs_offset) throw ();
89 
96  static dtn::data::Length getOffset(const dtn::data::EID &peer, const dtn::data::BundleID &id) throw ();
97 
104  static void split(const dtn::data::Bundle &bundle, const dtn::data::Length &maxPayloadLength, std::list<dtn::data::Bundle> &fragments) throw (FragmentationAbortedException);
105 
106  private:
107  class Transmission
108  {
109  public:
110  Transmission();
111  virtual ~Transmission();
112 
113  bool operator<(const Transmission &other) const;
114  bool operator==(const Transmission &other) const;
115 
116  dtn::data::EID peer;
118  dtn::data::Length offset;
119  dtn::data::Timestamp expires;
120  };
121 
122  static void expire_offsets(const dtn::data::Timestamp &timestamp);
123  static dtn::data::Length get_payload_offset(const dtn::data::Bundle &bundle, const dtn::data::Length &abs_offset) throw ();
124 
133  static void addBlocksFromBundleToFragment(const dtn::data::Bundle &bundle, dtn::data::Bundle &fragment, dtn::data::PayloadBlock &fragment_payloadBlock, bool isFirstFragment, bool isLastFragment);
134 
135  // search for similar bundles in the storage
136  void search(const dtn::data::MetaBundle &meta, dtn::storage::BundleResult &list);
137 
139  bool _running;
140 
141  static ibrcommon::Mutex _offsets_mutex;
142  static std::set<Transmission> _offsets;
143  };
144  } /* namespace core */
145 } /* namespace dtn */
146 #endif /* FRAGMENTMANAGER_H_ */