N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/Vaike/linux/system-addons/networking/mesh_link.h

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
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;  /* scales to 4,294,967,295 (UINT_MAX) */
00062   uint16_t protocol;
00063 } header_t;
00064 
00065 
00066 typedef struct {
00067   uint16_t rediscover;
00068   struct in_addr node;    /* target destination */
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;  /* for semi-reliable UDP */
00088   seqnum_t send_seq_num;
00089   seqnum_t recv_seq_num;
00090 
00091   msg_queue_t *routing_backlog;  /* on-demand 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_


© 2007, Los Alamos National Security, LLC.