Link.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _LINK_H_
00039 #define _LINK_H_
00040 
00041 #include <set>
00042 #include <oasys/debug/Formatter.h>
00043 #include <oasys/serialize/Serialize.h>
00044 
00045 #include "bundling/BundleList.h"
00046 #include "naming/EndpointID.h"
00047 
00048 #include "Contact.h"
00049 
00050 namespace dtn {
00051 
00052 class ConvergenceLayer;
00053 class CLInfo;
00054 class Contact;
00055 class Link;
00056 
00060 class LinkSet : public std::set<Link*> {};
00061 
00114 class Link : public oasys::Formatter,
00115              public oasys::Logger,
00116              public oasys::SerializableObject {
00117 public:
00121     typedef enum
00122     {
00123         LINK_INVALID = -1,
00124         
00130         ALWAYSON = 1,
00131         
00139         ONDEMAND = 2,
00140         
00144         SCHEDULED = 3,
00145         
00152         OPPORTUNISTIC = 4
00153     }
00154     link_type_t;
00155 
00159     static inline const char*
00160     link_type_to_str(link_type_t type)
00161     {
00162         switch(type) {
00163         case ALWAYSON:          return "ALWAYSON";
00164         case ONDEMAND:          return "ONDEMAND";
00165         case SCHEDULED:         return "SCHEDULED";
00166         case OPPORTUNISTIC:     return "OPPORTUNISTIC";
00167         default:                PANIC("bogus link_type_t");
00168         }
00169     }
00170 
00171     static inline link_type_t
00172     str_to_link_type(const char* str)
00173     {
00174         if (strcasecmp(str, "ALWAYSON") == 0)
00175             return ALWAYSON;
00176         
00177         if (strcasecmp(str, "ONDEMAND") == 0)
00178             return ONDEMAND;
00179         
00180         if (strcasecmp(str, "SCHEDULED") == 0)
00181             return SCHEDULED;
00182         
00183         if (strcasecmp(str, "OPPORTUNISTIC") == 0)
00184             return OPPORTUNISTIC;
00185         
00186         return LINK_INVALID;
00187     }
00188 
00192     typedef enum {
00193         UNAVAILABLE = 1,
00194 
00195 
00196         AVAILABLE = 2,  
00197 
00198 
00199 
00200 
00201 
00202         
00203         OPENING = 4,    
00204 
00205         
00206         OPEN = 8,       
00207 
00208 
00209 
00210 
00211 
00212 
00213         
00214         BUSY = 16,      
00215 
00216 
00217 
00218 
00219         CLOSED = 32     
00220 
00221 
00222 
00223         
00224     } state_t;
00225 
00229     static inline const char*
00230     state_to_str(state_t state)
00231     {
00232         switch(state) {
00233         case UNAVAILABLE:       return "UNAVAILABLE";
00234         case AVAILABLE:         return "AVAILABLE";
00235         case OPENING:           return "OPENING";
00236         case OPEN:              return "OPEN";
00237         case BUSY:              return "BUSY";
00238         case CLOSED:            return "CLOSED";
00239         }
00240 
00241         NOTREACHED;
00242     }
00243     
00247     static Link* create_link(const std::string& name, link_type_t type,
00248                              ConvergenceLayer* cl, const char* nexthop,
00249                              int argc, const char* argv[],
00250                              const char** invalid_argp = NULL);
00254     Link(const std::string& name, link_type_t type,
00255          ConvergenceLayer* cl, const char* nexthop);
00256 
00260     Link(const oasys::Builder& b);
00261     
00265     void serialize(oasys::SerializeAction* action);
00266 
00270     virtual int parse_args(int argc, const char* argv[],
00271                            const char** invalidp = NULL);
00272 
00277     virtual void set_initial_state();
00278 
00282     link_type_t type() { return type_; }
00283 
00287     const char* type_str() { return link_type_to_str(type_); }
00288 
00292     bool isopen() { return ( (state_ == OPEN) ||
00293                              (state_ == BUSY) ); }
00294 
00298     bool isavailable() { return (state_ != UNAVAILABLE); }
00299 
00303     bool isbusy() { return (state_ == BUSY); }
00304 
00308     bool isopening() { return (state_ == OPENING); }
00309     
00313     state_t state() { return state_; }
00314 
00328     void set_state(state_t state);
00329 
00333     const ContactRef& contact() const { return contact_; }
00334 
00338     void set_contact(Contact* contact)
00339     {
00340         // XXX/demmer check this invariant
00341         ASSERT(contact_ == NULL);
00342         contact_ = contact;
00343     }
00344 
00348     void set_cl_info(CLInfo* cl_info)
00349     {
00350         ASSERT((cl_info_ == NULL && cl_info != NULL) ||
00351                (cl_info_ != NULL && cl_info == NULL));
00352         
00353         cl_info_ = cl_info;
00354     }
00355 
00359     CLInfo* cl_info() const { return cl_info_; }
00360     
00364     ConvergenceLayer* clayer() const { return clayer_; }
00365 
00369     const char* name() const { return name_.c_str(); }
00370 
00374     const std::string& name_str() const { return name_; }
00375 
00379     const char* local() const { return local_.c_str(); }
00380 
00384     void set_local(const std::string& local) { local_.assign(local); }
00385 
00389     const char* nexthop() const { return nexthop_.c_str(); }
00390 
00394     void set_nexthop(const std::string& nexthop) { nexthop_.assign(nexthop); }
00395 
00399     bool is_reliable() const { return reliable_; }
00400 
00404     void set_reliable(bool r) { reliable_ = r; }
00405 
00409     void set_remote_eid(const EndpointID& remote) {
00410         remote_eid_.assign(remote);
00411     }
00412 
00416     const EndpointID& remote_eid() { return remote_eid_; }
00417 
00421     int format(char* buf, size_t sz) const;
00422 
00426     void dump(oasys::StringBuffer* buf);
00427 
00428     /**************************************************************
00429      * Link Parameters
00430      */
00431     struct Params {
00435         u_int mtu_;
00436          
00444         u_int min_retry_interval_;
00445     
00453         u_int max_retry_interval_;
00454 
00462         u_int idle_close_time_;
00463     };
00464 
00470     u_int retry_interval_;
00471 
00475     const Params& params() { return params_; }
00476 
00477     /*************************************************************
00478      * Link Statistics
00479      */
00480     struct Stats {
00484         u_int contact_attempts_;
00485         
00490         u_int contacts_;
00491         
00495         u_int bundles_transmitted_;
00496 
00501         u_int bytes_transmitted_;
00502 
00506         u_int bundles_inflight_;
00507 
00512         u_int bytes_inflight_;
00513     };
00514     
00518     Stats* stats() { return &stats_; }
00519 
00523     void reset_stats() const
00524     {
00525         memset(&stats_, 0, sizeof(stats_));
00526     }
00527 
00531     void dump_stats(oasys::StringBuffer* buf);
00532 
00533 protected:
00534     friend class BundleActions;
00535     friend class BundleDaemon;
00536     friend class ContactManager;
00537     friend class ParamCommand;
00538     
00544     virtual void open();
00545     
00551     virtual void close();
00552 
00554     link_type_t type_;
00555 
00557     state_t state_;
00558 
00560     std::string local_;
00561     
00563     std::string nexthop_;
00564     
00566     std::string name_;
00567 
00569     bool reliable_;
00570 
00572     Params params_;
00573 
00575     static Params default_params_;
00576 
00578     mutable Stats stats_;
00579 
00581     ContactRef contact_;
00582 
00584     ConvergenceLayer* clayer_;
00585 
00587     CLInfo* cl_info_;
00588 
00590     EndpointID remote_eid_;
00591 
00593     virtual ~Link();
00594 };
00595 
00596 } // namespace dtn
00597 
00598 #endif /* _LINK_H_ */

Generated on Fri Dec 22 14:47:59 2006 for DTN Reference Implementation by  doxygen 1.5.1