00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_NODE_H_
00018 #define _PROPHET_NODE_H_
00019
00020 #include <sys/types.h>
00021 #include <string>
00022 #include "PointerList.h"
00023
00024 namespace prophet
00025 {
00026
00027
00028 class Table;
00029 class RIBTLV;
00030 class NodeHeap;
00031
00036 struct NodeParams
00037 {
00041 static const double DEFAULT_P_ENCOUNTER;
00042
00046 static const double DEFAULT_BETA;
00047
00051 static const double DEFAULT_GAMMA;
00052
00057 static const u_int DEFAULT_KAPPA;
00058
00059 NodeParams()
00060 : encounter_(DEFAULT_P_ENCOUNTER),
00061 beta_(DEFAULT_BETA),
00062 gamma_(DEFAULT_GAMMA),
00063 kappa_(DEFAULT_KAPPA) {}
00064
00065 virtual ~NodeParams() {}
00066
00067 double encounter_;
00068 double beta_;
00069 double gamma_;
00070 u_int kappa_;
00071 };
00072
00079 class Node
00080 {
00081 public:
00082 static const bool DEFAULT_RELAY = true;
00083 static const bool DEFAULT_CUSTODY = true;
00084 static const bool DEFAULT_INTERNET = false;
00088 Node(const NodeParams* params = NULL);
00089
00093 Node(const Node& node);
00094
00098 Node(const std::string& dest_id,
00099 bool relay = DEFAULT_RELAY,
00100 bool custody = DEFAULT_CUSTODY,
00101 bool internet = DEFAULT_INTERNET,
00102 const NodeParams* params = NULL);
00103
00107 virtual ~Node();
00108
00110 double p_value() const { return p_value_; }
00111 bool relay() const { return relay_; }
00112 bool custody() const { return custody_; }
00113 bool internet_gw() const { return internet_gateway_; }
00114 virtual const char* dest_id() const { return dest_id_.c_str(); }
00115 u_int32_t age() const { return age_; }
00116 const NodeParams* params() const { return params_; }
00118
00122 Node& operator= (const Node& n)
00123 {
00124 p_value_ = n.p_value_;
00125 relay_ = n.relay_;
00126 custody_ = n.custody_;
00127 internet_gateway_ = n.internet_gateway_;
00128 dest_id_.assign(n.dest_id_);
00129 age_ = n.age_;
00130 delete params_;
00131 params_ = new NodeParams(*n.params_);
00132 heap_pos_ = n.heap_pos_;
00133 return *this;
00134 }
00135
00139 void update_pvalue();
00140
00145 void update_transitive(double ab, double bc);
00146
00151 void update_age();
00152
00154 size_t heap_pos() { return heap_pos_; }
00155 void set_heap_pos(size_t pos) { heap_pos_ = pos; }
00157
00158 protected:
00159 friend class Table;
00160 friend class RIBTLV;
00161
00163 void set_pvalue( double d )
00164 {
00165 if ( d >= 0.0 && d <= 1.0 ) p_value_ = d;
00166 };
00167 void set_relay( bool relay ) { relay_ = relay; }
00168 void set_custody( bool custody ) { custody_ = custody; }
00169 void set_internet_gw( bool gw ) { internet_gateway_ = gw; }
00170 virtual void set_dest_id( const std::string& eid )
00171 {
00172 dest_id_.assign(eid);
00173 }
00174 void set_age( u_int32_t age ) { age_ = age; }
00175 void set_params( const NodeParams* params )
00176 {
00177 delete params_;
00178 if (params != NULL)
00179 params_ = new NodeParams(*params);
00180 else
00181
00182 params_ = new NodeParams();
00183 }
00185
00190 u_int time_to_units(u_int32_t diff) const;
00191
00192 const NodeParams* params_;
00193 double p_value_;
00194 bool relay_;
00195 bool custody_;
00196 bool internet_gateway_;
00197 std::string dest_id_;
00198 u_int32_t age_;
00199 size_t heap_pos_;
00200 };
00201
00206 class RIBNode : public Node
00207 {
00208 public:
00212 RIBNode(const Node* node, u_int16_t sid)
00213 : Node(*node), sid_(sid) {}
00214
00218 RIBNode(u_int16_t sid = 0)
00219 : Node(), sid_(sid) {}
00220
00224 RIBNode(const RIBNode& a)
00225 : Node(a), sid_(a.sid_) {}
00226
00230 virtual ~RIBNode() {}
00231
00235 RIBNode& operator= (const RIBNode& a)
00236 {
00237 Node::operator=(a);
00238 sid_ = a.sid_;
00239 return *this;
00240 }
00241
00242 u_int16_t sid_;
00243 };
00244
00245 typedef PointerList<Node> NodeList;
00246 typedef PointerList<RIBNode> RIBNodeList;
00247
00248 };
00249
00250 #endif // _PROPHET_NODE_H_