Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
stack/pico_protocol.c@131:4758606c9316, 2013-12-16 (annotated)
- Committer:
- TASS Belgium NV
- Date:
- Mon Dec 16 11:25:54 2013 +0100
- Revision:
- 131:4758606c9316
- Parent:
- 68:0847e35d08a6
- Child:
- 133:5b075f5e141a
Syncronized with master branch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 68:0847e35d08a6 | 1 | /********************************************************************* |
TASS Belgium NV |
131:4758606c9316 | 2 | PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. |
TASS Belgium NV |
131:4758606c9316 | 3 | See LICENSE and COPYING for usage. |
tass | 68:0847e35d08a6 | 4 | |
TASS Belgium NV |
131:4758606c9316 | 5 | . |
tass | 68:0847e35d08a6 | 6 | |
TASS Belgium NV |
131:4758606c9316 | 7 | Authors: Daniele Lacamera |
TASS Belgium NV |
131:4758606c9316 | 8 | *********************************************************************/ |
tass | 68:0847e35d08a6 | 9 | |
tass | 68:0847e35d08a6 | 10 | |
tass | 68:0847e35d08a6 | 11 | #include "pico_protocol.h" |
tass | 68:0847e35d08a6 | 12 | #include "pico_tree.h" |
tass | 68:0847e35d08a6 | 13 | |
tass | 68:0847e35d08a6 | 14 | static int pico_proto_cmp(void *ka, void *kb) |
tass | 68:0847e35d08a6 | 15 | { |
TASS Belgium NV |
131:4758606c9316 | 16 | struct pico_protocol *a = ka, *b = kb; |
TASS Belgium NV |
131:4758606c9316 | 17 | if (a->hash < b->hash) |
TASS Belgium NV |
131:4758606c9316 | 18 | return -1; |
TASS Belgium NV |
131:4758606c9316 | 19 | |
TASS Belgium NV |
131:4758606c9316 | 20 | if (a->hash > b->hash) |
TASS Belgium NV |
131:4758606c9316 | 21 | return 1; |
TASS Belgium NV |
131:4758606c9316 | 22 | |
TASS Belgium NV |
131:4758606c9316 | 23 | return 0; |
tass | 68:0847e35d08a6 | 24 | } |
tass | 68:0847e35d08a6 | 25 | |
TASS Belgium NV |
131:4758606c9316 | 26 | PICO_TREE_DECLARE(Datalink_proto_tree, pico_proto_cmp); |
TASS Belgium NV |
131:4758606c9316 | 27 | PICO_TREE_DECLARE(Network_proto_tree, pico_proto_cmp); |
TASS Belgium NV |
131:4758606c9316 | 28 | PICO_TREE_DECLARE(Transport_proto_tree, pico_proto_cmp); |
TASS Belgium NV |
131:4758606c9316 | 29 | PICO_TREE_DECLARE(Socket_proto_tree, pico_proto_cmp); |
tass | 68:0847e35d08a6 | 30 | |
tass | 68:0847e35d08a6 | 31 | static int proto_loop(struct pico_protocol *proto, int loop_score, int direction) |
tass | 68:0847e35d08a6 | 32 | { |
TASS Belgium NV |
131:4758606c9316 | 33 | struct pico_frame *f; |
TASS Belgium NV |
131:4758606c9316 | 34 | |
TASS Belgium NV |
131:4758606c9316 | 35 | if (direction == PICO_LOOP_DIR_IN) { |
tass | 68:0847e35d08a6 | 36 | |
TASS Belgium NV |
131:4758606c9316 | 37 | while(loop_score > 0) { |
TASS Belgium NV |
131:4758606c9316 | 38 | if (proto->q_in->frames <= 0) |
TASS Belgium NV |
131:4758606c9316 | 39 | break; |
tass | 68:0847e35d08a6 | 40 | |
TASS Belgium NV |
131:4758606c9316 | 41 | f = pico_dequeue(proto->q_in); |
TASS Belgium NV |
131:4758606c9316 | 42 | if ((f) && (proto->process_in(proto, f) > 0)) { |
TASS Belgium NV |
131:4758606c9316 | 43 | loop_score--; |
TASS Belgium NV |
131:4758606c9316 | 44 | } |
TASS Belgium NV |
131:4758606c9316 | 45 | } |
TASS Belgium NV |
131:4758606c9316 | 46 | } else if (direction == PICO_LOOP_DIR_OUT) { |
tass | 68:0847e35d08a6 | 47 | |
TASS Belgium NV |
131:4758606c9316 | 48 | while(loop_score > 0) { |
TASS Belgium NV |
131:4758606c9316 | 49 | if (proto->q_out->frames <= 0) |
TASS Belgium NV |
131:4758606c9316 | 50 | break; |
TASS Belgium NV |
131:4758606c9316 | 51 | |
TASS Belgium NV |
131:4758606c9316 | 52 | f = pico_dequeue(proto->q_out); |
TASS Belgium NV |
131:4758606c9316 | 53 | if ((f) && (proto->process_out(proto, f) > 0)) { |
TASS Belgium NV |
131:4758606c9316 | 54 | loop_score--; |
TASS Belgium NV |
131:4758606c9316 | 55 | } |
TASS Belgium NV |
131:4758606c9316 | 56 | } |
tass | 68:0847e35d08a6 | 57 | } |
tass | 68:0847e35d08a6 | 58 | |
TASS Belgium NV |
131:4758606c9316 | 59 | return loop_score; |
tass | 68:0847e35d08a6 | 60 | } |
tass | 68:0847e35d08a6 | 61 | |
tass | 68:0847e35d08a6 | 62 | #define DL_LOOP_MIN 1 |
tass | 68:0847e35d08a6 | 63 | |
tass | 68:0847e35d08a6 | 64 | int pico_protocol_datalink_loop(int loop_score, int direction) |
tass | 68:0847e35d08a6 | 65 | { |
TASS Belgium NV |
131:4758606c9316 | 66 | struct pico_protocol *start; |
TASS Belgium NV |
131:4758606c9316 | 67 | static struct pico_protocol *next = NULL, *next_in = NULL, *next_out = NULL; |
TASS Belgium NV |
131:4758606c9316 | 68 | static struct pico_tree_node *next_node, *in_node, *out_node; |
TASS Belgium NV |
131:4758606c9316 | 69 | |
TASS Belgium NV |
131:4758606c9316 | 70 | if (next_in == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 71 | in_node = pico_tree_firstNode(Datalink_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 72 | if (in_node) |
TASS Belgium NV |
131:4758606c9316 | 73 | next_in = in_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 74 | } |
tass | 68:0847e35d08a6 | 75 | |
TASS Belgium NV |
131:4758606c9316 | 76 | if (next_out == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 77 | out_node = pico_tree_firstNode(Datalink_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 78 | if (out_node) |
TASS Belgium NV |
131:4758606c9316 | 79 | next_out = out_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 80 | } |
tass | 68:0847e35d08a6 | 81 | |
TASS Belgium NV |
131:4758606c9316 | 82 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 83 | { |
TASS Belgium NV |
131:4758606c9316 | 84 | next_node = in_node; |
TASS Belgium NV |
131:4758606c9316 | 85 | next = next_in; |
TASS Belgium NV |
131:4758606c9316 | 86 | } |
TASS Belgium NV |
131:4758606c9316 | 87 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 88 | { |
TASS Belgium NV |
131:4758606c9316 | 89 | next_node = out_node; |
TASS Belgium NV |
131:4758606c9316 | 90 | next = next_out; |
TASS Belgium NV |
131:4758606c9316 | 91 | } |
TASS Belgium NV |
131:4758606c9316 | 92 | |
TASS Belgium NV |
131:4758606c9316 | 93 | /* init start node */ |
TASS Belgium NV |
131:4758606c9316 | 94 | start = next; |
tass | 68:0847e35d08a6 | 95 | |
TASS Belgium NV |
131:4758606c9316 | 96 | /* round-robin all datalink protocols, break if traversed all protocols */ |
TASS Belgium NV |
131:4758606c9316 | 97 | while (loop_score > DL_LOOP_MIN && next != NULL) { |
TASS Belgium NV |
131:4758606c9316 | 98 | loop_score = proto_loop(next, loop_score, direction); |
TASS Belgium NV |
131:4758606c9316 | 99 | |
TASS Belgium NV |
131:4758606c9316 | 100 | /* next = RB_NEXT(pico_protocol_tree, &Datalink_proto_tree, next); */ |
TASS Belgium NV |
131:4758606c9316 | 101 | next_node = pico_tree_next(next_node); |
TASS Belgium NV |
131:4758606c9316 | 102 | next = next_node->keyValue; |
tass | 68:0847e35d08a6 | 103 | |
TASS Belgium NV |
131:4758606c9316 | 104 | if (next == NULL) |
TASS Belgium NV |
131:4758606c9316 | 105 | { |
TASS Belgium NV |
131:4758606c9316 | 106 | next_node = pico_tree_firstNode(Datalink_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 107 | next = next_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 108 | } |
tass | 68:0847e35d08a6 | 109 | |
TASS Belgium NV |
131:4758606c9316 | 110 | if (next == start) |
TASS Belgium NV |
131:4758606c9316 | 111 | break; |
tass | 68:0847e35d08a6 | 112 | } |
TASS Belgium NV |
131:4758606c9316 | 113 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 114 | { |
TASS Belgium NV |
131:4758606c9316 | 115 | in_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 116 | next_in = next; |
TASS Belgium NV |
131:4758606c9316 | 117 | } |
TASS Belgium NV |
131:4758606c9316 | 118 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 119 | { |
TASS Belgium NV |
131:4758606c9316 | 120 | out_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 121 | next_out = next; |
TASS Belgium NV |
131:4758606c9316 | 122 | } |
tass | 68:0847e35d08a6 | 123 | |
TASS Belgium NV |
131:4758606c9316 | 124 | return loop_score; |
tass | 68:0847e35d08a6 | 125 | } |
tass | 68:0847e35d08a6 | 126 | |
tass | 68:0847e35d08a6 | 127 | |
tass | 68:0847e35d08a6 | 128 | #define NW_LOOP_MIN 1 |
tass | 68:0847e35d08a6 | 129 | |
tass | 68:0847e35d08a6 | 130 | int pico_protocol_network_loop(int loop_score, int direction) |
tass | 68:0847e35d08a6 | 131 | { |
TASS Belgium NV |
131:4758606c9316 | 132 | struct pico_protocol *start; |
TASS Belgium NV |
131:4758606c9316 | 133 | static struct pico_protocol *next = NULL, *next_in = NULL, *next_out = NULL; |
TASS Belgium NV |
131:4758606c9316 | 134 | static struct pico_tree_node *next_node, *in_node, *out_node; |
TASS Belgium NV |
131:4758606c9316 | 135 | |
TASS Belgium NV |
131:4758606c9316 | 136 | if (next_in == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 137 | in_node = pico_tree_firstNode(Network_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 138 | if (in_node) |
TASS Belgium NV |
131:4758606c9316 | 139 | next_in = in_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 140 | } |
tass | 68:0847e35d08a6 | 141 | |
TASS Belgium NV |
131:4758606c9316 | 142 | if (next_out == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 143 | out_node = pico_tree_firstNode(Network_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 144 | if (out_node) |
TASS Belgium NV |
131:4758606c9316 | 145 | next_out = out_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 146 | } |
tass | 68:0847e35d08a6 | 147 | |
TASS Belgium NV |
131:4758606c9316 | 148 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 149 | { |
TASS Belgium NV |
131:4758606c9316 | 150 | next_node = in_node; |
TASS Belgium NV |
131:4758606c9316 | 151 | next = next_in; |
TASS Belgium NV |
131:4758606c9316 | 152 | } |
TASS Belgium NV |
131:4758606c9316 | 153 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 154 | { |
TASS Belgium NV |
131:4758606c9316 | 155 | next_node = out_node; |
TASS Belgium NV |
131:4758606c9316 | 156 | next = next_out; |
TASS Belgium NV |
131:4758606c9316 | 157 | } |
tass | 68:0847e35d08a6 | 158 | |
TASS Belgium NV |
131:4758606c9316 | 159 | /* init start node */ |
TASS Belgium NV |
131:4758606c9316 | 160 | start = next; |
TASS Belgium NV |
131:4758606c9316 | 161 | |
TASS Belgium NV |
131:4758606c9316 | 162 | /* round-robin all network protocols, break if traversed all protocols */ |
TASS Belgium NV |
131:4758606c9316 | 163 | while (loop_score > NW_LOOP_MIN && next != NULL) { |
TASS Belgium NV |
131:4758606c9316 | 164 | loop_score = proto_loop(next, loop_score, direction); |
tass | 68:0847e35d08a6 | 165 | |
TASS Belgium NV |
131:4758606c9316 | 166 | next_node = pico_tree_next(next_node); |
TASS Belgium NV |
131:4758606c9316 | 167 | next = next_node->keyValue; |
tass | 68:0847e35d08a6 | 168 | |
TASS Belgium NV |
131:4758606c9316 | 169 | if (next == NULL) |
TASS Belgium NV |
131:4758606c9316 | 170 | { |
TASS Belgium NV |
131:4758606c9316 | 171 | next_node = pico_tree_firstNode(Network_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 172 | next = next_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 173 | } |
TASS Belgium NV |
131:4758606c9316 | 174 | |
TASS Belgium NV |
131:4758606c9316 | 175 | if (next == start) |
TASS Belgium NV |
131:4758606c9316 | 176 | break; |
tass | 68:0847e35d08a6 | 177 | } |
TASS Belgium NV |
131:4758606c9316 | 178 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 179 | { |
TASS Belgium NV |
131:4758606c9316 | 180 | in_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 181 | next_in = next; |
TASS Belgium NV |
131:4758606c9316 | 182 | } |
TASS Belgium NV |
131:4758606c9316 | 183 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 184 | { |
TASS Belgium NV |
131:4758606c9316 | 185 | out_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 186 | next_out = next; |
TASS Belgium NV |
131:4758606c9316 | 187 | } |
tass | 68:0847e35d08a6 | 188 | |
TASS Belgium NV |
131:4758606c9316 | 189 | return loop_score; |
tass | 68:0847e35d08a6 | 190 | } |
tass | 68:0847e35d08a6 | 191 | |
tass | 68:0847e35d08a6 | 192 | #define TP_LOOP_MIN 1 |
tass | 68:0847e35d08a6 | 193 | |
tass | 68:0847e35d08a6 | 194 | int pico_protocol_transport_loop(int loop_score, int direction) |
tass | 68:0847e35d08a6 | 195 | { |
TASS Belgium NV |
131:4758606c9316 | 196 | struct pico_protocol *start; |
TASS Belgium NV |
131:4758606c9316 | 197 | static struct pico_protocol *next = NULL, *next_in = NULL, *next_out = NULL; |
TASS Belgium NV |
131:4758606c9316 | 198 | static struct pico_tree_node *next_node, *in_node, *out_node; |
TASS Belgium NV |
131:4758606c9316 | 199 | |
TASS Belgium NV |
131:4758606c9316 | 200 | if (next_in == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 201 | in_node = pico_tree_firstNode(Transport_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 202 | if (in_node) |
TASS Belgium NV |
131:4758606c9316 | 203 | next_in = in_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 204 | } |
tass | 68:0847e35d08a6 | 205 | |
TASS Belgium NV |
131:4758606c9316 | 206 | if (next_out == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 207 | out_node = pico_tree_firstNode(Transport_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 208 | if (out_node) |
TASS Belgium NV |
131:4758606c9316 | 209 | next_out = out_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 210 | } |
tass | 68:0847e35d08a6 | 211 | |
TASS Belgium NV |
131:4758606c9316 | 212 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 213 | { |
TASS Belgium NV |
131:4758606c9316 | 214 | next_node = in_node; |
TASS Belgium NV |
131:4758606c9316 | 215 | next = next_in; |
TASS Belgium NV |
131:4758606c9316 | 216 | } |
TASS Belgium NV |
131:4758606c9316 | 217 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 218 | { |
TASS Belgium NV |
131:4758606c9316 | 219 | next_node = out_node; |
TASS Belgium NV |
131:4758606c9316 | 220 | next = next_out; |
TASS Belgium NV |
131:4758606c9316 | 221 | } |
TASS Belgium NV |
131:4758606c9316 | 222 | |
TASS Belgium NV |
131:4758606c9316 | 223 | /* init start node */ |
TASS Belgium NV |
131:4758606c9316 | 224 | start = next; |
tass | 68:0847e35d08a6 | 225 | |
TASS Belgium NV |
131:4758606c9316 | 226 | /* round-robin all transport protocols, break if traversed all protocols */ |
TASS Belgium NV |
131:4758606c9316 | 227 | while (loop_score > DL_LOOP_MIN && next != NULL) { |
TASS Belgium NV |
131:4758606c9316 | 228 | loop_score = proto_loop(next, loop_score, direction); |
TASS Belgium NV |
131:4758606c9316 | 229 | |
TASS Belgium NV |
131:4758606c9316 | 230 | /* next = RB_NEXT(pico_protocol_tree, &Transport_proto_tree, next); */ |
TASS Belgium NV |
131:4758606c9316 | 231 | next_node = pico_tree_next(next_node); |
TASS Belgium NV |
131:4758606c9316 | 232 | next = next_node->keyValue; |
tass | 68:0847e35d08a6 | 233 | |
TASS Belgium NV |
131:4758606c9316 | 234 | if (next == NULL) |
TASS Belgium NV |
131:4758606c9316 | 235 | { |
TASS Belgium NV |
131:4758606c9316 | 236 | next_node = pico_tree_firstNode(Transport_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 237 | next = next_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 238 | } |
tass | 68:0847e35d08a6 | 239 | |
TASS Belgium NV |
131:4758606c9316 | 240 | if (next == start) |
TASS Belgium NV |
131:4758606c9316 | 241 | break; |
tass | 68:0847e35d08a6 | 242 | } |
TASS Belgium NV |
131:4758606c9316 | 243 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 244 | { |
TASS Belgium NV |
131:4758606c9316 | 245 | in_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 246 | next_in = next; |
TASS Belgium NV |
131:4758606c9316 | 247 | } |
TASS Belgium NV |
131:4758606c9316 | 248 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 249 | { |
TASS Belgium NV |
131:4758606c9316 | 250 | out_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 251 | next_out = next; |
TASS Belgium NV |
131:4758606c9316 | 252 | } |
tass | 68:0847e35d08a6 | 253 | |
TASS Belgium NV |
131:4758606c9316 | 254 | return loop_score; |
tass | 68:0847e35d08a6 | 255 | } |
tass | 68:0847e35d08a6 | 256 | |
tass | 68:0847e35d08a6 | 257 | |
tass | 68:0847e35d08a6 | 258 | #define SOCK_LOOP_MIN 1 |
tass | 68:0847e35d08a6 | 259 | |
tass | 68:0847e35d08a6 | 260 | int pico_protocol_socket_loop(int loop_score, int direction) |
tass | 68:0847e35d08a6 | 261 | { |
TASS Belgium NV |
131:4758606c9316 | 262 | struct pico_protocol *start; |
TASS Belgium NV |
131:4758606c9316 | 263 | static struct pico_protocol *next = NULL, *next_in = NULL, *next_out = NULL; |
TASS Belgium NV |
131:4758606c9316 | 264 | static struct pico_tree_node *next_node, *in_node, *out_node; |
TASS Belgium NV |
131:4758606c9316 | 265 | |
TASS Belgium NV |
131:4758606c9316 | 266 | if (next_in == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 267 | in_node = pico_tree_firstNode(Socket_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 268 | if(in_node) |
TASS Belgium NV |
131:4758606c9316 | 269 | next_in = in_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 270 | } |
tass | 68:0847e35d08a6 | 271 | |
TASS Belgium NV |
131:4758606c9316 | 272 | if (next_out == NULL) { |
TASS Belgium NV |
131:4758606c9316 | 273 | out_node = pico_tree_firstNode(Socket_proto_tree.root); |
TASS Belgium NV |
131:4758606c9316 | 274 | if(out_node) |
TASS Belgium NV |
131:4758606c9316 | 275 | next_out = out_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 276 | } |
tass | 68:0847e35d08a6 | 277 | |
TASS Belgium NV |
131:4758606c9316 | 278 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 279 | { |
TASS Belgium NV |
131:4758606c9316 | 280 | next_node = in_node; |
TASS Belgium NV |
131:4758606c9316 | 281 | next = next_in; |
TASS Belgium NV |
131:4758606c9316 | 282 | } |
TASS Belgium NV |
131:4758606c9316 | 283 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 284 | { |
TASS Belgium NV |
131:4758606c9316 | 285 | next_node = out_node; |
TASS Belgium NV |
131:4758606c9316 | 286 | next = next_out; |
TASS Belgium NV |
131:4758606c9316 | 287 | } |
tass | 68:0847e35d08a6 | 288 | |
TASS Belgium NV |
131:4758606c9316 | 289 | /* init start node */ |
TASS Belgium NV |
131:4758606c9316 | 290 | start = next; |
TASS Belgium NV |
131:4758606c9316 | 291 | |
TASS Belgium NV |
131:4758606c9316 | 292 | /* round-robin all transport protocols, break if traversed all protocols */ |
TASS Belgium NV |
131:4758606c9316 | 293 | while (loop_score > SOCK_LOOP_MIN && next != NULL) { |
TASS Belgium NV |
131:4758606c9316 | 294 | loop_score = proto_loop(next, loop_score, direction); |
tass | 68:0847e35d08a6 | 295 | |
TASS Belgium NV |
131:4758606c9316 | 296 | next_node = pico_tree_next(next_node); |
TASS Belgium NV |
131:4758606c9316 | 297 | next = next_node->keyValue; |
tass | 68:0847e35d08a6 | 298 | |
TASS Belgium NV |
131:4758606c9316 | 299 | if (next == NULL) |
TASS Belgium NV |
131:4758606c9316 | 300 | { |
TASS Belgium NV |
131:4758606c9316 | 301 | next_node = pico_tree_firstNode(next_node); |
TASS Belgium NV |
131:4758606c9316 | 302 | next = next_node->keyValue; |
TASS Belgium NV |
131:4758606c9316 | 303 | } |
TASS Belgium NV |
131:4758606c9316 | 304 | |
TASS Belgium NV |
131:4758606c9316 | 305 | if (next == start) |
TASS Belgium NV |
131:4758606c9316 | 306 | break; |
tass | 68:0847e35d08a6 | 307 | } |
TASS Belgium NV |
131:4758606c9316 | 308 | if (direction == PICO_LOOP_DIR_IN) |
TASS Belgium NV |
131:4758606c9316 | 309 | { |
TASS Belgium NV |
131:4758606c9316 | 310 | in_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 311 | next_in = next; |
TASS Belgium NV |
131:4758606c9316 | 312 | } |
TASS Belgium NV |
131:4758606c9316 | 313 | else if (direction == PICO_LOOP_DIR_OUT) |
TASS Belgium NV |
131:4758606c9316 | 314 | { |
TASS Belgium NV |
131:4758606c9316 | 315 | out_node = next_node; |
TASS Belgium NV |
131:4758606c9316 | 316 | next_out = next; |
TASS Belgium NV |
131:4758606c9316 | 317 | } |
tass | 68:0847e35d08a6 | 318 | |
TASS Belgium NV |
131:4758606c9316 | 319 | return loop_score; |
tass | 68:0847e35d08a6 | 320 | } |
tass | 68:0847e35d08a6 | 321 | |
tass | 68:0847e35d08a6 | 322 | int pico_protocols_loop(int loop_score) |
tass | 68:0847e35d08a6 | 323 | { |
tass | 68:0847e35d08a6 | 324 | /* |
TASS Belgium NV |
131:4758606c9316 | 325 | loop_score = pico_protocol_datalink_loop(loop_score); |
TASS Belgium NV |
131:4758606c9316 | 326 | loop_score = pico_protocol_network_loop(loop_score); |
TASS Belgium NV |
131:4758606c9316 | 327 | loop_score = pico_protocol_transport_loop(loop_score); |
TASS Belgium NV |
131:4758606c9316 | 328 | loop_score = pico_protocol_socket_loop(loop_score); |
TASS Belgium NV |
131:4758606c9316 | 329 | */ |
TASS Belgium NV |
131:4758606c9316 | 330 | return loop_score; |
tass | 68:0847e35d08a6 | 331 | } |
tass | 68:0847e35d08a6 | 332 | |
tass | 68:0847e35d08a6 | 333 | void pico_protocol_init(struct pico_protocol *p) |
tass | 68:0847e35d08a6 | 334 | { |
TASS Belgium NV |
131:4758606c9316 | 335 | if (!p) |
TASS Belgium NV |
131:4758606c9316 | 336 | return; |
tass | 68:0847e35d08a6 | 337 | |
TASS Belgium NV |
131:4758606c9316 | 338 | p->hash = pico_hash(p->name); |
TASS Belgium NV |
131:4758606c9316 | 339 | switch (p->layer) { |
tass | 68:0847e35d08a6 | 340 | case PICO_LAYER_DATALINK: |
TASS Belgium NV |
131:4758606c9316 | 341 | pico_tree_insert(&Datalink_proto_tree, p); |
TASS Belgium NV |
131:4758606c9316 | 342 | break; |
tass | 68:0847e35d08a6 | 343 | case PICO_LAYER_NETWORK: |
TASS Belgium NV |
131:4758606c9316 | 344 | pico_tree_insert(&Network_proto_tree, p); |
TASS Belgium NV |
131:4758606c9316 | 345 | break; |
tass | 68:0847e35d08a6 | 346 | case PICO_LAYER_TRANSPORT: |
TASS Belgium NV |
131:4758606c9316 | 347 | pico_tree_insert(&Transport_proto_tree, p); |
TASS Belgium NV |
131:4758606c9316 | 348 | break; |
tass | 68:0847e35d08a6 | 349 | case PICO_LAYER_SOCKET: |
TASS Belgium NV |
131:4758606c9316 | 350 | pico_tree_insert(&Socket_proto_tree, p); |
TASS Belgium NV |
131:4758606c9316 | 351 | break; |
TASS Belgium NV |
131:4758606c9316 | 352 | } |
TASS Belgium NV |
131:4758606c9316 | 353 | dbg("Protocol %s registered (layer: %d).\n", p->name, p->layer); |
tass | 68:0847e35d08a6 | 354 | |
tass | 68:0847e35d08a6 | 355 | } |
tass | 68:0847e35d08a6 | 356 |