00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_ENCOUNTER_H_
00018 #define _PROPHET_ENCOUNTER_H_
00019
00020 #include "Link.h"
00021 #include "BaseTLV.h"
00022 #include "HelloTLV.h"
00023 #include "ProphetTLV.h"
00024 #include "Oracle.h"
00025 #include "Table.h"
00026 #include "Dictionary.h"
00027 #include "BundleTLVEntryList.h"
00028 #include "Alarm.h"
00029
00030 namespace prophet
00031 {
00032
00050 class Encounter : public ExpirationHandler
00051 {
00052 public:
00053 typedef enum {
00054 UNDEFINED_STATE = 0,
00055 WAIT_NB,
00056 SYNSENT,
00057 SYNRCVD,
00058 ESTAB,
00059 WAIT_DICT,
00060 WAIT_RIB,
00061 OFFER,
00062 CREATE_DR,
00063 SEND_DR,
00064 REQUEST,
00065 WAIT_INFO
00066 } state_t;
00067
00068 static const char* state_to_str(state_t st) {
00069 switch(st) {
00070 #define CASE(_state) case _state: return # _state
00071 CASE(WAIT_NB);
00072 CASE(SYNSENT);
00073 CASE(SYNRCVD);
00074 CASE(ESTAB);
00075 CASE(WAIT_DICT);
00076 CASE(WAIT_RIB);
00077 CASE(OFFER);
00078 CASE(CREATE_DR);
00079 CASE(SEND_DR);
00080 CASE(REQUEST);
00081 CASE(WAIT_INFO);
00082 #undef CASE
00083 default: return "Unknown State";
00084 }
00085 }
00089 Encounter(const Link* nexthop, Oracle* oracle, u_int16_t instance);
00090
00094 Encounter(const Encounter& e);
00095
00099 ~Encounter();
00100
00102 bool operator< (const Encounter& e) const
00103 {
00104 return remote_instance_ < e.remote_instance_;
00105 }
00107
00109 u_int16_t remote_instance() const { return remote_instance_; }
00110 u_int16_t local_instance() const { return local_instance_; }
00111 const char* remote_eid() const { return next_hop_->remote_eid(); }
00112 const Link* nexthop() const { return next_hop_; }
00113 state_t state() const { return state_; }
00114 const char* state_str() const { return state_to_str(state_); }
00115 bool neighbor_gone() const { return neighbor_gone_; }
00116 u_int time_remaining() const { return alarm_->time_remaining(); }
00118
00123 void hello_interval_changed();
00124
00131 bool receive_tlv(ProphetTLV* tlv);
00132
00137 void handle_timeout();
00138
00142 void handle_bundle_received(const Bundle* b);
00143
00144 protected:
00145
00147 bool dispatch_tlv(BaseTLV* tlv);
00148 bool handle_hello_tlv(BaseTLV* hello);
00149 bool handle_ribd_tlv(BaseTLV* ribd);
00150 bool handle_rib_tlv(BaseTLV* rib);
00151 bool handle_offer_tlv(BaseTLV* offer);
00152 bool handle_response_tlv(BaseTLV* response);
00154
00156 bool send_hello(HelloTLV::hello_hf_t hf,
00157 ProphetTLV::header_result_t hr = ProphetTLV::NoSuccessAck,
00158 u_int32_t tid = 0);
00159 bool send_dictionary_rib(ProphetTLV::header_result_t hr =
00160 ProphetTLV::NoSuccessAck,
00161 u_int32_t tid = 0);
00162 bool send_offer(ProphetTLV::header_result_t hr = ProphetTLV::NoSuccessAck,
00163 u_int32_t tid = 0);
00164 bool send_response(ProphetTLV::header_result_t hr =
00165 ProphetTLV::NoSuccessAck,
00166 u_int32_t tid = 0);
00167 bool send_tlv(ProphetTLV* tlv);
00169
00170 Oracle* const oracle_;
00171 u_int16_t local_instance_;
00172 u_int16_t remote_instance_;
00173 u_int32_t tid_;
00174 u_int32_t next_tid_;
00175 u_int32_t timeout_;
00176 const Link* next_hop_;
00177 ProphetTLV* tlv_;
00178 const bool synsender_;
00179 state_t state_;
00180 bool synsent_;
00181 bool estab_;
00182 volatile bool neighbor_gone_;
00183 Dictionary local_ribd_;
00184 Dictionary remote_ribd_;
00185 BundleOfferList remote_offers_;
00186 BundleResponseList local_response_;
00187 Table remote_nodes_;
00188 u_int hello_rate_;
00189 u_int32_t data_sent_;
00190 u_int32_t data_rcvd_;
00191 Alarm* alarm_;
00192 };
00193
00194 };
00195
00196 #endif // _PROPHET_ENCOUNTER_H_