00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _MESH_LINK_H_
00036 #define _MESH_LINK_H_
00037
00038 #include <net/route.h>
00039 #include <limits.h>
00040 #include "mesh_protocol.h"
00041 #include "mesh_metrics.h"
00042 #include "mesh_net.h"
00043
00044
00045 #define MESH_LINK_STRLEN (NET_ADDR_LEN * 2 + 32 * 5)
00046 #define NUM_LINK_METRICS 4
00047 #define MAX_SEQNUM UINT32_MAX
00048 #define MAX_MTU 2048
00049
00050 typedef struct _q {
00051 seqnum_t id;
00052 void *data;
00053 unsigned int len;
00054 unsigned int port;
00055 u_int64_t timeout;
00056 struct _q *next;
00057 } msg_queue_t;
00058
00059
00060 typedef struct {
00061 uint32_t size;
00062 uint16_t protocol;
00063 } header_t;
00064
00065
00066 typedef struct {
00067 uint16_t rediscover;
00068 struct in_addr node;
00069
00070 uint32_t hop_count;
00071 int32_t metrics[NUM_LINK_METRICS];
00072
00073 struct in_addr next_hop;
00074 } link_t;
00075
00076 #define MESH_LINK_STR_FORMAT "%s:%u:%d:%d:%d:%d:%s"
00077
00078 typedef struct _link_entry {
00079 unsigned int node_id;
00080 u_int32_t requester;
00081
00082 protocol_t *protocol;
00083 link_t link;
00084 metric_t metrics;
00085 u_int64_t time_last_used;
00086
00087 struct avltree send_queue;
00088 seqnum_t send_seq_num;
00089 seqnum_t recv_seq_num;
00090
00091 msg_queue_t *routing_backlog;
00092 msg_queue_t *last_packet;
00093 unsigned short routing_pending;
00094
00095 char *iface;
00096 char bcast[NET_ADDR_LEN];
00097 char nmask[NET_ADDR_LEN];
00098
00099 struct _link_entry *next;
00100 } link_entry_t;
00101
00102
00103 typedef struct _db {
00104 header_t header;
00105 link_t links[];
00106 } database_t;
00107
00108
00109 void init_link(protocol_t *proto, link_t *link);
00110 void init_link_entry(protocol_t *proto, link_entry_t *entry);
00111 link_entry_t *new_link_entry(protocol_t *proto);
00112 void link_to_string(link_t *link, char *string);
00113
00114 database_t *new_database(protocol_t *proto, unsigned int size);
00115 size_t database_size(unsigned int num_links);
00116 void pack_database(database_t *db);
00117 void unpack_database(database_t *db);
00118
00119 int add_entry(protocol_t *proto, unsigned int id, link_entry_t *entry);
00120 int remove_entry(protocol_t *proto, unsigned int id, link_entry_t *entry);
00121 link_entry_t *retrieve_entry(protocol_t *proto, unsigned int id);
00122 link_entry_t *iterate_entries(protocol_t *proto);
00123 unsigned int num_entries(protocol_t *proto);
00124 void empty_entries(protocol_t *proto);
00125
00126 int add_msg(link_entry_t *link, unsigned int seq_num, msg_queue_t *msg);
00127 int remove_msg(link_entry_t *link, unsigned int seq_num, msg_queue_t *msg);
00128 msg_queue_t *retrieve_msg(link_entry_t *link, unsigned int seq_num);
00129 void empty_msgs(link_entry_t *link);
00130
00131 unsigned int ip_to_id(char *addr);
00132 char *ip_to_dot(unsigned int addr);
00133 size_t header_size(void);
00134 void unpack_header(header_t *hdr);
00135
00136
00137 #endif // _MESH_LINK_H_