Skip to content

Commit 9dd2f7b

Browse files
committed
feat: added CCSDS 734.20-O-1 Bundle Protocol Orange Book compliant management information
1 parent cf48ed4 commit 9dd2f7b

File tree

4 files changed

+134
-2
lines changed

4 files changed

+134
-2
lines changed

core/dtn7/src/core/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ pub mod bundlepack;
33
pub mod helpers;
44
pub mod peer;
55
pub mod processing;
6+
pub mod stats;
67
pub mod store;
78

89
use crate::cla::ConvergenceLayerAgent;
910
use crate::core::bundlepack::Constraint;
1011
pub use crate::core::peer::{DtnPeer, PeerType};
12+
use crate::core::stats::{NodeStats, RegistrationInformation};
1113
use crate::core::store::BundleStore;
1214
use crate::routing::RoutingAgentsEnum;
13-
use crate::{routing_notify, store_delete_expired, store_get_bundle, store_get_metadata, CLAS};
15+
use crate::{
16+
routing_notify, store_delete_expired, store_get_bundle, store_get_metadata, CLAS, DTNCORE,
17+
};
1418
pub use crate::{store_has_item, store_push_bundle};
1519
use crate::{RoutingNotifcation, CONFIG};
1620
use crate::{PEERS, STORE};
@@ -36,19 +40,49 @@ pub struct DtnStatistics {
3640
pub delivered: u64,
3741
pub failed: u64,
3842
pub broken: u64,
43+
pub node: NodeStats,
3944
}
4045

