IBR-DTNSuite  0.12
SchedulingBundleIndex.h
Go to the documentation of this file.
1 /*
2  * SchedulingBundleIndex.h
3  *
4  * Created on: 21.01.2013
5  * Author: morgenro
6  */
7 
8 #ifndef SCHEDULINGBUNDLEINDEX_H_
9 #define SCHEDULINGBUNDLEINDEX_H_
10 
11 #include "storage/BundleIndex.h"
12 #include <ibrdtn/data/Number.h>
13 #include <ibrcommon/thread/Mutex.h>
14 
15 namespace dtn
16 {
17  namespace routing
18  {
20  {
21  public:
23  virtual ~SchedulingBundleIndex();
24 
25  virtual void add(const dtn::data::MetaBundle &b);
26  virtual void remove(const dtn::data::BundleID &id);
27 
35 
40  virtual const std::set<dtn::data::EID> getDistinctDestinations();
41 
42  private:
43  struct CMP_BUNDLE_PRIORITY
44  {
45  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
46  {
47  if (lhs.net_priority > rhs.net_priority)
48  return true;
49  if (lhs.net_priority != rhs.net_priority)
50  return false;
51 
52  if (lhs.getPriority() > rhs.getPriority())
53  return true;
54  if (lhs.getPriority() != rhs.getPriority())
55  return false;
56 
57  if (lhs.expiretime < rhs.expiretime)
58  return true;
59  if (lhs.expiretime != rhs.expiretime)
60  return false;
61 
62 
63  // use payloadlength for not fragmented bundles and
64  // appdatalength for fragments
65  dtn::data::Length complete_payloadlength_lhs, complete_payloadlength_rhs;
66 
67  if (lhs.isFragment())
68  complete_payloadlength_lhs = lhs.appdatalength.get<dtn::data::Length>();
69  else
70  complete_payloadlength_lhs = lhs.getPayloadLength();
71 
72  if (rhs.isFragment())
73  complete_payloadlength_rhs = rhs.appdatalength.get<dtn::data::Length>();
74  else
75  complete_payloadlength_rhs = rhs.getPayloadLength();
76 
77 
78  if (complete_payloadlength_lhs < complete_payloadlength_rhs)
79  return true;
80  if (complete_payloadlength_lhs != complete_payloadlength_rhs)
81  return false;
82 
83  return lhs < rhs;
84  }
85  };
86 
87  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> priority_index;
88  priority_index _priority_index;
89  ibrcommon::Mutex _index_mutex;
90  };
91  } /* namespace routing */
92 } /* namespace dtn */
93 #endif /* SCHEDULINGBUNDLEINDEX_H_ */