00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <oasys/util/ScratchBuffer.h>
00040
00041 #include "AdminRegistration.h"
00042 #include "RegistrationTable.h"
00043 #include "bundling/BundleDaemon.h"
00044 #include "bundling/BundleProtocol.h"
00045 #include "bundling/CustodySignal.h"
00046 #include "routing/BundleRouter.h"
00047
00048 namespace dtn {
00049
00050 AdminRegistration::AdminRegistration()
00051 : Registration(ADMIN_REGID,
00052 BundleDaemon::instance()->local_eid(),
00053 Registration::DEFER,
00054 0)
00055 {
00056 logpathf("/reg/admin");
00057 }
00058
00059 void
00060 AdminRegistration::deliver_bundle(Bundle* bundle)
00061 {
00062 u_char typecode;
00063
00064 size_t payload_len = bundle->payload_.length();
00065 oasys::ScratchBuffer<u_char*, 256> scratch(payload_len);
00066 const u_char* payload_buf =
00067 bundle->payload_.read_data(0, payload_len, scratch.buf(payload_len));
00068
00069 log_debug("got %zu byte bundle", payload_len);
00070
00071 if (payload_len == 0) {
00072 log_err("admin registration got 0 byte bundle *%p", bundle);
00073 goto done;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 typecode = payload_buf[0] >> 4;
00089
00090 switch(typecode) {
00091 case BundleProtocol::ADMIN_STATUS_REPORT:
00092 {
00093 log_err("status report *%p received at admin registration", bundle);
00094 break;
00095 }
00096
00097 case BundleProtocol::ADMIN_CUSTODY_SIGNAL:
00098 {
00099 log_info("ADMIN_CUSTODY_SIGNAL *%p received", bundle);
00100 CustodySignal::data_t data;
00101
00102 bool ok = CustodySignal::parse_custody_signal(&data, payload_buf, payload_len);
00103 if (!ok) {
00104 log_err("malformed custody signal *%p", bundle);
00105 break;
00106 }
00107
00108 BundleDaemon::post(new CustodySignalEvent(data));
00109
00110 break;
00111 }
00112 case BundleProtocol::ADMIN_ECHO:
00113 {
00114 log_info("ADMIN_ECHO from %s", bundle->source_.c_str());
00115
00116 Bundle* reply = new Bundle();
00117 reply->source_.assign(bundle->dest_);
00118 reply->dest_.assign(bundle->source_);
00119 reply->replyto_.assign(EndpointID::NULL_EID());
00120 reply->custodian_.assign(EndpointID::NULL_EID());
00121 reply->expiration_ = bundle->expiration_;
00122
00123
00124 size_t payload_len = bundle->payload_.length();
00125
00126 u_char buf[1024];
00127 const u_char* bp = bundle->payload_.read_data(0, payload_len, buf);
00128 reply->payload_.set_data(bp, payload_len);
00129
00130 BundleDaemon::post(new BundleReceivedEvent(reply, EVENTSRC_ADMIN, payload_len));
00131
00132 break;
00133 }
00134 case BundleProtocol::ADMIN_NULL:
00135 {
00136 log_info("ADMIN_NULL from %s", bundle->source_.c_str());
00137 break;
00138 }
00139 case BundleProtocol::ADMIN_ANNOUNCE:
00140 {
00141 log_info("ADMIN_ANNOUNCE from %s", bundle->source_.c_str());
00142 break;
00143 }
00144
00145 default:
00146 log_warn("unexpected admin bundle with type 0x%x *%p",
00147 typecode, bundle);
00148 }
00149
00150 done:
00151 BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00152 }
00153
00154
00155 }