4146
impl DtnStatistics {
4247
pub fn new() -> DtnStatistics {
48+
let nodestats = NodeStats::new();
4349
DtnStatistics {
4450
incoming: 0,
4551
dups: 0,
4652
outgoing: 0,
4753
delivered: 0,
4854
failed: 0,
4955
broken: 0,
56+
node: nodestats,
5057
}
5158
}
59+
pub fn update_node_stats(&mut self) {
60+
println!("Updating node stats");
61+
self.node.error_info.failed_forwards_bundle_count = self.failed;
62+
self.node.registrations.clear();
63+
let eids = (*DTNCORE.lock()).eids();
64+
for eid in eids {
65+
if let Some(aa) =
66+
(*DTNCORE.lock()).get_endpoint(&EndpointID::try_from(eid.clone()).unwrap())
67+
{
68+
let singleton = !aa.eid().is_non_singleton();
69+
let registration = RegistrationInformation {
70+
eid: eid.clone(),
71+
active: aa.delivery_addr().is_some(),
72+
singleton: singleton,
73+
default_failure_action: stats::FailureAction::Defer,
74+
};
75+
self.node.registrations.push(registration);
76+
}
77+
}
78+
self.node.bundles.bundles_stored = (*STORE.lock()).count();
79+
self.node.bundles.forward_pending_bundle_count = (*STORE.lock()).forwarding().len() as u64;
80+
// TODO get correct number of bundles with dispatch pending
81+
// self.node.bundles.dispatch_pending_bundle_count = (*STORE.lock()).pending().len() as u64;
82+
// TODO get correct number of bundles with reassembly pending
83+
// self.node.bundles.reassembly_pending_bundle_count =
84+
// (*STORE.lock()).reassembly_pending().len() as u64;
85+
}
5286
}
5387
#[derive(Debug)]
5488
pub struct DtnCore {

core/dtn7/src/core/stats.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::CONFIG;
4+
5+
/// CCSDS 734.20-O-1 Bundle Protocol Orange Book - Annex C Managed Information
6+
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
7+
pub struct NodeStats {
8+
pub registrations: Vec<RegistrationInformation>,
9+
pub node_state: NodeStateInformation,
10+
pub error_info: ErrorInformation,
11+
pub bundles: BundleStateInformation,
12+
}
13+
14+
impl NodeStats {
15+
pub fn new() -> Self {
16+
let mut mib = NodeStats {
17+
registrations: Vec::new(),
18+
node_state: NodeStateInformation::default(),
19+
error_info: ErrorInformation::default(),
20+
bundles: BundleStateInformation::default(),
21+
};
22+
mib.node_state.administrative_eid = CONFIG.lock().host_eid.clone().to_string();
23+
mib.node_state.bp_versions = vec![7]; // Bundle Protocol version - fixed to 7 for now
24+
25+
// mib.error_info.failed_forwards_bundle_count = (*STATS.lock()).failed;
26+
return mib;
27+
}
28+
}
29+
30+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
31+
pub enum FailureAction {
32+
Abandon = 0,
33+
Defer = 1,
34+
}
35+
36+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
37+
/// CCSDS Bundle Protocol Orange Book - Annex C Bundle State Information Table C-1
38+
pub struct BundleStateInformation {
39+
pub forward_pending_bundle_count: u64,
40+
pub dispatch_pending_bundle_count: u64,
41+
pub reassembly_pending_bundle_count: u64,
42+
pub bundles_created: u64,
43+
pub bundles_stored: u64,
44+
pub bundles_fragmented: u64,
45+
pub fragments_created: u64,
46+
}
47+
48+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
49+
/// CCSDS Bundle Protocol Orange Book - Annex C Error and Reporting Information Table C-2
50+
pub struct ErrorInformation {
51+
/// The number of bundles/bytes that have experienced a forwarding failure at this node.
52+
pub failed_forwards_bundle_count: u64,
53+
/// The number of bundles/bytes whose delivery has been abandoned at this node.
54+
pub abandoned_delivery_bundle_count: u64,
55+
/// The number of bundles/bytes discarded at this node.
56+
pub discarded_bundle_count: u64,
57+
}
58+
59+
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
60+
/// CCSDS Bundle Protocol Orange Book - Annex C Node State Information Table C-4
61+
pub struct NodeStateInformation {
62+
/// The EID that uniquely and permanently identifies this node’s administrative endpoint.
63+
pub administrative_eid: String,
64+
/// The number(s) of the version(s) of the BP supported at this node.
65+
pub bp_versions: Vec<u8>, // Bundle Protocol version - fixed to 7 for now
66+
/// The number of kilobytes of storage allocated to bundle retention at this node and not currently occupied by bundles.
67+
pub storage_available: u64,
68+
/// The most recent time at which the operation of this node was started or restarted.
69+
pub last_up_time: u64,
70+
/// The number of different endpoints in which this node has been registered since it was started or restarted.
71+
pub registration_count: u64, // optional
72+
}
73+
74+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
75+
/// CCSDS Bundle Protocol Orange Book - Annex C Registration Information Table C-4
76+
pub struct RegistrationInformation {
77+
/// The EID of the endpoint for which this registration applies.
78+
pub eid: String,
79+
/// The current state of the EID, at the time the managed information was queried. True - ACTIVE, False - PASSIVE
80+
pub active: bool,
81+
/// Whether this EID is a singleton EID.
82+
pub singleton: bool,
83+
/// The default action to be taken when delivery is not possible.
84+
/// One of: ABANDON or DEFER.
85+
pub default_failure_action: FailureAction,
86+
}

core/dtn7/src/dtnd/httpd.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ async fn status_peers() -> String {
301301
}
302302
//#[get("/status/info")]
303303
async fn status_info() -> String {
304+
STATS.lock().update_node_stats();
304305
let stats = &(*STATS.lock()).clone();
305306
serde_json::to_string_pretty(&stats).unwrap()
306307
}
@@ -427,7 +428,9 @@ async fn insert_get(extract::RawQuery(query): extract::RawQuery) -> Result<Strin
427428
bndl.id(),
428429
bndl.primary.destination
429430
);
430-
431+
if bndl.primary.source.node() == (*CONFIG.lock()).host_eid.node() {
432+
STATS.lock().node.bundles.bundles_created += 1;
433+
}
431434
crate::core::processing::send_bundle(bndl).await;
432435
Ok(format!("Sent {} bytes", b_len))
433436
} else {
@@ -453,6 +456,10 @@ async fn insert_post(body: bytes::Bytes) -> Result<String, (StatusCode, &'static
453456
bndl.primary.destination
454457
);
455458

459+
if bndl.primary.source.node() == (*CONFIG.lock()).host_eid.node() {
460+
STATS.lock().node.bundles.bundles_created += 1;
461+
}
462+
456463
crate::core::processing::send_bundle(bndl).await;
457464
Ok(format!("Sent {} bytes", b_len))
458465
} else {
@@ -525,6 +532,7 @@ async fn send_post(
525532
);
526533
let bid = bndl.id();
527534
crate::core::processing::send_bundle(bndl).await;
535+
STATS.lock().node.bundles.bundles_created += 1;
528536
Ok(format!("Sent ADU in bundle {} with {} bytes", bid, b_len))
529537
}
530538

core/dtn7/src/dtnd/ws.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::core::application_agent::ApplicationAgent;
22
use crate::CONFIG;
33
use crate::DTNCORE;
4+
use crate::STATS;
45

56
use anyhow::{bail, Result};
67
use axum::extract::ws::{Message, WebSocket};
@@ -353,6 +354,7 @@ impl WsAASession {
353354
async move { crate::core::processing::send_bundle(bndl).await },
354355
);
355356
debug!("sent bundle");
357+
STATS.lock().node.bundles.bundles_created += 1;
356358

357359
ws_reply_text!(
358360
socket,
@@ -422,6 +424,8 @@ impl WsAASession {
422424
async move { crate::core::processing::send_bundle(bndl).await },
423425
);
424426
debug!("sent bundle");
427+
STATS.lock().node.bundles.bundles_created += 1;
428+
425429
//crate::core::processing::send_through_task(bndl);
426430
ws_reply_text!(
427431
socket,

0 commit comments

Comments
 (0)