Contiki 2.5
redundancy_basic.c
Go to the documentation of this file.
1 /**
2  * \addtogroup redundancy
3  * @{
4  */
5 
6 /**
7  * \defgroup redundancy_basic basic redundancy check module
8  *
9  * @{
10  */
11 
12 /**
13  * \file
14  * \brief implementation of basic redundancy check module
15  * \author Georg von Zengen <vonzeng@ibr.cs.tu-bs.de>
16  * \author Wolf-Bastian Poettner <poettner@ibr.cs.tu-bs.de>
17  */
18 
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h> // memset
22 
23 #include "lib/list.h"
24 #include "lib/memb.h"
25 #include "contiki.h"
26 #include "sys/ctimer.h"
27 #include "logging.h"
28 
29 #include "sdnv.h"
30 #include "redundancy.h"
31 #include "bundle.h"
32 #include "agent.h"
33 
34 uint32_t redundance_bundle_list[REDUNDANCE_MAX];
35 uint8_t redundance_bundle_active[REDUNDANCE_MAX];
36 uint8_t redundance_bundle_list_pointer;
37 
38 /**
39  * \brief checks if bundle was delivered before
40  * \param bundlemem pointer to bundle
41  * \return 1 if bundle was delivered before, 0 otherwise
42  */
44 {
45  int i;
46 
47  LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG, "REDUNDANCE: Checking bundle %lu for redundancy", bundle_number);
48 
49  for(i=0; i<REDUNDANCE_MAX; i++) {
50  if( redundance_bundle_active[i] == 0 ) {
51  continue;
52  }
53 
54  if( redundance_bundle_list[i] == bundle_number) {
55  LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG, "REDUNDANCE: bundle %lu is redundant", bundle_number);
56  return 1;
57  }
58  }
59 
60  return 0;
61 }
62 
63 /**
64  * \brief saves the bundle in a list of delivered bundles
65  * \param bundlemem pointer to bundle
66  * \return 1 on successor 0 on error
67  */
69 {
70  redundance_bundle_list[redundance_bundle_list_pointer] = bundle_number;
71  redundance_bundle_active[redundance_bundle_list_pointer] = 1;
72  redundance_bundle_list_pointer = (redundance_bundle_list_pointer + 1) % REDUNDANCE_MAX;
73 
74  return 1;
75 }
76 
77 /**
78  * \brief called by agent at startup
79  */
81 {
82  LOG(LOGD_DTN, LOG_AGENT, LOGL_DBG, "REDUNDANCE: starting");
83 
84  // Initialize our bundle list
85  memset(redundance_bundle_list, 0, sizeof(uint32_t) * REDUNDANCE_MAX);
86  memset(redundance_bundle_active, 0, REDUNDANCE_MAX);
87 
88  // And initialize our ring-buffer pointer
89  redundance_bundle_list_pointer = 0;
90 }
91 
92 const struct redundance_check redundancy_basic ={
93  "B_REDUNDANCE",
97 };
98 /** @} */
99 /** @} */