The Fragment Manager maintains state for all of the fragmentary bundles, reconstructing whole bundles from partial bundles. More...
#include <FragmentManager.h>
Public Member Functions | |
FragmentManager () | |
Constructor. | |
Bundle * | create_fragment (Bundle *bundle, BlockInfoVec *blocks, size_t offset, size_t length) |
Create a bundle fragment from another bundle. | |
Bundle * | create_fragment (Bundle *bundle, const LinkRef &link, const BlockInfoPointerList &blocks_to_copy, size_t offset, size_t length) |
Create a fragment to be sent out on a particular link. | |
void | convert_to_fragment (Bundle *bundle, size_t length) |
Turn a bundle into a fragment. | |
FragmentState * | proactively_fragment (Bundle *bundle, const LinkRef &link, size_t max_length) |
Given the given fragmentation threshold, determine whether the given bundle should be split into several smaller bundles. | |
FragmentState * | get_fragment_state (Bundle *bundle) |
void | erase_fragment_state (FragmentState *fragment) |
bool | try_to_reactively_fragment (Bundle *bundle, BlockInfoVec *blocks, size_t bytes_sent) |
If only part of the given bundle was sent successfully, split it into two. | |
bool | try_to_convert_to_fragment (Bundle *bundle) |
Convert a partially received bundle into a fragment. | |
void | process_for_reassembly (Bundle *fragment) |
Given a newly arrived bundle fragment, append it to the table of fragments and see if it allows us to reassemble the bundle. | |
void | delete_obsoleted_fragments (Bundle *fragment) |
Delete any fragments that are no longer needed given the incoming (non-fragment) bundle. | |
void | delete_fragment (Bundle *fragment) |
Delete reassembly state for a bundle. | |
Protected Types | |
typedef oasys::StringHashMap < FragmentState * > | FragmentTable |
Check if the bundle has been completely reassembled. | |
Protected Member Functions | |
void | get_hash_key (const Bundle *, std::string *key) |
Calculate a hash table key from a bundle. | |
Protected Attributes | |
FragmentTable | fragment_table_ |
The Fragment Manager maintains state for all of the fragmentary bundles, reconstructing whole bundles from partial bundles.
It also implements the routine for creating bundle fragments from larger bundles.
Definition at line 49 of file FragmentManager.h.
typedef oasys::StringHashMap<FragmentState*> dtn::FragmentManager::FragmentTable [protected] |
Check if the bundle has been completely reassembled.
Table of partial bundles
Definition at line 160 of file FragmentManager.h.
dtn::FragmentManager::FragmentManager | ( | ) |
Constructor.
Definition at line 35 of file FragmentManager.cc.
void dtn::FragmentManager::convert_to_fragment | ( | Bundle * | bundle, | |
size_t | length | |||
) |
Turn a bundle into a fragment.
Note this is used just for reactive fragmentation on a newly received partial bundle and therefore the offset is implicitly zero (unless the bundle was already a fragment).
Bundle * dtn::FragmentManager::create_fragment | ( | Bundle * | bundle, | |
const LinkRef & | link, | |||
const BlockInfoPointerList & | blocks_to_copy, | |||
size_t | offset, | |||
size_t | length | |||
) |
Create a fragment to be sent out on a particular link.
Definition at line 102 of file FragmentManager.cc.
References dtn::Bundle::copy_metadata(), dtn::LinkBlockSet::create_blocks(), dtn::Bundle::frag_offset(), dtn::Bundle::is_fragment(), dtn::BundlePayload::length(), dtn::Bundle::mutable_payload(), dtn::Bundle::orig_length(), dtn::Bundle::payload(), dtn::Bundle::set_do_not_fragment(), dtn::Bundle::set_frag_offset(), dtn::Bundle::set_is_fragment(), dtn::BundlePayload::set_length(), dtn::Bundle::set_orig_length(), dtn::BundlePayload::write_data(), and dtn::Bundle::xmit_blocks().
Bundle * dtn::FragmentManager::create_fragment | ( | Bundle * | bundle, | |
BlockInfoVec * | blocks, | |||
size_t | offset, | |||
size_t | length | |||
) |
Create a bundle fragment from another bundle.
bundle | the source bundle from which we create the fragment. Note: the bundle may itself be a fragment | |
offset | the offset relative to this bundle (not the original) for the for the new fragment. note that if this bundle is already a fragment, the offset into the original bundle will be this bundle's frag_offset + offset | |
length | the length of the fragment we want |
Definition at line 42 of file FragmentManager.cc.
References dtn::BundleProtocol::BLOCK_FLAG_REPLICATE, dtn::Bundle::copy_metadata(), dtn::Bundle::frag_offset(), dtn::Bundle::is_fragment(), dtn::BundlePayload::length(), dtn::Bundle::mutable_payload(), dtn::Bundle::mutable_recv_blocks(), dtn::Bundle::orig_length(), dtn::Bundle::payload(), dtn::BundleProtocol::PAYLOAD_BLOCK, dtn::BundleProtocol::PRIMARY_BLOCK, dtn::Bundle::set_do_not_fragment(), dtn::Bundle::set_frag_offset(), dtn::Bundle::set_is_fragment(), dtn::BundlePayload::set_length(), dtn::Bundle::set_orig_length(), and dtn::BundlePayload::write_data().
Referenced by proactively_fragment(), and try_to_reactively_fragment().
void dtn::FragmentManager::delete_fragment | ( | Bundle * | fragment | ) |
Delete reassembly state for a bundle.
Definition at line 502 of file FragmentManager.cc.
References ASSERT, dtn::FragmentState::erase_fragment(), fragment_table_, get_hash_key(), dtn::Bundle::is_fragment(), and dtn::FragmentState::num_fragments().
void dtn::FragmentManager::delete_obsoleted_fragments | ( | Bundle * | fragment | ) |
Delete any fragments that are no longer needed given the incoming (non-fragment) bundle.
Definition at line 462 of file FragmentManager.cc.
References ASSERT, dtn::Bundle::bundleid(), dtn::BundleList::empty(), dtn::FragmentState::fragment_list(), fragment_table_, get_hash_key(), dtn::BundleList::lock(), dtn::FragmentState::num_fragments(), dtn::BundleList::pop_back(), dtn::BundleDaemon::post(), dtn::BundleProtocol::REASON_NO_ADDTL_INFO, and dtn::BundleList::size().
void dtn::FragmentManager::erase_fragment_state | ( | FragmentState * | fragment | ) |
Definition at line 315 of file FragmentManager.cc.
References dtn::FragmentState::bundle(), fragment_table_, and get_hash_key().
FragmentState * dtn::FragmentManager::get_fragment_state | ( | Bundle * | bundle | ) |
Definition at line 300 of file FragmentManager.cc.
void dtn::FragmentManager::get_hash_key | ( | const Bundle * | bundle, | |
std::string * | key | |||
) | [protected] |
Calculate a hash table key from a bundle.
Definition at line 227 of file FragmentManager.cc.
References buf, dtn::EndpointID::c_str(), dtn::Bundle::creation_ts(), dtn::Bundle::dest(), dtn::BundleTimestamp::seconds_, dtn::BundleTimestamp::seqno_, and dtn::Bundle::source().
Referenced by delete_fragment(), delete_obsoleted_fragments(), erase_fragment_state(), proactively_fragment(), and process_for_reassembly().
FragmentState * dtn::FragmentManager::proactively_fragment | ( | Bundle * | bundle, | |
const LinkRef & | link, | |||
size_t | max_length | |||
) |
Given the given fragmentation threshold, determine whether the given bundle should be split into several smaller bundles.
If so, this returns true and generates a bunch of bundle received events for the individual fragments.
Return the number of fragments created or zero if none were created.
Definition at line 241 of file FragmentManager.cc.
References dtn::FragmentState::add_fragment(), ASSERT, dtn::BundleProtocol::BLOCK_FLAG_REPLICATE, count, create_fragment(), dtn::LinkBlockSet::find_blocks(), dtn::BlockInfo::flags(), fragment_table_, get_hash_key(), dtn::BundlePayload::length(), dtn::Bundle::payload(), dtn::BundleProtocol::PAYLOAD_BLOCK, dtn::BundleProtocol::PRIMARY_BLOCK, dtn::BlockInfo::type(), and dtn::Bundle::xmit_blocks().
void dtn::FragmentManager::process_for_reassembly | ( | Bundle * | fragment | ) |
Given a newly arrived bundle fragment, append it to the table of fragments and see if it allows us to reassemble the bundle.
If it does, a ReassemblyCompletedEvent will be posted.
Definition at line 384 of file FragmentManager.cc.
References dtn::FragmentState::add_fragment(), ASSERT, dtn::FragmentState::bundle(), dtn::Bundle::bundleid(), dtn::FragmentState::check_completed(), dtn::Bundle::copy_metadata(), dtn::Bundle::frag_offset(), dtn::FragmentState::fragment_list(), fragment_table_, get_hash_key(), dtn::Bundle::is_fragment(), dtn::BundlePayload::length(), dtn::Bundle::orig_length(), dtn::Bundle::payload(), dtn::BundleDaemon::post_at_head(), dtn::Bundle::recv_blocks(), and dtn::BundleList::size().
Referenced by dtn::BundleDaemon::handle_bundle_query().
Convert a partially received bundle into a fragment.
Return true if a fragment was created
Definition at line 161 of file FragmentManager.cc.
References ASSERT, dtn::BlockInfo::complete(), dtn::BlockInfo::data_length(), dtn::BlockInfo::data_offset(), dtn::Bundle::do_not_fragment(), dtn::BlockInfoVec::find_block(), dtn::Bundle::is_fragment(), dtn::BlockInfo::last_block(), dtn::BundlePayload::length(), dtn::Bundle::mutable_payload(), dtn::Bundle::payload(), dtn::BundleProtocol::PAYLOAD_BLOCK, dtn::Bundle::recv_blocks(), dtn::Bundle::set_frag_offset(), dtn::Bundle::set_fragmented_incoming(), dtn::Bundle::set_is_fragment(), dtn::Bundle::set_orig_length(), and dtn::BundlePayload::truncate().
bool dtn::FragmentManager::try_to_reactively_fragment | ( | Bundle * | bundle, | |
BlockInfoVec * | blocks, | |||
size_t | bytes_sent | |||
) |
If only part of the given bundle was sent successfully, split it into two.
The original bundle
Return true if a fragment was created
Definition at line 324 of file FragmentManager.cc.
References ASSERT, create_fragment(), dtn::Bundle::do_not_fragment(), dtn::EVENTSRC_FRAGMENTATION, dtn::BlockInfoVec::find_block(), dtn::BlockInfo::last_block(), dtn::BundlePayload::length(), dtn::Bundle::payload(), dtn::BundleProtocol::PAYLOAD_BLOCK, dtn::BundleProtocol::payload_offset(), dtn::BundleDaemon::post_at_head(), and dtn::BundleProtocol::total_length().
FragmentTable dtn::FragmentManager::fragment_table_ [protected] |
Definition at line 161 of file FragmentManager.h.
Referenced by delete_fragment(), delete_obsoleted_fragments(), erase_fragment_state(), proactively_fragment(), and process_for_reassembly().