00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _LINK_H_
00018 #define _LINK_H_
00019
00020 #include <set>
00021 #include <oasys/debug/Formatter.h>
00022 #include <oasys/serialize/Serialize.h>
00023
00024 #include "bundling/BundleList.h"
00025 #include "naming/EndpointID.h"
00026
00027 #include "Contact.h"
00028
00029 namespace dtn {
00030
00031 class ConvergenceLayer;
00032 class CLInfo;
00033 class Contact;
00034 class Link;
00035
00039 class LinkSet : public std::set<Link*> {};
00040
00093 class Link : public oasys::Formatter,
00094 public oasys::Logger,
00095 public oasys::SerializableObject {
00096 public:
00100 typedef enum
00101 {
00102 LINK_INVALID = -1,
00103
00109 ALWAYSON = 1,
00110
00118 ONDEMAND = 2,
00119
00123 SCHEDULED = 3,
00124
00131 OPPORTUNISTIC = 4
00132 }
00133 link_type_t;
00134
00138 static inline const char*
00139 link_type_to_str(link_type_t type)
00140 {
00141 switch(type) {
00142 case ALWAYSON: return "ALWAYSON";
00143 case ONDEMAND: return "ONDEMAND";
00144 case SCHEDULED: return "SCHEDULED";
00145 case OPPORTUNISTIC: return "OPPORTUNISTIC";
00146 default: PANIC("bogus link_type_t");
00147 }
00148 }
00149
00150 static inline link_type_t
00151 str_to_link_type(const char* str)
00152 {
00153 if (strcasecmp(str, "ALWAYSON") == 0)
00154 return ALWAYSON;
00155
00156 if (strcasecmp(str, "ONDEMAND") == 0)
00157 return ONDEMAND;
00158
00159 if (strcasecmp(str, "SCHEDULED") == 0)
00160 return SCHEDULED;
00161
00162 if (strcasecmp(str, "OPPORTUNISTIC") == 0)
00163 return OPPORTUNISTIC;
00164
00165 return LINK_INVALID;
00166 }
00167
00171 typedef enum {
00172 UNAVAILABLE = 1,
00173
00174
00175 AVAILABLE = 2,
00176
00177
00178
00179
00180
00181
00182 OPENING = 4,
00183
00184
00185 OPEN = 8,
00186
00187
00188
00189
00190
00191
00192
00193 BUSY = 16,
00194
00195
00196
00197
00198 CLOSED = 32
00199
00200
00201
00202
00203 } state_t;
00204
00208 static inline const char*
00209 state_to_str(state_t state)
00210 {
00211 switch(state) {
00212 case UNAVAILABLE: return "UNAVAILABLE";
00213 case AVAILABLE: return "AVAILABLE";
00214 case OPENING: return "OPENING";
00215 case OPEN: return "OPEN";
00216 case BUSY: return "BUSY";
00217 case CLOSED: return "CLOSED";
00218 }
00219
00220 NOTREACHED;
00221 }
00222
00226 static Link* create_link(const std::string& name, link_type_t type,
00227 ConvergenceLayer* cl, const char* nexthop,
00228 int argc, const char* argv[],
00229 const char** invalid_argp = NULL);
00233 Link(const std::string& name, link_type_t type,
00234 ConvergenceLayer* cl, const char* nexthop);
00235
00239 Link(const oasys::Builder& b);
00240
00244 void serialize(oasys::SerializeAction* action);
00245
00249 virtual int parse_args(int argc, const char* argv[],
00250 const char** invalidp = NULL);
00251
00256 virtual void set_initial_state();
00257
00261 link_type_t type() { return static_cast<link_type_t>(type_); }
00262
00266 const char* type_str() { return link_type_to_str(
00267 static_cast<link_type_t>(type_)); }
00268
00272 bool isopen() { return ( (state_ == OPEN) ||
00273 (state_ == BUSY) ); }
00274
00278 bool isavailable() { return (state_ != UNAVAILABLE); }
00279
00283 bool isbusy() { return (state_ == BUSY); }
00284
00288 bool isopening() { return (state_ == OPENING); }
00289
00293 state_t state() { return static_cast<state_t>(state_); }
00294
00308 void set_state(state_t state);
00309
00313 const ContactRef& contact() const { return contact_; }
00314
00318 void set_contact(Contact* contact)
00319 {
00320
00321 ASSERT(contact_ == NULL);
00322 contact_ = contact;
00323 }
00324
00328 void set_cl_info(CLInfo* cl_info)
00329 {
00330 ASSERT((cl_info_ == NULL && cl_info != NULL) ||
00331 (cl_info_ != NULL && cl_info == NULL));
00332
00333 cl_info_ = cl_info;
00334 }
00335
00339 CLInfo* cl_info() const { return cl_info_; }
00340
00344 ConvergenceLayer* clayer() const { return clayer_; }
00345
00349 const char* name() const { return name_.c_str(); }
00350
00354 const std::string& name_str() const { return name_; }
00355
00359 const char* local() const { return local_.c_str(); }
00360
00364 void set_local(const std::string& local) { local_.assign(local); }
00365
00369 const char* nexthop() const { return nexthop_.c_str(); }
00370
00374 void set_nexthop(const std::string& nexthop) { nexthop_.assign(nexthop); }
00375
00379 bool is_reliable() const { return reliable_; }
00380
00384 void set_reliable(bool r) { reliable_ = r; }
00385
00389 void set_remote_eid(const EndpointID& remote) {
00390 remote_eid_.assign(remote);
00391 }
00392
00396 const EndpointID& remote_eid() { return remote_eid_; }
00397
00401 BundleList* queue() { return &queue_; }
00402
00406 int format(char* buf, size_t sz) const;
00407
00411 void dump(oasys::StringBuffer* buf);
00412
00413
00414
00415
00416 struct Params {
00420 Params();
00421
00425 u_int mtu_;
00426
00434 u_int min_retry_interval_;
00435
00443 u_int max_retry_interval_;
00444
00452 u_int idle_close_time_;
00453
00458 bool prevhop_hdr_;
00459 };
00460
00466 u_int retry_interval_;
00467
00471 const Params& params() { return params_; }
00472
00473
00474
00475
00476 struct Stats {
00480 u_int contact_attempts_;
00481
00486 u_int contacts_;
00487
00491 u_int bundles_transmitted_;
00492
00497 u_int bytes_transmitted_;
00498
00502 u_int bundles_queued_;
00503
00508 u_int bytes_queued_;
00509
00513 u_int bundles_inflight_;
00514
00519 u_int bytes_inflight_;
00520 };
00521
00525 Stats* stats() { return &stats_; }
00526
00530 void reset_stats() const
00531 {
00532 memset(&stats_, 0, sizeof(stats_));
00533 }
00534
00538 void dump_stats(oasys::StringBuffer* buf);
00539
00540 protected:
00541 friend class BundleActions;
00542 friend class BundleDaemon;
00543 friend class ContactManager;
00544 friend class ParamCommand;
00545
00551 virtual void open();
00552
00558 virtual void close();
00559
00561 int type_;
00562
00564 int state_;
00565
00567 std::string local_;
00568
00570 std::string nexthop_;
00571
00573 std::string name_;
00574
00576 bool reliable_;
00577
00579 Params params_;
00580
00582 static Params default_params_;
00583
00585 BundleList queue_;
00586
00588 mutable Stats stats_;
00589
00591 ContactRef contact_;
00592
00594 ConvergenceLayer* clayer_;
00595
00597 CLInfo* cl_info_;
00598
00600 EndpointID remote_eid_;
00601
00603 virtual ~Link();
00604 };
00605
00606 }
00607
00608 #endif