#include <FragmentManager.h>
It also implements the routine for creating bundle fragments from larger bundles.
Definition at line 45 of file FragmentManager.h.
Public Member Functions | |
FragmentManager () | |
Constructor. | |
Bundle * | create_fragment (Bundle *bundle, size_t offset, size_t length) |
Create a bundle fragment from another bundle. | |
void | convert_to_fragment (Bundle *bundle, size_t length) |
Turn a bundle into a fragment. | |
int | proactively_fragment (Bundle *bundle, size_t max_length) |
Given the given fragmentation threshold, determine whether the given bundle should be split into several smaller bundles. | |
bool | try_to_reactively_fragment (Bundle *bundle, size_t payload_offset, 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, size_t payload_offset, size_t bytes_rcvd) |
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_fragment (Bundle *fragment) |
Delete reassembly state for a bundle. | |
Protected Types | |
typedef oasys::StringHashMap < ReassemblyState * > | ReassemblyTable |
Table of partial bundles. | |
Protected Member Functions | |
void | get_hash_key (const Bundle *, std::string *key) |
Calculate a hash table key from a bundle. | |
bool | check_completed (ReassemblyState *state) |
Check if the bundle has been completely reassembled. | |
Protected Attributes | |
ReassemblyTable | reassembly_table_ |
Classes | |
struct | ReassemblyState |
Reassembly state structure. More... |
typedef oasys::StringHashMap<ReassemblyState*> dtn::FragmentManager::ReassemblyTable [protected] |
dtn::FragmentManager::FragmentManager | ( | ) |
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 35 of file FragmentManager.cc.
References dtn::Bundle::copy_metadata(), dtn::Bundle::do_not_fragment_, dtn::Bundle::frag_offset_, dtn::Bundle::is_fragment_, dtn::BundlePayload::length(), dtn::Bundle::orig_length_, dtn::Bundle::payload_, dtn::BundlePayload::set_length(), and dtn::BundlePayload::write_data().
Referenced by proactively_fragment(), and try_to_reactively_fragment().
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).
int dtn::FragmentManager::proactively_fragment | ( | Bundle * | bundle, | |
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 228 of file FragmentManager.cc.
References ASSERT, count, create_fragment(), dtn::EVENTSRC_FRAGMENTATION, dtn::BundlePayload::length(), log_info, dtn::Bundle::payload_, and dtn::BundleDaemon::post().
bool dtn::FragmentManager::try_to_reactively_fragment | ( | Bundle * | bundle, | |
size_t | payload_offset, | |||
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 268 of file FragmentManager.cc.
References create_fragment(), dtn::EVENTSRC_FRAGMENTATION, dtn::BundlePayload::length(), log_debug, dtn::Bundle::payload_, and dtn::BundleDaemon::post_at_head().
Referenced by dtn::BundleDaemon::handle_bundle_transmitted().
bool dtn::FragmentManager::try_to_convert_to_fragment | ( | Bundle * | bundle, | |
size_t | payload_offset, | |||
size_t | bytes_rcvd | |||
) |
Convert a partially received bundle into a fragment.
Return true if a fragment was created
Definition at line 72 of file FragmentManager.cc.
References dtn::Bundle::frag_offset_, dtn::Bundle::is_fragment_, dtn::BundlePayload::length(), log_debug, dtn::Bundle::orig_length_, dtn::Bundle::payload_, and dtn::BundlePayload::truncate().
Referenced by dtn::BundleDaemon::handle_bundle_received().
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 300 of file FragmentManager.cc.
References ASSERT, dtn::FragmentManager::ReassemblyState::bundle_, dtn::Bundle::bundleid_, check_completed(), dtn::Bundle::copy_metadata(), dtn::BundlePayload::DISK, dtn::Bundle::frag_offset_, dtn::FragmentManager::ReassemblyState::fragments_, get_hash_key(), dtn::BundleList::insert_sorted(), dtn::Bundle::is_fragment_, dtn::BundlePayload::length(), log_debug, oasys::Ref< _Type >::object(), dtn::Bundle::orig_length_, dtn::Bundle::payload_, dtn::BundleDaemon::post_at_head(), reassembly_table_, dtn::BundleList::size(), and dtn::BundleList::SORT_FRAG_OFFSET.
Referenced by dtn::BundleDaemon::deliver_to_registration().
void dtn::FragmentManager::delete_fragment | ( | Bundle * | fragment | ) |
Delete reassembly state for a bundle.
Definition at line 364 of file FragmentManager.cc.
References ASSERT, dtn::FragmentManager::ReassemblyState::bundle_, dtn::BundleList::erase(), dtn::Bundle::frag_offset_, dtn::FragmentManager::ReassemblyState::fragments_, get_hash_key(), dtn::Bundle::is_fragment_, dtn::BundlePayload::length(), dtn::Bundle::payload_, reassembly_table_, and dtn::BundleList::size().
Referenced by dtn::BundleDaemon::delete_bundle().
void dtn::FragmentManager::get_hash_key | ( | const Bundle * | bundle, | |
std::string * | key | |||
) | [protected] |
Calculate a hash table key from a bundle.
Definition at line 106 of file FragmentManager.cc.
References dtn::EndpointID::c_str(), dtn::Bundle::creation_ts_, dtn::Bundle::dest_, dtn::BundleTimestamp::seconds_, dtn::BundleTimestamp::seqno_, snprintf(), and dtn::Bundle::source_.
Referenced by delete_fragment(), and process_for_reassembly().
bool dtn::FragmentManager::check_completed | ( | ReassemblyState * | state | ) | [protected] |
Check if the bundle has been completely reassembled.
Definition at line 120 of file FragmentManager.cc.
References ASSERT, dtn::BundleList::begin(), dtn::FragmentManager::ReassemblyState::bundle_, dtn::BundleList::end(), dtn::Bundle::frag_offset_, dtn::FragmentManager::ReassemblyState::fragments_, dtn::Bundle::is_fragment_, ExamineDump::l, dtn::BundlePayload::length(), dtn::BundleList::lock(), log_debug, NOTREACHED, dtn::Bundle::orig_length_, dtn::Bundle::payload_, and dtn::BundleList::size().
Referenced by process_for_reassembly().
Definition at line 145 of file FragmentManager.h.
Referenced by delete_fragment(), and process_for_reassembly().