servlib/bundling/BundleEvent.h
changeset 0 2b3e5ec03512
child 5 1849bf57d910
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _BUNDLE_EVENT_H_
       
    18 #define _BUNDLE_EVENT_H_
       
    19 
       
    20 #include "Bundle.h"
       
    21 #include "BundleProtocol.h"
       
    22 #include "BundleRef.h"
       
    23 #include "BundleList.h"
       
    24 #include "CustodySignal.h"
       
    25 #include "contacts/Link.h"
       
    26 #include "contacts/NamedAttribute.h"
       
    27 #include "GbofId.h"
       
    28 
       
    29 namespace dtn {
       
    30 
       
    31 /**
       
    32  * All signaling from various components to the routing layer is done
       
    33  * via the Bundle Event message abstraction. This file defines the
       
    34  * event type codes and corresponding classes.
       
    35  */
       
    36 
       
    37 class Bundle;
       
    38 class Contact;
       
    39 class Interface;
       
    40 class Registration;
       
    41 class RouteEntry;
       
    42 
       
    43 /**
       
    44  * Type codes for events / requests.
       
    45  */
       
    46 typedef enum {
       
    47     BUNDLE_RECEIVED = 0x1,      ///< New bundle arrival
       
    48     BUNDLE_TRANSMITTED,         ///< Bundle or fragment successfully sent
       
    49     BUNDLE_DELIVERED,           ///< Bundle locally delivered
       
    50     BUNDLE_DELIVERY,            ///< Bundle delivery (with payload)
       
    51     BUNDLE_EXPIRED,             ///< Bundle expired
       
    52     BUNDLE_NOT_NEEDED,          ///< Bundle no longer needed
       
    53     BUNDLE_FREE,                ///< No more references to the bundle
       
    54     BUNDLE_FORWARD_TIMEOUT,     ///< A Mapping timed out
       
    55     BUNDLE_SEND,                ///< Send a bundle
       
    56     BUNDLE_CANCEL,              ///< Cancel a bundle transmission
       
    57     BUNDLE_CANCELLED,           ///< Bundle send cancelled
       
    58     BUNDLE_INJECT,              ///< Inject a bundle
       
    59     BUNDLE_INJECTED,            ///< A bundle was injected
       
    60     BUNDLE_ACCEPT_REQUEST,      ///< Request acceptance of a new bundle
       
    61     BUNDLE_DELETE,              ///< Request deletion of a bundle
       
    62     BUNDLE_QUERY,               ///< Bundle query
       
    63     BUNDLE_REPORT,              ///< Response to bundle query
       
    64     BUNDLE_ATTRIB_QUERY,        ///< Query for a bundle's attributes
       
    65     BUNDLE_ATTRIB_REPORT,       ///< Report with bundle attributes
       
    66 
       
    67     CONTACT_UP,                 ///< Contact is up
       
    68     CONTACT_DOWN,               ///< Contact abnormally terminated
       
    69     CONTACT_QUERY,              ///< Contact query
       
    70     CONTACT_REPORT,             ///< Response to contact query
       
    71     CONTACT_ATTRIB_CHANGED,     ///< An attribute changed
       
    72 
       
    73     LINK_CREATED,               ///< Link is created into the system
       
    74     LINK_DELETED,               ///< Link is deleted from the system
       
    75     LINK_AVAILABLE,             ///< Link is available
       
    76     LINK_UNAVAILABLE,           ///< Link is unavailable
       
    77     LINK_BUSY,                  ///< Link is busy 
       
    78     LINK_CREATE,                ///< Create and open a new link
       
    79     LINK_DELETE,                ///< Delete a link
       
    80     LINK_RECONFIGURE,           ///< Reconfigure a link
       
    81     LINK_QUERY,                 ///< Link query
       
    82     LINK_REPORT,                ///< Response to link query
       
    83     LINK_ATTRIB_CHANGED,        ///< An attribute changed
       
    84 
       
    85     LINK_STATE_CHANGE_REQUEST,  ///< Link state should be changed
       
    86 
       
    87     REASSEMBLY_COMPLETED,       ///< Reassembly completed
       
    88 
       
    89     REGISTRATION_ADDED,         ///< New registration arrived
       
    90     REGISTRATION_REMOVED,       ///< Registration removed
       
    91     REGISTRATION_EXPIRED,       ///< Registration expired
       
    92     REGISTRATION_DELETE,	///< Registration to be deleted
       
    93 
       
    94     ROUTE_ADD,                  ///< Add a new entry to the route table
       
    95     ROUTE_DEL,                  ///< Remove an entry from the route table
       
    96     ROUTE_QUERY,                ///< Static route query
       
    97     ROUTE_REPORT,               ///< Response to static route query
       
    98 
       
    99     CUSTODY_SIGNAL,             ///< Custody transfer signal received
       
   100     CUSTODY_TIMEOUT,            ///< Custody transfer timer fired
       
   101 
       
   102     DAEMON_SHUTDOWN,            ///< Shut the daemon down cleanly
       
   103     DAEMON_STATUS,              ///< No-op event to check the daemon
       
   104 
       
   105     CLA_SET_PARAMS,             ///< Set CLA configuration
       
   106     CLA_PARAMS_SET,             ///< CLA configuration changed
       
   107     CLA_SET_LINK_DEFAULTS,      ///< Set defaults for new links
       
   108     CLA_EID_REACHABLE,          ///< A new EID has been discovered
       
   109 
       
   110     CLA_BUNDLE_QUEUED_QUERY,    ///< Query if a bundle is queued at the CLA
       
   111     CLA_BUNDLE_QUEUED_REPORT,   ///< Report if a bundle is queued at the CLA
       
   112     CLA_EID_REACHABLE_QUERY,    ///< Query if an EID is reachable by the CLA
       
   113     CLA_EID_REACHABLE_REPORT,   ///< Report if an EID is reachable by the CLA
       
   114     CLA_LINK_ATTRIB_QUERY,      ///< Query CLA for a link's attributes
       
   115     CLA_LINK_ATTRIB_REPORT,     ///< Report from CLA with link attributes
       
   116     CLA_IFACE_ATTRIB_QUERY,     ///< Query CLA for an interface's attributes
       
   117     CLA_IFACE_ATTRIB_REPORT,    ///< Report from CLA with interface attributes
       
   118     CLA_PARAMS_QUERY,           ///< Query CLA for config parameters
       
   119     CLA_PARAMS_REPORT,          ///< Report from CLA with config paramters
       
   120 
       
   121 } event_type_t;
       
   122 
       
   123 /**
       
   124  * Conversion function from an event to a string.
       
   125  */
       
   126 inline const char*
       
   127 event_to_str(event_type_t event)
       
   128 {
       
   129     switch(event) {
       
   130 
       
   131     case BUNDLE_RECEIVED:       return "BUNDLE_RECEIVED";
       
   132     case BUNDLE_TRANSMITTED:    return "BUNDLE_TRANSMITTED";
       
   133     case BUNDLE_DELIVERED:      return "BUNDLE_DELIVERED";
       
   134     case BUNDLE_DELIVERY:       return "BUNDLE_DELIVERY";
       
   135     case BUNDLE_EXPIRED:        return "BUNDLE_EXPIRED";
       
   136     case BUNDLE_FREE:           return "BUNDLE_FREE";
       
   137     case BUNDLE_NOT_NEEDED:     return "BUNDLE_NOT_NEEDED";
       
   138     case BUNDLE_FORWARD_TIMEOUT:return "BUNDLE_FORWARD_TIMEOUT";
       
   139     case BUNDLE_SEND:           return "BUNDLE_SEND";
       
   140     case BUNDLE_CANCEL:         return "BUNDLE_CANCEL";
       
   141     case BUNDLE_CANCELLED:      return "BUNDLE_CANCELLED";
       
   142     case BUNDLE_INJECT:         return "BUNDLE_INJECT";
       
   143     case BUNDLE_INJECTED:       return "BUNDLE_INJECTED";
       
   144     case BUNDLE_ACCEPT_REQUEST: return "BUNDLE_ACCEPT_REQUEST";
       
   145     case BUNDLE_DELETE:         return "BUNDLE_DELETE";
       
   146     case BUNDLE_QUERY:          return "BUNDLE_QUERY";
       
   147     case BUNDLE_REPORT:         return "BUNDLE_REPORT";
       
   148     case BUNDLE_ATTRIB_QUERY:   return "BUNDLE_ATTRIB_QUERY";
       
   149     case BUNDLE_ATTRIB_REPORT:  return "BUNDLE_ATTRIB_REPORT";
       
   150 
       
   151     case CONTACT_UP:            return "CONTACT_UP";
       
   152     case CONTACT_DOWN:          return "CONTACT_DOWN";
       
   153     case CONTACT_QUERY:         return "CONTACT_QUERY";
       
   154     case CONTACT_REPORT:        return "CONTACT_REPORT";
       
   155     case CONTACT_ATTRIB_CHANGED:return "CONTACT_ATTRIB_CHANGED";
       
   156 
       
   157     case LINK_CREATED:          return "LINK_CREATED";
       
   158     case LINK_DELETED:          return "LINK_DELETED";
       
   159     case LINK_AVAILABLE:        return "LINK_AVAILABLE";
       
   160     case LINK_UNAVAILABLE:      return "LINK_UNAVAILABLE";
       
   161     case LINK_BUSY:             return "LINK_BUSY";
       
   162     case LINK_CREATE:           return "LINK_CREATE";
       
   163     case LINK_DELETE:           return "LINK_DELETE";
       
   164     case LINK_RECONFIGURE:      return "LINK_RECONFIGURE";
       
   165     case LINK_QUERY:            return "LINK_QUERY";
       
   166     case LINK_REPORT:           return "LINK_REPORT";
       
   167     case LINK_ATTRIB_CHANGED:   return "LINK_ATTRIB_CHANGED";
       
   168 
       
   169     case LINK_STATE_CHANGE_REQUEST:return "LINK_STATE_CHANGE_REQUEST";
       
   170 
       
   171     case REASSEMBLY_COMPLETED:  return "REASSEMBLY_COMPLETED";
       
   172 
       
   173     case REGISTRATION_ADDED:    return "REGISTRATION_ADDED";
       
   174     case REGISTRATION_REMOVED:  return "REGISTRATION_REMOVED";
       
   175     case REGISTRATION_EXPIRED:  return "REGISTRATION_EXPIRED";
       
   176     case REGISTRATION_DELETE:   return "REGISTRATION_DELETE";
       
   177 
       
   178     case ROUTE_ADD:             return "ROUTE_ADD";
       
   179     case ROUTE_DEL:             return "ROUTE_DEL";
       
   180     case ROUTE_QUERY:           return "ROUTE_QUERY";
       
   181     case ROUTE_REPORT:          return "ROUTE_REPORT";
       
   182 
       
   183     case CUSTODY_SIGNAL:        return "CUSTODY_SIGNAL";
       
   184     case CUSTODY_TIMEOUT:       return "CUSTODY_TIMEOUT";
       
   185     
       
   186     case DAEMON_SHUTDOWN:       return "SHUTDOWN";
       
   187     case DAEMON_STATUS:         return "DAEMON_STATUS";
       
   188         
       
   189     case CLA_SET_PARAMS:        return "CLA_SET_PARAMS";
       
   190     case CLA_PARAMS_SET:        return "CLA_PARAMS_SET";
       
   191     case CLA_SET_LINK_DEFAULTS: return "CLA_SET_LINK_DEFAULTS";
       
   192     case CLA_EID_REACHABLE:     return "CLA_EID_REACHABLE";
       
   193 
       
   194     case CLA_BUNDLE_QUEUED_QUERY:  return "CLA_BUNDLE_QUEUED_QUERY";
       
   195     case CLA_BUNDLE_QUEUED_REPORT: return "CLA_BUNDLE_QUEUED_REPORT";
       
   196     case CLA_EID_REACHABLE_QUERY:  return "CLA_EID_REACHABLE_QUERY";
       
   197     case CLA_EID_REACHABLE_REPORT: return "CLA_EID_REACHABLE_REPORT";
       
   198     case CLA_LINK_ATTRIB_QUERY:    return "CLA_LINK_ATTRIB_QUERY";
       
   199     case CLA_LINK_ATTRIB_REPORT:   return "CLA_LINK_ATTRIB_REPORT";
       
   200     case CLA_IFACE_ATTRIB_QUERY:   return "CLA_IFACE_ATTRIB_QUERY";
       
   201     case CLA_IFACE_ATTRIB_REPORT:  return "CLA_IFACE_ATTRIB_REPORT";
       
   202     case CLA_PARAMS_QUERY:         return "CLA_PARAMS_QUERY";
       
   203     case CLA_PARAMS_REPORT:        return "CLA_PARAMS_REPORT";
       
   204 
       
   205     default:                   return "(invalid event type)";
       
   206         
       
   207     }
       
   208 }
       
   209 
       
   210 /**
       
   211  * Possible sources for events.
       
   212  */
       
   213 typedef enum {
       
   214     EVENTSRC_PEER   = 1,        ///< a peer dtn forwarder
       
   215     EVENTSRC_APP    = 2,        ///< a local application
       
   216     EVENTSRC_STORE  = 3,        ///< the data store
       
   217     EVENTSRC_ADMIN  = 4,        ///< the admin logic
       
   218     EVENTSRC_FRAGMENTATION = 5, ///< the fragmentation engine
       
   219     EVENTSRC_ROUTER = 6         ///< the routing logic
       
   220 } event_source_t;
       
   221 
       
   222 /**
       
   223  * Conversion function from a source to a string
       
   224  * suitable for use with plug-in arch XML messaging.
       
   225  */
       
   226 inline const char*
       
   227 source_to_str(event_source_t source)
       
   228 {
       
   229     switch(source) {
       
   230 
       
   231     case EVENTSRC_PEER:             return "peer";
       
   232     case EVENTSRC_APP:              return "application";
       
   233     case EVENTSRC_STORE:            return "dataStore";
       
   234     case EVENTSRC_ADMIN:            return "admin";
       
   235     case EVENTSRC_FRAGMENTATION:    return "fragmentation";
       
   236     case EVENTSRC_ROUTER:           return "router";
       
   237 
       
   238     default:                        return "(invalid source type)";
       
   239     }
       
   240 }
       
   241 
       
   242 class MetadataBlockRequest {
       
   243 public:
       
   244     enum QueryType { QueryByIdentifier, QueryByType, QueryAll };
       
   245 
       
   246     MetadataBlockRequest(QueryType query_type, unsigned int query_value) :
       
   247         _query_type(query_type), _query_value(query_value) { }
       
   248 
       
   249     int          query_type()  const { return _query_type; }
       
   250     unsigned int query_value() const { return _query_value; }
       
   251 
       
   252 private:
       
   253     QueryType    _query_type;
       
   254     unsigned int _query_value;
       
   255 };
       
   256 typedef std::vector<MetadataBlockRequest> MetaBlockRequestVector;
       
   257 
       
   258 /**
       
   259  * Event base class.
       
   260  */
       
   261 class BundleEvent {
       
   262 public:
       
   263     /**
       
   264      * The event type code.
       
   265      */
       
   266     const event_type_t type_;
       
   267 
       
   268     /**
       
   269      * Bit indicating whether this event is for the daemon only or if
       
   270      * it should be propagated to other components (i.e. the various
       
   271      * routers).
       
   272      */
       
   273     bool daemon_only_;
       
   274 
       
   275     /**
       
   276      * Slot for a notifier to indicate that the event was processed.
       
   277      */
       
   278     oasys::Notifier* processed_notifier_;
       
   279 
       
   280     /**
       
   281      * Slot to record the time that the event was put into the queue.
       
   282      */
       
   283     oasys::Time posted_time_;
       
   284 
       
   285     /**
       
   286      * Used for printing
       
   287      */
       
   288     const char* type_str() {
       
   289         return event_to_str(type_);
       
   290     }
       
   291 
       
   292     /**
       
   293      * Need a virtual destructor to make sure all the right bits are
       
   294      * cleaned up.
       
   295      */
       
   296     virtual ~BundleEvent() {}
       
   297 
       
   298 protected:
       
   299     /**
       
   300      * Constructor (protected since one of the subclasses should
       
   301      * always be that which is actually initialized.
       
   302      */
       
   303     BundleEvent(event_type_t type)
       
   304         : type_(type),
       
   305           daemon_only_(false),
       
   306           processed_notifier_(NULL) {}
       
   307 };
       
   308 
       
   309 /**
       
   310  * Event class for new bundle arrivals.
       
   311  */
       
   312 class BundleReceivedEvent : public BundleEvent {
       
   313 public:
       
   314     /*
       
   315      * Constructor for bundles arriving from a peer, named by the
       
   316      * prevhop and optionally marked with the link it arrived on.
       
   317      */
       
   318     BundleReceivedEvent(Bundle*           bundle,
       
   319                         event_source_t    source,
       
   320                         u_int32_t         bytes_received,
       
   321                         const EndpointID& prevhop,
       
   322                         Link*             originator = NULL)
       
   323 
       
   324         : BundleEvent(BUNDLE_RECEIVED),
       
   325           bundleref_(bundle, "BundleReceivedEvent"),
       
   326           source_(source),
       
   327           bytes_received_(bytes_received),
       
   328           link_(originator, "BundleReceivedEvent"),
       
   329           prevhop_(prevhop),
       
   330           registration_(NULL)
       
   331     {
       
   332         ASSERT(source == EVENTSRC_PEER);
       
   333     }
       
   334 
       
   335     /*
       
   336      * Constructor for bundles arriving from a local application
       
   337      * identified by the given Registration.
       
   338      */
       
   339     BundleReceivedEvent(Bundle*        bundle,
       
   340                         event_source_t source,
       
   341                         Registration*  registration)
       
   342         : BundleEvent(BUNDLE_RECEIVED),
       
   343           bundleref_(bundle, "BundleReceivedEvent"),
       
   344           source_(source),
       
   345           bytes_received_(0),
       
   346           link_("BundleReceivedEvent"),
       
   347           prevhop_(EndpointID::NULL_EID()),
       
   348           registration_(registration)
       
   349     {
       
   350     }
       
   351 
       
   352     /*
       
   353      * Constructor for other "arriving" bundles, including reloading
       
   354      * from storage and generated signals.
       
   355      */
       
   356     BundleReceivedEvent(Bundle*        bundle,
       
   357                         event_source_t source)
       
   358         : BundleEvent(BUNDLE_RECEIVED),
       
   359           bundleref_(bundle, "BundleReceivedEvent"),
       
   360           source_(source),
       
   361           bytes_received_(0),
       
   362           link_("BundleReceivedEvent"),
       
   363           prevhop_(EndpointID::NULL_EID()),
       
   364           registration_(NULL)
       
   365     {
       
   366     }
       
   367 
       
   368     /// The newly arrived bundle
       
   369     BundleRef bundleref_;
       
   370 
       
   371     /// The source of the bundle
       
   372     int source_;
       
   373 
       
   374     /// The total bytes actually received
       
   375     u_int32_t bytes_received_;
       
   376 
       
   377     /// Link from which bundle was received, if applicable
       
   378     LinkRef link_;
       
   379 
       
   380     /// Previous hop endpoint id
       
   381     EndpointID prevhop_;
       
   382 
       
   383     /// Registration where the bundle arrived
       
   384     Registration* registration_;
       
   385 };
       
   386 
       
   387 /**
       
   388  * Event class for bundle or fragment transmission.
       
   389  */
       
   390 class BundleTransmittedEvent : public BundleEvent {
       
   391 public:
       
   392     BundleTransmittedEvent(Bundle* bundle, const ContactRef& contact,
       
   393                            const LinkRef& link, u_int32_t bytes_sent,
       
   394                            u_int32_t reliably_sent)
       
   395         : BundleEvent(BUNDLE_TRANSMITTED),
       
   396           bundleref_(bundle, "BundleTransmittedEvent"),
       
   397           contact_(contact.object(), "BundleTransmittedEvent"),
       
   398           bytes_sent_(bytes_sent),
       
   399           reliably_sent_(reliably_sent),
       
   400           link_(link.object(), "BundleTransmittedEvent") {}
       
   401 
       
   402     /// The transmitted bundle
       
   403     BundleRef bundleref_;
       
   404 
       
   405     /// The contact where the bundle was sent
       
   406     ContactRef contact_;
       
   407 
       
   408     /// Total number of bytes sent
       
   409     u_int32_t bytes_sent_;
       
   410 
       
   411     /// If the convergence layer that we sent on is reliable, this is
       
   412     /// the count of the bytes reliably sent, which must be less than
       
   413     /// or equal to the bytes transmitted
       
   414     u_int32_t reliably_sent_;
       
   415 
       
   416     /// The link over which the bundle was sent
       
   417     /// (may not have a contact when the transmission result is reported)
       
   418     LinkRef link_;
       
   419 
       
   420 };
       
   421 
       
   422 /**
       
   423  * Event class for local bundle delivery.
       
   424  */
       
   425 class BundleDeliveredEvent : public BundleEvent {
       
   426 public:
       
   427     BundleDeliveredEvent(Bundle* bundle, Registration* registration)
       
   428         : BundleEvent(BUNDLE_DELIVERED),
       
   429           bundleref_(bundle, "BundleDeliveredEvent"),
       
   430           registration_(registration) {}
       
   431 
       
   432     /// The delivered bundle
       
   433     BundleRef bundleref_;
       
   434 
       
   435     /// The registration that got it
       
   436     Registration* registration_;
       
   437 };
       
   438 
       
   439 /**
       
   440  * Event class for local bundle delivery.
       
   441  */
       
   442 class BundleDeliveryEvent : public BundleEvent {
       
   443 public:
       
   444     BundleDeliveryEvent(Bundle* bundle,
       
   445                          event_source_t source)
       
   446         : BundleEvent(BUNDLE_DELIVERY),
       
   447           bundleref_(bundle, "BundleDeliveryEvent"),
       
   448           source_(source) {}
       
   449 
       
   450     /// The bundle we're delivering
       
   451     BundleRef bundleref_;
       
   452 
       
   453     /// The source of the bundle
       
   454     int source_;
       
   455 };
       
   456 
       
   457 /**
       
   458  * Event class for bundle expiration.
       
   459  */
       
   460 class BundleExpiredEvent : public BundleEvent {
       
   461 public:
       
   462     BundleExpiredEvent(Bundle* bundle)
       
   463         : BundleEvent(BUNDLE_EXPIRED),
       
   464           bundleref_(bundle, "BundleExpiredEvent") {}
       
   465 
       
   466     /// The expired bundle
       
   467     BundleRef bundleref_;
       
   468 };
       
   469 
       
   470 /**
       
   471  * Event class for bundles that have no more references to them.
       
   472  */
       
   473 class BundleFreeEvent : public BundleEvent {
       
   474 public:
       
   475     BundleFreeEvent(Bundle* bundle)
       
   476         : BundleEvent(BUNDLE_FREE),
       
   477           bundle_(bundle)
       
   478     {
       
   479         // should be processed only by the daemon
       
   480         daemon_only_ = true;
       
   481     }
       
   482 
       
   483     /// The freed bundle
       
   484     Bundle* bundle_;
       
   485 };
       
   486 
       
   487 /**
       
   488  * Abstract class for the subset of events related to contacts and
       
   489  * links that defines a reason code enumerated type.
       
   490  */
       
   491 class ContactEvent : public BundleEvent {
       
   492 public:
       
   493     /**
       
   494      * Reason codes for contact state operations
       
   495      */
       
   496     typedef enum {
       
   497         INVALID = 0,    ///< Should not be used
       
   498         NO_INFO,        ///< No additional info
       
   499         USER,           ///< User action (i.e. console / config)
       
   500         BROKEN,         ///< Unexpected session interruption
       
   501         DISCOVERY,      ///< Dynamically discovered link
       
   502         CL_ERROR,       ///< Convergence layer protocol error
       
   503         CL_VERSION,     ///< Convergence layer version mismatch
       
   504         SHUTDOWN,       ///< Clean connection shutdown
       
   505         RECONNECT,      ///< Re-establish link after failure
       
   506         IDLE,           ///< Idle connection shut down by the CL
       
   507         TIMEOUT,        ///< Scheduled link ended duration
       
   508     } reason_t;
       
   509 
       
   510     /**
       
   511      * Reason to string conversion.
       
   512      */
       
   513     static const char* reason_to_str(int reason) {
       
   514         switch(reason) {
       
   515         case INVALID:   return "INVALID";
       
   516         case NO_INFO:   return "no additional info";
       
   517         case USER:      return "user action";
       
   518         case DISCOVERY: return "link discovery";
       
   519         case SHUTDOWN:  return "peer shut down";
       
   520         case BROKEN:    return "connection broken";
       
   521         case CL_ERROR:  return "cl protocol error";
       
   522         case CL_VERSION:return "cl version mismatch";
       
   523         case RECONNECT: return "re-establishing connection";
       
   524         case IDLE:      return "connection idle";
       
   525         case TIMEOUT:   return "schedule timed out";
       
   526         }
       
   527         NOTREACHED;
       
   528     }
       
   529 
       
   530     /// Constructor
       
   531     ContactEvent(event_type_t type, reason_t reason = NO_INFO)
       
   532         : BundleEvent(type), reason_(reason) {}
       
   533 
       
   534     int reason_;        ///< reason code for the event
       
   535 };
       
   536 
       
   537 /**
       
   538  * Event class for contact up events
       
   539  */
       
   540 class ContactUpEvent : public ContactEvent {
       
   541 public:
       
   542     ContactUpEvent(const ContactRef& contact)
       
   543         : ContactEvent(CONTACT_UP),
       
   544           contact_(contact.object(), "ContactUpEvent") {}
       
   545 
       
   546     /// The contact that is up
       
   547     ContactRef contact_;
       
   548 };
       
   549 
       
   550 /**
       
   551  * Event class for contact down events
       
   552  */
       
   553 class ContactDownEvent : public ContactEvent {
       
   554 public:
       
   555     ContactDownEvent(const ContactRef& contact, reason_t reason)
       
   556         : ContactEvent(CONTACT_DOWN, reason),
       
   557           contact_(contact.object(), "ContactDownEvent") {}
       
   558 
       
   559     /// The contact that is now down
       
   560     ContactRef contact_;
       
   561 };
       
   562 
       
   563 /**
       
   564  * Event classes for contact queries and responses
       
   565  */
       
   566 class ContactQueryRequest: public BundleEvent {
       
   567 public:
       
   568     ContactQueryRequest() : BundleEvent(CONTACT_QUERY)
       
   569     {
       
   570         // should be processed only by the daemon
       
   571         daemon_only_ = true;
       
   572     }
       
   573 };
       
   574 
       
   575 class ContactReportEvent : public BundleEvent {
       
   576 public:
       
   577     ContactReportEvent() : BundleEvent(CONTACT_REPORT) {}
       
   578 };
       
   579 
       
   580 /**
       
   581  * Event class for a change in contact attributes.
       
   582  */
       
   583 class ContactAttributeChangedEvent: public ContactEvent {
       
   584 public:
       
   585     ContactAttributeChangedEvent(const ContactRef& contact, reason_t reason)
       
   586         : ContactEvent(CONTACT_ATTRIB_CHANGED, reason),
       
   587           contact_(contact.object(), "ContactAttributeChangedEvent") {}
       
   588 
       
   589     ///< The link/contact that changed
       
   590     ContactRef contact_;
       
   591 };
       
   592 
       
   593 /**
       
   594  * Event class for link creation events
       
   595  */
       
   596 class LinkCreatedEvent : public ContactEvent {
       
   597 public:
       
   598     LinkCreatedEvent(const LinkRef& link, reason_t reason = ContactEvent::USER)
       
   599         : ContactEvent(LINK_CREATED, reason),
       
   600           link_(link.object(), "LinkCreatedEvent") {}
       
   601 
       
   602     /// The link that was created
       
   603     LinkRef link_;
       
   604 };
       
   605 
       
   606 /**
       
   607  * Event class for link deletion events
       
   608  */
       
   609 class LinkDeletedEvent : public ContactEvent {
       
   610 public:
       
   611     LinkDeletedEvent(const LinkRef& link, reason_t reason = ContactEvent::USER)
       
   612         : ContactEvent(LINK_DELETED, reason),
       
   613           link_(link.object(), "LinkDeletedEvent") {}
       
   614 
       
   615     /// The link that was deleted
       
   616     LinkRef link_;
       
   617 };
       
   618 
       
   619 /**
       
   620  * Event class for link available events
       
   621  */
       
   622 class LinkAvailableEvent : public ContactEvent {
       
   623 public:
       
   624     LinkAvailableEvent(const LinkRef& link, reason_t reason)
       
   625         : ContactEvent(LINK_AVAILABLE, reason),
       
   626           link_(link.object(), "LinkAvailableEvent") {}
       
   627 
       
   628     /// The link that is available
       
   629     LinkRef link_;
       
   630 };
       
   631 
       
   632 /**
       
   633  * Event class for link unavailable events
       
   634  */
       
   635 class LinkUnavailableEvent : public ContactEvent {
       
   636 public:
       
   637     LinkUnavailableEvent(const LinkRef& link, reason_t reason)
       
   638         : ContactEvent(LINK_UNAVAILABLE, reason),
       
   639           link_(link.object(), "LinkUnavailableEvent") {}
       
   640 
       
   641     /// The link that is unavailable
       
   642     LinkRef link_;
       
   643 };
       
   644 
       
   645 /**
       
   646  * Request class for link state change requests that are sent to the
       
   647  * daemon thread for processing. This includes requests to open or
       
   648  * close the link, and changing its status to available or
       
   649  * unavailable.
       
   650  *
       
   651  * When closing a link, a reason must be given for the event.
       
   652  */
       
   653 class LinkStateChangeRequest : public ContactEvent {
       
   654 public:
       
   655     /// Shared type code for state_t with Link
       
   656     typedef Link::state_t state_t;
       
   657 
       
   658     LinkStateChangeRequest(const LinkRef& link, state_t state, reason_t reason)
       
   659         : ContactEvent(LINK_STATE_CHANGE_REQUEST, reason),
       
   660           link_(link.object(), "LinkStateChangeRequest"),
       
   661           state_(state), contact_("LinkStateChangeRequest")
       
   662     {
       
   663         daemon_only_ = true;
       
   664         
       
   665         contact_   = link->contact();
       
   666         old_state_ = link->state();
       
   667     }
       
   668 
       
   669     LinkStateChangeRequest(const oasys::Builder&,
       
   670                            state_t state, reason_t reason)
       
   671         : ContactEvent(LINK_STATE_CHANGE_REQUEST, reason),
       
   672           state_(state), contact_("LinkStateChangeRequest")
       
   673     {
       
   674         daemon_only_ = true;
       
   675     }
       
   676 
       
   677     /// The link to be changed
       
   678     LinkRef link_;
       
   679 
       
   680     /// Requested state
       
   681     int state_;
       
   682     
       
   683     /// The active Contact when the request was made
       
   684     ContactRef contact_;
       
   685 
       
   686     /// State when the request was made
       
   687     int old_state_;
       
   688 };
       
   689 
       
   690 /**
       
   691  * Event class for new registration arrivals.
       
   692  */
       
   693 class RegistrationAddedEvent : public BundleEvent {
       
   694 public:
       
   695     RegistrationAddedEvent(Registration* reg, event_source_t source)
       
   696         : BundleEvent(REGISTRATION_ADDED), registration_(reg),
       
   697           source_(source) {}
       
   698 
       
   699     /// The newly added registration
       
   700     Registration* registration_;
       
   701 
       
   702     /// Why is the registration added
       
   703     int source_;
       
   704 };
       
   705 
       
   706 /**
       
   707  * Event class for registration removals.
       
   708  */
       
   709 class RegistrationRemovedEvent : public BundleEvent {
       
   710 public:
       
   711     RegistrationRemovedEvent(Registration* reg)
       
   712         : BundleEvent(REGISTRATION_REMOVED), registration_(reg) {}
       
   713 
       
   714     /// The to-be-removed registration
       
   715     Registration* registration_;
       
   716 };
       
   717 
       
   718 /**
       
   719  * Event class for registration expiration.
       
   720  */
       
   721 class RegistrationExpiredEvent : public BundleEvent {
       
   722 public:
       
   723     RegistrationExpiredEvent(Registration* registration)
       
   724         : BundleEvent(REGISTRATION_EXPIRED),
       
   725           registration_(registration) {}
       
   726     
       
   727     /// The to-be-removed registration 
       
   728     Registration* registration_;
       
   729 };
       
   730 
       
   731 /**
       
   732  * Daemon-only event class used to delete a registration after it's
       
   733  * removed or expired.
       
   734  */
       
   735 class RegistrationDeleteRequest : public BundleEvent {
       
   736 public:
       
   737     RegistrationDeleteRequest(Registration* registration)
       
   738         : BundleEvent(REGISTRATION_DELETE),
       
   739           registration_(registration)
       
   740     {
       
   741         daemon_only_ = true;
       
   742     }
       
   743 
       
   744     /// The registration to be deleted
       
   745     Registration* registration_;
       
   746 };
       
   747 
       
   748 /**
       
   749  * Event class for route add events
       
   750  */
       
   751 class RouteAddEvent : public BundleEvent {
       
   752 public:
       
   753     RouteAddEvent(RouteEntry* entry)
       
   754         : BundleEvent(ROUTE_ADD), entry_(entry) {}
       
   755 
       
   756     /// The route table entry to be added
       
   757     RouteEntry* entry_;
       
   758 };
       
   759 
       
   760 /**
       
   761  * Event class for route delete events
       
   762  */
       
   763 class RouteDelEvent : public BundleEvent {
       
   764 public:
       
   765     RouteDelEvent(const EndpointIDPattern& dest)
       
   766         : BundleEvent(ROUTE_DEL), dest_(dest) {}
       
   767 
       
   768     /// The destination eid to be removed
       
   769     EndpointIDPattern dest_;
       
   770 };
       
   771 
       
   772 /**
       
   773  * Event classes for static route queries and responses
       
   774  */
       
   775 class RouteQueryRequest: public BundleEvent {
       
   776 public:
       
   777     RouteQueryRequest() : BundleEvent(ROUTE_QUERY)
       
   778     {
       
   779         // should be processed only by the daemon
       
   780         daemon_only_ = true;
       
   781     }
       
   782 };
       
   783 
       
   784 class RouteReportEvent : public BundleEvent {
       
   785 public:
       
   786     RouteReportEvent() : BundleEvent(ROUTE_REPORT) {}
       
   787 };
       
   788 
       
   789 /**
       
   790  * Event class for reassembly completion.
       
   791  */
       
   792 class ReassemblyCompletedEvent : public BundleEvent {
       
   793 public:
       
   794     ReassemblyCompletedEvent(Bundle* bundle, BundleList* fragments)
       
   795         : BundleEvent(REASSEMBLY_COMPLETED),
       
   796           bundle_(bundle, "ReassemblyCompletedEvent"),
       
   797           fragments_("ReassemblyCompletedEvent")
       
   798     {
       
   799         fragments->move_contents(&fragments_);
       
   800     }
       
   801 
       
   802     /// The newly reassembled bundle
       
   803     BundleRef bundle_;
       
   804 
       
   805     /// The list of bundle fragments
       
   806     BundleList fragments_;
       
   807 };
       
   808 
       
   809 /**
       
   810  * Event class for custody transfer signal arrivals.
       
   811  */
       
   812 class CustodySignalEvent : public BundleEvent {
       
   813 public:
       
   814     CustodySignalEvent(const CustodySignal::data_t& data)
       
   815         : BundleEvent(CUSTODY_SIGNAL), data_(data) {}
       
   816     
       
   817     /// The parsed data from the custody transfer signal
       
   818     CustodySignal::data_t data_;
       
   819 };
       
   820 
       
   821 /**
       
   822  * Event class for custody transfer timeout events
       
   823  */
       
   824 class CustodyTimeoutEvent : public BundleEvent {
       
   825 public:
       
   826     CustodyTimeoutEvent(Bundle* bundle, const LinkRef& link)
       
   827         : BundleEvent(CUSTODY_TIMEOUT),
       
   828           bundle_(bundle, "CustodyTimeoutEvent"),
       
   829           link_(link.object(), "CustodyTimeoutEvent") {}
       
   830 
       
   831     ///< The bundle whose timer fired
       
   832     BundleRef bundle_;
       
   833 
       
   834     ///< The link it was sent on
       
   835     LinkRef link_;
       
   836 };
       
   837 
       
   838 /**
       
   839  * Event class for shutting down a daemon. The daemon closes and
       
   840  * deletes all links, then cleanly closes the various data stores,
       
   841  * then calls exit().
       
   842  */
       
   843 class ShutdownRequest : public BundleEvent {
       
   844 public:
       
   845     ShutdownRequest() : BundleEvent(DAEMON_SHUTDOWN)
       
   846     {
       
   847         daemon_only_ = true;
       
   848     }
       
   849 };
       
   850 
       
   851 /**
       
   852  * Event class for checking that the daemon is still running.
       
   853  */
       
   854 class StatusRequest : public BundleEvent {
       
   855 public:
       
   856     StatusRequest() : BundleEvent(DAEMON_STATUS)
       
   857     {
       
   858         daemon_only_ = true;
       
   859     }
       
   860 };
       
   861 
       
   862 /**
       
   863  * Event class for sending a bundle
       
   864  */
       
   865 class BundleSendRequest: public BundleEvent {
       
   866 public:
       
   867     BundleSendRequest() : BundleEvent(BUNDLE_SEND)
       
   868     {
       
   869         // should be processed only by the daemon
       
   870         daemon_only_ = true;
       
   871     }
       
   872  
       
   873     BundleSendRequest(const BundleRef& bundle,
       
   874                       const std::string& link,
       
   875                       int action)
       
   876         : BundleEvent(BUNDLE_SEND),
       
   877           bundle_(bundle.object(), "BundleSendRequest"),
       
   878           link_(link),
       
   879           action_(action)
       
   880     {
       
   881         // should be processed only by the daemon
       
   882         daemon_only_ = true;
       
   883     }
       
   884  
       
   885     ///< Bundle to be sent
       
   886     BundleRef bundle_;
       
   887 
       
   888     ///< Link on which to send the bundle
       
   889     std::string link_;
       
   890 
       
   891     ///< Forwarding action to use when sending bundle
       
   892     int action_;
       
   893 };
       
   894 
       
   895 /**
       
   896  * Event class for canceling a bundle transmission
       
   897  */
       
   898 class BundleCancelRequest: public BundleEvent {
       
   899 public:
       
   900     BundleCancelRequest() : BundleEvent(BUNDLE_CANCEL)
       
   901     {
       
   902         // should be processed only by the daemon
       
   903         daemon_only_ = true;
       
   904     }
       
   905 
       
   906     BundleCancelRequest(const BundleRef& bundle, const std::string& link) 
       
   907         : BundleEvent(BUNDLE_CANCEL),
       
   908           bundle_(bundle.object(), "BundleCancelRequest"),
       
   909           link_(link)
       
   910     {
       
   911         // should be processed only by the daemon
       
   912         daemon_only_ = true;
       
   913     }
       
   914 
       
   915     ///< Bundle to be cancelled
       
   916     BundleRef bundle_;
       
   917 
       
   918     ///< Link where the bundle is destined
       
   919     std::string link_;
       
   920 };
       
   921 
       
   922 /**
       
   923  * Event class for succesful cancellation of a bundle send.
       
   924  */
       
   925 class BundleSendCancelledEvent : public BundleEvent {
       
   926 public:
       
   927     BundleSendCancelledEvent(Bundle* bundle, const LinkRef& link)
       
   928         : BundleEvent(BUNDLE_CANCELLED),
       
   929           bundleref_(bundle, "BundleSendCancelledEvent"),
       
   930           link_(link.object(), "BundleSendCancelledEvent") {}
       
   931 
       
   932     /// The cancelled bundle
       
   933     BundleRef bundleref_;
       
   934 
       
   935     /// The link it was queued on
       
   936     LinkRef link_;
       
   937 };
       
   938 
       
   939 /**
       
   940  * Event class for injecting a bundle
       
   941  */
       
   942 class BundleInjectRequest: public BundleEvent {
       
   943 public:
       
   944     BundleInjectRequest() : BundleEvent(BUNDLE_INJECT)
       
   945     {
       
   946         // should be processed only by the daemon
       
   947         daemon_only_ = true;
       
   948     }
       
   949     
       
   950     // Bundle properties
       
   951     std::string src_;
       
   952     std::string dest_;
       
   953     std::string replyto_;
       
   954     std::string custodian_;
       
   955     u_int8_t    priority_;
       
   956     u_int32_t   expiration_;
       
   957     std::string payload_file_;
       
   958 
       
   959     // Outgoing link
       
   960     std::string link_;
       
   961 
       
   962     // Forwarding action
       
   963     int action_;
       
   964 
       
   965     // Request ID for the event, to identify corresponding BundleInjectedEvent
       
   966     std::string request_id_;
       
   967 };
       
   968 
       
   969 /**
       
   970  * Event class for a succesful bundle injection
       
   971  */
       
   972 class BundleInjectedEvent: public BundleEvent {
       
   973 public:
       
   974     BundleInjectedEvent(Bundle *bundle, const std::string &request_id)
       
   975         : BundleEvent(BUNDLE_INJECTED),
       
   976           bundleref_(bundle, "BundleInjectedEvent"),
       
   977           request_id_(request_id)
       
   978     {
       
   979     }
       
   980 
       
   981     /// The injected bundle
       
   982     BundleRef bundleref_;
       
   983 
       
   984     // Request ID from the inject request
       
   985     std::string request_id_;
       
   986 };
       
   987 
       
   988 /**
       
   989  * Event class for requestion deletion of a bundle
       
   990  */
       
   991 class BundleDeleteRequest: public BundleEvent {
       
   992 public:
       
   993     BundleDeleteRequest() : BundleEvent(BUNDLE_DELETE)
       
   994     {
       
   995         // should be processed only by the daemon
       
   996         daemon_only_ = true;
       
   997     }
       
   998 
       
   999     BundleDeleteRequest(Bundle* bundle,
       
  1000                         BundleProtocol::status_report_reason_t reason)
       
  1001         : BundleEvent(BUNDLE_DELETE),
       
  1002           bundle_(bundle, "BundleDeleteRequest"),
       
  1003           reason_(reason)
       
  1004     {
       
  1005         // should be processed only by the daemon
       
  1006         daemon_only_ = true;
       
  1007     }
       
  1008 
       
  1009     BundleDeleteRequest(const BundleRef& bundle,
       
  1010                         BundleProtocol::status_report_reason_t reason)
       
  1011         : BundleEvent(BUNDLE_DELETE),
       
  1012           bundle_(bundle.object(), "BundleDeleteRequest"),
       
  1013           reason_(reason)
       
  1014     {
       
  1015         // should be processed only by the daemon
       
  1016         daemon_only_ = true;
       
  1017     }
       
  1018 
       
  1019     ///< Bundle to be deleted
       
  1020     BundleRef bundle_;
       
  1021 
       
  1022     /// The reason code
       
  1023     BundleProtocol::status_report_reason_t reason_;
       
  1024 };
       
  1025 
       
  1026 /**
       
  1027  * Event class to optionally probe if a bundle can be accepted by the
       
  1028  * system before a BundleReceivedEvent is posted. Currently used for
       
  1029  * backpressure via the API.
       
  1030  *
       
  1031  * Note that the bundle may not be completely constructed when this
       
  1032  * event is posted. In particular, the payload need not be filled in
       
  1033  * yet, and other security fields may not be present. At a minimum
       
  1034  * though, the fields from the primary block and the payload length
       
  1035  * must be known.
       
  1036  */
       
  1037 class BundleAcceptRequest : public BundleEvent {
       
  1038 public:
       
  1039     BundleAcceptRequest(const BundleRef& bundle,
       
  1040                         event_source_t   source,
       
  1041                         bool*            result,
       
  1042                         int*             reason)
       
  1043         : BundleEvent(BUNDLE_ACCEPT_REQUEST),
       
  1044           bundle_(bundle.object(), "BundleAcceptRequest"),
       
  1045           source_(source),
       
  1046           result_(result),
       
  1047           reason_(reason)
       
  1048     {
       
  1049     }
       
  1050     
       
  1051     /// The newly arrived bundle
       
  1052     BundleRef bundle_;
       
  1053 
       
  1054     /// The source of the event
       
  1055     int source_;
       
  1056 
       
  1057     /// Pointer to the expected result
       
  1058     bool* result_;
       
  1059 
       
  1060     /// Pointer to the reason code
       
  1061     int* reason_;
       
  1062 };
       
  1063 
       
  1064 /**
       
  1065  * Event classes for bundle queries and responses
       
  1066  */
       
  1067 class BundleQueryRequest: public BundleEvent {
       
  1068 public:
       
  1069     BundleQueryRequest() : BundleEvent(BUNDLE_QUERY)
       
  1070     {
       
  1071         // should be processed only by the daemon
       
  1072         daemon_only_ = true;
       
  1073     }
       
  1074 };
       
  1075 
       
  1076 class BundleReportEvent : public BundleEvent {
       
  1077 public:
       
  1078     BundleReportEvent() : BundleEvent(BUNDLE_REPORT) {}
       
  1079 };
       
  1080 
       
  1081 class BundleAttributesQueryRequest: public BundleEvent {
       
  1082 public:
       
  1083     BundleAttributesQueryRequest(const std::string& query_id,
       
  1084                                  const BundleRef& bundle,
       
  1085                                  const AttributeNameVector& attribute_names)
       
  1086         : BundleEvent(BUNDLE_ATTRIB_QUERY),
       
  1087           query_id_(query_id),
       
  1088           bundle_(bundle.object(), "BundleAttributesQueryRequest"),
       
  1089           attribute_names_(attribute_names) {}
       
  1090 
       
  1091     /// Query Identifier
       
  1092     std::string query_id_;
       
  1093 
       
  1094     ///< Bundle being queried
       
  1095     BundleRef bundle_;
       
  1096 
       
  1097     /// bundle attributes requested by name.
       
  1098     AttributeNameVector attribute_names_;
       
  1099 
       
  1100     /// metadata blocks requested by type/identifier
       
  1101     MetaBlockRequestVector metadata_blocks_;
       
  1102 };
       
  1103 
       
  1104 class BundleAttributesReportEvent: public BundleEvent {
       
  1105 public:
       
  1106     BundleAttributesReportEvent(const std::string& query_id,
       
  1107                                 const BundleRef& bundle,
       
  1108                                 const AttributeNameVector& attribute_names,
       
  1109                                 const MetaBlockRequestVector& metadata_blocks)
       
  1110         : BundleEvent(BUNDLE_ATTRIB_REPORT),
       
  1111           query_id_(query_id),
       
  1112           bundle_(bundle.object(), "BundleAttributesReportEvent"),
       
  1113           attribute_names_(attribute_names),
       
  1114           metadata_blocks_(metadata_blocks) {}
       
  1115 
       
  1116     /// Query Identifier
       
  1117     std::string query_id_;
       
  1118 
       
  1119     /// Bundle that was queried
       
  1120     BundleRef bundle_;
       
  1121 
       
  1122     /// bundle attributes requested by name.
       
  1123     AttributeNameVector attribute_names_;
       
  1124 
       
  1125     /// metadata blocks requested by type/identifier
       
  1126     MetaBlockRequestVector metadata_blocks_;
       
  1127 };
       
  1128 
       
  1129 /**
       
  1130  * Event class for creating and opening a link
       
  1131  */
       
  1132 class LinkCreateRequest: public BundleEvent {
       
  1133 public:
       
  1134     LinkCreateRequest(const std::string &name, Link::link_type_t link_type,
       
  1135                       const std::string &endpoint,
       
  1136                       ConvergenceLayer *cla, AttributeVector &parameters)
       
  1137         : BundleEvent(LINK_CREATE),
       
  1138           name_(name),
       
  1139           endpoint_(endpoint),
       
  1140           link_type_(link_type),
       
  1141           cla_(cla),
       
  1142           parameters_(parameters)
       
  1143         
       
  1144     {
       
  1145         // should be processed only by the daemon
       
  1146         daemon_only_ = true;
       
  1147     }
       
  1148 
       
  1149     ///< Identifier for the link
       
  1150     std::string name_;
       
  1151 
       
  1152     ///< Next hop EID
       
  1153     std::string endpoint_;
       
  1154 
       
  1155     ///< Type of link
       
  1156     Link::link_type_t link_type_;
       
  1157 
       
  1158     ///< CL to use
       
  1159     ConvergenceLayer *cla_;
       
  1160 
       
  1161     ///< An optional set of key, value pairs
       
  1162     AttributeVector parameters_;
       
  1163 };
       
  1164 
       
  1165 /**
       
  1166  * Event class for reconfiguring an existing link.
       
  1167  */
       
  1168 class LinkReconfigureRequest: public BundleEvent {
       
  1169 public:
       
  1170     LinkReconfigureRequest(const LinkRef& link,
       
  1171                            AttributeVector &parameters)
       
  1172         : BundleEvent(LINK_RECONFIGURE),
       
  1173           link_(link.object(), "LinkReconfigureRequest"),
       
  1174           parameters_(parameters)
       
  1175     {
       
  1176         // should be processed only by the daemon
       
  1177         daemon_only_ = true;
       
  1178     }
       
  1179 
       
  1180     ///< The link to be changed
       
  1181     LinkRef link_;
       
  1182 
       
  1183     ///< Set of key, value pairs
       
  1184     AttributeVector parameters_;
       
  1185 };
       
  1186 
       
  1187 /**
       
  1188  * Event class for requesting deletion of a link.
       
  1189  */
       
  1190 class LinkDeleteRequest: public BundleEvent {
       
  1191 public:
       
  1192     LinkDeleteRequest(const LinkRef& link) :
       
  1193         BundleEvent(LINK_DELETE),
       
  1194         link_(link.object(), "LinkDeleteRequest")
       
  1195     {
       
  1196         // should be processed only by the daemon
       
  1197         daemon_only_ = true;
       
  1198     }
       
  1199 
       
  1200     ///< The link to be deleted
       
  1201     LinkRef link_;
       
  1202 };
       
  1203 
       
  1204 /**
       
  1205  * Event class for a change in link attributes.
       
  1206  */
       
  1207 class LinkAttributeChangedEvent: public ContactEvent {
       
  1208 public:
       
  1209     LinkAttributeChangedEvent(const LinkRef& link,
       
  1210                               AttributeVector attributes,
       
  1211                               reason_t reason = ContactEvent::NO_INFO)
       
  1212         : ContactEvent(LINK_ATTRIB_CHANGED, reason),
       
  1213           link_(link.object(), "LinkAttributeChangedEvent"),
       
  1214           attributes_(attributes)
       
  1215     {
       
  1216     }
       
  1217 
       
  1218     ///< The link that changed
       
  1219     LinkRef link_;
       
  1220 
       
  1221     ///< Attributes that changed
       
  1222     AttributeVector attributes_;
       
  1223 };
       
  1224 
       
  1225 /**
       
  1226  * Event classes for link queries and responses
       
  1227  */
       
  1228 class LinkQueryRequest: public BundleEvent {
       
  1229 public:
       
  1230     LinkQueryRequest() : BundleEvent(LINK_QUERY)
       
  1231     {
       
  1232         // should be processed only by the daemon
       
  1233         daemon_only_ = true;
       
  1234     }
       
  1235 };
       
  1236 
       
  1237 class LinkReportEvent : public BundleEvent {
       
  1238 public:
       
  1239     LinkReportEvent() : BundleEvent(LINK_REPORT) {}
       
  1240 };
       
  1241 
       
  1242 /**
       
  1243  * Event class for DP-originated CLA parameter change requests.
       
  1244  */
       
  1245 class CLASetParamsRequest : public BundleEvent {
       
  1246 public:
       
  1247     CLASetParamsRequest(ConvergenceLayer *cla, AttributeVector &parameters)
       
  1248         : BundleEvent(CLA_SET_PARAMS), cla_(cla), parameters_(parameters)
       
  1249     {
       
  1250         // should be processed only by the daemon
       
  1251         daemon_only_ = true;
       
  1252     }
       
  1253 
       
  1254     ///< CL to change
       
  1255     ConvergenceLayer *cla_;
       
  1256 
       
  1257     ///< Set of key, value pairs
       
  1258     AttributeVector parameters_;
       
  1259 };
       
  1260 
       
  1261 /**
       
  1262  * Event class for CLA parameter change request completion events.
       
  1263  */
       
  1264 class CLAParamsSetEvent : public BundleEvent {
       
  1265 public:
       
  1266     CLAParamsSetEvent(ConvergenceLayer *cla, std::string name)
       
  1267         : BundleEvent(CLA_PARAMS_SET), cla_(cla), name_(name) {}
       
  1268 
       
  1269     ///< CL that changed
       
  1270     ConvergenceLayer *cla_;
       
  1271 
       
  1272     ///< Name of CL (if cla_ is External)
       
  1273     std::string name_;
       
  1274 };
       
  1275 
       
  1276 /**
       
  1277  * Event class for DP-originated requests to set link defaults.
       
  1278  */
       
  1279 class SetLinkDefaultsRequest : public BundleEvent {
       
  1280 public:
       
  1281     SetLinkDefaultsRequest(AttributeVector &parameters)
       
  1282         : BundleEvent(CLA_SET_LINK_DEFAULTS), parameters_(parameters)
       
  1283     {
       
  1284         // should be processed only by the daemon
       
  1285         daemon_only_ = true;
       
  1286     }
       
  1287 
       
  1288     ///< Set of key, value pairs
       
  1289     AttributeVector parameters_;
       
  1290 };
       
  1291 
       
  1292 /**
       
  1293  * Event class for discovery of a new EID.
       
  1294  */
       
  1295 class NewEIDReachableEvent: public BundleEvent {
       
  1296 public:
       
  1297     NewEIDReachableEvent(Interface* iface, const std::string &endpoint)
       
  1298         : BundleEvent(CLA_EID_REACHABLE),
       
  1299           iface_(iface),
       
  1300           endpoint_(endpoint) {}
       
  1301 
       
  1302     ///< The interface the peer was discovered on
       
  1303     Interface* iface_;
       
  1304 
       
  1305     ///> The EID of the discovered peer
       
  1306     std::string endpoint_;
       
  1307 };
       
  1308 
       
  1309 /**
       
  1310  *  Event classes for queries to and reports from the CLA.
       
  1311  */
       
  1312 
       
  1313 class CLAQueryReport: public BundleEvent {
       
  1314 public:
       
  1315 
       
  1316     /// Query Identifier
       
  1317     std::string query_id_;
       
  1318 
       
  1319 protected:
       
  1320 
       
  1321     /**
       
  1322      * Constructor; protected because this class should only be
       
  1323      * instantiated via a subclass.
       
  1324      */
       
  1325     CLAQueryReport(event_type_t type,
       
  1326                    const std::string& query_id,
       
  1327                    bool daemon_only = false)
       
  1328         : BundleEvent(type),
       
  1329           query_id_(query_id)
       
  1330     {
       
  1331         daemon_only_ = daemon_only;
       
  1332     }
       
  1333 };
       
  1334 
       
  1335 class BundleQueuedQueryRequest: public CLAQueryReport {
       
  1336 public:
       
  1337     BundleQueuedQueryRequest(const std::string& query_id,
       
  1338                              Bundle* bundle,
       
  1339                              const LinkRef& link)
       
  1340         : CLAQueryReport(CLA_BUNDLE_QUEUED_QUERY, query_id, true),
       
  1341           bundle_(bundle, "BundleQueuedQueryRequest"),
       
  1342           link_(link.object(), "BundleQueuedQueryRequest") {}
       
  1343 
       
  1344     /// Bundle to be checked for queued status.
       
  1345     BundleRef bundle_;
       
  1346 
       
  1347     /// Link on which to check if the given bundle is queued.
       
  1348     LinkRef link_;
       
  1349 };
       
  1350 
       
  1351 class BundleQueuedReportEvent: public CLAQueryReport {
       
  1352 public:
       
  1353     BundleQueuedReportEvent(const std::string& query_id,
       
  1354                             bool is_queued)
       
  1355         : CLAQueryReport(CLA_BUNDLE_QUEUED_REPORT, query_id),
       
  1356           is_queued_(is_queued) {}
       
  1357 
       
  1358     /// True if the queried bundle was queued on the given link;
       
  1359     /// otherwise false.
       
  1360     bool is_queued_;
       
  1361 };
       
  1362 
       
  1363 class EIDReachableQueryRequest: public CLAQueryReport {
       
  1364 public:
       
  1365     EIDReachableQueryRequest(const std::string& query_id,
       
  1366                              Interface* iface,
       
  1367                              const std::string& endpoint)
       
  1368         : CLAQueryReport(CLA_EID_REACHABLE_QUERY, query_id, true),
       
  1369           iface_(iface),
       
  1370           endpoint_(endpoint) {}
       
  1371 
       
  1372     /// Interface on which to check if the given endpoint is reachable.
       
  1373     Interface* iface_;
       
  1374 
       
  1375     /// Endpoint to be checked for reachable status.
       
  1376     std::string endpoint_;
       
  1377 };
       
  1378 
       
  1379 class EIDReachableReportEvent: public CLAQueryReport {
       
  1380 public:
       
  1381     EIDReachableReportEvent(const std::string& query_id,
       
  1382                             bool is_reachable)
       
  1383         : CLAQueryReport(CLA_EID_REACHABLE_REPORT, query_id),
       
  1384           is_reachable_(is_reachable) {}
       
  1385 
       
  1386     /// True if the queried endpoint is reachable via the given interface;
       
  1387     /// otherwise false.
       
  1388     bool is_reachable_;
       
  1389 };
       
  1390 
       
  1391 class LinkAttributesQueryRequest: public CLAQueryReport {
       
  1392 public:
       
  1393     LinkAttributesQueryRequest(const std::string& query_id,
       
  1394                                const LinkRef& link,
       
  1395                                const AttributeNameVector& attribute_names)
       
  1396         : CLAQueryReport(CLA_LINK_ATTRIB_QUERY, query_id, true),
       
  1397           link_(link.object(), "LinkAttributesQueryRequest"),
       
  1398           attribute_names_(attribute_names) {}
       
  1399 
       
  1400     /// Link for which the given attributes are requested.
       
  1401     LinkRef link_;
       
  1402 
       
  1403     /// Link attributes requested by name.
       
  1404     AttributeNameVector attribute_names_;
       
  1405 };
       
  1406 
       
  1407 class LinkAttributesReportEvent: public CLAQueryReport {
       
  1408 public:
       
  1409     LinkAttributesReportEvent(const std::string& query_id,
       
  1410                               const AttributeVector& attributes)
       
  1411         : CLAQueryReport(CLA_LINK_ATTRIB_REPORT, query_id),
       
  1412           attributes_(attributes) {}
       
  1413 
       
  1414     /// Link attribute values given by name.
       
  1415     AttributeVector attributes_;
       
  1416 };
       
  1417 
       
  1418 class IfaceAttributesQueryRequest: public CLAQueryReport {
       
  1419 public:
       
  1420     IfaceAttributesQueryRequest(const std::string& query_id,
       
  1421                                 Interface* iface,
       
  1422                                 const AttributeNameVector& attribute_names)
       
  1423         : CLAQueryReport(CLA_IFACE_ATTRIB_QUERY, query_id, true),
       
  1424           iface_(iface),
       
  1425           attribute_names_(attribute_names) {}
       
  1426 
       
  1427     /// Interface for which the given attributes are requested.
       
  1428     Interface* iface_;
       
  1429 
       
  1430     /// Link attributes requested by name.
       
  1431     AttributeNameVector attribute_names_;
       
  1432 };
       
  1433 
       
  1434 class IfaceAttributesReportEvent: public CLAQueryReport {
       
  1435 public:
       
  1436     IfaceAttributesReportEvent(const std::string& query_id,
       
  1437                                const AttributeVector& attributes)
       
  1438         : CLAQueryReport(CLA_IFACE_ATTRIB_REPORT, query_id),
       
  1439           attributes_(attributes) {}
       
  1440 
       
  1441     /// Interface attribute values by name.
       
  1442     AttributeVector attributes_;
       
  1443 };
       
  1444 
       
  1445 class CLAParametersQueryRequest: public CLAQueryReport {
       
  1446 public:
       
  1447     CLAParametersQueryRequest(const std::string& query_id,
       
  1448                               ConvergenceLayer* cla,
       
  1449                               const AttributeNameVector& parameter_names)
       
  1450         : CLAQueryReport(CLA_PARAMS_QUERY, query_id, true),
       
  1451           cla_(cla),
       
  1452           parameter_names_(parameter_names) {}
       
  1453 
       
  1454     /// Convergence layer for which the given parameters are requested.
       
  1455     ConvergenceLayer* cla_;
       
  1456 
       
  1457     /// Convergence layer parameters requested by name.
       
  1458     AttributeNameVector parameter_names_;
       
  1459 };
       
  1460 
       
  1461 class CLAParametersReportEvent: public CLAQueryReport {
       
  1462 public:
       
  1463     CLAParametersReportEvent(const std::string& query_id,
       
  1464                              const AttributeVector& parameters)
       
  1465         : CLAQueryReport(CLA_PARAMS_REPORT, query_id),
       
  1466           parameters_(parameters) {}
       
  1467 
       
  1468     /// Convergence layer parameter values by name.
       
  1469     AttributeVector parameters_;
       
  1470 };
       
  1471 
       
  1472 } // namespace dtn
       
  1473 
       
  1474 #endif /* _BUNDLE_EVENT_H_ */