UnknownBlockProcessor.cc

Go to the documentation of this file.
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 "UnknownBlockProcessor.h"
00018 
00019 #include "BlockInfo.h"
00020 #include "BundleProtocol.h"
00021 
00022 namespace dtn {
00023 
00024 template <> UnknownBlockProcessor*
00025 oasys::Singleton<UnknownBlockProcessor>::instance_ = NULL;
00026 
00027 //----------------------------------------------------------------------
00028 UnknownBlockProcessor::UnknownBlockProcessor()
00029     : BlockProcessor(0xff) // typecode is ignored for this processor
00030 {
00031 }
00032 
00033 //----------------------------------------------------------------------
00034 void
00035 UnknownBlockProcessor::prepare(const Bundle*    bundle,
00036                                Link*            link,
00037                                BlockInfoVec*    blocks,
00038                                const BlockInfo* source)
00039 {
00040     ASSERT(source != NULL);
00041     ASSERT(source->owner() == this);
00042 
00043     if (source->flags() & BundleProtocol::BLOCK_FLAG_DISCARD_BLOCK_ONERROR) {
00044         return;
00045     }
00046 
00047     BlockProcessor::prepare(bundle, link, blocks, source);
00048 }
00049 
00050 //----------------------------------------------------------------------
00051 void
00052 UnknownBlockProcessor::generate(const Bundle* bundle,
00053                                 Link*         link,
00054                                 BlockInfo*    block,
00055                                 bool          last)
00056 {
00057     (void)bundle;
00058     (void)link;
00059     
00060     // This can only be called if there was a corresponding block in
00061     // the input path
00062     const BlockInfo* source = block->source();
00063     ASSERT(source != NULL);
00064     ASSERT(source->owner() == this);
00065 
00066     // We shouldn't be here if the block has the following flags set
00067     ASSERT((source->flags() &
00068             BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR) == 0);
00069     ASSERT((source->flags() &
00070             BundleProtocol::BLOCK_FLAG_DISCARD_BLOCK_ONERROR) == 0);
00071     
00072     // The source better have some contents, but doesn't need to have
00073     // any data necessarily
00074     ASSERT(source->contents().len() != 0);
00075     ASSERT(source->data_offset() != 0);
00076     
00077     u_int8_t flags = source->flags();
00078     if (last) {
00079         flags |= BundleProtocol::BLOCK_FLAG_LAST_BLOCK;
00080     } else {
00081         flags &= ~BundleProtocol::BLOCK_FLAG_LAST_BLOCK;
00082     }
00083     flags |= BundleProtocol::BLOCK_FLAG_FORWARDED_UNPROCESSED;
00084 
00085     generate_preamble(block, source->type(), flags,
00086                       source->data_length());
00087     ASSERT(block->data_offset() == source->data_offset());
00088     ASSERT(block->data_length() == source->data_length());
00089     
00090     BlockInfo::DataBuffer* contents = block->writable_contents();
00091     memcpy(contents->buf()          + block->data_offset(),
00092            source->contents().buf() + block->data_offset(),
00093            block->data_length());
00094     contents->set_len(block->full_length());
00095 }
00096 
00097 //----------------------------------------------------------------------
00098 bool
00099 UnknownBlockProcessor::validate(const Bundle* bundle, BlockInfo* block,
00100                  BundleProtocol::status_report_reason_t* reception_reason,
00101                  BundleProtocol::status_report_reason_t* deletion_reason)
00102 {
00103     // check for generic block errors
00104     if (!BlockProcessor::validate(bundle, block,
00105                                   reception_reason, deletion_reason)) {
00106         return false;
00107     }
00108 
00109     // extension blocks of unknown type are considered to be "invalid"
00110     if (block->flags() & BundleProtocol::BLOCK_FLAG_REPORT_ONERROR) {
00111         *reception_reason = BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE;
00112     }
00113 
00114     if (block->flags() & BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR) {
00115         *deletion_reason = BundleProtocol::REASON_BLOCK_UNINTELLIGIBLE;
00116         return false;
00117     }
00118 
00119     return true;
00120 }
00121 
00122 } // namespace dtn

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