BundleRouter.cc

Go to the documentation of this file.
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 
00018 #include <stdlib.h>
00019 
00020 #include <config.h>
00021 #include "BundleRouter.h"
00022 #include "bundling/BundleDaemon.h"
00023 #include "bundling/BundleActions.h"
00024 #include "bundling/BundleList.h"
00025 #include "storage/BundleStore.h"
00026 
00027 #include "StaticBundleRouter.h"
00028 #include "FloodBundleRouter.h"
00029 #include "NeighborhoodRouter.h"
00030 #include "ProphetRouter.h"
00031 #include "LinkStateRouter.h"
00032 #include "ExternalRouter.h"
00033 #include "TcaRouter.h"
00034 
00035 namespace dtn {
00036 
00037 //----------------------------------------------------------------------
00038 BundleRouter::Config::Config()
00039     : type_("static"),
00040       add_nexthop_routes_(true),
00041       default_priority_(0),
00042       storage_quota_(0) {}
00043 
00044 BundleRouter::Config BundleRouter::config_;
00045 
00046 //----------------------------------------------------------------------
00047 BundleRouter*
00048 BundleRouter::create_router(const char* type)
00049 {
00050     if (strcmp(type, "static") == 0) {
00051         return new StaticBundleRouter();
00052     }
00053     else if (strcmp(type, "neighborhood") == 0) {
00054         return new NeighborhoodRouter();
00055     }
00056     else if (strcmp(type, "prophet") == 0) {
00057         return new ProphetRouter();
00058     }
00059     else if (strcmp(type, "flood") == 0) {
00060         return new FloodBundleRouter();
00061     }
00062     else if (strcmp(type, "linkstate") == 0) {
00063         return new LinkStateRouter();
00064     }    
00065     else if (!strcmp(type, "tca_router")) {
00066         return new TcaRouter(TcaRouter::TCA_ROUTER);
00067     }
00068     else if (!strcmp(type, "tca_gateway")) {
00069         return new TcaRouter(TcaRouter::TCA_GATEWAY);
00070     }
00071 #ifdef XERCES_C_ENABLED
00072     else if (strcmp(type, "external") == 0) {
00073         return new ExternalRouter();
00074     }    
00075 #endif
00076     else {
00077         PANIC("unknown type %s for router", type);
00078     }
00079 }
00080 
00081 //----------------------------------------------------------------------
00082 BundleRouter::BundleRouter(const char* classname, const std::string& name)
00083     : BundleEventHandler(classname, "/dtn/route"),
00084       name_(name)
00085 {
00086     logpathf("/dtn/route/%s", name.c_str());
00087     
00088     actions_ = BundleDaemon::instance()->actions();
00089     
00090     // XXX/demmer maybe change this?
00091     pending_bundles_ = BundleDaemon::instance()->pending_bundles();
00092     custody_bundles_ = BundleDaemon::instance()->custody_bundles();
00093 }
00094 
00095 //----------------------------------------------------------------------
00096 void
00097 BundleRouter::initialize()
00098 {
00099 }
00100 
00101 //----------------------------------------------------------------------
00102 BundleRouter::~BundleRouter()
00103 {
00104 }
00105 
00106 //----------------------------------------------------------------------
00107 bool
00108 BundleRouter::accept_bundle(Bundle* bundle, int* errp)
00109 {
00110     // XXX/demmer this could (should?) be abstracted into a
00111     // StoragePolicy class hierarchy of some sort
00112 
00113     BundleStore* bs = BundleStore::instance();
00114     if (bs->payload_quota() != 0 &&
00115         (bs->total_size() + bundle->payload_.length() > bs->payload_quota()))
00116     {
00117         log_info("accept_bundle: rejecting bundle *%p since "
00118                  "cur size %llu + bundle size %zu > quota %llu",
00119                  bundle, U64FMT(bs->total_size()), bundle->payload_.length(),
00120                  U64FMT(bs->payload_quota()));
00121         *errp = BundleProtocol::REASON_DEPLETED_STORAGE;
00122         return false;
00123     } 
00124 
00125     *errp = 0;
00126     return true;
00127 }
00128 
00129 //----------------------------------------------------------------------
00130 void
00131 BundleRouter::shutdown()
00132 {
00133 }
00134 
00135 } // namespace dtn

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1