00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef HAVE_CONFIG_H
00019 # include <dtn-config.h>
00020 #endif
00021
00022 #include "GbofId.h"
00023 #include <sstream>
00024
00025
00026
00027 namespace oasys {
00028
00029
00030 template<>
00031 const char*
00032 InlineFormatter<dtn::GbofId>
00033 ::format(const dtn::GbofId& id)
00034 {
00035 if (! id.is_fragment_) {
00036 buf_.appendf("<%s, %u.%u>",
00037 id.source_.c_str(),
00038 id.creation_ts_.seconds_,
00039 id.creation_ts_.seqno_);
00040 } else {
00041 buf_.appendf("<%s, %u.%u, FRAG len %u offset %u>",
00042 id.source_.c_str(),
00043 id.creation_ts_.seconds_,
00044 id.creation_ts_.seqno_,
00045 id.frag_length_, id.frag_offset_);
00046 }
00047 return buf_.c_str();
00048 }
00049 }
00050
00051 namespace dtn {
00052
00053
00054 GbofId::GbofId()
00055 {
00056 }
00057
00058
00059 GbofId::GbofId(EndpointID source,
00060 BundleTimestamp creation_ts,
00061 bool is_fragment,
00062 u_int32_t frag_length,
00063 u_int32_t frag_offset)
00064 : source_(source),
00065 creation_ts_(creation_ts),
00066 is_fragment_(is_fragment),
00067 frag_length_(frag_length),
00068 frag_offset_(frag_offset)
00069 {
00070 }
00071
00072
00073 GbofId::~GbofId()
00074 {
00075 }
00076
00077
00078 bool
00079 GbofId::equals(const GbofId& id) const
00080 {
00081 if (creation_ts_.seconds_ == id.creation_ts_.seconds_ &&
00082 creation_ts_.seqno_ == id.creation_ts_.seqno_ &&
00083 is_fragment_ == id.is_fragment_ &&
00084 (!is_fragment_ ||
00085 (frag_length_ == id.frag_length_ && frag_offset_ == id.frag_offset_)) &&
00086 source_.equals(id.source_))
00087 {
00088 return true;
00089 } else {
00090 return false;
00091 }
00092 }
00093
00094
00095 bool
00096 GbofId::operator<(const GbofId& other) const
00097 {
00098 if (source_ < other.source_) return true;
00099 if (other.source_ < source_) return false;
00100
00101 if (creation_ts_ < other.creation_ts_) return true;
00102 if (creation_ts_ > other.creation_ts_) return false;
00103
00104 if (is_fragment_ && !other.is_fragment_) return true;
00105 if (!is_fragment_ && other.is_fragment_) return false;
00106
00107 if (is_fragment_) {
00108 if (frag_length_ < other.frag_length_) return true;
00109 if (other.frag_length_ < frag_length_) return false;
00110
00111 if (frag_offset_ < other.frag_offset_) return true;
00112 if (other.frag_offset_ < frag_offset_) return false;
00113 }
00114
00115 return false;
00116 }
00117
00118
00119 bool
00120 GbofId::equals(EndpointID source,
00121 BundleTimestamp creation_ts,
00122 bool is_fragment,
00123 u_int32_t frag_length,
00124 u_int32_t frag_offset) const
00125 {
00126 if (creation_ts_.seconds_ == creation_ts.seconds_ &&
00127 creation_ts_.seqno_ == creation_ts.seqno_ &&
00128 is_fragment_ == is_fragment &&
00129 (!is_fragment ||
00130 (frag_length_ == frag_length && frag_offset_ == frag_offset)) &&
00131 source_.equals(source))
00132 {
00133 return true;
00134 } else {
00135 return false;
00136 }
00137 }
00138
00139
00140 std::string
00141 GbofId::str() const
00142 {
00143 std::ostringstream oss;
00144
00145 oss << source_.str() << ","
00146 << creation_ts_.seconds_ << ","
00147 << creation_ts_.seqno_ << ","
00148 << is_fragment_ << ","
00149 << frag_length_ << ","
00150 << frag_offset_;
00151
00152 return oss.str();
00153 }
00154
00155 }