Contiki 3.x
deluge.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header for Deluge.
36  * \author
37  * Nicolas Tsiftes <nvt@sics.se>
38  */
39 
40 #ifndef DELUGE_H
41 #define DELUGE_H
42 
43 #include "net/rime/rime.h"
44 
45 PROCESS_NAME(deluge_process);
46 
47 #define LONG_TIMER(et, counter, time) \
48  do { \
49  for (counter = 0; counter < time; counter++) { \
50  etimer_set(&et, CLOCK_SECOND); \
51  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); \
52  } \
53  } while (0)
54 
55 #define DELUGE_UNICAST_CHANNEL 55
56 #define DELUGE_BROADCAST_CHANNEL 56
57 
58 /* All the packets in a page have been received. */
59 #define PAGE_COMPLETE 1
60 /* All pages up to, and including, this page are complete. */
61 #define PAGE_AVAILABLE 1
62 
63 #define S_PKT 64 /* Deluge packet size. */
64 #define N_PKT 4 /* Packets per page. */
65 #define S_PAGE (S_PKT * N_PKT) /* Fixed page size. */
66 
67 /* Bounds for the round time in seconds. */
68 #define T_LOW 2
69 #define T_HIGH 64
70 
71 /* Random interval for request transmissions in jiffies. */
72 #define T_R (CLOCK_SECOND * 2)
73 
74 /* Bound for the number of advertisements. */
75 #define CONST_K 1
76 
77 /* The number of pages in this object. */
78 #define OBJECT_PAGE_COUNT(obj) (((obj).size + (S_PAGE - 1)) / S_PAGE)
79 
80 #define ALL_PACKETS ((1 << N_PKT) - 1)
81 
82 #define DELUGE_CMD_SUMMARY 1
83 #define DELUGE_CMD_REQUEST 2
84 #define DELUGE_CMD_PACKET 3
85 #define DELUGE_CMD_PROFILE 4
86 
87 #define DELUGE_STATE_MAINTAIN 1
88 #define DELUGE_STATE_RX 2
89 #define DELUGE_STATE_TX 3
90 
91 #define CONST_LAMBDA 2
92 #define CONST_ALPHA 0.5
93 
94 #define CONST_OMEGA 8
95 #define ESTIMATED_TX_TIME (CLOCK_SECOND)
96 
97 typedef uint8_t deluge_object_id_t;
98 
99 struct deluge_msg_summary {
100  uint8_t cmd;
101  uint8_t version;
102  uint8_t highest_available;
103  deluge_object_id_t object_id;
104 };
105 
106 struct deluge_msg_request {
107  uint8_t cmd;
108  uint8_t version;
109  uint8_t pagenum;
110  uint8_t request_set;
111  deluge_object_id_t object_id;
112 };
113 
114 struct deluge_msg_packet {
115  uint8_t cmd;
116  uint8_t version;
117  uint8_t pagenum;
118  uint8_t packetnum;
119  uint16_t crc;
120  deluge_object_id_t object_id;
121  unsigned char payload[S_PKT];
122 };
123 
124 struct deluge_msg_profile {
125  uint8_t cmd;
126  uint8_t version;
127  uint8_t npages;
128  deluge_object_id_t object_id;
129  uint8_t version_vector[];
130 };
131 
132 struct deluge_object {
133  char *filename;
134  uint16_t object_id;
135  uint16_t size;
136  uint8_t version;
137  uint8_t update_version;
138  struct deluge_page *pages;
139  uint8_t current_rx_page;
140  int8_t current_tx_page;
141  uint8_t nrequests;
142  uint8_t current_page[S_PAGE];
143  uint8_t tx_set;
144  int cfs_fd;
145  linkaddr_t summary_from;
146 };
147 
148 struct deluge_page {
149  uint32_t packet_set;
150  uint16_t crc;
151  clock_time_t last_request;
152  clock_time_t last_data;
153  uint8_t flags;
154  uint8_t version;
155 };
156 
157 int deluge_disseminate(char *file, unsigned version);
158 
159 #endif
#define PROCESS_NAME(name)
Declare the name of a process.
Definition: process.h:286
Header file for the Rime stack