1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-27 07:21:18 +01:00

[sys net sixlowpan]

- HACK: added simple static MESH routing on MAC layer, see
projects/tlayer/main.c for explanation and usage.
This commit is contained in:
Oliver 2012-02-14 21:28:51 +01:00
parent 5176640664
commit f57e4078e5
10 changed files with 122 additions and 8 deletions

View File

@ -269,6 +269,7 @@ void send_tcp_bandwidth_test(char *str)
int i = 0, count;
char command[80];
// char msg_string[] = "abcdefghijklmnopqrstuvwxyz0123456789!-";
char msg_string[] = "abcdefghijklmnopqrstuvwxyz0123456789!-=/%$";
sscanf(str, "tcp_bw %i", &count);
@ -561,6 +562,50 @@ void ignore(char *addr) {
}
#endif
/* HACK: Simple mesh routing on MAC layer:
*
* This routing method is used to forward layer 3 fragments over N hops in 2 directions.
*
* Example: A <--> B <--> C <--> D (N = 4)
*
* To achieve the network topology described in the example above one has to
* declare the nodes A and D as "head nodes" and the nodes B and C as "routing nodes".
* For every static route with N hops there are always N-2 nodes which are
* routing nodes and 2 head nodes (start and end).
*
* A "head node" is a node receiving or sending packets of higher layers (i.e. layer 3 or higher)
* and does not route any fragments on the MAC layer.
* A "routing node" is a node forwarding fragments from local addresses < its own address to
* nodes (head or routing) with local address > its own address (own_address+1).
* It also forwards fragments from local addresses > its own address to nodes with
* local address < its own address (own_address-1).
*
* The variables which need to be set are static_route in sys/net/sixlowpan/sixlowmac.c for
* routing nodes and route_head in sys/net/sixlowpan/sixlowpan.c for head nodes. */
void static_routing (char *str)
{
if (static_route == 0)
{
static_route = 1;
}
else
{
static_route = 0;
}
}
void static_head (char *str)
{
if (route_head == 0)
{
route_head = 1;
}
else
{
route_head = 0;
}
}
const shell_command_t shell_commands[] = {
{"init", "", init},
{"addr", "", get_r_address},
@ -584,6 +629,8 @@ const shell_command_t shell_commands[] = {
{"boots", "", boot_server},
{"bootc", "", boot_client},
{"print_nbr_cache", "", show_nbr_cache},
{"static_routing", "", static_routing},
{"static_head", "", static_head},
#ifdef DBG_IGNORE
{"ign", "ignore node", ignore},
#endif

View File

@ -18,7 +18,7 @@
void init_transport_layer(void)
{
printf("Initializing transport layer packages.\n");
printf("Initializing transport layer packages. Size of socket_type: %u\n", sizeof(socket_internal_t));
// SOCKETS
memset(sockets, 0, MAX_SOCKETS*sizeof(socket_internal_t));

View File

@ -18,6 +18,8 @@
#include "sys/net/net_help/net_help.h"
#include "sys/net/net_help/msg_help.h"
socket_internal_t sockets[MAX_SOCKETS];
void printf_tcp_context(tcp_hc_context_t *current_tcp_context)
{
printf("Context: %u\n", current_tcp_context->context_id);
@ -614,6 +616,11 @@ void calculate_rto(tcp_cb_t *tcp_control, timex_t current_time)
{
rto = SECOND;
}
// if (((rto > (SECOND-1)) && (rto < (SECOND+1))))
// {
// printf("RTO is correct!\n");
// }
tcp_control->srtt = srtt;
tcp_control->rttvar = rttvar;
tcp_control->rto = rto;

View File

@ -189,7 +189,7 @@ typedef struct socket_in_t
uint8_t tcp_input_buffer[MAX_TCP_BUFFER];
} socket_internal_t;
socket_internal_t sockets[MAX_SOCKETS];
extern socket_internal_t sockets[MAX_SOCKETS];
int socket(int domain, int type, int protocol);
int connect(int socket, sockaddr6_t *addr, uint32_t addrlen);

View File

@ -5,8 +5,11 @@
* Author: Oliver
*/
#include <thread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "tcp_timer.h"
#include "vtimer.h"
#include "thread.h"
@ -47,10 +50,30 @@ void handle_synchro_timeout(socket_internal_t *current_socket)
}
}
char *double2string (double d, int stellen) {
int num_int_digits = 0;
char* returnstr = NULL;
if ((int) d != 0)
num_int_digits = (int) log10 (abs((int) d)) + 1;
else
num_int_digits = 1;
returnstr = malloc (num_int_digits + 1 + stellen + 1);
sprintf (returnstr, "%.*f", stellen, d);
return returnstr;
}
void handle_established(socket_internal_t *current_socket)
{
msg_t send;
double current_timeout = current_socket->socket_values.tcp_control.rto;
if (current_timeout < SECOND)
{
current_timeout = SECOND;
}
uint8_t i;
if ((current_socket->socket_values.tcp_control.send_nxt > current_socket->socket_values.tcp_control.send_una) &&
(thread_getstatus(current_socket->send_pid) == STATUS_RECEIVE_BLOCKED))

View File

@ -10,12 +10,12 @@
#define TCP_TIMER_RESOLUTION 500*1000
#define SECOND 1000*1000
#define TCP_TIMER_STACKSIZE 2048
#define SECOND 1000.0f*1000.0f
#define TCP_TIMER_STACKSIZE 2800
#define TCP_SYN_INITIAL_TIMEOUT 6*SECOND
#define TCP_SYN_TIMEOUT 24*SECOND
#define TCP_MAX_SYN_RETRIES 3
#define TCP_INITIAL_ACK_TIMEOUT 3*SECOND // still static, should be calculated via RTT
#define TCP_INITIAL_ACK_TIMEOUT 3.0f*SECOND // still static, should be calculated via RTT
#define TCP_ACK_MAX_TIMEOUT 30*SECOND // TODO: Set back to 90 Seconds
#define TCP_ALPHA 1.0f/8.0f

View File

@ -32,6 +32,7 @@ static radio_packet_t p;
static msg_t mesg;
int transceiver_type;
static transceiver_command_t tcmd;
uint8_t static_route = 0;
uint8_t get_radio_address(void){
int16_t address;
@ -111,9 +112,29 @@ void recv_ieee802154_frame(void){
hdrlen = read_802154_frame(p->data, &frame, p->length);
length = p->length - hdrlen;
/* deliver packet to network(6lowpan)-layer */
lowpan_read(frame.payload, length, (ieee_802154_long_t*)&frame.src_addr,
(ieee_802154_long_t*)&frame.dest_addr);
if (static_route == 1)
{
if (frame.src_addr[7] < frame.dest_addr[7])
{
ieee_802154_long_t dest_addr;
frame.dest_addr[7] += 1;
memcpy(&dest_addr, &frame.dest_addr, 8);
send_ieee802154_frame(&dest_addr, frame.payload, frame.payload_len, 0);
}
else
{
ieee_802154_long_t dest_addr;
frame.dest_addr[7] -= 1;
memcpy(&dest_addr, &frame.dest_addr, 8);
send_ieee802154_frame(&dest_addr, frame.payload, frame.payload_len, 0);
}
}
else
{
/* deliver packet to network(6lowpan)-layer */
lowpan_read(frame.payload, length, (ieee_802154_long_t*)&frame.src_addr,
(ieee_802154_long_t*)&frame.dest_addr);
}
p->processing--;
}

View File

@ -14,6 +14,8 @@
#define RADIO_SND_BUF_SIZE 100
#define RADIO_SENDING_DELAY 1000
extern uint8_t static_route;
uint8_t get_radio_address(void);
void set_radio_address(uint8_t addr);
void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,

View File

@ -58,6 +58,7 @@ char con_buf[CON_STACKSIZE];
char lowpan_transfer_buf[LOWPAN_TRANSFER_BUF_STACKSIZE];
lowpan_context_t contexts[LOWPAN_CONTEXT_MAX];
uint8_t context_len = 0;
uint8_t route_head = 0;
void lowpan_context_auto_remove(void);
@ -78,6 +79,18 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data){
data = &comp_buf[0];
packet_length = comp_len;
if (route_head == 1)
{
if (laddr.uint8[7] < get_radio_address())
{
laddr.uint8[7] = get_radio_address() - 1;
}
else
{
laddr.uint8[7] = get_radio_address() + 1;
}
}
/* check if packet needs to be fragmented */
if(packet_length + header_size > PAYLOAD_SIZE - IEEE_802154_MAX_HDR_LEN){
uint8_t fragbuf[packet_length + header_size];

View File

@ -32,6 +32,7 @@
#include <time.h>
extern mutex_t lowpan_context_mutex;
extern uint8_t route_head;
typedef struct lowpan_context_t {
uint8_t num;