IBR-DTNSuite  0.10
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 
14 namespace dtn
15 {
16  namespace routing
17  {
19  {
20  public:
22  virtual ~SchedulingBundleIndex();
23 
24  virtual void add(const dtn::data::MetaBundle &b);
25  virtual void remove(const dtn::data::BundleID &id);
26 
34 
39  virtual const std::set<dtn::data::EID> getDistinctDestinations();
40 
41  private:
42  struct CMP_BUNDLE_PRIORITY
43  {
44  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
45  {
46  if (lhs.net_priority > rhs.net_priority)
47  return true;
48  if (lhs.net_priority != rhs.net_priority)
49  return false;
50 
51  if (lhs.getPriority() > rhs.getPriority())
52  return true;
53  if (lhs.getPriority() != rhs.getPriority())
54  return false;
55 
56  if (lhs.expiretime < rhs.expiretime)
57  return true;
58  if (lhs.expiretime != rhs.expiretime)
59  return false;
60 
61 
62  // use payloadlength for not fragmented bundles and
63  // appdatalength for fragments
64  dtn::data::Number complete_payloadlength_lhs, complete_payloadlength_rhs;
65 
66  if (lhs.fragment)
67  complete_payloadlength_lhs = lhs.appdatalength;
68  else
69  complete_payloadlength_lhs = lhs.payloadlength;
70 
71  if (rhs.fragment)
72  complete_payloadlength_rhs = rhs.appdatalength;
73  else
74  complete_payloadlength_rhs = rhs.payloadlength;
75 
76 
77  if (complete_payloadlength_lhs < complete_payloadlength_rhs)
78  return true;
79  if (complete_payloadlength_lhs != complete_payloadlength_rhs)
80  return false;
81 
82  return lhs < rhs;
83  }
84  };
85 
86  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> priority_index;
87  priority_index _priority_index;
88  };
89  } /* namespace routing */
90 } /* namespace dtn */
91 #endif /* SCHEDULINGBUNDLEINDEX_H_ */