00001 /* 00002 * Copyright 2006-2007 The MITRE Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * The US Government will not be charged any license fee and/or royalties 00017 * related to this software. Neither name of The MITRE Corporation; nor the 00018 * names of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 */ 00021 00022 #ifndef _EXTERNAL_ROUTER_H_ 00023 #define _EXTERNAL_ROUTER_H_ 00024 00025 #ifndef DTN_CONFIG_STATE 00026 #error "MUST INCLUDE dtn-config.h before including this file" 00027 #endif 00028 00029 #if defined(XERCES_C_ENABLED) && defined(EXTERNAL_DP_ENABLED) 00030 00031 #include "router-custom.h" 00032 #include "BundleRouter.h" 00033 #include "RouteTable.h" 00034 #include <reg/Registration.h> 00035 #include <oasys/serialize/XercesXMLSerialize.h> 00036 #include <oasys/io/UDPClient.h> 00037 00038 #define EXTERNAL_ROUTER_SERVICE_TAG "/ext.rtr/*" 00039 00040 namespace dtn { 00041 00051 class ExternalRouter : public BundleRouter { 00052 public: 00054 static u_int16_t server_port; 00055 00057 static u_int16_t hello_interval; 00058 00060 static bool server_validation; 00061 00063 static std::string schema; 00064 00066 static bool client_validation; 00067 00069 static RouteTable *route_table; 00070 00071 ExternalRouter(); 00072 virtual ~ExternalRouter(); 00073 00077 virtual void initialize(); 00078 00082 virtual void shutdown(); 00083 00088 virtual void get_routing_state(oasys::StringBuffer* buf); 00089 00094 virtual void handle_event(BundleEvent *event); 00095 virtual void handle_bundle_received(BundleReceivedEvent *event); 00096 virtual void handle_bundle_transmitted(BundleTransmittedEvent* event); 00097 virtual void handle_bundle_delivered(BundleDeliveredEvent* event); 00098 virtual void handle_bundle_expired(BundleExpiredEvent* event); 00099 virtual void handle_bundle_cancelled(BundleSendCancelledEvent* event); 00100 virtual void handle_bundle_injected(BundleInjectedEvent* event); 00101 virtual void handle_contact_up(ContactUpEvent* event); 00102 virtual void handle_contact_down(ContactDownEvent* event); 00103 virtual void handle_link_created(LinkCreatedEvent *event); 00104 virtual void handle_link_deleted(LinkDeletedEvent *event); 00105 virtual void handle_link_available(LinkAvailableEvent *event); 00106 virtual void handle_link_unavailable(LinkUnavailableEvent *event); 00107 virtual void handle_link_attribute_changed(LinkAttributeChangedEvent *event); 00108 virtual void handle_contact_attribute_changed(ContactAttributeChangedEvent *event); 00109 // virtual void handle_link_busy(LinkBusyEvent *event); 00110 virtual void handle_new_eid_reachable(NewEIDReachableEvent* event); 00111 virtual void handle_registration_added(RegistrationAddedEvent* event); 00112 virtual void handle_registration_removed(RegistrationRemovedEvent* event); 00113 virtual void handle_registration_expired(RegistrationExpiredEvent* event); 00114 virtual void handle_route_add(RouteAddEvent* event); 00115 virtual void handle_route_del(RouteDelEvent* event); 00116 virtual void handle_custody_signal(CustodySignalEvent* event); 00117 virtual void handle_custody_timeout(CustodyTimeoutEvent* event); 00118 virtual void handle_link_report(LinkReportEvent *event); 00119 virtual void handle_link_attributes_report(LinkAttributesReportEvent *event); 00120 virtual void handle_contact_report(ContactReportEvent* event); 00121 virtual void handle_bundle_report(BundleReportEvent *event); 00122 virtual void handle_bundle_attributes_report(BundleAttributesReportEvent *event); 00123 virtual void handle_route_report(RouteReportEvent* event); 00124 00125 virtual void send(rtrmessage::bpa &message); 00126 00127 protected: 00128 class ModuleServer; 00129 class HelloTimer; 00130 class ERRegistration; 00131 00132 // XXX This function should really go in ContactEvent 00133 // but ExternalRouter needs a less verbose version 00134 static const char *reason_to_str(int reason); 00135 00137 ModuleServer *srv_; 00138 00140 RouteTable *route_table_; 00141 00143 ERRegistration *reg_; 00144 00146 HelloTimer *hello_; 00147 }; 00148 00153 class ExternalRouter::ModuleServer : public oasys::Thread, 00154 public oasys::UDPClient { 00155 public: 00156 ModuleServer(); 00157 virtual ~ModuleServer(); 00158 00162 virtual void run(); 00163 00169 void process_action(const char *payload); 00170 00172 oasys::MsgQueue< std::string * > *eventq; 00173 00175 oasys::XercesXMLUnmarshal *parser_; 00176 00177 oasys::SpinLock *lock_; 00178 00179 private: 00180 Link::link_type_t convert_link_type(rtrmessage::linkTypeType type); 00181 Bundle::priority_values_t convert_priority(rtrmessage::bundlePriorityType); 00182 00183 ForwardingInfo::action_t 00184 convert_fwd_action(rtrmessage::bundleForwardActionType); 00185 }; 00186 00190 class ExternalRouter::HelloTimer : public oasys::Timer { 00191 public: 00192 HelloTimer(ExternalRouter *router); 00193 ~HelloTimer(); 00194 00198 void timeout(const struct timeval &now); 00199 00200 ExternalRouter *router_; 00201 }; 00202 00207 class ExternalRouter::ERRegistration : public Registration { 00208 public: 00209 ERRegistration(ExternalRouter *router); 00210 00214 void deliver_bundle(Bundle *bundle); 00215 00216 ExternalRouter *router_; 00217 }; 00218 00222 void external_rtr_shutdown(void *args); 00223 00224 } // namespace dtn 00225 00226 #endif // XERCES_C_ENABLED && EXTERNAL_DP_ENABLED 00227 #endif //_EXTERNAL_ROUTER_H_