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/sensor_mesh.c

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 #include <sys/socket.h>
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 
00039 #include "sensor_mesh.h"
00040 #include "mesh_ipc.h"
00041 #include "mesh_net.h"
00042 
00043 
00044 int mesh_proactive_rediscover(char *protocol_name)
00045 {
00046   return mesh_ioctl(MESH_IOREDISCVR, protocol_name);
00047 }
00048 
00049 
00050 double mesh_route_reliability(char *destination)
00051 {
00052   double data = 0.0;
00053   if (mesh_ioctl(MESH_IOGRTMTR, &data, "reliability", destination) < 0)
00054     return -1.0;
00055   return data;
00056 }
00057 
00058 
00059 double mesh_route_goodput(char *destination)
00060 {
00061   double data = 0.0;
00062   if (mesh_ioctl(MESH_IOGRTMTR, &data, "goodput", destination) < 0)
00063     return -1.0;
00064   return data;
00065 }
00066 
00067 
00068 double mesh_route_energy_cost(char *destination)
00069 {
00070   double data = 0.0;
00071   if (mesh_ioctl(MESH_IOGRTMTR, &data, "energy", destination) < 0)
00072     return -1.0;
00073   return data;
00074 }
00075 
00076 
00077 int neighbor_address(unsigned char *mac_addr, float angle, unsigned int dist)
00078 {
00079   return mesh_ioctl(MESH_IOGNGHADDR, mac_addr, angle, dist);
00080 }
00081 
00082 
00083 int neighbor_position(float *angle, unsigned int *dist,
00084                       unsigned char *mac_addr)
00085 {
00086   return mesh_ioctl(MESH_IOGNGHPOS, angle, dist, mac_addr);
00087 }
00088 
00089 
00090 double mesh_link_reliability(float angle, int dist)
00091 {
00092   double data = 0.0;
00093   unsigned char mac_addr[MAC_ADDR_LEN];
00094   neighbor_address(mac_addr, angle, dist);
00095   if (mesh_ioctl(MESH_IOGLNKMTR, &data, "reliability", mac_addr) < 0)
00096     return -1.0;
00097   return data;
00098 }
00099 
00100 
00101 double mesh_link_goodput(float angle, int dist)
00102 {
00103   double data = 0.0;
00104   unsigned char mac_addr[MAC_ADDR_LEN];
00105   neighbor_address(mac_addr, angle, dist);
00106   if (mesh_ioctl(MESH_IOGLNKMTR, &data, "goodput", mac_addr) < 0)
00107     return -1.0;
00108   return data;
00109 }
00110 
00111 
00112 double mesh_link_energy(float angle, int dist)
00113 {
00114   double data = 0.0;
00115   unsigned char mac_addr[MAC_ADDR_LEN];
00116   neighbor_address(mac_addr, angle, dist);
00117   if (mesh_ioctl(MESH_IOGLNKMTR, &data, "energy", mac_addr) < 0)
00118     return -1.0;
00119   return data;
00120 }
00121 
00122 
00123 int mesh_get_sendqueue(void)
00124 {
00125   int error, data = 0;
00126   if ((error = mesh_ioctl(MESH_IOGSNDQ, &data)) < 0)
00127     return error;
00128   return data;
00129 }
00130 
00131 
00132 int mesh_set_sendqueue(int size)
00133 {
00134   return mesh_ioctl(MESH_IOSSNDQ, size);
00135 }
00136 
00137 
00138 int mesh_get_mtu(void)
00139 {
00140   int error, data = 0;
00141   if ((error = mesh_ioctl(MESH_IOGMTU, &data)) < 0)
00142     return error;
00143   return data;
00144 }
00145 
00146 
00147 int mesh_set_mtu(int size)
00148 {
00149   return mesh_ioctl(MESH_IOSMTU, size);
00150 }
00151 
00152 
00153 int mesh_get_resend_timeout(struct timeval *tv)
00154 {
00155   return mesh_ioctl(MESH_IOGSNDTMO, &tv->tv_sec, &tv->tv_usec);
00156 }
00157 
00158 
00159 int mesh_set_resend_timeout(struct timeval *tv)
00160 {
00161   return mesh_ioctl(MESH_IOGSNDTMO, tv->tv_sec, tv->tv_usec);
00162 }
00163 
00164 
00165 ssize_t mesh_sendto(int sd, void *buf, size_t len, struct sockaddr_in *to)
00166 {
00167   return mesh_ioctl(MESH_IOSENDSEQ, sd, buf, len, inet_ntoa(to->sin_addr));
00168 }
00169 
00170 
00171 ssize_t mesh_recvfrom(int sd, void *buf, size_t len, struct sockaddr_in *from)
00172 {
00173   char from_str[NET_ADDR_LEN];
00174   int nbytes = mesh_ioctl(MESH_IORECVSEQ, sd, buf, len, from_str);
00175   inet_aton(from_str, &from->sin_addr);
00176   return nbytes;
00177 }
00178 
00179 
00180 ssize_t mesh_raw_sendto(int sd, void *buf, size_t len, struct sockaddr_in *to)
00181 {
00182   return mesh_ioctl(MESH_IOSENDRAW, sd, buf, len, inet_ntoa(to->sin_addr));
00183 }
00184 
00185 
00186 ssize_t mesh_raw_recvfrom(int sd, void *buf, size_t len,
00187                           struct sockaddr_in *from)
00188 {
00189   char from_str[NET_ADDR_LEN];
00190   int nbytes = mesh_ioctl(MESH_IORECVRAW, sd, buf, len, from_str);
00191   inet_aton(from_str, &from->sin_addr);
00192   return nbytes;
00193 }
00194 
00195 
00196 ssize_t mesh_sendto_nextdoor(int sd, void *buf, size_t len,
00197                              float angle, int dist)
00198 {
00199   unsigned char mac_addr[MAC_ADDR_LEN];
00200   neighbor_address(mac_addr, angle, dist);
00201   return mesh_ioctl(MESH_IOSENDNEAR, sd, buf, len, mac_addr);
00202 }
00203 
00204 
00205 ssize_t mesh_recvfrom_nextdoor(int sd, void *buf, size_t len,
00206                                float *angle, int *dist)
00207 {
00208   unsigned char mac_addr[MAC_ADDR_LEN];
00209   int nbytes = mesh_ioctl(MESH_IORECVNEAR, sd, buf, len, mac_addr);
00210   neighbor_position(angle, dist, mac_addr);
00211   return nbytes;
00212 }


© 2007, Los Alamos National Security, LLC.