From e3efb662bb6548a4a82fc19ca14eb1b167dba183 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 30 Dec 2023 14:20:12 +0100 Subject: [PATCH 1/8] AA removes bundles from store --- core/dtn7/src/core/application_agent.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/dtn7/src/core/application_agent.rs b/core/dtn7/src/core/application_agent.rs index 6cb40d12..403a3724 100644 --- a/core/dtn7/src/core/application_agent.rs +++ b/core/dtn7/src/core/application_agent.rs @@ -1,11 +1,12 @@ use bp7::{Bundle, EndpointID}; use enum_dispatch::enum_dispatch; -use log::{debug, trace}; +use log::{debug, error, trace}; use std::collections::VecDeque; use std::fmt::Debug; use tokio::sync::mpsc::Sender; use crate::dtnd::ws::BundleDelivery; +use crate::store_remove; //use crate::dtnd::ws::WsAASession; #[enum_dispatch] @@ -50,6 +51,13 @@ impl ApplicationAgent for SimpleApplicationAgent { // save in temp buffer for delivery self.bundles.push_back(bundle.clone()); } + + if !bundle.primary.destination.is_non_singleton() { + debug!("Removing bundle with singleton destination from store"); + if let Err(e) = store_remove(&bundle.id()) { + error!("Error while removing bundle from store: {e:?}"); + } + } } fn pop(&mut self) -> Option { self.bundles.pop_front() From ca933bd2e989b0e86117e56f18715c3c80b98b0b Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 1 Feb 2024 21:52:16 +0100 Subject: [PATCH 2/8] delete bundle from store --- core/dtn7/src/core/application_agent.rs | 24 +++++++++++++++++------- core/dtn7/src/core/store/mem.rs | 4 +++- core/dtn7/src/lib.rs | 4 +++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/dtn7/src/core/application_agent.rs b/core/dtn7/src/core/application_agent.rs index 403a3724..87e0679e 100644 --- a/core/dtn7/src/core/application_agent.rs +++ b/core/dtn7/src/core/application_agent.rs @@ -52,15 +52,25 @@ impl ApplicationAgent for SimpleApplicationAgent { self.bundles.push_back(bundle.clone()); } - if !bundle.primary.destination.is_non_singleton() { - debug!("Removing bundle with singleton destination from store"); - if let Err(e) = store_remove(&bundle.id()) { - error!("Error while removing bundle from store: {e:?}"); - } - } + // if !bundle.primary.destination.is_non_singleton() { + // debug!("Removing bundle with singleton destination from store"); + // if let Err(e) = store_remove(&bundle.id()) { + // error!("Error while removing bundle from store: {e:?}"); + // } + // } } fn pop(&mut self) -> Option { - self.bundles.pop_front() + let bundle = self.bundles.pop_front(); + bundle.as_ref().and_then(|b| { + if !b.primary.destination.is_non_singleton() { + debug!("Removing bundle with singleton destination from store"); + if let Err(e) = store_remove(&b.id()) { + error!("Error while removing bundle from store: {:?}", e); + } + } + Some(()) + }); + bundle } fn set_delivery_addr(&mut self, addr: Sender) { diff --git a/core/dtn7/src/core/store/mem.rs b/core/dtn7/src/core/store/mem.rs index 031bc4c6..731e1860 100644 --- a/core/dtn7/src/core/store/mem.rs +++ b/core/dtn7/src/core/store/mem.rs @@ -44,7 +44,9 @@ impl BundleStore for InMemoryBundleStore { } else { bail!("Bundle meta data not in store!"); } - if self.bundles.remove(bid).is_none() { + let v = self.bundles.remove(bid); + debug!("Removed bundle {v:?}"); + if v.is_none() { bail!("Bundle not in store!"); } Ok(()) diff --git a/core/dtn7/src/lib.rs b/core/dtn7/src/lib.rs index 9e91a45f..58b74aec 100644 --- a/core/dtn7/src/lib.rs +++ b/core/dtn7/src/lib.rs @@ -180,10 +180,12 @@ pub fn store_add_bundle_if_unknown(bndl: &Bundle) -> Result { } pub fn store_remove(bid: &str) -> Result<()> { - info!("Removing bundle {}", bid); + info!("store_remove: Removing bundle {}", bid); if let Err(err) = (*STORE.lock()).remove(bid) { error!("store_remove: {}", err); return Err(err); + } else { + debug!("store_remove: Success!"); } Ok(()) } From 1c69bde58680ba10fc1b1ab53675609cb8793578 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 2 Feb 2024 12:48:43 +0100 Subject: [PATCH 3/8] code cleanup --- core/dtn7/src/core/application_agent.rs | 16 ++++------------ core/dtn7/src/core/store/mem.rs | 4 +--- core/dtn7/src/lib.rs | 4 +--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/core/dtn7/src/core/application_agent.rs b/core/dtn7/src/core/application_agent.rs index 87e0679e..e5f704bb 100644 --- a/core/dtn7/src/core/application_agent.rs +++ b/core/dtn7/src/core/application_agent.rs @@ -51,25 +51,17 @@ impl ApplicationAgent for SimpleApplicationAgent { // save in temp buffer for delivery self.bundles.push_back(bundle.clone()); } - - // if !bundle.primary.destination.is_non_singleton() { - // debug!("Removing bundle with singleton destination from store"); - // if let Err(e) = store_remove(&bundle.id()) { - // error!("Error while removing bundle from store: {e:?}"); - // } - // } } fn pop(&mut self) -> Option { let bundle = self.bundles.pop_front(); - bundle.as_ref().and_then(|b| { - if !b.primary.destination.is_non_singleton() { + if let Some(bndl) = bundle.as_ref() { + if !bndl.primary.destination.is_non_singleton() { debug!("Removing bundle with singleton destination from store"); - if let Err(e) = store_remove(&b.id()) { + if let Err(e) = store_remove(&bndl.id()) { error!("Error while removing bundle from store: {:?}", e); } } - Some(()) - }); + }; bundle } diff --git a/core/dtn7/src/core/store/mem.rs b/core/dtn7/src/core/store/mem.rs index 731e1860..031bc4c6 100644 --- a/core/dtn7/src/core/store/mem.rs +++ b/core/dtn7/src/core/store/mem.rs @@ -44,9 +44,7 @@ impl BundleStore for InMemoryBundleStore { } else { bail!("Bundle meta data not in store!"); } - let v = self.bundles.remove(bid); - debug!("Removed bundle {v:?}"); - if v.is_none() { + if self.bundles.remove(bid).is_none() { bail!("Bundle not in store!"); } Ok(()) diff --git a/core/dtn7/src/lib.rs b/core/dtn7/src/lib.rs index 58b74aec..9e91a45f 100644 --- a/core/dtn7/src/lib.rs +++ b/core/dtn7/src/lib.rs @@ -180,12 +180,10 @@ pub fn store_add_bundle_if_unknown(bndl: &Bundle) -> Result { } pub fn store_remove(bid: &str) -> Result<()> { - info!("store_remove: Removing bundle {}", bid); + info!("Removing bundle {}", bid); if let Err(err) = (*STORE.lock()).remove(bid) { error!("store_remove: {}", err); return Err(err); - } else { - debug!("store_remove: Success!"); } Ok(()) } From 0d8d1154e833af532dd8a0c48caff0a8533f5fa9 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 2 Feb 2024 14:58:30 +0100 Subject: [PATCH 4/8] adds integration test --- run_all_tests.sh | 1 + tests/store_delete_singleton.sh | 112 ++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100755 tests/store_delete_singleton.sh diff --git a/run_all_tests.sh b/run_all_tests.sh index d3f395a1..8b20cb32 100755 --- a/run_all_tests.sh +++ b/run_all_tests.sh @@ -43,6 +43,7 @@ cargo test $TARGET_OPT && filter_output ./tests/local_nodes_dtn_httppull.sh && filter_output ./tests/local_nodes_http_dtn.sh && filter_output ./tests/store_delete.sh && + filter_output ./tests/store_delete_singleton.sh && filter_output ./tests/lifetime.sh && filter_output ./tests/cla_chain_test.sh && filter_output ./tests/ecla_test.sh && diff --git a/tests/store_delete_singleton.sh b/tests/store_delete_singleton.sh new file mode 100755 index 00000000..bfdf2ab8 --- /dev/null +++ b/tests/store_delete_singleton.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +. $(dirname $(perl -MCwd -e 'print Cwd::abs_path shift' "$0"))/libshelltests.sh + +prepare_test + +#DB1="-W /tmp/node1 -D sled" +#DB1="-W /tmp/node1 -D sneakers" +PORT_NODE1=$(get_current_port) +start_dtnd -d -j5s -i0 -C tcp:port=2342 -e incoming -e ~group -r epidemic -n node1 $DB1 + +sleep 0.5 + +echo + +echo "Sending 'test' to node 1" +BID_SINGLE=$(echo test | $BINS/dtnsend -r dtn://node1/incoming -p $PORT_NODE1 | grep "dtn://" | awk '{print $2}') +BID_GRP=$(echo test | $BINS/dtnsend -r dtn://node1/~group -p $PORT_NODE1 | grep "dtn://" | awk '{print $2}') + +sleep 0.5 + +echo +echo -n "Bundles in store on node 1: " +NUM_BUNDLES=$($BINS/dtnquery store | grep "dtn://" | wc -l | awk '{print $1}') +echo -n $NUM_BUNDLES + +EXPECTED_BUNDLES=2 + +echo " / $EXPECTED_BUNDLES" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + echo "Correct number of bundles in store!" +else + echo "Incorrect number of bundles in store!" + +fi +echo + +# Receive bundle IDs - should not change number of bundles +echo "Receiving bundles $BID_SINGLE and $BID_GRP on node 1: " +$BINS/dtnrecv -v -b $BID_SINGLE -p $PORT_NODE1 || exit $? +$BINS/dtnrecv -v -b $BID_GRP -p $PORT_NODE1 || exit $? +echo -n "Bundles in store on node 1: " +NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}') +echo -n $NUM_BUNDLES + +EXPECTED_BUNDLES=2 + +echo " / $EXPECTED_BUNDLES" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + echo "Correct number of bundles in store!" +else + echo "Incorrect number of bundles in store!" + wait_for_key $1 + cleanup + exit 1 +fi + + +# Receive singleton endpoint - should decrease number of bundles to 1 +echo "Receiving from endpoint 'incoming' on node 1: " +$BINS/dtnrecv -v -e incoming -p $PORT_NODE1 +RC=$? +echo +echo "RET: $RC" +echo +echo +echo -n "Bundles in store on node 1: " +NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}') +echo -n $NUM_BUNDLES + +EXPECTED_BUNDLES=1 + +echo " / $EXPECTED_BUNDLES" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + echo "Correct number of bundles in store!" +else + echo "Incorrect number of bundles in store!" + wait_for_key $1 + cleanup + exit 1 +fi + +# Receive group endpoint - should not change number of bundles +echo "Receiving from endpoint '~group' on node 1: " +$BINS/dtnrecv -v -e ~group -p $PORT_NODE1 +RC=$? +echo +echo "RET: $RC" +echo +echo +echo -n "Bundles in store on node 1: " +NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}') +echo -n $NUM_BUNDLES + +EXPECTED_BUNDLES=1 + +echo " / $EXPECTED_BUNDLES" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + echo "Correct number of bundles in store!" +else + echo "Incorrect number of bundles in store!" +fi + +wait_for_key $1 + +cleanup + +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + exit $RC +else + exit 1 +fi From c36090c1f8f51d66e12e76a511fe11275a76a6c9 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 26 Feb 2024 15:34:52 +0100 Subject: [PATCH 5/8] delete on WS push as well --- core/dtn7/src/core/application_agent.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/dtn7/src/core/application_agent.rs b/core/dtn7/src/core/application_agent.rs index e5f704bb..593e625e 100644 --- a/core/dtn7/src/core/application_agent.rs +++ b/core/dtn7/src/core/application_agent.rs @@ -46,6 +46,8 @@ impl ApplicationAgent for SimpleApplicationAgent { if addr.try_send(BundleDelivery(bundle.clone())).is_err() { self.bundles.push_back(bundle.clone()); + } else { + remove_singleton_bundle_from_store(&bundle); } } else { // save in temp buffer for delivery @@ -55,12 +57,7 @@ impl ApplicationAgent for SimpleApplicationAgent { fn pop(&mut self) -> Option { let bundle = self.bundles.pop_front(); if let Some(bndl) = bundle.as_ref() { - if !bndl.primary.destination.is_non_singleton() { - debug!("Removing bundle with singleton destination from store"); - if let Err(e) = store_remove(&bndl.id()) { - error!("Error while removing bundle from store: {:?}", e); - } - } + remove_singleton_bundle_from_store(bndl); }; bundle } @@ -87,3 +84,13 @@ impl SimpleApplicationAgent { } } } + +/// Removes a bundle from the store if its destination is a singleton endpoint +fn remove_singleton_bundle_from_store(bundle: &Bundle) { + if !bundle.primary.destination.is_non_singleton() { + debug!("Removing bundle with singleton destination from store"); + if let Err(e) = store_remove(&bundle.id()) { + error!("Error while removing bundle from store: {:?}", e); + } + } +} From 573323f002515065e8e69119214a358ce07da130 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 26 Feb 2024 22:32:07 +0100 Subject: [PATCH 6/8] conserve Deleted constraint after pushing to AA --- core/dtn7/src/core/processing.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/dtn7/src/core/processing.rs b/core/dtn7/src/core/processing.rs index 6339055b..bb8ac7a2 100644 --- a/core/dtn7/src/core/processing.rs +++ b/core/dtn7/src/core/processing.rs @@ -464,11 +464,6 @@ pub async fn local_delivery(mut bp: BundlePack) -> Result<()> { } bp.add_constraint(Constraint::LocalEndpoint); bp.sync()?; - if let Some(aa) = (*DTNCORE.lock()).get_endpoint_mut(&bp.destination) { - info!("Delivering {}", bp.id()); - aa.push(&bndl); - STATS.lock().delivered += 1; - } if is_local_node_id(&bp.destination) { if bndl .primary @@ -489,6 +484,11 @@ pub async fn local_delivery(mut bp: BundlePack) -> Result<()> { bp.add_constraint(Constraint::ForwardPending); } bp.sync()?; + if let Some(aa) = (*DTNCORE.lock()).get_endpoint_mut(&bp.destination) { + info!("Delivering {}", bp.id()); + aa.push(&bndl); + STATS.lock().delivered += 1; + } Ok(()) } pub fn contraindicated(mut bp: BundlePack) -> Result<()> { From e15e6b790535dc8a80f43237a1ab309e3f68d365 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 26 Feb 2024 22:45:43 +0100 Subject: [PATCH 7/8] augments local_ping_echo.sh with test for correct number of bundles in store --- tests/local_ping_echo.sh | 15 +++++++++++++++ tests/store_delete_singleton.sh | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/local_ping_echo.sh b/tests/local_ping_echo.sh index f0cbebc6..0fc1436e 100755 --- a/tests/local_ping_echo.sh +++ b/tests/local_ping_echo.sh @@ -21,6 +21,21 @@ $BINS/examples/dtnping -d 'dtn://node1/echo' -c 6 -t 500ms RC=$? echo "RET: $RC" +echo -n "Bundles in store on node 1: " +NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}') +echo -n $NUM_BUNDLES + +EXPECTED_BUNDLES=0 + +echo " / $EXPECTED_BUNDLES" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then + echo "Correct number of bundles in store!" +else + echo "Incorrect number of bundles in store!" + RC=1 +fi + + wait_for_key $1 #kill $PID_ECHO1 diff --git a/tests/store_delete_singleton.sh b/tests/store_delete_singleton.sh index bfdf2ab8..c76e2fb9 100755 --- a/tests/store_delete_singleton.sh +++ b/tests/store_delete_singleton.sh @@ -31,7 +31,9 @@ if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then echo "Correct number of bundles in store!" else echo "Incorrect number of bundles in store!" - + wait_for_key $1 + cleanup + exit 1 fi echo From 230babdc94761008953b317b8357684f882d527d Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 27 Feb 2024 11:24:51 +0100 Subject: [PATCH 8/8] cleanup and additional tests --- core/dtn7/src/core/application_agent.rs | 18 ++++-------------- core/dtn7/src/lib.rs | 10 ++++++++++ tests/local_ping_echo.sh | 9 +++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/dtn7/src/core/application_agent.rs b/core/dtn7/src/core/application_agent.rs index 593e625e..d9a74ee4 100644 --- a/core/dtn7/src/core/application_agent.rs +++ b/core/dtn7/src/core/application_agent.rs @@ -1,12 +1,12 @@ use bp7::{Bundle, EndpointID}; use enum_dispatch::enum_dispatch; -use log::{debug, error, trace}; +use log::{debug, trace}; use std::collections::VecDeque; use std::fmt::Debug; use tokio::sync::mpsc::Sender; use crate::dtnd::ws::BundleDelivery; -use crate::store_remove; +use crate::store_remove_if_singleton_bundle; //use crate::dtnd::ws::WsAASession; #[enum_dispatch] @@ -47,7 +47,7 @@ impl ApplicationAgent for SimpleApplicationAgent { if addr.try_send(BundleDelivery(bundle.clone())).is_err() { self.bundles.push_back(bundle.clone()); } else { - remove_singleton_bundle_from_store(&bundle); + store_remove_if_singleton_bundle(bundle); } } else { // save in temp buffer for delivery @@ -57,7 +57,7 @@ impl ApplicationAgent for SimpleApplicationAgent { fn pop(&mut self) -> Option { let bundle = self.bundles.pop_front(); if let Some(bndl) = bundle.as_ref() { - remove_singleton_bundle_from_store(bndl); + store_remove_if_singleton_bundle(bndl); }; bundle } @@ -84,13 +84,3 @@ impl SimpleApplicationAgent { } } } - -/// Removes a bundle from the store if its destination is a singleton endpoint -fn remove_singleton_bundle_from_store(bundle: &Bundle) { - if !bundle.primary.destination.is_non_singleton() { - debug!("Removing bundle with singleton destination from store"); - if let Err(e) = store_remove(&bundle.id()) { - error!("Error while removing bundle from store: {:?}", e); - } - } -} diff --git a/core/dtn7/src/lib.rs b/core/dtn7/src/lib.rs index 9e91a45f..2d826fd8 100644 --- a/core/dtn7/src/lib.rs +++ b/core/dtn7/src/lib.rs @@ -188,6 +188,16 @@ pub fn store_remove(bid: &str) -> Result<()> { Ok(()) } +/// Removes a bundle from the store if its destination is a singleton endpoint +fn store_remove_if_singleton_bundle(bundle: &Bundle) { + if !bundle.primary.destination.is_non_singleton() { + debug!("Removing bundle with singleton destination from store"); + if let Err(e) = store_remove(&bundle.id()) { + error!("Error while removing bundle from store: {:?}", e); + } + } +} + pub fn store_update_metadata(bp: &BundlePack) -> Result<()> { (*STORE.lock()).update_metadata(bp) } diff --git a/tests/local_ping_echo.sh b/tests/local_ping_echo.sh index 0fc1436e..383153a2 100755 --- a/tests/local_ping_echo.sh +++ b/tests/local_ping_echo.sh @@ -21,14 +21,15 @@ $BINS/examples/dtnping -d 'dtn://node1/echo' -c 6 -t 500ms RC=$? echo "RET: $RC" -echo -n "Bundles in store on node 1: " NUM_BUNDLES=$($BINS/dtnquery bundles | grep "dtn://" | wc -l | awk '{print $1}') -echo -n $NUM_BUNDLES +NUM_DELETED=$($BINS/dtnquery store | grep -o "Deleted" | wc -l | awk '{print $1}') EXPECTED_BUNDLES=0 +EXPECTED_DELETED=12 -echo " / $EXPECTED_BUNDLES" -if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ]; then +echo "Bundles in store on node 1: : $NUM_BUNDLES / $EXPECTED_BUNDLES" +echo "Bundles marked as Deleted in store on node 1: : $NUM_DELETED / $EXPECTED_DELETED" +if [ "$NUM_BUNDLES" = "$EXPECTED_BUNDLES" ] && [ "$NUM_DELETED" = "$EXPECTED_DELETED" ]; then echo "Correct number of bundles in store!" else echo "Incorrect number of bundles in store!"