44 PROCESS(agent_process,
"AGENT process");
45 AUTOSTART_PROCESSES(&agent_process);
60 uint32_t * bundle_number_ptr =
NULL;
74 convergence_layer_init();
96 printf(
"Starting DTN Bundle Protocol Agent with EID ipn:%lu\n", dtn_node_id);
105 LOG(LOGD_DTN, LOG_AGENT, LOGL_INF,
"New Service registration for endpoint %lu", reg->app_id);
112 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"Service switching status to %i", reg->status);
113 if(reg->status == APP_ACTIVE)
115 else if(reg->status == APP_PASSIVE)
119 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"no registration found to switch");
127 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"Unregistering service for endpoint %lu", reg->app_id);
135 struct process * source_process =
NULL;
136 struct mmem * bundleptr;
137 uint32_t bundle_flags = 0;
139 bundleptr = (
struct mmem *) data;
140 if( bundleptr ==
NULL ) {
141 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"dtn_send_bundle_event with invalid pointer");
147 if( bundle ==
NULL ) {
148 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"dtn_send_bundle_event with invalid MMEM structure");
155 if( app_id == 0xFFFF && bundle->source_process != &agent_process) {
156 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"Unregistered process %s tries to send a bundle", PROCESS_NAME_STRING(bundle->source_process));
163 uint32_t service_app_id;
167 if( service_app_id == 0 ) {
176 if( bundle_flags & BUNDLE_FLAG_REPORT ) {
177 uint32_t report_to_node = 0;
180 if( report_to_node == 0 ) {
184 uint32_t report_to_service = 0;
187 if( report_to_service ) {
192 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"dtn_send_bundle_event(%p) with seqNo %lu", bundleptr, dtn_seq_nr);
199 source_process = bundle->source_process;
202 bundle->bundle_num =
HASH.hash_convenience(bundle->tstamp_seq, bundle->tstamp, bundle->src_node, bundle->frag_offs, bundle->app_len);
228 data = (
void *) bundle_number_ptr;
229 ev = dtn_bundle_in_storage_event;
235 if(ev == dtn_send_admin_record_event) {
236 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"Send admin record currently not implemented");
240 if(ev == dtn_beacon_event){
241 rimeaddr_t* src =(rimeaddr_t*) data;
243 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"dtn_beacon_event for %u.%u", src->u8[0], src->u8[1]);
247 if(ev == dtn_bundle_in_storage_event){
250 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"bundle %lu in storage", *bundle_number);
252 if(
ROUTING.new_bundle(bundle_number) < 0){
253 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"routing reports error when announcing new bundle %lu", *bundle_number);
262 struct mmem * bundlemem =
NULL;
265 bundlemem = (
struct mmem *) data;
266 if( bundlemem ==
NULL ) {
267 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"dtn_processing_finished with invalid pointer");
272 if( bundle ==
NULL ) {
273 LOG(LOGD_DTN, LOG_AGENT, LOGL_ERR,
"dtn_send_bundle_event with invalid MMEM structure");
277 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"service has processed bundle %lu", bundle->bundle_num);
280 ROUTING.locally_delivered(bundlemem);
289 void agent_delete_bundle(uint32_t bundle_number){
290 LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG,
"Agent deleting bundle no %lu", bundle_number);
292 convergence_layer_delete_bundle(bundle_number);
293 ROUTING.del_bundle(bundle_number);
294 CUSTODY.del_from_list(bundle_number);