32 #include "profiling.h"
39 extern unsigned int avail_memory;
47 struct bundle_list_entry_t {
49 struct bundle_list_entry_t *
next;
67 #define STORAGE_MMEM_FLAGS_LOCKED 0x1
75 static uint16_t bundles_in_storage;
78 static struct ctimer r_store_timer;
101 LOG(LOGD_DTN, LOG_STORE, LOGL_INF,
"storage_mmem init");
112 bundles_in_storage = 0;
125 uint32_t elapsed_time;
126 struct bundle_list_entry_t *
entry =
NULL;
134 elapsed_time = clock_seconds() - bundle->rec_time;
136 if( bundle->lifetime < elapsed_time ) {
137 LOG(LOGD_DTN, LOG_STORE, LOGL_INF,
"bundle lifetime expired of bundle %lu", entry->bundle_num);
150 struct bundle_list_entry_t *
entry =
NULL;
174 if( bundlemem ==
NULL ) {
178 #if BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DO_NOT_DELETE
183 #elif (BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDEST || BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGEST )
186 struct bundle_list_entry_t *
entry =
NULL;
190 unsigned long comparator = 0;
191 struct bundle_list_entry_t * deletor =
NULL;
208 if( (bundle_old->flags & BUNDLE_PRIORITY_MASK) > (bundle_new->flags & BUNDLE_PRIORITY_MASK ) ) {
212 #if BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDEST
213 if( (clock_seconds() - bundle->rec_time) > comparator || comparator == 0) {
214 comparator = clock_seconds() - bundle_old->rec_time;
217 #elif BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGEST
218 if( (clock_seconds() - bundle->rec_time) < comparator || comparator == 0) {
219 comparator = clock_seconds() - bundle_old->rec_time;
226 if( entry ==
NULL ) {
234 #elif (BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDER || BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGER )
237 struct bundle_list_entry_t * entry =
NULL;
258 if( (bundle_old->flags & BUNDLE_PRIORITY_MASK) > (bundle_new->flags & BUNDLE_PRIORITY_MASK ) ) {
262 #if BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_OLDER
266 if( bundle_new->lifetime - (clock_seconds() - bundle_new->rec_time) >= bundle_old->lifetime - (clock_seconds() - bundle_old->rec_time) ) {
269 #elif BUNDLE_STORAGE_BEHAVIOUR == BUNDLE_STORAGE_BEHAVIOUR_DELETE_YOUNGER
271 if( bundle_new->lifetime - (clock_seconds() - bundle_new->rec_time) >= bundle_old->lifetime - (clock_seconds() - bundle_old->rec_time) ) {
278 if( entry ==
NULL ) {
287 #error No Bundle Deletion Strategy defined
303 struct bundle_list_entry_t *
entry =
NULL;
305 if( bundlemem ==
NULL ) {
306 LOG(LOGD_DTN, LOG_STORE, LOGL_WRN,
"storage_mmem_save_bundle with invalid pointer %p", bundlemem);
313 if( bundle ==
NULL ) {
314 LOG(LOGD_DTN, LOG_STORE, LOGL_ERR,
"storage_mmem_save_bundle with invalid MMEM structure");
325 if( bundle->bundle_num == entrybdl->bundle_num ) {
326 LOG(LOGD_DTN, LOG_STORE, LOGL_DBG,
"%lu is the same bundle", entry->bundle_num);
327 *bundle_number_ptr = &entry->bundle_num;
334 LOG(LOGD_DTN, LOG_STORE, LOGL_ERR,
"Cannot store bundle, no room");
346 if( entry ==
NULL ) {
347 LOG(LOGD_DTN, LOG_STORE, LOGL_ERR,
"unable to allocate struct, cannot store bundle");
353 memset(entry, 0,
sizeof(
struct bundle_list_entry_t));
356 entry->bundle = bundlemem;
358 bundles_in_storage++;
361 entry->bundle_num = bundle->bundle_num;
363 LOG(LOGD_DTN, LOG_STORE, LOGL_INF,
"New Bundle %lu (%lu), Src %lu, Dest %lu, Seq %lu", bundle->bundle_num, entry->bundle_num, bundle->src_node, bundle->dst_node, bundle->tstamp_seq);
377 *bundle_number_ptr = &entry->bundle_num;
391 struct bundle_list_entry_t *
entry =
NULL;
393 LOG(LOGD_DTN, LOG_STORE, LOGL_INF,
"Deleting Bundle %lu with reason %u", bundle_number, reason);
401 if( bundle->bundle_num == bundle_number ) {
406 if( entry ==
NULL ) {
407 LOG(LOGD_DTN, LOG_STORE, LOGL_ERR,
"Could not find bundle %lu on storage_mmem_delete_bundle", bundle_number);
413 bundle->del_reason = reason;
415 if( reason != REASON_DELIVERED ) {
416 if( (bundle->flags & BUNDLE_FLAG_CUST_REQ ) || (bundle->flags & BUNDLE_FLAG_REP_DELETE) ){
417 if (bundle->src_node != dtn_node_id){
418 STATUSREPORT.send(entry->bundle, 16, bundle->del_reason);
424 agent_delete_bundle(bundle_number);
432 bundles_in_storage--;
450 struct bundle_list_entry_t *
entry =
NULL;
459 if( bundle->bundle_num == bundle_num ) {
464 if( entry ==
NULL ) {
465 LOG(LOGD_DTN, LOG_STORE, LOGL_WRN,
"Could not find bundle %lu in storage_mmem_read_bundle", bundle_num);
469 if( entry->bundle->size == 0 ) {
470 LOG(LOGD_DTN, LOG_STORE, LOGL_WRN,
"Found bundle %lu but file size is %u", bundle_num, entry->bundle->size);
478 uint32_t elapsed_time = clock_seconds() - bundle->rec_time;
481 if( bundle->lifetime < elapsed_time ) {
482 bundle->lifetime = 0;
483 bundle->rec_time = clock_seconds();
485 bundle->lifetime = bundle->lifetime - elapsed_time;
486 bundle->rec_time = clock_seconds();
489 return entry->bundle;
507 return bundles_in_storage;
527 struct bundle_list_entry_t *
entry =
NULL;
533 if( entry->bundle_num == bundle_num ) {
538 if( entry ==
NULL ) {
552 struct bundle_list_entry_t *
entry =
NULL;
558 if( entry->bundle_num == bundle_num ) {
563 if( entry ==
NULL ) {