Kea  2.3.5-git
serial.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <dns/serial.h>
10 
11 namespace isc {
12 namespace dns {
13 
14 bool
15 Serial::operator==(const Serial& other) const {
16  return (value_ == other.getValue());
17 }
18 
19 bool
20 Serial::operator!=(const Serial& other) const {
21  return (value_ != other.getValue());
22 }
23 
24 bool
25 Serial::operator<(const Serial& other) const {
26  uint32_t other_val = other.getValue();
27  bool result = false;
28  if (value_ < other_val) {
29  result = ((other_val - value_) <= MAX_SERIAL_INCREMENT);
30  } else if (other_val < value_) {
31  result = ((value_ - other_val) > MAX_SERIAL_INCREMENT);
32  }
33  return (result);
34 }
35 
36 bool
37 Serial::operator<=(const Serial& other) const {
38  return (operator==(other) || operator<(other));
39 }
40 
41 bool
42 Serial::operator>(const Serial& other) const {
43  return (!operator==(other) && !operator<(other));
44 }
45 
46 bool
47 Serial::operator>=(const Serial& other) const {
48  return (!operator<(other));
49 }
50 
51 Serial
52 Serial::operator+(uint32_t other_val) const {
53  uint64_t new_val = static_cast<uint64_t>(value_) +
54  static_cast<uint64_t>(other_val);
55  return Serial(static_cast<uint32_t>(new_val % MAX_SERIAL_VALUE));
56 }
57 
58 Serial
59 Serial::operator+(const Serial& other) const {
60  return (operator+(other.getValue()));
61 }
62 
63 std::ostream&
64 operator<<(std::ostream& os, const Serial& serial) {
65  return (os << serial.getValue());
66 }
67 
68 } // end namespace dns
69 } // end namespace isc
70 
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
bool operator>=(const Serial &other) const
Returns true if the serial value of this serial is equal to or greater than the other, according to serial arithmetic as described in RFC 1982.
Definition: serial.cc:47
This class defines DNS serial numbers and serial arithmetic.
Definition: serial.h:41
uint32_t getValue() const
Returns the uint32_t representation of this serial value.
Definition: serial.h:67
const uint64_t MAX_SERIAL_VALUE
Maximum value a serial can have, used in + operator.
Definition: serial.h:22
bool operator<(const Serial &other) const
Returns true if the serial value of this serial is smaller than the other, according to serial arithm...
Definition: serial.cc:25
bool operator==(const Serial &other) const
Returns true if the serial values are equal.
Definition: serial.cc:15
Defines the logger used by the top-level component of kea-lfc.
bool operator!=(const Serial &other) const
Returns true if the serial values are not equal.
Definition: serial.cc:20
const uint32_t MAX_SERIAL_INCREMENT
The maximum difference between two serial numbers.
Definition: serial.h:19
bool operator>(const Serial &other) const
Returns true if the serial value of this serial is greater than the other, according to serial arithm...
Definition: serial.cc:42
Serial operator+(const Serial &other) const
Adds the given value to the serial number.
Definition: serial.cc:59
Serial(uint32_t value)
Constructor with value.
Definition: serial.h:46
bool operator<=(const Serial &other) const
Returns true if the serial value of this serial is equal to or smaller than the other, according to serial arithmetic as described in RFC 1982.
Definition: serial.cc:37