22 process_event_t dtn_statistics_overrun;
24 unsigned long statistics_timestamp = 0;
25 struct statistics_element_t statistics_array[STATISTICS_ELEMENTS];
26 struct contact_element_t statistics_contacts[STATISTICS_CONTACTS];
27 struct process * statistics_event_process =
NULL;
28 uint8_t contacts_pointer = 0;
29 unsigned long contacts_timestamp = 0;
36 #if STATISTICS_PERIOD > 0
38 unsigned long elapsed = clock_seconds() - statistics_timestamp;
41 uint8_t ptr = elapsed / STATISTICS_PERIOD;
43 if( ptr >= STATISTICS_ELEMENTS ) {
44 ptr = STATISTICS_ELEMENTS - 1;
59 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"setup()");
65 statistics_event_process = process;
70 return STATISTICS_PERIOD * STATISTICS_ELEMENTS;
81 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"get_bundle(%p, %u)", buffer, maximum_length);
84 memcpy(buffer + offset, &statistics_timestamp,
sizeof(statistics_timestamp));
85 offset +=
sizeof(statistics_timestamp);
88 buffer[offset++] = (STATISTICS_PERIOD & 0x00FF) >> 0;
89 buffer[offset++] = (STATISTICS_PERIOD & 0xFF00) >> 8;
92 buffer[offset++] = STATISTICS_ELEMENTS;
95 memcpy(buffer + offset, &statistics_array,
sizeof(
struct statistics_element_t) * STATISTICS_ELEMENTS);
96 offset +=
sizeof(
struct statistics_element_t) * STATISTICS_ELEMENTS;
109 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"get_contacts_bundle(%p, %u)", buffer, maximum_length);
112 if( contacts_pointer > STATISTICS_CONTACTS ) {
113 contacts_pointer = STATISTICS_CONTACTS;
117 buffer[offset++] = contacts_pointer;
119 buffer[offset++] = (contacts_timestamp & 0x000000FF) >> 0;
120 buffer[offset++] = (contacts_timestamp & 0x0000FF00) >> 8;
121 buffer[offset++] = (contacts_timestamp & 0x00FF0000) >> 16;
122 buffer[offset++] = (contacts_timestamp & 0xFF000000) >> 24;
125 memcpy(buffer + offset, &statistics_contacts,
sizeof(
struct contact_element_t) * contacts_pointer);
126 offset +=
sizeof(
struct contact_element_t) * contacts_pointer;
136 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"reset_contacts()");
138 memset(statistics_contacts, 0,
sizeof(
struct contact_element_t) * STATISTICS_CONTACTS);
139 contacts_pointer = 0;
140 contacts_timestamp = 0;
148 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"reset()");
151 memset(statistics_array, 0,
sizeof(
struct statistics_element_t) * STATISTICS_ELEMENTS);
154 statistics_timestamp = clock_seconds();
162 #if STATISTICS_ELEMENTS > 0
163 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"bundle_incoming(%u)", count);
174 #if STATISTICS_ELEMENTS > 0
175 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"bundle_outgoing(%u)", count);
186 #if STATISTICS_ELEMENTS > 0
187 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"bundle_generated(%u)", count);
198 #if STATISTICS_ELEMENTS > 0
199 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"statistics_bundle_delivered(%u)", count);
210 #if STATISTICS_ELEMENTS > 0
211 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"storage_bundles(%u)", bundles);
222 #if STATISTICS_ELEMENTS > 0
223 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"storage_memory(%u)", free);
234 #if STATISTICS_ELEMENTS > 0
235 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"contacts_up(%u.%u)", peer->u8[0], peer->u8[1]);
244 #if STATISTICS_ELEMENTS > 0
245 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"contacts_down(%u.%u, %u)", peer->u8[0], peer->u8[1], duration);
251 #if STATISTICS_CONTACTS > 0
255 if( duration == 0 ||
id > dtn_node_id ) {
259 if( contacts_pointer >= STATISTICS_CONTACTS ) {
261 contacts_pointer = STATISTICS_CONTACTS - 1;
265 unsigned long timestamp = clock_seconds() - duration;
267 if( contacts_timestamp == 0 && contacts_pointer == 0 ) {
268 contacts_timestamp = timestamp;
271 statistics_contacts[contacts_pointer].time_difference = (uint16_t) (timestamp - contacts_timestamp);
272 statistics_contacts[contacts_pointer].peer = (uint8_t)
id;
273 statistics_contacts[contacts_pointer].duration = duration;
277 if( contacts_pointer >= STATISTICS_CONTACTS && statistics_event_process !=
NULL ) {
278 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"contacts full, sending event");
280 }
else if( statistics_event_process ==
NULL ) {
282 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"contacts full, clearing array");