source: source/ariba/overlay/SequenceNumber.cpp@ 12764

Last change on this file since 12764 was 12060, checked in by hock@…, 11 years ago

Reintegrate branch: 20130111-hock-message_classes

improvements:

  • new message classes (reboost, zero-copy)
  • "fast path" for direct links (skip overlay layer)
  • link-properties accessible from the application
  • SystemQueue can call boost::bind functions
  • protlib compatibility removed (32bit overhead saved in every message)
  • addressing2
  • AddressDiscovery discoveres only addresses on which we're actually listening
  • ariba serialization usage reduced (sill used in OverlayMsg)
  • Node::connect, easier and cleaner interface to start-up ariba from the application
  • ariba configs via JSON, XML, etc (boost::property_tree)
  • keep-alive overhead greatly reduced
  • (relayed) overlay links can actually be closed now
  • lost messages are detected in most cases
  • notification to the application when link is transformed into direct-link
  • overlay routing: send message to second best hop if it would be dropped otherwise
  • SequenceNumbers (only mechanisms, so for: upward compatibility)
  • various small fixes


regressions:

  • bluetooth is not yet working again
  • bootstrap modules deactivated
  • liblog4xx is not working (use cout-logging)

This patch brings great performance and stability improvements at cost of backward compatibility.
Also bluetooth and the bootstrap modules have not been ported to the new interfaces, yet.

File size: 3.3 KB
Line 
1
2#include "SequenceNumber.h"
3#include <ctime>
4#include <limits>
5
6namespace ariba {
7namespace overlay {
8
9/** static initializers **/
10// DISABLED_SEQNUM const
11const SequenceNumber SequenceNumber::DISABLED;
12
13// seed the RNG
14boost::mt19937 SequenceNumber::rng_32bit(std::time(NULL));
15
16boost::uniform_int<uint32_t> SequenceNumber::seqnum_distribution_32bit(
17 MIN_SEQ_NUM, std::numeric_limits<uint32_t>::max());
18
19boost::uniform_int<uint32_t> SequenceNumber::distribution_full32bit(
20 0, std::numeric_limits<uint32_t>::max());
21
22
23
24/** class implementation **/
25SequenceNumber::SequenceNumber():
26 seqnum_32(SEQ_NUM_DISABLED),
27 seqnum_64(SEQ_NUM_DISABLED)
28{
29}
30SequenceNumber::SequenceNumber(uint32_t seqnum):
31 seqnum_32(seqnum),
32 seqnum_64(SEQ_NUM_DISABLED)
33{
34}
35SequenceNumber::SequenceNumber(uint64_t seqnum):
36 seqnum_32(SEQ_NUM_DISABLED),
37 seqnum_64(seqnum)
38{
39}
40
41
42SequenceNumber SequenceNumber::createRandomSeqNum_Short()
43{
44 uint32_t num = seqnum_distribution_32bit(rng_32bit);
45 return SequenceNumber(num);
46}
47
48SequenceNumber SequenceNumber::createRandomSeqNum_Long()
49{
50 uint64_t num = distribution_full32bit(rng_32bit);
51 num << 32;
52 num += seqnum_distribution_32bit(rng_32bit);
53
54 return SequenceNumber(num);
55}
56
57bool SequenceNumber::isShortSeqNum() const
58{
59 return seqnum_32 >= MIN_SEQ_NUM && seqnum_64 == SEQ_NUM_DISABLED;
60}
61
62bool SequenceNumber::isLongSeqNum() const
63{
64 return seqnum_32 == SEQ_NUM_DISABLED && seqnum_64 >= MIN_SEQ_NUM;
65}
66
67bool SequenceNumber::isDisabled() const
68{
69 return seqnum_32 == SEQ_NUM_DISABLED && seqnum_64 == SEQ_NUM_DISABLED;
70}
71
72bool SequenceNumber::isValid() const
73{
74 return isShortSeqNum() || isLongSeqNum();
75}
76
77void SequenceNumber::increment()
78{
79 // BRANCH: short seqnum
80 if ( isShortSeqNum() )
81 {
82 seqnum_32++;
83
84 // wrap overflow
85 if ( seqnum_32 < MIN_SEQ_NUM )
86 {
87 seqnum_32 = MIN_SEQ_NUM;
88 }
89 }
90
91 // BRANCH: long seqnum
92 else if ( isLongSeqNum() )
93 {
94 seqnum_64++;
95
96 // wrap overflow
97 if ( seqnum_64 < MIN_SEQ_NUM )
98 {
99 seqnum_64 = MIN_SEQ_NUM;
100 }
101 }
102}
103
104bool SequenceNumber::operator==(const SequenceNumber& rhs) const
105{
106 return seqnum_32 + seqnum_64 == rhs.seqnum_32 + rhs.seqnum_64;
107}
108
109bool SequenceNumber::operator<(const SequenceNumber& rhs) const
110{
111 return seqnum_32 + seqnum_64 < rhs.seqnum_32 + rhs.seqnum_64;
112}
113
114bool SequenceNumber::isSuccessor(const SequenceNumber& rhs)
115{
116 // TODO implement
117
118 return false;
119}
120
121bool SequenceNumber::isPredecessor(const SequenceNumber& rhs)
122{
123 // TODO implement
124
125 return false;
126}
127
128uint32_t SequenceNumber::getShortSeqNum() const
129{
130 return seqnum_32;
131}
132
133uint64_t SequenceNumber::getLongSeqNum() const
134{
135 return seqnum_64;
136}
137
138
139std::ostream& operator<<(std::ostream& stream, const SequenceNumber& rhs)
140{
141 if ( rhs.isDisabled() )
142 {
143 return stream << "DISABLED";
144 }
145
146 else if ( ! rhs.isValid() )
147 {
148 return stream << "INVALID";
149 }
150
151 else if ( rhs.isShortSeqNum() )
152 {
153 return stream << rhs.seqnum_32;
154 }
155
156 else if ( rhs.isLongSeqNum() )
157 {
158 return stream << rhs.seqnum_64;
159 }
160
161 else
162 {
163 return stream << "ERROR";
164 }
165}
166
167}} // [namespace ariba::overlay]
Note: See TracBrowser for help on using the repository browser.