aboutsummaryrefslogtreecommitdiffstats
path: root/icnet/ccnx
diff options
context:
space:
mode:
authorMauro Sardara <msardara+fdio@cisco.com>2017-02-22 14:37:37 +0100
committerMauro Sardara <msardara+fdio@cisco.com>2017-02-22 13:46:08 +0000
commitba8541cad3a4069886444abbd1848b6ef3fff72c (patch)
tree39226dd9b036ca7e513c2cccd8e71e15e09b86bc /icnet/ccnx
parent9b30fc10fb1cbebe651e5a107e8ca5b24de54675 (diff)
Initial Commit: libicnet
Change-Id: I10a72cb0d84b76553a85c168416b847f6a4ff5f6 Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
Diffstat (limited to 'icnet/ccnx')
-rw-r--r--icnet/ccnx/icnet_ccnx_common.h49
-rw-r--r--icnet/ccnx/icnet_ccnx_content_object.cc202
-rw-r--r--icnet/ccnx/icnet_ccnx_content_object.h121
-rw-r--r--icnet/ccnx/icnet_ccnx_facade.h27
-rw-r--r--icnet/ccnx/icnet_ccnx_interest.cc147
-rw-r--r--icnet/ccnx/icnet_ccnx_interest.h92
-rw-r--r--icnet/ccnx/icnet_ccnx_key_locator.cc40
-rw-r--r--icnet/ccnx/icnet_ccnx_key_locator.h52
-rw-r--r--icnet/ccnx/icnet_ccnx_key_locator_type.h22
-rw-r--r--icnet/ccnx/icnet_ccnx_local_connector.cc195
-rw-r--r--icnet/ccnx/icnet_ccnx_local_connector.h98
-rw-r--r--icnet/ccnx/icnet_ccnx_manifest.cc78
-rw-r--r--icnet/ccnx/icnet_ccnx_manifest.h55
-rw-r--r--icnet/ccnx/icnet_ccnx_name.cc218
-rw-r--r--icnet/ccnx/icnet_ccnx_name.h120
-rw-r--r--icnet/ccnx/icnet_ccnx_network_message.cc88
-rw-r--r--icnet/ccnx/icnet_ccnx_network_message.h70
-rw-r--r--icnet/ccnx/icnet_ccnx_payload_type.h37
-rw-r--r--icnet/ccnx/icnet_ccnx_pending_interest.cc94
-rw-r--r--icnet/ccnx/icnet_ccnx_pending_interest.h93
-rw-r--r--icnet/ccnx/icnet_ccnx_portal.cc204
-rw-r--r--icnet/ccnx/icnet_ccnx_portal.h105
-rw-r--r--icnet/ccnx/icnet_ccnx_segment.cc78
-rw-r--r--icnet/ccnx/icnet_ccnx_segment.h71
24 files changed, 2356 insertions, 0 deletions
diff --git a/icnet/ccnx/icnet_ccnx_common.h b/icnet/ccnx/icnet_ccnx_common.h
new file mode 100644
index 00000000..d8020fe7
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_common.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_COMMON_H_
+#define ICNET_CCNX_COMMON_H_
+
+// require C++11
+#if __cplusplus < 201103L && !defined(__GXX_EXPERIMENTAL_CXX0X__)
+# error "libconsumer-producer must be compiled using the C++11 standard"
+#endif
+
+// Avoid use of C keyword restrict
+#define restrict __restrict__
+
+// Each ccnx name has to start with ccnx:
+#define CCNX_START_PREFIX "ccnx:"
+
+// #include "config.hpp"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <string>
+#include <map>
+#include <memory>
+#include <chrono>
+
+#if defined(__GNUC__) || defined(__clang__)
+# define DEPRECATED(func) func __attribute__ ((deprecated))
+#elif defined(_MSC_VER)
+# define DEPRECATED(func) __declspec(deprecated) func
+#else
+# pragma message("DEPRECATED not implemented")
+# define DEPRECATED(func) func
+#endif
+
+#endif // ICNET_CCNX_COMMON_H_
diff --git a/icnet/ccnx/icnet_ccnx_content_object.cc b/icnet/ccnx/icnet_ccnx_content_object.cc
new file mode 100644
index 00000000..1a7fa3c6
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_content_object.cc
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_content_object.h"
+
+extern "C" {
+#include <ccnx/common/ccnx_WireFormatMessage.h>
+};
+
+namespace icnet {
+
+namespace ccnx {
+
+ContentObject::ContentObject()
+ : name_(ccnxName_Create()),
+ ccnx_content_object_(ccnxContentObject_CreateWithNameAndPayload(name_.getWrappedStructure(), NULL)),
+ content_type_(PayloadType::DATA) {
+}
+
+ContentObject::ContentObject(const Name &name, uint8_t *payload, std::size_t size)
+ : name_(name), content_type_(PayloadType::DATA) {
+ PARCBuffer *buffer = parcBuffer_CreateFromArray(payload, size);
+ buffer = parcBuffer_Flip(buffer);
+ ccnx_content_object_ = ccnxContentObject_CreateWithNameAndPayload(name.getWrappedStructure(), buffer);
+ parcBuffer_Release(&buffer);
+}
+
+ContentObject::ContentObject(const CCNxContentObjectStructure *content_object) : name_(ccnxContentObject_GetName(
+ content_object)),
+ ccnx_content_object_(
+ ccnxContentObject_Acquire(
+ content_object)),
+ content_type_((PayloadType) ccnxContentObject_GetPayloadType(
+ content_object)) {
+}
+
+ContentObject::ContentObject(const Name &name)
+ : name_(name),
+ ccnx_content_object_(ccnxContentObject_CreateWithNameAndPayload(name.getWrappedStructure(), NULL)),
+ content_type_(PayloadType::DATA) {
+}
+
+ContentObject::ContentObject(Name &&name)
+ : name_(std::move(name)),
+ ccnx_content_object_(ccnxContentObject_CreateWithNameAndPayload(name.getWrappedStructure(), NULL)),
+ content_type_(PayloadType::DATA) {
+}
+
+ContentObject::~ContentObject() {
+ ccnxContentObject_Release(&ccnx_content_object_);
+}
+
+bool ContentObject::operator==(const ContentObject &content_object) {
+ return ccnxContentObject_Equals(ccnx_content_object_, content_object.ccnx_content_object_);
+}
+
+PayloadType ContentObject::getContentType() const {
+ return (PayloadType) ccnxContentObject_GetPayloadType(ccnx_content_object_);
+}
+
+void ContentObject::setContentType(PayloadType payload_type) {
+ content_type_ = payload_type;
+}
+
+bool ContentObject::setContent(PayloadType content_type, const uint8_t *buffer, size_t buffer_size) {
+ content_type_ = content_type;
+ return setContent(buffer, buffer_size);
+}
+
+bool ContentObject::setContent(const uint8_t *buffer, size_t buffer_size) {
+ bool ret;
+ PARCBuffer *parc_buffer = parcBuffer_CreateFromArray(buffer, buffer_size);
+ parc_buffer = parcBuffer_Flip(parc_buffer);
+
+ if (content_type_ != PayloadType::DATA) {
+ ret = ccnxContentObject_SetPayload(ccnx_content_object_, (CCNxPayloadType) content_type_, parc_buffer);
+ } else {
+ ret = ccnxContentObject_SetPayload(ccnx_content_object_, (CCNxPayloadType) PayloadType::DATA, parc_buffer);
+ }
+
+ parcBuffer_Release(&parc_buffer);
+
+ return ret;
+}
+
+Array ContentObject::getContent() const {
+ PARCBuffer *buffer = ccnxContentObject_GetPayload(ccnx_content_object_);
+ return Array(parcBuffer_Overlay(buffer, 0), parcBuffer_Remaining(buffer));
+}
+
+void ContentObject::setSignature() {
+
+}
+
+void ContentObject::signWithSha256(KeyLocator &key_locator) {
+ // ccnxValidationCRC32C_Set(ccnx_content_object_);
+}
+
+void ContentObject::setFinalChunkNumber(uint64_t final_chunk_number) {
+ ccnxContentObject_SetFinalChunkNumber(ccnx_content_object_, final_chunk_number);
+}
+
+bool ContentObject::hasFinalChunkNumber() {
+ return ccnxContentObject_HasFinalChunkNumber(ccnx_content_object_);
+}
+
+uint64_t ContentObject::getFinalChunkNumber() {
+ return ccnxContentObject_GetFinalChunkNumber(ccnx_content_object_);
+}
+
+void ContentObject::setExpiryTime(uint64_t expiry_time) {
+ std::chrono::milliseconds
+ ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
+ uint64_t expiration = ms.count() + expiry_time;
+ ccnxContentObject_SetExpiryTime(ccnx_content_object_, expiration);
+}
+
+uint64_t ContentObject::getExpiryTime() {
+ return ccnxContentObject_GetExpiryTime(ccnx_content_object_);
+}
+
+const Name &ContentObject::getName() const {
+ return name_;
+}
+
+std::size_t ContentObject::getPacketSize() const {
+ PARCBuffer *packet = ccnxWireFormatMessage_GetWireFormatBuffer(ccnx_content_object_);
+ std::size_t ret = parcBuffer_Remaining(packet);
+ return ret;
+}
+
+void ContentObject::setName(const Name &name) {
+ PARCBuffer *buffer = parcBuffer_Acquire(ccnxContentObject_GetPayload(ccnx_content_object_));
+ ccnxContentObject_Release(&ccnx_content_object_);
+ ccnx_content_object_ = ccnxContentObject_CreateWithNameAndPayload(name.getWrappedStructure(), buffer);
+ parcBuffer_Release(&buffer);
+ name_ = std::move(name);
+}
+
+void ContentObject::setName(Name &&name) {
+ PARCBuffer *buffer = parcBuffer_Acquire(ccnxContentObject_GetPayload(ccnx_content_object_));
+ ccnxContentObject_Release(&ccnx_content_object_);
+ ccnx_content_object_ = ccnxContentObject_CreateWithNameAndPayload(name.getWrappedStructure(), buffer);
+ parcBuffer_Release(&buffer);
+ name_ = std::move(name);
+}
+
+CCNxContentObjectStructure *ContentObject::getWrappedStructure() {
+ return ccnx_content_object_;
+}
+
+uint8_t ContentObject::getPathLabel() const {
+ if (ccnxContentObject_HasPathLabel(ccnx_content_object_)) {
+ return (uint8_t) ccnxContentObject_GetPathLabel(ccnx_content_object_);
+ }
+
+ return 0;
+}
+
+Array::Array(const void *array, size_t size) {
+ this->array_ = array;
+ this->size_ = size;
+}
+
+Array::Array() {
+ this->array_ = nullptr;
+ this->size_ = 0;
+}
+
+const void *Array::data() {
+ return array_;
+}
+
+std::size_t Array::size() {
+ return size_;
+}
+
+Array &Array::setData(const void *data) {
+ array_ = data;
+ return *this;
+}
+
+Array &Array::setSize(std::size_t size) {
+ size_ = size;
+ return *this;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet
diff --git a/icnet/ccnx/icnet_ccnx_content_object.h b/icnet/ccnx/icnet_ccnx_content_object.h
new file mode 100644
index 00000000..148587bb
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_content_object.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_CONTENT_OBJECT_H_
+#define ICNET_CCNX_CONTENT_OBJECT_H_
+
+#include "icnet_ccnx_common.h"
+#include "icnet_ccnx_name.h"
+#include "icnet_ccnx_key_locator.h"
+#include "icnet_ccnx_payload_type.h"
+
+extern "C" {
+#include <ccnx/common/ccnx_ContentObject.h>
+#include <ccnx/common/validation/ccnxValidation_CRC32C.h>
+#include <ccnx/common/codec/ccnxCodec_TlvPacket.h>
+};
+
+namespace icnet {
+
+namespace ccnx {
+
+typedef CCNxContentObject CCNxContentObjectStructure;
+
+// This class is used just to transfer buffer pointers
+// without making a copy, as std::vector<> would do
+
+class Array {
+ public:
+ explicit Array(const void *array, size_t size);
+
+ Array();
+
+ const void *data();
+
+ std::size_t size();
+
+ Array &setData(const void *data);
+
+ Array &setSize(std::size_t size);
+
+ private:
+ std::size_t size_;
+ const void *array_;
+};
+
+class ContentObject : public std::enable_shared_from_this<ContentObject> {
+ public:
+ ContentObject();
+
+ ContentObject(const Name &name, uint8_t *payload, std::size_t size);
+
+ ContentObject(const CCNxContentObjectStructure *content_object);
+
+ ContentObject(const Name &name);
+
+ ContentObject(Name &&name);
+
+ ~ContentObject();
+
+ bool operator==(const ContentObject &content_object);
+
+ PayloadType getContentType() const;
+
+ bool setContent(PayloadType content_type, const uint8_t *buffer, size_t buffer_size);
+
+ bool setContent(const uint8_t *buffer, size_t buffer_size);
+
+ void setContentType(PayloadType payload_type);
+
+ Array getContent() const;
+
+ void setSignature();
+
+ void signWithSha256(KeyLocator &key_locator);
+
+ void setFinalChunkNumber(uint64_t final_chunk_number);
+
+ bool hasFinalChunkNumber();
+
+ uint64_t getFinalChunkNumber();
+
+ void setExpiryTime(uint64_t expiry_time);
+
+ uint64_t getExpiryTime();
+
+ const Name &getName() const;
+
+ std::size_t getPacketSize() const;
+
+ void setName(const Name &name);
+
+ void setName(Name &&name);
+
+ CCNxContentObjectStructure *getWrappedStructure();
+
+ uint8_t getPathLabel() const;
+
+ protected:
+
+ Name name_;
+ CCNxContentObjectStructure *ccnx_content_object_;
+ PayloadType content_type_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif //CP_API_CCNXDATA_H_
diff --git a/icnet/ccnx/icnet_ccnx_facade.h b/icnet/ccnx/icnet_ccnx_facade.h
new file mode 100644
index 00000000..13a5fd43
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_facade.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_FACADE_H_
+#define ICNET_CCNX_FACADE_H_
+
+#include "icnet_ccnx_segment.h"
+#include "icnet_ccnx_name.h"
+#include "icnet_ccnx_content_object.h"
+#include "icnet_ccnx_interest.h"
+#include "icnet_ccnx_portal.h"
+#include "icnet_ccnx_manifest.h"
+#include "icnet_ccnx_key_locator.h"
+
+#endif // ICNET_CCNX_FACADE_H_
diff --git a/icnet/ccnx/icnet_ccnx_interest.cc b/icnet/ccnx/icnet_ccnx_interest.cc
new file mode 100644
index 00000000..a2bcf72e
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_interest.cc
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_interest.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+Interest::Interest(const Name &interest_name)
+ : name_(interest_name), interest_(ccnxInterest_CreateSimple(name_.getWrappedStructure())) {
+}
+
+Interest::Interest(Name &&interestName)
+ : name_(std::move(interestName)), interest_(ccnxInterest_CreateSimple(name_.getWrappedStructure())) {
+}
+
+Interest::Interest(CCNxInterestStruct *interest)
+ : name_(ccnxInterest_GetName(interest)), interest_(ccnxInterest_Acquire(interest)) {
+}
+
+Interest::Interest(const Interest &other_interest) : name_(other_interest.name_),
+ interest_(ccnxInterest_CreateSimple(other_interest.name_
+ .getWrappedStructure())) {
+ PARCBuffer *buffer = nullptr;
+
+ // Key Id restriction
+ buffer = ccnxInterest_GetKeyIdRestriction(other_interest.interest_);
+ if (buffer) {
+ ccnxInterest_SetKeyIdRestriction(interest_, buffer);
+ }
+
+ // Content Hash restriction
+ buffer = ccnxInterest_GetContentObjectHashRestriction(other_interest.interest_);
+ if (buffer) {
+ ccnxInterest_SetContentObjectHashRestriction(interest_, buffer);
+ }
+
+ // Optional Payload
+ buffer = ccnxInterest_GetPayload(other_interest.interest_);
+ if (buffer) {
+ ccnxInterest_SetPayload(interest_, buffer);
+ }
+
+ ccnxInterest_SetHopLimit(interest_, ccnxInterest_GetHopLimit(other_interest.interest_));
+ ccnxInterest_SetLifetime(interest_, ccnxInterest_GetLifetime(other_interest.interest_));
+}
+
+Interest::Interest(Interest &&other_interest) : name_(std::move(other_interest.name_)),
+ interest_(ccnxInterest_Acquire(other_interest.interest_)) {
+}
+
+Interest &Interest::operator=(const Interest &other_interest) {
+ ccnxInterest_Release(&interest_);
+ name_ = other_interest.name_;
+ interest_ = ccnxInterest_CreateSimple(name_.getWrappedStructure());
+ return *this;
+}
+
+Interest::~Interest() {
+ ccnxInterest_Release(&interest_);
+}
+
+bool Interest::operator==(const Interest &interest) {
+ return ccnxInterest_Equals(interest_, interest.interest_);
+}
+
+const Name &Interest::getName() const {
+ return name_;
+}
+
+void Interest::setInterestLifetime(uint32_t lifetime) {
+ ccnxInterest_SetLifetime(interest_, lifetime);
+}
+
+const uint32_t Interest::getInterestLifetime() const {
+ return ccnxInterest_GetLifetime(interest_);
+}
+
+bool Interest::setKeyId(const PARCBuffer *keyId) {
+ return ccnxInterest_SetKeyIdRestriction(interest_, keyId);
+}
+
+PARCBuffer *Interest::getKeyId() {
+ return ccnxInterest_GetKeyIdRestriction(interest_);
+}
+
+PARCBuffer *Interest::getContentHash() {
+ return ccnxInterest_GetContentObjectHashRestriction(interest_);
+}
+
+bool Interest::setContentHash(PARCBuffer *hash) {
+ return ccnxInterest_SetContentObjectHashRestriction(interest_, hash);
+}
+
+std::string Interest::toString() {
+ char *str = ccnxInterest_ToString(interest_);
+ std::string ret(str);
+
+ free(str);
+
+ return ret;
+}
+
+bool Interest::setPayload(const PARCBuffer *payload) {
+ return ccnxInterest_SetPayload(interest_, payload);
+}
+
+bool Interest::setPayloadAndId(const PARCBuffer *payload) {
+ return ccnxInterest_SetPayloadAndId(interest_, payload);
+}
+
+bool Interest::setPayloadWithId(const PARCBuffer *payload, const CCNxInterestPayloadId *payload_id) {
+ return ccnxInterest_SetPayloadWithId(interest_, payload, payload_id);
+}
+
+PARCBuffer *Interest::getPayload() {
+ return ccnxInterest_GetPayload(interest_);
+}
+
+void Interest::setHopLimit(uint32_t hop_limit) {
+ ccnxInterest_SetHopLimit(interest_, hop_limit);
+}
+
+uint32_t Interest::getHopLimit() {
+ return ccnxInterest_GetHopLimit(interest_);
+}
+
+CCNxInterestStruct *Interest::getWrappedStructure() const {
+ return interest_;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_interest.h b/icnet/ccnx/icnet_ccnx_interest.h
new file mode 100644
index 00000000..2156b56f
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_interest.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_INTEREST_H_
+#define ICNET_CCNX_INTEREST_H_
+
+#include "icnet_ccnx_common.h"
+
+extern "C" {
+#include <ccnx/common/ccnx_Interest.h>
+};
+
+//#include "interest.hpp"
+#include "icnet_ccnx_name.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+typedef CCNxInterest CCNxInterestStruct;
+
+class Interest : public std::enable_shared_from_this<Interest> {
+ public:
+ Interest(const Name &interest_name);
+
+ Interest(Name &&name);
+
+ Interest(CCNxInterestStruct *interest);
+
+ Interest(const Interest &other_interest);
+
+ Interest(Interest &&other_interest);
+
+ ~Interest();
+
+ bool operator==(const Interest &interest);
+
+ Interest &operator=(const Interest &other_interest);
+
+ const Name &getName() const;
+
+ void setInterestLifetime(uint32_t lifetime);
+
+ const uint32_t getInterestLifetime() const;
+
+ bool setKeyId(const PARCBuffer *keyId);
+
+ PARCBuffer *getKeyId();
+
+ PARCBuffer *getContentHash();
+
+ bool setContentHash(PARCBuffer *hash);
+
+ std::string toString();
+
+ bool setPayload(const PARCBuffer *payload);
+
+ bool setPayloadAndId(const PARCBuffer *payload);
+
+ bool setPayloadWithId(const PARCBuffer *payload, const CCNxInterestPayloadId *payload_id);
+
+ PARCBuffer *getPayload();
+
+ void setHopLimit(uint32_t hop_limit);
+
+ uint32_t getHopLimit();
+
+ CCNxInterestStruct *getWrappedStructure() const;
+
+ private:
+
+ Name name_;
+ CCNxInterestStruct *interest_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_INTEREST_H_
diff --git a/icnet/ccnx/icnet_ccnx_key_locator.cc b/icnet/ccnx/icnet_ccnx_key_locator.cc
new file mode 100644
index 00000000..193573a9
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_key_locator.cc
@@ -0,0 +1,40 @@
+//
+// Created by msardara on 01/11/16.
+//
+
+#include "icnet_ccnx_key_locator.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+KeyLocator::KeyLocator() : type_(KeyLocatorType::UNKNOWN) {
+}
+
+KeyLocator::KeyLocator(KeyLocatorType type, Name &name) : type_(type), name_(name) {
+}
+
+Name &KeyLocator::getName() {
+ return name_;
+}
+
+void KeyLocator::setName(Name &name) {
+ name_ = name;
+}
+
+void KeyLocator::setType(KeyLocatorType type) {
+ type_ = type;
+}
+
+KeyLocatorType KeyLocator::getType() {
+ return type_;
+}
+
+void KeyLocator::clear() {
+ type_ = KeyLocatorType::UNKNOWN;
+ name_.clear();
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_key_locator.h b/icnet/ccnx/icnet_ccnx_key_locator.h
new file mode 100644
index 00000000..c55ff5f1
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_key_locator.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_KEY_LOCATOR_H_
+#define ICNET_CCNX_KEY_LOCATOR_H_
+
+#include "icnet_ccnx_common.h"
+#include "icnet_ccnx_key_locator_type.h"
+#include "icnet_ccnx_name.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+class KeyLocator : public std::enable_shared_from_this<KeyLocator> {
+ public:
+ KeyLocator();
+
+ KeyLocator(KeyLocatorType type, Name &name);
+
+ KeyLocatorType getType();
+
+ void setType(KeyLocatorType type);
+
+ void setName(Name &name);
+
+ Name &getName();
+
+ void clear();
+
+ private:
+ KeyLocatorType type_;
+ Name name_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_KEY_LOCATOR_H_
diff --git a/icnet/ccnx/icnet_ccnx_key_locator_type.h b/icnet/ccnx/icnet_ccnx_key_locator_type.h
new file mode 100644
index 00000000..477870d3
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_key_locator_type.h
@@ -0,0 +1,22 @@
+//
+// Created by msardara on 16/02/2017.
+//
+
+#ifndef ICNET_CCNX_KEY_LOCATOR_TYPE_H_
+#define ICNET_CCNX_KEY_LOCATOR_TYPE_H_
+
+namespace icnet {
+
+namespace ccnx {
+
+enum Type {
+ NAME = 0, KEY_DIGEST = 1, UNKNOWN = 255
+};
+
+typedef enum Type KeyLocatorType;
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_KEY_LOCATOR_TYPE_H_
diff --git a/icnet/ccnx/icnet_ccnx_local_connector.cc b/icnet/ccnx/icnet_ccnx_local_connector.cc
new file mode 100644
index 00000000..2a47c117
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_local_connector.cc
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_local_connector.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+LocalConnector::LocalConnector(boost::asio::io_service &io_service,
+ std::string &ip_address,
+ std::string &port,
+ MessageReceivedCallback receive_callback,
+ std::list<Name> &name_list)
+ : io_service_(io_service),
+ socket_(io_service_),
+ resolver_(io_service_),
+ endpoint_iterator_(resolver_.resolve({ip_address, port})),
+ timer_(io_service),
+ is_connecting_(false),
+ is_reconnection_(false),
+ data_available_(false),
+ receive_callback_(receive_callback),
+ served_name_list_(name_list) {
+ startConnectionTimer();
+ doConnect();
+}
+
+LocalConnector::~LocalConnector() {
+}
+
+void LocalConnector::bind(Name &name) {
+ CCNxControl *control = ccnxControl_CreateAddRouteToSelfRequest(name.getWrappedStructure());
+ CCNxMetaMessage *message = ccnxMetaMessage_CreateFromControl(control);
+ ccnxControl_Release(&control);
+
+ send(message);
+
+ ccnxMetaMessage_Release((CCNxMetaMessage **) &message);
+
+}
+
+void LocalConnector::send(CCNxMetaMessage *message) {
+ CCNxMetaMessage *msg = ccnxMetaMessage_Acquire(message);
+
+ io_service_.post([this, msg]() {
+ bool write_in_progres = !write_msgs_.empty();
+ write_msgs_.push_back(msg);
+ if (!is_connecting_) {
+ if (!write_in_progres) {
+ doWrite();
+ }
+ } else {
+ // Tell the handle connect it has data to write
+ data_available_ = true;
+ }
+ });
+}
+
+void LocalConnector::close() {
+ io_service_.post([this]() { socket_.close(); });
+}
+
+void LocalConnector::doWrite() {
+ CCNxMetaMessage *message = write_msgs_.front();
+ CCNxCodecNetworkBufferIoVec *network_buffer = ccnxCodecSchemaV1PacketEncoder_DictionaryEncode(message, NULL);
+ const iovec *iov = ccnxCodecNetworkBufferIoVec_GetArray(network_buffer);
+
+ boost::asio::async_write(socket_,
+ boost::asio::buffer(iov->iov_base, iov->iov_len),
+ [this, network_buffer, message](boost::system::error_code ec, std::size_t /*length*/) {
+ if (!ec) {
+ ccnxMetaMessage_Release((CCNxMetaMessage **) &message);
+ write_msgs_.pop_front();
+
+ if (!write_msgs_.empty()) {
+ doWrite();
+ }
+ } else {
+ tryReconnect();
+ }
+
+ ccnxCodecNetworkBufferIoVec_Release((CCNxCodecNetworkBufferIoVec **) &network_buffer);
+
+ });
+
+}
+
+void LocalConnector::doReadBody() {
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.body(), read_msg_.bodyLength()),
+ boost::asio::transfer_exactly(read_msg_.bodyLength()),
+ [this](boost::system::error_code ec, std::size_t length) {
+ if (!ec) {
+ receive_callback_(read_msg_.decodeMessage());
+ doReadHeader();
+ } else {
+ tryReconnect();
+ }
+ });
+}
+
+void LocalConnector::doReadHeader() {
+ boost::asio::async_read(socket_,
+ boost::asio::buffer(read_msg_.data(), TransportMessage::header_length),
+ boost::asio::transfer_exactly(TransportMessage::header_length),
+ [this](boost::system::error_code ec, std::size_t /*length*/) {
+ if (!ec) {
+ if (read_msg_.decodeHeader()) {
+ doReadBody();
+ } else {
+ std::cerr << "Decoding error" << std::endl;
+ }
+ } else {
+ tryReconnect();
+ }
+ });
+}
+
+void LocalConnector::tryReconnect() {
+ if (!is_connecting_) {
+ std::cerr << "Connection lost. Trying to reconnect..." << std::endl;
+ is_connecting_ = true;
+ is_reconnection_ = true;
+ io_service_.post([this]() {
+ socket_.close();
+ startConnectionTimer();
+ doConnect();
+ });
+ }
+}
+
+void LocalConnector::doConnect() {
+ boost::asio::async_connect(socket_,
+ endpoint_iterator_,
+ [this](boost::system::error_code ec, tcp::resolver::iterator) {
+ if (!ec) {
+ timer_.cancel();
+ is_connecting_ = false;
+ doReadHeader();
+
+ if (data_available_) {
+ data_available_ = false;
+ doWrite();
+ }
+
+ if (is_reconnection_) {
+ is_reconnection_ = false;
+ std::cout << "Connection recovered!" << std::endl;
+ for (auto &name : served_name_list_) {
+ bind(name);
+ }
+ }
+
+ } else {
+ sleep(1);
+ doConnect();
+ }
+ });
+}
+
+bool LocalConnector::checkConnected() {
+ return !is_connecting_;
+}
+
+void LocalConnector::startConnectionTimer() {
+ timer_.expires_from_now(boost::posix_time::seconds(20));
+ timer_.async_wait(std::bind(&LocalConnector::handleDeadline, this, std::placeholders::_1));
+}
+
+void LocalConnector::handleDeadline(const boost::system::error_code &ec) {
+ if (!ec) {
+ io_service_.post([this]() {
+ socket_.close();
+ std::cerr << "Error connecting. Is the forwarder running?" << std::endl;
+ io_service_.stop();
+ });
+ }
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_local_connector.h b/icnet/ccnx/icnet_ccnx_local_connector.h
new file mode 100644
index 00000000..b08d1c5a
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_local_connector.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_LOCAL_CONNECTOR_H_
+#define ICNET_CCNX_LOCAL_CONNECTOR_H_
+
+#include "icnet_ccnx_common.h"
+#include "icnet_ccnx_network_message.h"
+#include "icnet_ccnx_name.h"
+#include <boost/asio.hpp>
+#include <deque>
+
+extern "C" {
+#include <ccnx/common/ccnx_Interest.h>
+#include <ccnx/common/ccnx_ContentObject.h>
+#include <parc/security/parc_Security.h>
+#include <ccnx/api/ccnx_Portal/ccnx_Portal.h>
+#include <ccnx/api/ccnx_Portal/ccnx_PortalRTA.h>
+#include <ccnx/common/codec/schema_v1/ccnxCodecSchemaV1_PacketEncoder.h>
+};
+
+namespace icnet {
+
+namespace ccnx {
+
+using boost::asio::ip::tcp;
+typedef std::deque<CCNxMetaMessage *> CcnxTransportMessageQueue;
+typedef std::function<void(CCNxMetaMessage *)> MessageReceivedCallback;
+
+class LocalConnector {
+ public:
+ LocalConnector(boost::asio::io_service &io_service,
+ std::string &ip_address,
+ std::string &port,
+ MessageReceivedCallback receive_callback,
+ std::list<Name> &name_list);
+
+ ~LocalConnector();
+
+ void send(CCNxMetaMessage *message);
+
+ void bind(Name &name);
+
+ void close();
+
+ private:
+ void doConnect();
+
+ void doReadHeader();
+
+ void doReadBody();
+
+ void doWrite();
+
+ bool checkConnected();
+
+ private:
+
+ void handleDeadline(const boost::system::error_code &ec);
+
+ void startConnectionTimer();
+
+ void tryReconnect();
+
+ boost::asio::io_service &io_service_;
+ boost::asio::ip::tcp::socket socket_;
+ boost::asio::ip::tcp::resolver resolver_;
+ boost::asio::ip::tcp::resolver::iterator endpoint_iterator_;
+ boost::asio::deadline_timer timer_;
+
+ TransportMessage read_msg_;
+ CcnxTransportMessageQueue write_msgs_;
+
+ bool is_connecting_;
+ bool is_reconnection_;
+ bool data_available_;
+
+ MessageReceivedCallback receive_callback_;
+ std::list<Name> &served_name_list_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_LOCAL_CONNECTOR_H_
diff --git a/icnet/ccnx/icnet_ccnx_manifest.cc b/icnet/ccnx/icnet_ccnx_manifest.cc
new file mode 100644
index 00000000..c818f110
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_manifest.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_manifest.h"
+#include <boost/property_tree/json_parser.hpp>
+
+namespace icnet {
+
+namespace ccnx {
+
+Manifest::Manifest(Name &name) : ContentObject(name) {
+}
+
+std::size_t Manifest::estimateManifestSize() {
+ std::size_t capacity = 0;
+
+ // for (auto pair : m_mapNameDigest)
+ // capacity += pair.first.size() + pair.second.data().size();
+
+ return capacity;
+}
+
+Manifest::Manifest(ContentObject &content_object) {
+ decode();
+}
+
+void Manifest::encode() {
+ std::stringstream ss;
+ //boost::property_tree::write_json(ss, m_mapNameDigest);
+
+ std::string json_string = ss.str();
+
+ ContentObject::setContent(PayloadType::MANIFEST, (uint8_t *) json_string.c_str(), json_string.size());
+}
+
+void Manifest::decode() {
+ PARCBuffer *payload = ccnxContentObject_GetPayload(ccnx_content_object_);
+ char *buffer = parcBuffer_ToString(payload);
+
+ std::stringstream ss;
+ ss << buffer;
+
+ //boost::property_tree::read_json(ss, m_mapNameDigest);
+
+ free(buffer);
+}
+
+std::string Manifest::getDigest(ContentObject &content_object) {
+ // ContentObject &ccnxData = (ContentObject &) content_object;
+ // for (auto pair : m_mapNameDigest)
+ // if (pair.second.content_object() == ccnxData.getName().toUri()) {
+ // return pair.second.content_object();
+ // }
+
+ return std::string();
+}
+
+void Manifest::addNameToCatalogue(Name &name, uint8_t *digest, std::size_t digest_size) {
+ // Name &ccnxName = (Name &) name;
+ // m_mapNameDigest.put(ccnxName.toUri(), std::string((char *) digest, digest_size));
+ return;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_manifest.h b/icnet/ccnx/icnet_ccnx_manifest.h
new file mode 100644
index 00000000..92118777
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_manifest.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_MANIFEST_H_
+#define ICNET_CCNX_MANIFEST_H_
+
+#include "icnet_ccnx_common.h"
+//#include <boost/property_tree/ptree.hpp>
+
+#include "icnet_ccnx_name.h"
+#include "icnet_ccnx_content_object.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+class Manifest : public ContentObject // public api::Manifest
+{
+ public:
+ Manifest(Name &name);
+
+ Manifest(ContentObject &content_object);
+
+ std::size_t estimateManifestSize();
+
+ void encode();
+
+ void decode();
+
+ std::string getDigest(ContentObject &content_object);
+
+ void addNameToCatalogue(Name &name, uint8_t *digest, std::size_t digest_size);
+
+ private:
+ // boost::property_tree::ptree map_name_digest_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+
+#endif // ICNET_CCNX_MANIFEST_H_
diff --git a/icnet/ccnx/icnet_ccnx_name.cc b/icnet/ccnx/icnet_ccnx_name.cc
new file mode 100644
index 00000000..2ea0d8ab
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_name.cc
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_name.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+Name::Name() {
+ name_ = ccnxName_Create();
+}
+
+Name::Name(const char *uri) : name_(ccnxName_CreateFromCString(uri)) {
+ ccnxName_AssertValid(name_);
+}
+
+Name::Name(std::string uri) : Name(uri.c_str()) {
+}
+
+Name::Name(const CCNxNameStructure *name) : name_(ccnxName_Acquire(name)) {
+ ccnxName_AssertValid(name_);
+}
+
+Name::Name(const Name &name) : name_(ccnxName_Copy(name.name_)) {
+}
+
+Name::Name(Name &&otherName) : name_(ccnxName_Acquire(otherName.name_)) {
+}
+
+Name &Name::operator=(const Name &name) {
+ ccnxName_Release(&this->name_);
+ this->name_ = ccnxName_Copy(name.name_);
+ return *this;
+}
+
+Name &Name::operator=(Name &&name) {
+ ccnxName_Release(&this->name_);
+ this->name_ = ccnxName_Acquire(name.name_);
+ return *this;
+}
+
+bool Name::operator==(const Name &name) const {
+ return ccnxName_Equals(this->name_, name.name_);
+}
+
+Name::~Name() {
+ ccnxName_Release(&name_);
+}
+
+bool Name::equals(const Name &name) {
+ return ccnxName_Equals(this->name_, name.name_);
+}
+
+bool Name::isValid() {
+ return ccnxName_IsValid(name_);
+}
+
+const std::string &Name::toString() {
+ char *str = ccnxName_ToString(name_);
+ name_string_ = std::string(str);
+ free(str);
+ return name_string_;
+}
+
+void Name::appendComponent(const Segment &suffix) {
+ ccnxName_Append(name_, suffix.getWrappedStructure());
+}
+
+void Name::append(const Name &suffix) {
+ if (ccnxName_IsValid(suffix.name_)) {
+
+ size_t number_of_components = ccnxName_GetSegmentCount(suffix.getWrappedStructure());
+
+ for (uint32_t i = 0; i < number_of_components; i++) {
+ ccnxName_Append(name_, ccnxName_GetSegment(suffix.getWrappedStructure(), i));
+ }
+ }
+}
+
+Name Name::getPrefix(ssize_t number_of_components) const {
+ std::size_t segment_count = ccnxName_GetSegmentCount(name_);
+
+ if (number_of_components >= 0) {
+ assert((std::size_t) number_of_components < segment_count);
+ return getSubName(0, number_of_components);
+ } else {
+ assert(segment_count + number_of_components >= 0);
+ return getSubName(0, number_of_components + segment_count);
+ }
+
+}
+
+Segment Name::get(ssize_t index) const {
+ std::size_t segment_count = ccnxName_GetSegmentCount(name_);
+ size_t componentIndex = 0;
+
+ if (index >= 0) {
+ assert((size_t) index < segment_count);
+ componentIndex = (size_t) index;
+ } else {
+ assert(segment_count + index >= 0);
+ componentIndex = segment_count + index;
+ }
+
+ CCNxNameSegment *segment = ccnxName_GetSegment(name_, componentIndex);
+ Segment ret(segment);
+
+ return ret;
+}
+
+Name Name::getSubName(ssize_t start_component, ssize_t number_of_components) const {
+
+ size_t name_size = ccnxName_GetSegmentCount(name_);
+ size_t begin;
+
+ if (start_component >= 0) {
+ assert((size_t) start_component < name_size);
+ begin = static_cast<size_t>(start_component);
+ } else {
+ assert((ssize_t) (start_component + name_size) >= 0);
+ begin = start_component + name_size;
+ }
+
+ size_t end = begin;
+ end += number_of_components < 0 ? name_size : static_cast<size_t>(number_of_components);
+
+ if (end >= name_size) {
+ end = name_size;
+ }
+
+ CCNxName *name = ccnxName_Create();
+
+ for (size_t i = begin; i < end; i++) {
+ ccnxName_Append(name, ccnxName_GetSegment(name_, i));
+ }
+
+ Name ret(name);
+ ccnxName_Release(&name);
+
+ return ret;
+}
+
+bool Name::isPrefixOf(const Name &name) {
+ Name &ccnx_name = (Name &) name;
+ return ccnxName_StartsWith(ccnx_name.name_, name_);
+}
+
+Name &Name::appendSegment(const uint64_t chunk_number) {
+ CCNxNameSegmentStructure *ns = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, chunk_number);
+ name_ = ccnxName_Append(name_, ns);
+ ccnxNameSegment_Release(&ns);
+
+ return *this;
+}
+
+bool Name::empty() const {
+ return ccnxName_GetSegmentCount(name_) == 0;
+}
+
+void Name::clear() {
+ ccnxName_Release(&name_);
+ name_ = ccnxName_Create();
+}
+
+std::size_t Name::getSegmentCount() {
+ return ccnxName_GetSegmentCount(name_);
+}
+
+std::size_t Name::size() {
+ std::size_t number_of_segments = ccnxName_GetSegmentCount(name_);
+ std::size_t name_bytes = 0;
+
+ for (std::size_t i = 0; i < number_of_segments; i++) {
+ name_bytes += ccnxNameSegment_Length(ccnxName_GetSegment(name_, i));
+ }
+
+ return name_bytes;
+}
+
+std::ostream &operator<<(std::ostream &os, const Name &name) {
+ const std::string &str = const_cast<Name &>(name).toString();
+
+ if (name.empty()) {
+ os << "ccnx:/";
+ } else {
+ os << str;
+ }
+
+ return os;
+}
+
+CCNxNameStructure *Name::getWrappedStructure() const {
+ return name_;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+namespace std {
+size_t hash<icnet::ccnx::Name>::operator()(const icnet::ccnx::Name &name) const {
+ return ccnxName_HashCode(name.getWrappedStructure());;
+}
+
+} // end namespace std \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_name.h b/icnet/ccnx/icnet_ccnx_name.h
new file mode 100644
index 00000000..68c4d19e
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_name.h
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_NAME_H_
+#define ICNET_CCNX_NAME_H_
+
+#include "icnet_ccnx_common.h"
+
+#include <unordered_map>
+#include <assert.h>
+#include <list>
+
+extern "C" {
+#include <ccnx/common/ccnx_Name.h>
+};
+
+//#include "name.hpp"
+#include "icnet_ccnx_segment.h"
+#include <vector>
+
+typedef CCNxName CCNxNameStructure;
+
+namespace icnet {
+
+namespace ccnx {
+
+class Name : public std::enable_shared_from_this<Name> // : public api::Name
+{
+ public:
+ Name();
+
+ /**
+ * @brief Create name
+ * @param uri The null-terminated URI string
+ */
+ Name(const char *uri);
+
+ /**
+ * @brief Create name from @p uri (ICN URI scheme)
+ * @param uri The URI string
+ */
+ Name(std::string uri);
+
+ Name(const Name &name);
+
+ Name(Name &&otherName);
+
+ Name(const CCNxNameStructure *name);
+
+ Name &operator=(const Name &name);
+
+ Name &operator=(Name &&name);
+
+ bool operator==(const Name &name) const;
+
+ bool isValid();
+
+ const std::string &toString();
+
+ void appendComponent(const Segment &component);
+
+ void append(const Name &suffix);
+
+ Name getPrefix(ssize_t number_of_components) const;
+
+ Name &appendSegment(const uint64_t chunk_number);
+
+ bool isPrefixOf(const Name &name);
+
+ bool equals(const Name &name);
+
+ Segment get(ssize_t index) const;
+
+ Name getSubName(ssize_t start_component, ssize_t number_of_components = -1) const;
+
+ bool empty() const;
+
+ void clear();
+
+ std::size_t getSegmentCount();
+
+ std::size_t size();
+
+ ~Name();
+
+ CCNxNameStructure *getWrappedStructure() const;
+
+ private:
+
+ CCNxNameStructure *name_;
+ std::string name_string_;
+};
+
+std::ostream &operator<<(std::ostream &os, const Name &name);
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+namespace std {
+template<>
+struct hash<icnet::ccnx::Name> {
+ size_t operator()(const icnet::ccnx::Name &name) const;
+};
+
+} // end namespace std
+
+#endif // ICNET_CCNX_NAME_H_
diff --git a/icnet/ccnx/icnet_ccnx_network_message.cc b/icnet/ccnx/icnet_ccnx_network_message.cc
new file mode 100644
index 00000000..70dff5f7
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_network_message.cc
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_network_message.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+TransportMessage::TransportMessage() : packet_length_(0) {
+}
+
+const uint8_t *TransportMessage::data() const {
+ return data_;
+}
+
+uint8_t *TransportMessage::data() {
+ return data_;
+}
+
+std::size_t TransportMessage::length() const {
+ return packet_length_;
+}
+
+const uint8_t *TransportMessage::body() const {
+ return data_ + header_length;
+}
+
+uint8_t *TransportMessage::body() {
+ return data_ + header_length;
+}
+
+std::size_t TransportMessage::bodyLength() const {
+ return packet_length_ - header_length;
+}
+
+void TransportMessage::bodyLength(std::size_t new_length) {
+ packet_length_ = new_length;
+ if (packet_length_ > max_packet_length) {
+ packet_length_ = max_packet_length;
+ }
+}
+
+bool TransportMessage::decodeHeader() {
+ // General checks
+
+ uint8_t message_version = data_[0];
+
+ if (message_version != 1) {
+ std::cerr << "Illegal packet version " << message_version << std::endl;
+ return false;
+ }
+
+ // Get packet length
+
+ packet_length_ = data_[2];
+ packet_length_ <<= 8;
+ packet_length_ |= data_[3];
+
+ return true;
+}
+
+CCNxMetaMessage *TransportMessage::decodeMessage() {
+ std::size_t total_length = packet_length_;
+ PARCBuffer *buffer = parcBuffer_CreateFromArray((void *) data_, total_length);
+ buffer = parcBuffer_Flip(buffer);
+ CCNxMetaMessage *ret = ccnxMetaMessage_CreateFromWireFormatBuffer(buffer);
+ parcBuffer_Release((PARCBuffer **) &buffer);
+
+ return ret;
+
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_network_message.h b/icnet/ccnx/icnet_ccnx_network_message.h
new file mode 100644
index 00000000..a5cbfccc
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_network_message.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_NETWORK_MESSAGE_H_
+#define ICNET_CCNX_NETWORK_MESSAGE_H_
+
+#include "icnet_ccnx_common.h"
+#include <iostream>
+
+extern "C" {
+#include <ccnx/common/codec/schema_v1/ccnxCodecSchemaV1_PacketDecoder.h>
+#include <parc/algol/parc_Buffer.h>
+#include <ccnx/transport/common/transport_MetaMessage.h>
+};
+
+namespace icnet {
+
+namespace ccnx {
+
+class TransportMessage {
+ public:
+ enum {
+ header_length = 8
+ };
+ enum {
+ max_packet_length = 1500
+ };
+
+ TransportMessage();
+
+ const uint8_t *data() const;
+
+ uint8_t *data();
+
+ std::size_t length() const;
+
+ const uint8_t *body() const;
+
+ uint8_t *body();
+
+ std::size_t bodyLength() const;
+
+ void bodyLength(std::size_t new_length);
+
+ bool decodeHeader();
+
+ CCNxMetaMessage *decodeMessage();
+
+ private:
+ uint8_t data_[max_packet_length];
+ std::size_t packet_length_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_NETWORK_MESSAGE_H_
diff --git a/icnet/ccnx/icnet_ccnx_payload_type.h b/icnet/ccnx/icnet_ccnx_payload_type.h
new file mode 100644
index 00000000..36231c52
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_payload_type.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_PAYLOAD_TYPE_H_
+#define ICNET_CCNX_PAYLOAD_TYPE_H_
+
+#include <ccnx/common/ccnx_PayloadType.h>
+
+namespace icnet {
+
+namespace ccnx {
+
+typedef enum {
+ DATA = CCNxPayloadType_DATA,
+ KEY = CCNxPayloadType_KEY,
+ LINK = CCNxPayloadType_LINK,
+ MANIFEST = CCNxPayloadType_MANIFEST,
+ NONE = 999
+} PayloadType;
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_PAYLOAD_TYPE_H_
diff --git a/icnet/ccnx/icnet_ccnx_pending_interest.cc b/icnet/ccnx/icnet_ccnx_pending_interest.cc
new file mode 100644
index 00000000..9536e4fb
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_pending_interest.cc
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_pending_interest.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+PendingInterest::PendingInterest(std::shared_ptr<Interest> &interest,
+ boost::asio::io_service &portal_io_service,
+ const OnContentObjectCallback &on_content_object,
+ const OnInterestTimeoutCallback &on_interest_timeout)
+ : interest_(interest),
+ io_service_(portal_io_service),
+ timer_(io_service_),
+ on_content_object_callback_(on_content_object),
+ on_interest_timeout_callback_(on_interest_timeout),
+ received_(false),
+ valid_(true) {
+}
+
+PendingInterest::~PendingInterest() {
+ interest_.reset();
+}
+
+void PendingInterest::startCountdown(BoostCallback &cb) {
+ timer_.expires_from_now(boost::posix_time::milliseconds(interest_->getInterestLifetime()));
+ timer_.async_wait(cb);
+}
+
+void PendingInterest::cancelTimer() {
+ timer_.cancel();
+}
+
+bool PendingInterest::isReceived() const {
+ return received_;
+}
+
+void PendingInterest::setReceived() {
+ received_ = true;
+}
+
+const std::shared_ptr<Interest> &PendingInterest::getInterest() const {
+ return interest_;
+}
+
+void PendingInterest::setInterest(const std::shared_ptr<Interest> &interest) {
+ PendingInterest::interest_ = interest;
+}
+
+const OnContentObjectCallback &PendingInterest::getOnDataCallback() const {
+ return on_content_object_callback_;
+}
+
+void PendingInterest::setOnDataCallback(const OnContentObjectCallback &on_content_object) {
+ PendingInterest::on_content_object_callback_ = on_content_object;
+}
+
+const OnInterestTimeoutCallback &PendingInterest::getOnTimeoutCallback() const {
+ return on_interest_timeout_callback_;
+}
+
+void PendingInterest::setOnTimeoutCallback(const OnInterestTimeoutCallback &on_interest_timeout) {
+ PendingInterest::on_interest_timeout_callback_ = on_interest_timeout;
+}
+
+void PendingInterest::setReceived(bool received) {
+ PendingInterest::received_ = received;
+}
+
+bool PendingInterest::isValid() const {
+ return valid_;
+}
+
+void PendingInterest::setValid(bool valid) {
+ PendingInterest::valid_ = valid;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_pending_interest.h b/icnet/ccnx/icnet_ccnx_pending_interest.h
new file mode 100644
index 00000000..692c63e7
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_pending_interest.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_PENDING_INTEREST_H_
+#define ICNET_CCNX_PENDING_INTEREST_H_
+
+#include "icnet_ccnx_interest.h"
+#include "icnet_ccnx_content_object.h"
+#include "icnet_ccnx_name.h"
+
+#include <boost/asio.hpp>
+
+namespace icnet {
+
+namespace ccnx {
+
+typedef std::function<void(const Interest &, ContentObject &)>
+OnContentObjectCallback;
+typedef std::function<void( const Interest
+&)>
+OnInterestTimeoutCallback;
+typedef std::function<void(const Name &, const Interest
+&)>
+OnInterestCallback;
+typedef std::function<void(const boost::system::error_code &)> BoostCallback;
+
+class PendingInterest {
+ public:
+
+ friend class Portal;
+
+ PendingInterest(std::shared_ptr<Interest> &interest,
+ boost::asio::io_service &portal_io_service,
+ const OnContentObjectCallback &on_content_object,
+ const OnInterestTimeoutCallback &on_interest_timeout);
+
+ ~PendingInterest();
+
+ bool isReceived() const;
+
+ void startCountdown(BoostCallback &cb);
+
+ void cancelTimer();
+
+ void setReceived();
+
+ const std::shared_ptr<Interest> &getInterest() const;
+
+ void setInterest(const std::shared_ptr<Interest> &interest);
+
+ const OnContentObjectCallback &getOnDataCallback() const;
+
+ void setOnDataCallback(const OnContentObjectCallback &on_content_object);
+
+ const OnInterestTimeoutCallback &getOnTimeoutCallback() const;
+
+ void setOnTimeoutCallback(const OnInterestTimeoutCallback &on_interest_timeout);
+
+ void setReceived(bool received);
+
+ bool isValid() const;
+
+ void setValid(bool valid);
+
+ private:
+ std::shared_ptr<Interest> interest_;
+ boost::asio::io_service &io_service_;
+ boost::asio::deadline_timer timer_;
+
+ private:
+ OnContentObjectCallback on_content_object_callback_;
+ OnInterestTimeoutCallback on_interest_timeout_callback_;
+ bool received_;
+ bool valid_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_PENDING_INTEREST_H_
diff --git a/icnet/ccnx/icnet_ccnx_portal.cc b/icnet/ccnx/icnet_ccnx_portal.cc
new file mode 100644
index 00000000..5b14ace3
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_portal.cc
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_portal.h"
+
+#define UNSET_CALLBACK 0
+#define MAX_ARRAY_SIZE 16000
+
+namespace icnet {
+
+namespace ccnx {
+
+Portal::Portal(std::string forwarder_ip_address, std::string forwarder_port)
+ : is_running_(true),
+ clear_(false),
+ on_interest_callback_(UNSET_CALLBACK),
+ connector_(io_service_,
+ forwarder_ip_address,
+ forwarder_port,
+ std::bind(&Portal::processIncomingMessages, this, std::placeholders::_1),
+ served_name_list_) {
+ io_service_.reset();
+}
+
+Portal::~Portal() {
+ connector_.close();
+ stopEventsLoop();
+ clear();
+}
+
+void Portal::sendInterest(const Interest &interest,
+ const OnContentObjectCallback &on_content_object,
+ const OnInterestTimeoutCallback &on_interest_timeout) {
+ std::shared_ptr<Interest> _interest = const_cast<Interest &>(interest).shared_from_this();
+
+ // Create new message
+ CCNxMetaMessage *message = ccnxMetaMessage_CreateFromInterest(_interest->getWrappedStructure());
+
+ // Send it
+ connector_.send(message);
+ clear_ = false;
+ std::function<void(const boost::system::error_code &)> timer_callback;
+
+ PendingInterest *pend_interest = new PendingInterest(_interest, io_service_, on_content_object, on_interest_timeout);
+ const Name &name = _interest->getName();
+
+ pending_interest_hash_table_[name] = std::unique_ptr<PendingInterest>(pend_interest);
+
+ timer_callback = [this, name](const boost::system::error_code &ec) {
+
+ if (clear_ || !is_running_) {
+ return;
+ }
+
+ if (ec.value() != boost::system::errc::operation_canceled) {
+ std::unordered_map<Name, std::unique_ptr<PendingInterest>>::iterator it = pending_interest_hash_table_.find(name);
+ if (it != pending_interest_hash_table_.end()) {
+ it->second->getOnTimeoutCallback()(*it->second->getInterest());
+ } else {
+ std::cerr << "Timeout on interest already received_! [" << it->second->getInterest()->getName() << "]"
+ << std::endl;
+ }
+ }
+ };
+
+ pend_interest->startCountdown(timer_callback);
+
+ ccnxMetaMessage_Release(&message);
+}
+
+void Portal::bind(Name &name, const OnInterestCallback &on_interest_callback) {
+ on_interest_callback_ = on_interest_callback;
+ served_name_list_.push_back(name);
+ work_ = std::shared_ptr<boost::asio::io_service::work>(new boost::asio::io_service::work(io_service_));
+ connector_.bind(name);
+}
+
+void Portal::sendContentObject(const ContentObject &content_object) {
+ ContentObject &ccnx_data = const_cast<ContentObject &>(content_object);
+ CCNxMetaMessageStructure *message = ccnxMetaMessage_CreateFromContentObject(ccnx_data.getWrappedStructure());
+
+ ccnxContentObject_AssertValid(ccnx_data.getWrappedStructure());
+
+ connector_.send(message);
+
+ ccnxMetaMessage_Release(&message);
+}
+
+void Portal::runEventsLoop() {
+ if (io_service_.stopped()) {
+ io_service_.reset(); // ensure that run()/poll() will do some work
+ }
+
+ is_running_ = true;
+ this->io_service_.run();
+}
+
+void Portal::stopEventsLoop() {
+ is_running_ = false;
+ work_.reset();
+ io_service_.stop();
+}
+
+void Portal::clear() {
+ pending_interest_hash_table_.clear();
+ clear_ = true;
+}
+
+void Portal::processInterest(CCNxMetaMessage *response) {
+ // Interest for a producer
+ CCNxInterest *interest_ptr = ccnxInterest_Acquire(ccnxMetaMessage_GetInterest(response));
+
+ if (on_interest_callback_ != UNSET_CALLBACK) {
+
+ Interest interest(interest_ptr);
+ if (on_interest_callback_) {
+ on_interest_callback_(interest.getName(), interest);
+ }
+ ccnxInterest_Release((CCNxInterest **) &interest_ptr);
+ }
+}
+
+void Portal::processControlMessage(CCNxMetaMessage *response) {
+ // Control message as response to the route set by a producer
+
+ CCNxControl *control_message = ccnxMetaMessage_GetControl(response);
+
+ if (ccnxControl_IsACK(control_message)) {
+ std::cout << "Route set correctly!" << std::endl;
+ } else {
+ std::cout << "Failed to set the route." << std::endl;
+ }
+}
+
+void Portal::processContentObject(CCNxMetaMessage *response) {
+ // Content object for a consumer
+
+ CCNxContentObject *content_object = ccnxContentObject_Acquire(ccnxMetaMessage_GetContentObject(response));
+
+ CCNxName *n = ccnxContentObject_GetName(content_object);
+ size_t n_components = ccnxName_GetSegmentCount(n);
+ CCNxNameSegment *last_segment = ccnxName_GetSegment(n, n_components - 1);
+
+ bool has_chunk_number = ccnxNameSegmentNumber_IsValid(last_segment);
+
+ PendingInterestHashTable::iterator it = pending_interest_hash_table_.find(Name(n));
+
+ if (it != pending_interest_hash_table_.end()) {
+
+ std::unique_ptr<PendingInterest> &interest_ptr = it->second;
+
+ interest_ptr->cancelTimer();
+ std::shared_ptr<ContentObject> data_ptr = std::make_shared<ContentObject>(content_object);
+
+ if (!interest_ptr->isReceived()) {
+ interest_ptr->setReceived();
+ interest_ptr->getOnDataCallback()(*interest_ptr->getInterest(), *data_ptr);
+
+ if (!has_chunk_number) {
+ pending_interest_hash_table_.erase(interest_ptr->getInterest()->getName());
+ }
+ }
+ }
+
+ ccnxContentObject_Release((CCNxContentObject **) &content_object);
+}
+
+void Portal::processIncomingMessages(CCNxMetaMessage *response) {
+ if (clear_ || !is_running_) {
+ return;
+ }
+
+ if (response) {
+ if (ccnxMetaMessage_IsContentObject(response)) {
+ processContentObject(response);
+ } else if (ccnxMetaMessage_IsInterest(response)) {
+ processInterest(response);
+ } else if (ccnxMetaMessage_IsControl(response)) {
+ processControlMessage(response);
+ }
+ ccnxMetaMessage_Release(&response);
+ }
+
+}
+
+boost::asio::io_service &Portal::getIoService() {
+ return io_service_;
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/ccnx/icnet_ccnx_portal.h b/icnet/ccnx/icnet_ccnx_portal.h
new file mode 100644
index 00000000..5076fcd9
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_portal.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_PORTAL_H_
+#define ICNET_CCNX_PORTAL_H_
+
+#include "icnet_ccnx_common.h"
+
+#include <unordered_map>
+#include <memory>
+#include <boost/asio/deadline_timer.hpp>
+#include <boost/asio/io_service.hpp>
+#include <boost/asio.hpp>
+#include <future>
+
+extern "C" {
+#include <ccnx/api/ccnx_Portal/ccnx_Portal.h>
+#include <ccnx/api/ccnx_Portal/ccnx_PortalRTA.h>
+#include <ccnx/api/control/cpi_Acks.h>
+#include <ccnx/common/ccnx_ContentObject.h>
+#include <parc/security/parc_Security.h>
+#include <parc/security/parc_IdentityFile.h>
+#include <parc/security/parc_Pkcs12KeyStore.h>
+#include <parc/algol/parc_Memory.h>
+};
+
+#include "icnet_ccnx_interest.h"
+#include "icnet_ccnx_pending_interest.h"
+#include "icnet_ccnx_name.h"
+#include "icnet_ccnx_content_object.h"
+#include "icnet_ccnx_local_connector.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+typedef std::unordered_map<Name, std::unique_ptr<PendingInterest>> PendingInterestHashTable;
+typedef uint64_t PendingInterestId;
+typedef CCNxMetaMessage CCNxMetaMessageStructure;
+
+class Portal : public std::enable_shared_from_this<Portal> // : public api::Face
+{
+ public:
+ Portal(std::string forwarder_ip_address = "127.0.0.1", std::string forwarder_port = "9695");
+
+ ~Portal();
+
+ void sendInterest(const Interest &interest,
+ const OnContentObjectCallback &on_content_object_callback,
+ const OnInterestTimeoutCallback &on_interest_timeout_callback);
+
+ void bind(Name &name, const OnInterestCallback &on_interest_callback);
+
+ void runEventsLoop();
+
+ void sendContentObject(const ContentObject &content_object);
+
+ void stopEventsLoop();
+
+ void clear();
+
+ boost::asio::io_service &getIoService();
+
+ private:
+
+ void processIncomingMessages(CCNxMetaMessageStructure *response);
+
+ void processInterest(CCNxMetaMessage *response);
+
+ void processContentObject(CCNxMetaMessage *response);
+
+ void processControlMessage(CCNxMetaMessage *response);
+
+ volatile bool is_running_;
+ bool clear_;
+
+ boost::asio::io_service io_service_;
+
+ std::shared_ptr<boost::asio::io_service::work> work_;
+
+ PendingInterestHashTable pending_interest_hash_table_;
+
+ OnInterestCallback on_interest_callback_;
+ std::list<Name> served_name_list_;
+
+ LocalConnector connector_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_PORTAL_H_
diff --git a/icnet/ccnx/icnet_ccnx_segment.cc b/icnet/ccnx/icnet_ccnx_segment.cc
new file mode 100644
index 00000000..4215650a
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_segment.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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.
+ */
+
+#include "icnet_ccnx_segment.h"
+
+namespace icnet {
+
+namespace ccnx {
+
+Segment::Segment(CCNxNameLabelType type, std::string &segment_value) : name_segment_(
+ ccnxNameSegment_CreateTypeValueArray(type, segment_value.length(), segment_value.c_str())) {
+}
+
+Segment::Segment(CCNxNameSegmentStructure *segment) : name_segment_(ccnxNameSegment_Acquire(segment)) {
+}
+
+Segment::Segment(const Segment &segment) : name_segment_(ccnxNameSegment_Copy(segment.name_segment_)) {
+}
+
+Segment::Segment(Segment &&otherSegment) : name_segment_(ccnxNameSegment_Acquire(otherSegment.name_segment_)) {
+}
+
+Segment::~Segment() {
+ ccnxNameSegment_Release(&name_segment_);
+}
+
+Segment &Segment::operator=(const Segment &segment) {
+ ccnxNameSegment_Release(&name_segment_);
+ this->name_segment_ = ccnxNameSegment_Copy(segment.name_segment_);
+ return *this;
+}
+
+bool Segment::operator==(const Segment &segment) {
+ return ccnxNameSegment_Equals(this->name_segment_, segment.name_segment_);
+}
+
+const std::string &Segment::toString() {
+ char *str = ccnxNameSegment_ToString(name_segment_);
+ name_segment_string_ = std::string(str);
+ free(str);
+ return name_segment_string_;
+}
+
+std::size_t Segment::getSize() {
+ return ccnxNameSegment_Length(name_segment_);
+}
+
+CCNxNameLabelType Segment::getType() {
+ return ccnxNameSegment_GetType(name_segment_);
+}
+
+CCNxNameSegmentStructure *Segment::getWrappedStructure() const {
+ return this->name_segment_;
+}
+
+bool Segment::isSegment() const {
+ return ccnxNameSegmentNumber_IsValid(name_segment_);
+}
+
+uint64_t Segment::toSegment() const {
+ return ccnxNameSegmentNumber_Value(name_segment_);
+}
+
+} // end namespace ccnx
+
+} // end namespace icnet
diff --git a/icnet/ccnx/icnet_ccnx_segment.h b/icnet/ccnx/icnet_ccnx_segment.h
new file mode 100644
index 00000000..6620ee74
--- /dev/null
+++ b/icnet/ccnx/icnet_ccnx_segment.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * 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 ICNET_CCNX_SEGMENT_H_
+#define ICNET_CCNX_SEGMENT_H_
+
+#include "icnet_ccnx_common.h"
+
+extern "C" {
+#include <ccnx/common/ccnx_NameLabel.h>
+#include <ccnx/common/ccnx_NameSegment.h>
+#include <ccnx/common/ccnx_NameSegmentNumber.h>
+};
+
+typedef CCNxNameSegment CCNxNameSegmentStructure;
+
+namespace icnet {
+
+namespace ccnx {
+
+class Segment : public std::enable_shared_from_this<Segment> // : public api::Component
+{
+ public:
+ Segment(CCNxNameLabelType type, std::string &segment_value);
+
+ Segment(const Segment &segment);
+
+ Segment(Segment &&otherSegment);
+
+ Segment(CCNxNameSegmentStructure *segment);
+
+ ~Segment();
+
+ Segment &operator=(const Segment &segment);
+
+ bool operator==(const Segment &segment);
+
+ const std::string &toString();
+
+ std::size_t getSize();
+
+ CCNxNameLabelType getType();
+
+ CCNxNameSegmentStructure *getWrappedStructure() const;
+
+ bool isSegment() const;
+
+ uint64_t toSegment() const;
+
+ private:
+ CCNxNameSegmentStructure *name_segment_;
+ std::string name_segment_string_;
+};
+
+} // end namespace ccnx
+
+} // end namespace icnet
+
+#endif // ICNET_CCNX_PORTAL_H_