00001 /* 00002 * Copyright 2004-2006 Intel 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 00017 #ifdef HAVE_CONFIG_H 00018 # include <dtn-config.h> 00019 #endif 00020 00021 #include "BundleRouter.h" 00022 #include "RouteTable.h" 00023 #include "bundling/Bundle.h" 00024 #include "bundling/BundleActions.h" 00025 #include "bundling/BundleDaemon.h" 00026 #include "bundling/BundleList.h" 00027 #include "contacts/Contact.h" 00028 #include "reg/Registration.h" 00029 #include <stdlib.h> 00030 00031 #include "FloodBundleRouter.h" 00032 00033 namespace dtn { 00034 00035 //---------------------------------------------------------------------- 00036 FloodBundleRouter::FloodBundleRouter() 00037 : TableBasedRouter("FloodBundleRouter", "flood"), 00038 all_bundles_("FloodBundleRouter::all_bundles"), 00039 all_eids_(EndpointIDPattern::WILDCARD_EID()) 00040 { 00041 log_info("FloodBundleRouter initialized"); 00042 ASSERT(all_eids_.valid()); 00043 } 00044 00045 //---------------------------------------------------------------------- 00046 void 00047 FloodBundleRouter::initialize() 00048 { 00049 TableBasedRouter::initialize(); 00050 config_.add_nexthop_routes_ = false; 00051 } 00052 00053 //---------------------------------------------------------------------- 00054 void 00055 FloodBundleRouter::handle_bundle_received(BundleReceivedEvent* event) 00056 { 00057 Bundle* bundle = event->bundleref_.object(); 00058 log_debug("bundle received *%p", bundle); 00059 all_bundles_.push_back(bundle); 00060 00061 TableBasedRouter::handle_bundle_received(event); 00062 } 00063 00064 //---------------------------------------------------------------------- 00065 void 00066 FloodBundleRouter::handle_link_created(LinkCreatedEvent* event) 00067 { 00068 TableBasedRouter::handle_link_created(event); 00069 00070 LinkRef link = event->link_; 00071 ASSERT(link != NULL); 00072 ASSERT(!link->isdeleted()); 00073 00074 log_debug("FloodBundleRouter::handle_link_created: " 00075 "link_created *%p", link.object()); 00076 00077 RouteEntry* entry = new RouteEntry(all_eids_, link); 00078 entry->set_action(ForwardingInfo::COPY_ACTION); 00079 00080 // adds the route to the table and checks for bundles that may 00081 // need to be sent to the new link 00082 add_route(entry); 00083 } 00084 00085 //---------------------------------------------------------------------- 00086 void 00087 FloodBundleRouter::handle_bundle_expired(BundleExpiredEvent* event) 00088 { 00089 TableBasedRouter::handle_bundle_expired(event); 00090 00091 Bundle* bundle = event->bundleref_.object(); 00092 log_debug("bundle_expired *%p", bundle); 00093 all_bundles_.erase(bundle); 00094 } 00095 00096 } // namespace dtn