00001 /* 00002 * License Agreement 00003 * 00004 * NOTICE 00005 * This software (or technical data) was produced for the U. S. 00006 * Government under contract W15P7T-05-C-F600, and is 00007 * subject to the Rights in Data-General Clause 52.227-14 (JUNE 1987) 00008 * 00009 * Copyright (C) 2006. The MITRE Corporation (http://www.mitre.org/). 00010 * All Rights Reserved. 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted provided that the following conditions 00014 * are met: 00015 * 00016 * * Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 00019 * * Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in the 00021 * documentation and/or other materials provided with the distribution. 00022 * 00023 * * The US Government will not be charged any license fee and/or 00024 * royalties related to this software. 00025 * 00026 * * Neither name of The MITRE Corporation; nor the names of its 00027 * contributors may be used to endorse or promote products derived from 00028 * this software without specific prior written permission. 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00031 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00032 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00033 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00034 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00035 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00036 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00037 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00038 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00039 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00040 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00041 */ 00042 00043 #ifndef _EXTERNAL_ROUTER_H_ 00044 #define _EXTERNAL_ROUTER_H_ 00045 00046 #include <config.h> 00047 #ifdef XERCES_C_ENABLED 00048 00049 #include "BundleRouter.h" 00050 #include "RouteTable.h" 00051 00052 #include <reg/Registration.h> 00053 #include <oasys/serialize/XercesXMLSerialize.h> 00054 00055 #include <oasys/io/UDPClient.h> 00056 00057 #define EXTERNAL_ROUTER_SERVICE_TAG "/ext.rtr/*" 00058 00059 namespace dtn { 00060 00070 class ExternalRouter : public BundleRouter { 00071 public: 00073 static u_int16_t server_port; 00074 00076 static u_int16_t hello_interval; 00077 00079 static bool server_validation; 00080 00082 static std::string schema; 00083 00085 static bool client_validation; 00086 00088 static RouteTable *route_table; 00089 00090 ExternalRouter(); 00091 virtual ~ExternalRouter(); 00092 00096 virtual void initialize(); 00097 00102 virtual void get_routing_state(oasys::StringBuffer* buf); 00103 00107 void build_route_report(oasys::SerializeAction *a); 00108 00113 virtual void handle_event(BundleEvent *event); 00114 00118 virtual void shutdown(); 00119 00120 protected: 00121 class ModuleServer; 00122 class HelloTimer; 00123 class ERRegistration; 00124 00126 ModuleServer *srv_; 00127 00129 RouteTable *route_table_; 00130 00132 ERRegistration *reg_; 00133 00135 HelloTimer *hello_; 00136 }; 00137 00142 class ExternalRouter::ModuleServer : public oasys::Thread, 00143 public oasys::UDPClient { 00144 public: 00145 ModuleServer(); 00146 virtual ~ModuleServer(); 00147 00151 virtual void run(); 00152 00158 void process_action(const char *payload); 00159 00165 BundleEvent * instantiate(const char *event_tag); 00166 00168 oasys::MsgQueue< std::string * > *eventq; 00169 00171 oasys::XercesXMLUnmarshal parser_; 00172 00173 oasys::SpinLock *lock_; 00174 }; 00175 00179 class ExternalRouter::HelloTimer : public oasys::Timer { 00180 public: 00181 HelloTimer(ExternalRouter *router); 00182 ~HelloTimer(); 00183 00187 void timeout(const struct timeval &now); 00188 00189 ExternalRouter *router_; 00190 }; 00191 00196 class ExternalRouter::ERRegistration : public Registration { 00197 public: 00198 ERRegistration(ExternalRouter *router); 00199 00203 void deliver_bundle(Bundle *bundle); 00204 00205 ExternalRouter *router_; 00206 }; 00207 00211 void external_rtr_shutdown(void *args); 00212 00213 } // namespace dtn 00214 00215 #endif // XERCES_C_ENABLED 00216 #endif //_EXTERNAL_ROUTER_H_