Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackcatn13 committed Jun 13, 2018
2 parents d622a9f + 9f3ce70 commit 09f88d6
Show file tree
Hide file tree
Showing 82 changed files with 12,785 additions and 4,708 deletions.
37 changes: 19 additions & 18 deletions BundleAgent/Bundle/Bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ Bundle::Bundle(const std::string &rawData)
* A bundle is formed by a PrimaryBlock, and other blocks.
* In this other blocks one of it must be a PayloadBlock.
*/
LOG(35) << "New Bundle from raw Data";
LOG(81) << "New Bundle from raw Data";
// First generate a PrimaryBlock with the data.
LOG(35) << "Generating Primary Block";
LOG(81) << "Generating Primary Block";
try {
m_primaryBlock = std::shared_ptr<PrimaryBlock>(new PrimaryBlock(rawData));
m_blocks.push_back(m_primaryBlock);
Expand All @@ -67,7 +67,7 @@ Bundle::Bundle(const std::string &rawData)
case CanonicalBlockTypes::PAYLOAD_BLOCK: {
// Check if another payload block is present
if (m_payloadBlock == nullptr) {
LOG(35) << "Generating Payload Block";
LOG(81) << "Generating Payload Block";
b = std::shared_ptr<PayloadBlock>(new PayloadBlock(data, true));
m_payloadBlock = std::static_pointer_cast<PayloadBlock>(b);
} else {
Expand All @@ -79,41 +79,41 @@ Bundle::Bundle(const std::string &rawData)
case CanonicalBlockTypes::METADATA_EXTENSION_BLOCK: {
// This is an abstraction of the metadata block, so we need to create
// a derived block of it.
LOG(35) << "Generating Metadata Extension Block";
LOG(81) << "Generating Metadata Extension Block";
auto m = MetadataExtensionBlock(data);
LOG(35) << std::to_string(m.getMetadataType());
LOG(81) << std::to_string(m.getMetadataType());
switch (static_cast<MetadataTypes>(m.getMetadataType())) {
case MetadataTypes::ROUTING_SELECTION_MEB: {
b = std::make_shared<RoutingSelectionMEB>(
RoutingSelectionMEB(data));
break;
}
case MetadataTypes::FORWARDING_MEB: {
LOG(35) << "Generating ForwardingMEB Block.";
LOG(81) << "Generating ForwardingMEB Block.";
b = std::make_shared<ForwardingMEB>(ForwardingMEB(data, true));
break;
}
case MetadataTypes::ROUTE_REPORTING_MEB: {
LOG(35) << "Generating RouteReporting Metadata Extension Block";
LOG(81) << "Generating RouteReporting Metadata Extension Block";
b = std::make_shared<RouteReportingMEB>(RouteReportingMEB(data));
break;
}
case MetadataTypes::CODE_DATA_CARRIER_MEB: {
LOG(35) << "Generating New Metadata Extension Block";
LOG(81) << "Generating New Metadata Extension Block";
b = std::make_shared<CodeDataCarrierMEB>(
CodeDataCarrierMEB(data));
break;
}
case MetadataTypes::FRAMEWORK_MEB: {
LOG(35) << "Generating New Framework Metadata Extension Block";
LOG(81) << "Generating New Framework Metadata Extension Block";
b = std::make_shared<FrameworkMEB>(FrameworkMEB(data));
break;
}
}
break;
}
default: {
LOG(35) << "Generating Canonical Block";
LOG(81) << "Generating Canonical Block";
b = std::shared_ptr<CanonicalBlock>(new CanonicalBlock(data));
break;
}
Expand All @@ -137,7 +137,7 @@ Bundle::Bundle(const std::string &rawData)

Bundle::Bundle(std::string origin, std::string destination, std::string payload)
: m_raw() {
LOG(34) << "Generating new bundle with parameters [Source: " << origin
LOG(82) << "Generating new bundle with parameters [Source: " << origin
<< "][Destination: " << destination << "][Payload: " << payload
<< "]";
TimestampManager *tm = TimestampManager::getInstance();
Expand All @@ -151,18 +151,18 @@ Bundle::Bundle(std::string origin, std::string destination, std::string payload)
}

Bundle::~Bundle() {
LOG(36) << "Deleting Bundle";
LOG(83) << "Deleting Bundle";
}

std::string Bundle::getRaw() {
return m_raw;
}

std::string Bundle::toRaw() {
LOG(36) << "Generating bundle in raw format";
LOG(81) << "Generating bundle in raw format";
std::string raw = m_raw;
std::stringstream ss;
LOG(36) << "Getting the primary block in raw";
LOG(81) << "Getting the primary block in raw";
std::vector<std::shared_ptr<Block>>::reverse_iterator finalBlock = m_blocks
.rbegin();
std::static_pointer_cast<CanonicalBlock>(*finalBlock)->setProcFlag(
Expand Down Expand Up @@ -191,20 +191,21 @@ std::vector<std::shared_ptr<Block>> Bundle::getBlocks() {
void Bundle::addBlock(std::shared_ptr<CanonicalBlock> newBlock) {
// Check if the block type is a PayloadBlock
// only one can be present into a bundle.
LOG(37) << "Adding new Block to the bundle";
LOG(81) << "Adding new Block to the bundle";
if (newBlock->getBlockType()
!= static_cast<uint8_t>(CanonicalBlockTypes::PAYLOAD_BLOCK)) {
m_blocks.push_back(newBlock);
} else {
LOG(3) << "Some one is trying to add another Payload block";
LOG(5) << "Some one is trying to add another Payload block";
throw BundleException("[Bundle] a paylod block is present");
}
}

std::string Bundle::getId() {
std::stringstream ss;
ss << m_primaryBlock->getSource() << "_" << m_primaryBlock->getCreationTimestamp()
<< "_" << m_primaryBlock->getCreationTimestampSeqNumber();
ss << m_primaryBlock->getSource() << "_"
<< m_primaryBlock->getCreationTimestamp() << "_"
<< m_primaryBlock->getCreationTimestampSeqNumber();
return ss.str();
}

Expand Down
71 changes: 58 additions & 13 deletions BundleAgent/Bundle/BundleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,80 @@

#include "Bundle/BundleInfo.h"
#include <string>
#include <ctime>
#include <vector>
#include "Bundle/PrimaryBlock.h"
#include "Bundle/CanonicalBlock.h"
#include "Bundle/MetadataExtensionBlock.h"

const uint64_t g_timeFrom2000 = 946684800;

BundleInfo::BundleInfo(Bundle &bundle)
: m_bundle(bundle) {
: m_id(bundle.getId()),
m_destination(bundle.getPrimaryBlock()->getDestination()),
m_source(bundle.getPrimaryBlock()->getSource()),
m_creationTimestamp(bundle.getPrimaryBlock()->getCreationTimestamp()),
m_creationTimestampSeqNumber(
bundle.getPrimaryBlock()->getCreationTimestampSeqNumber()),
m_lifetime(bundle.getPrimaryBlock()->getLifetime()),
m_size(bundle.toRaw().length()) {
std::vector<std::shared_ptr<Block>> blocks = bundle.getBlocks();
blocks.erase(blocks.begin());
for (auto c : blocks) {
std::shared_ptr<CanonicalBlock> canonical_block = std::static_pointer_cast<
CanonicalBlock>(c);
m_canoniclaTypeBlocks.insert(canonical_block->getBlockType());
if (static_cast<CanonicalBlockTypes>(canonical_block->getBlockType())
== CanonicalBlockTypes::METADATA_EXTENSION_BLOCK) {
std::shared_ptr<MetadataExtensionBlock> meb = std::static_pointer_cast<
MetadataExtensionBlock>(canonical_block);
m_metadataTypeBlocks.insert(meb->getMetadataType());
}
}
}

BundleInfo::~BundleInfo() {
}

std::string BundleInfo::getId() {
return m_bundle.getId();
std::string BundleInfo::getId() const {
return m_id;
}

std::string BundleInfo::getDestination() const {
return m_destination;
}

std::string BundleInfo::getSource() const {
return m_source;
}

std::string BundleInfo::getDestination() {
return m_bundle.getPrimaryBlock()->getDestination();
uint64_t BundleInfo::getCreationTimestamp() const {
return m_creationTimestamp;
}

std::string BundleInfo::getSource() {
return m_bundle.getPrimaryBlock()->getSource();
uint64_t BundleInfo::getCreationTimestampSeqNumber() const {
return m_creationTimestampSeqNumber;
}

uint64_t BundleInfo::getCreationTimestamp() {
return m_bundle.getPrimaryBlock()->getCreationTimestamp();
uint64_t BundleInfo::getLifetime() const {
return m_lifetime;
}

uint64_t BundleInfo::getCreationTimestampSeqNumber() {
return m_bundle.getPrimaryBlock()->getCreationTimestampSeqNumber();
uint64_t BundleInfo::getCurrentLifetime() const {
return (time(NULL) - g_timeFrom2000 - m_creationTimestamp - m_lifetime);
}

uint64_t BundleInfo::getLifetime() {
return m_bundle.getPrimaryBlock()->getLifetime();
uint64_t BundleInfo::getSize() const {
return m_size;
}

bool BundleInfo::hasMetadataTypeBlock(uint8_t type) const {
auto it = m_metadataTypeBlocks.find(type);
return (it != m_metadataTypeBlocks.end());
}

bool BundleInfo::hasCanonicalTypeBlock(uint8_t type) const {
auto it = m_canoniclaTypeBlocks.find(type);
return (it != m_canoniclaTypeBlocks.end());
}

71 changes: 63 additions & 8 deletions BundleAgent/Bundle/BundleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define BUNDLEAGENT_BUNDLE_BUNDLEINFO_H_

#include <string>
#include <unordered_set>
#include "Bundle/Bundle.h"

/**
Expand All @@ -48,38 +49,92 @@ class BundleInfo {
* Returns the id of the bundle.
* @return The id.
*/
std::string getId();
std::string getId() const;
/**
* Returns the destination of the bundle.
* @return The destination.
*/
std::string getDestination();
std::string getDestination() const;
/**
* Returns the source of the bundle.
* @return The source.
*/
std::string getSource();
std::string getSource() const;
/**
* Returns the timestamp of the bundle.
* @return The creation timestamp.
*/
uint64_t getCreationTimestamp();
uint64_t getCreationTimestamp() const;
/**
* Returns the timestamp sequence number of the bundle.
* @return The timestamp sequence number.
*/
uint64_t getCreationTimestampSeqNumber();
uint64_t getCreationTimestampSeqNumber() const;
/**
* Returns the lifetime of the bundle.
* @return The lifetime.
*/
uint64_t getLifetime();
uint64_t getLifetime() const;
/**
* Returns the seconds that the bundle has of life.
* @return The time to life
*/
uint64_t getCurrentLifetime() const;
/**
* Returns the size of the bundle in bytes.
* @return The bytes size
*/
uint64_t getSize() const;
/**
* Returns if the bundle has one metadata block of the specified type.
* @param type The type to search.
* @return True if the block exist in the bundle.
*/
bool hasMetadataTypeBlock(uint8_t type) const;
/**
* Returns if the bundle has one canonical block of the specified type.
* @param type The type to search.
* @return True if the block exist in the bundle.
*/
bool hasCanonicalTypeBlock(uint8_t type) const;

private:
/**
* The bundle that holds the data.
* Variable to hold the bundle id.
*/
std::string m_id;
/**
* Variable to hold the destination.
*/
std::string m_destination;
/**
* Variable to hold the source
*/
std::string m_source;
/**
* Variable to hold the creation timestamp.
*/
uint64_t m_creationTimestamp;
/**
* Variable to hold the creation timestamp sequence.
*/
uint64_t m_creationTimestampSeqNumber;
/**
* Variable to hold the lifetime.
*/
uint64_t m_lifetime;
/**
* Variable to hold the bundle size.
*/
uint64_t m_size;
/**
* Variable to hold the metadata types.
*/
std::unordered_set<uint8_t> m_metadataTypeBlocks;
/**
* Variable to hold the canonical block types.
*/
Bundle m_bundle;
std::unordered_set<uint8_t> m_canoniclaTypeBlocks;
};

#endif // BUNDLEAGENT_BUNDLE_BUNDLEINFO_H_
2 changes: 1 addition & 1 deletion BundleAgent/Bundle/BundleTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef BUNDLEAGENT_BUNDLE_BUNDLETYPES_H_
#define BUNDLEAGENT_BUNDLE_BUNDLETYPES_H_

#include <cstdio>
#include <cstdint>

enum class PrimaryBlockControlFlags : uint32_t {
IS_FRAGMENT = 0,
Expand Down
8 changes: 4 additions & 4 deletions BundleAgent/Bundle/CanonicalBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CanonicalBlock::~CanonicalBlock() {
}

void CanonicalBlock::initFromRaw(const std::string &rawData) {
LOG(39) << "Generating canonicalblock from raw data";
LOG(83) << "Generating canonicalblock from raw data";
// Get the Block Type
try {
m_blockType = static_cast<uint8_t>(rawData[0]);
Expand Down Expand Up @@ -109,17 +109,17 @@ uint8_t CanonicalBlock::getBlockType() {
}

void CanonicalBlock::setProcFlag(CanonicalBlockControlFlags procFlag) {
LOG(38) << "Setting Flag " << static_cast<int>(procFlag);
LOG(83) << "Setting Flag " << static_cast<int>(procFlag);
m_procFlags.set(static_cast<uint32_t>(procFlag));
}

void CanonicalBlock::unsetProcFlag(CanonicalBlockControlFlags procFlag) {
LOG(38) << "Clearing Flag " << static_cast<int>(procFlag);
LOG(83) << "Clearing Flag " << static_cast<int>(procFlag);
m_procFlags.reset(static_cast<uint32_t>(procFlag));
}

bool CanonicalBlock::checkProcFlag(CanonicalBlockControlFlags procFlag) {
LOG(38) << "Testing Flag " << static_cast<int>(procFlag);
LOG(83) << "Testing Flag " << static_cast<int>(procFlag);
return m_procFlags.test(static_cast<uint32_t>(procFlag));
}

Expand Down
2 changes: 1 addition & 1 deletion BundleAgent/Bundle/CodeDataCarrierMEB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CodeDataCarrierMEB::initFromRaw(const std::string& rawData) {
}

std::string CodeDataCarrierMEB::toRaw() {
LOG(39) << "Generating raw data from Code Data Carrier MEB";
LOG(88) << "Generating raw data from Code Data Carrier MEB";
m_metadata = std::to_string(m_code.length()) + m_code + m_data.dump();
std::stringstream ss;
ss << m_blockType;
Expand Down
6 changes: 3 additions & 3 deletions BundleAgent/Bundle/FrameworkExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include "FrameworkExtension.h"
#include <iostream>

FrameworkExtension::FrameworkExtension(uint8_t fwkExtId,
std::string swSrcCode) : m_fwkExtId(fwkExtId), m_swSrcCode(swSrcCode) {
FrameworkExtension::FrameworkExtension(uint8_t fwkExtId, std::string swSrcCode)
: m_fwkExtId(fwkExtId),
m_swSrcCode(swSrcCode) {
}

FrameworkExtension::~FrameworkExtension() {
Expand All @@ -52,4 +53,3 @@ bool FrameworkExtension::operator ==(const FrameworkExtension &fe) const {
return (id && code);
}


Loading

0 comments on commit 09f88d6

Please sign in to comment.