--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlib/bundling/BPQBlock.cc Wed May 04 15:44:40 2011 +0100
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2006 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <dtn-config.h>
+#endif
+
+#include "BPQBlock.h"
+
+namespace dtn {
+
+BPQBlock::BPQBlock(BlockInfo* block)
+{
+ static const char* log = "/dtn/bundle/protocol";
+ log_err_p(log, "BPQBlock: constructor");
+
+ log_err_p(log, "block->data_length(): %d",block->data_length());
+ log_err_p(log, "block->data_offset(): %d",block->data_offset());
+ log_err_p(log, "block->full_length(): %d",block->full_length());
+
+
+ size_t len = block->writable_contents()->buf_len();
+ u_char* buf = block->writable_contents()->buf(len);
+
+ size_t i=0;
+//, j=0, decoding_len=0;
+
+ // BPQ-kind 1-byte
+ if (i<len) {
+ kind_ = (u_int) buf[i++];
+ log_err_p(log, "kind: %d",kind_);
+ }
+
+ // matching rule type 1-byte
+ if (i<len) {
+ matching_rule_ = (u_int) buf[i++];
+ log_err_p(log, "marching rule: %d",matching_rule_);
+ }
+ log_err_p(log, "leaving constructor");
+}
+
+BPQBlock::~BPQBlock()
+{
+ static const char* log = "/dtn/bundle/protocol";
+ log_err_p(log, "BPQBlock: destructor");
+}
+
+
+} // namespace dtn
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlib/bundling/BPQBlock.h Wed May 04 15:44:40 2011 +0100
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2008 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BPQ_BLOCK_H_
+#define _BPQ_BLOCK_H_
+
+#ifdef HAVE_CONFIG_H
+# include <dtn-config.h>
+#endif
+
+#include "BlockInfo.h"
+namespace dtn {
+
+class BPQFragment{
+public:
+ BPQFragment() {}
+ ~BPQFragment() {}
+
+ /// @{ Accessors
+ u_int offset() const { return offset_; }
+ u_int length() const { return length_; }
+ /// @}
+
+private:
+ u_int offset_; ///< Fragment offset
+ u_int length_; ///< Fragment length
+};
+
+class BPQBlock {
+public:
+ BPQBlock(BlockInfo* block);
+ ~BPQBlock();
+
+ /// @{ Accessors
+ u_int kind() const { return kind_; }
+ u_int matching_rule() const { return matching_rule_; }
+ u_int query_len() const { return query_len_; }
+ const char* query_val() const { return query_val_; }
+ /// @}
+
+ /// @{ Typedefs and wrappers for the BPQFragment vector and iterators
+ typedef std::vector<BPQFragment> BPQFragmentVec;
+ typedef BPQFragmentVec::iterator iterator;
+ typedef BPQFragmentVec::const_iterator const_iterator;
+
+ bool empty() const { return fragments_.empty(); }
+ BPQFragmentVec::iterator begin() { return fragments_.begin(); }
+ BPQFragmentVec::iterator end() { return fragments_.end(); }
+ BPQFragmentVec::const_iterator begin() const { return fragments_.begin(); }
+ BPQFragmentVec::const_iterator end() const { return fragments_.end(); }
+ /// @}
+
+
+private:
+ u_int kind_; ///< Query || Response
+ u_int matching_rule_; ///< Exact
+ u_int query_len_; ///< Length of the query value
+ char* query_val_; ///< Query value
+ BPQFragmentVec fragments_; ///< List of fragments returned
+};
+
+} // namespace dtn
+
+#endif /* _BPQ_BLOCK_H_ */
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlib/bundling/BPQBlockProcessor.cc Wed May 04 15:44:40 2011 +0100
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2006 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <dtn-config.h>
+#endif
+
+#include "BPQBlockProcessor.h"
+#include "BPQBlock.h"
+
+#include "BlockInfo.h"
+#include "BundleProtocol.h"
+
+namespace dtn {
+
+//----------------------------------------------------------------------
+BPQBlockProcessor::BPQBlockProcessor() :
+ BlockProcessor(BundleProtocol::QUERY_EXTENSION_BLOCK)
+{
+}
+
+//----------------------------------------------------------------------
+int
+BPQBlockProcessor::consume(Bundle* bundle,
+ BlockInfo* block,
+ u_char* buf,
+ size_t len)
+{
+ (void)bundle;
+ (void)block;
+ (void)buf;
+ (void)len;
+
+ //static const char* log = "/home/aidan/Desktop/dtn_log";
+ static const char* log = "/dtn/bundle/protocol";
+ log_err_p(log, "BPQ: consume() returning -1");
+
+ return -1;
+}
+
+//----------------------------------------------------------------------
+int
+BPQBlockProcessor::generate(const Bundle* bundle,
+ BlockInfoVec* xmit_blocks,
+ BlockInfo* block,
+ const LinkRef& link,
+ bool last)
+{
+
+ //static const char* log = "/home/aidan/Desktop/dtn_log";
+ static const char* log = "/dtn/bundle/protocol";
+ log_err_p(log, "BPQ: generate() returning %d", BP_SUCCESS);
+
+ BPQBlock* bpq_block = new BPQBlock(block);
+
+/*
+ for (BlockInfoVec::iterator iter = bundle->recv_blocks().begin();
+ iter != bundle->recv_blocks().end();
+ ++iter)
+ {
+ log_err_p(log,"\n type: 0x%02x ", iter->type());
+ if (iter->data_offset() == 0)
+ log_err_p(log,"(runt)");
+ else {
+ if (!iter->complete())
+ log_err_p(log,"(incomplete) ");
+ log_err_p(log,"data length: %d", iter->full_length());
+ }
+ }
+
+
+
+
+*/
+/* oasys::StaticStringBuffer<1024> buf;
+ bundle->format_verbose(&buf);
+ log_multiline(oasys::LOG_NOTICE, buf.c_str());
+
+*/
+ /*oasys::StringBuffer *sb = new oasys::StringBuffer();
+ //char c[10000];
+ bundle->format_verbose(sb);
+ log_err_p(log, "%s", sb->data());
+ */
+
+
+
+ u_int8_t flags = BundleProtocol::BLOCK_FLAG_DISCARD_BUNDLE_ONERROR |
+ (last ? BundleProtocol::BLOCK_FLAG_LAST_BLOCK : 0);
+
+ generate_preamble(xmit_blocks,
+ block,
+ BundleProtocol::QUERY_EXTENSION_BLOCK,
+ flags,
+ 1 );
+
+
+ // source block must include at least a block header, if not actual data
+// ASSERT(source->contents().len() != 0);
+// ASSERT(source->data_offset() != 0);
+
+// generate_preamble(xmit_blocks, block, source->type(), flags, source->data_length());
+// ASSERT(block->data_offset() == source->data_offset());
+// ASSERT(block->data_length() == source->data_length());
+/*
+ BlockInfo::DataBuffer* contents = block->writable_contents();
+ contents->reserve(block->full_length());
+ memcpy(contents->buf() + block->data_offset(),
+ source->contents().buf() + block->data_offset(),
+ block->data_length());
+ contents->set_len(block->full_length());
+*/
+
+ return BP_SUCCESS;
+}
+
+} // namespace dtn
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servlib/bundling/BPQBlockProcessor.h Wed May 04 15:44:40 2011 +0100
@@ -0,0 +1,35 @@
+#ifndef _BPQ_BLOCK_PROCESSOR_H_
+#define _BPQ_BLOCK_PROCESSOR_H_
+
+#include "BlockProcessor.h"
+#include <oasys/util/StringBuffer.h>
+
+namespace dtn {
+
+/**
+ * Block processor implementation for the BPQ Extension Block
+ */
+class BPQBlockProcessor : public BlockProcessor {
+public:
+ /// Constructor
+ BPQBlockProcessor();
+
+ /// @{ Virtual from BlockProcessor
+
+ int consume(Bundle* bundle,
+ BlockInfo* block,
+ u_char* buf,
+ size_t len);
+
+ int generate(const Bundle* bundle,
+ BlockInfoVec* xmit_blocks,
+ BlockInfo* block,
+ const LinkRef& link,
+ bool last);
+
+ /// @}
+};
+
+} // namespace dtn
+
+#endif /* _BPQ_BLOCK_PROCESSOR_H_ */