00001 /* 00002 * Copyright 2006 Baylor University 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 00017 #include "BundleRouter.h" 00018 #include "bundling/Bundle.h" 00019 #include "bundling/BundleActions.h" 00020 #include "bundling/BundleDaemon.h" 00021 #include "bundling/BundleList.h" 00022 #include "bundling/AnnounceBundle.h" 00023 #include "contacts/Contact.h" 00024 #include "contacts/ContactManager.h" 00025 #include <oasys/util/StringBuffer.h> 00026 #include <stdlib.h> 00027 00028 #include "ProphetRouter.h" 00029 00030 namespace dtn { 00031 00032 ProphetParams ProphetRouter::params_; 00033 00034 ProphetRouter::ProphetRouter() 00035 : BundleRouter("ProphetRouter", "prophet") 00036 { 00037 log_info("ProphetRouter constructor"); 00038 // params_ default values are set by ProphetCommand 00039 } 00040 00041 ProphetRouter::~ProphetRouter() 00042 { 00043 oracle_->shutdown(); 00044 delete oracle_; 00045 } 00046 00047 void 00048 ProphetRouter::initialize() 00049 { 00050 // Call factory to instantiate ProphetController 00051 ProphetController::init(¶ms_,pending_bundles_,actions_); 00052 00053 // For convenience, grab hold of that instance variable 00054 oracle_ = ProphetController::instance(); 00055 00056 // all done 00057 log_info("ProphetRouter initialized"); 00058 } 00059 00060 void 00061 ProphetRouter::handle_event(BundleEvent* event) 00062 { 00063 dispatch_event(event); 00064 } 00065 00066 void 00067 ProphetRouter::get_routing_state(oasys::StringBuffer* buf) 00068 { 00069 oracle_->dump_state(buf); 00070 } 00071 00072 void 00073 ProphetRouter::handle_bundle_received(BundleReceivedEvent *event) 00074 { 00075 Bundle* bundle = event->bundleref_.object(); 00076 oracle_->handle_bundle_received(bundle,event->contact_); 00077 } 00078 00079 void 00080 ProphetRouter::handle_bundle_delivered(BundleReceivedEvent* event) 00081 { 00082 Bundle* bundle = event->bundleref_.object(); 00083 oracle_->handle_bundle_delivered(bundle); 00084 } 00085 00086 void 00087 ProphetRouter::handle_bundle_expired(BundleExpiredEvent *event) 00088 { 00089 Bundle* bundle = event->bundleref_.object(); 00090 oracle_->handle_bundle_expired(bundle); 00091 } 00092 00093 void 00094 ProphetRouter::handle_link_created(LinkCreatedEvent* event) 00095 { 00096 // can't do anything with "only" a link, except to police this one ASSERTion 00097 ASSERT(event->link_->remote_eid().equals(EndpointID::NULL_EID()) == false); 00098 } 00099 00100 void 00101 ProphetRouter::handle_contact_up(ContactUpEvent* event) 00102 { 00103 // ProphetController demux's which ProphetEncounter handles this contact 00104 // (or creates a new one) 00105 oracle_->new_neighbor(event->contact_); 00106 } 00107 00108 void 00109 ProphetRouter::handle_contact_down(ContactDownEvent* event) 00110 { 00111 // Let ProphetController know that the contact's off the wire 00112 oracle_->neighbor_gone(event->contact_); 00113 } 00114 00115 void 00116 ProphetRouter::handle_link_state_change_request(LinkStateChangeRequest* req) 00117 { 00118 // Signals the appropriate ProphetEncounter instance to clear any 00119 // pending outbound queues 00120 if (req->old_state_ == Link::BUSY && req->state_ == Link::AVAILABLE) 00121 { 00122 oracle_->handle_link_state_change_request(req->contact_); 00123 } 00124 } 00125 00126 } // namespace dtn