00001 /* 00002 * Copyright 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 #include <oasys/util/ScratchBuffer.h> 00018 #include "AnnounceBundle.h" 00019 #include "BundleProtocol.h" 00020 00021 namespace dtn { 00022 00023 void 00024 AnnounceBundle::create_announce_bundle(Bundle* announce, 00025 const EndpointID& route_eid) 00026 { 00027 // only meant for DTN admin consumption 00028 announce->is_admin_ = true; 00029 00030 // assign router's local EID as bundle source 00031 announce->source_.assign(route_eid); 00032 00033 // null out the rest 00034 announce->dest_.assign(EndpointID::NULL_EID()); 00035 announce->replyto_.assign(EndpointID::NULL_EID()); 00036 announce->custodian_.assign(EndpointID::NULL_EID()); 00037 00038 // non-zero expire time 00039 announce->expiration_ = 3600; 00040 00041 // one byte payload: admin type 00042 u_char buf = (BundleProtocol::ADMIN_ANNOUNCE << 4); 00043 announce->payload_.set_data(&buf,1); 00044 } 00045 00046 bool 00047 AnnounceBundle::parse_announce_bundle(Bundle* bundle, 00048 EndpointID *route_eid) 00049 { 00050 if (bundle->is_admin_ == false) 00051 return false; 00052 00053 size_t payload_len = bundle->payload_.length(); 00054 if (payload_len <= 0) return false; 00055 00056 oasys::ScratchBuffer<u_char*, 256> scratch(payload_len); 00057 const u_char* payload_buf = 00058 bundle->payload_.read_data(0, payload_len, scratch.buf(payload_len)); 00059 00060 if ((*payload_buf >> 4) == BundleProtocol::ADMIN_ANNOUNCE) { 00061 00062 if(route_eid != NULL) 00063 route_eid->assign(bundle->source_); 00064 00065 return true; 00066 } 00067 00068 return false; 00069 } 00070 00071 } // dtn