AdminRegistration.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 <oasys/util/ScratchBuffer.h>
00019 
00020 #include "AdminRegistration.h"
00021 #include "RegistrationTable.h"
00022 #include "bundling/BundleDaemon.h"
00023 #include "bundling/BundleProtocol.h"
00024 #include "bundling/CustodySignal.h"
00025 #include "routing/BundleRouter.h"
00026 
00027 namespace dtn {
00028 
00029 AdminRegistration::AdminRegistration()
00030     : Registration(ADMIN_REGID,
00031                    BundleDaemon::instance()->local_eid(),
00032                    Registration::DEFER,
00033                    0)
00034 {
00035     logpathf("/dtn/reg/admin");
00036     set_active(true);
00037 }
00038 
00039 void
00040 AdminRegistration::deliver_bundle(Bundle* bundle)
00041 {
00042     u_char typecode;
00043 
00044     size_t payload_len = bundle->payload_.length();
00045     oasys::ScratchBuffer<u_char*, 256> scratch(payload_len);
00046     const u_char* payload_buf = 
00047         bundle->payload_.read_data(0, payload_len, scratch.buf(payload_len));
00048     
00049     log_debug("got %zu byte bundle", payload_len);
00050         
00051     if (payload_len == 0) {
00052         log_err("admin registration got 0 byte *%p", bundle);
00053         goto done;
00054     }
00055 
00056     if (!bundle->is_admin_) {
00057         log_warn("non-admin *%p sent to local eid", bundle);
00058         goto done;
00059     }
00060 
00061     /*
00062      * As outlined in the bundle specification, the first four bits of
00063      * all administrative bundles hold the type code, with the
00064      * following values:
00065      *
00066      * 0x1     - bundle status report
00067      * 0x2     - custodial signal
00068      * 0x3     - echo request
00069      * 0x4     - null request
00070      * 0x5     - announce
00071      * (other) - reserved
00072      */
00073     typecode = payload_buf[0] >> 4;
00074     
00075     switch(typecode) {
00076     case BundleProtocol::ADMIN_STATUS_REPORT:
00077     {
00078         log_err("status report *%p received at admin registration", bundle);
00079         break;
00080     }
00081     
00082     case BundleProtocol::ADMIN_CUSTODY_SIGNAL:
00083     {
00084         log_info("ADMIN_CUSTODY_SIGNAL *%p received", bundle);
00085         CustodySignal::data_t data;
00086         
00087         bool ok = CustodySignal::parse_custody_signal(&data, payload_buf, payload_len);
00088         if (!ok) {
00089             log_err("malformed custody signal *%p", bundle);
00090             break;
00091         }
00092 
00093         BundleDaemon::post(new CustodySignalEvent(data));
00094 
00095         break;
00096     }
00097     case BundleProtocol::ADMIN_ANNOUNCE:
00098     {
00099         log_info("ADMIN_ANNOUNCE from %s", bundle->source_.c_str());
00100         break;
00101     }
00102         
00103     default:
00104         log_warn("unexpected admin bundle with type 0x%x *%p",
00105                  typecode, bundle);
00106     }    
00107 
00108  done:
00109     BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00110 }
00111 
00112 
00113 } // namespace dtn

Generated on Sat Sep 8 08:36:15 2007 for DTN Reference Implementation by  doxygen 1.5.3