|
| 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 | +} |
0 commit comments