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/OrbisQuartus/shared/sim_if.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 
00036 #ifndef _SIM_IF_H_
00037 #define _SIM_IF_H_
00038 
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <sys/time.h>
00042 //#include "config.h"
00043 #include "oq.h"
00044 
00045 
00046 struct list_head {
00047         struct list_head *next, *prev;
00048 };
00049 
00050 
00051 # define OQ_MAGIC          0xAA
00052 # define OQ_RESP_INIT      _IOR(OQ_MAGIC, 1, int)
00053 # define OQ_RESP_REINIT    _IOR(OQ_MAGIC, 2, int)
00054 # define OQ_RESP_RESULT    _IOWR(OQ_MAGIC, 3, int)
00055 # define OQ_RESP_PAUSE     _IO(OQ_MAGIC, 4)
00056 
00057 # define OQ_REQ_RECONFIG   (INT_MAX - OQ_MAGIC)
00058 # define OQ_REQ_REPEAT     ((INT_MAX - OQ_MAGIC) - 1)
00059 
00060 enum { OQ_RADIO_TX = 1, OQ_RADIO_RX = 2, };
00061 
00062 # define OQ_MAC_BUFS       4
00063 # define OQ_MAC_LEN        128
00064 # define V_MTU             256
00065 
00066 
00067 struct sock_buff {
00068         unsigned short tx_rx;       /* enum oq_tx_rx flag */
00069         unsigned short to_me;       /* recvr is intended recipient */
00070         unsigned short is_base;     /* base station flag */
00071 
00072         char mac[OQ_MAC_LEN];       /* simulated MAC hdr (pkt to 1st '|') */
00073         unsigned long length;       /* time to xfer this packet in microsecs */
00074         unsigned long long seq_num; /* 'unique' packet id */
00075 
00076         unsigned long slot_time;    /* in microseconds */
00077         unsigned int slot_idx;      /* CSMA collisions or assigned TDMA slot */
00078         unsigned int next_slot;     /* slots to wait */
00079 
00080         int code;                   /* MAC sim return value */
00081         void *skbuf;                /* for kernel reference only */
00082 };
00083 
00084 
00085 
00086 
00087 typedef struct oq_req_resp {
00088         struct list_head list;
00089         struct sock_buff msgs[OQ_MAC_BUFS];
00090         unsigned int num_msgs;
00091 
00092         char type[MAX_NAME];        /* sensor type */
00093         int node_id;
00094         int sensor_id;
00095         char data[V_MTU];           /* (partial) content of sk_buf/signal */
00096         int size;                   /* true size of content */
00097         struct timespec timestamp;  /* in nanoseconds */
00098 } oq_req_resp_t;
00099 
00100 
00101 
00102 
00103 static inline oq_req_resp_t *new_req_resp(void)
00104 {
00105         struct oq_req_resp *request = 
00106                 (struct oq_req_resp *) malloc(sizeof(struct oq_req_resp));
00107         return request;
00108 }
00109 
00110 
00111 
00112 static inline struct oq_req_resp *new_request(char *type, int node, int sensor,
00113                                                char *data, unsigned long time)
00114 {
00115         struct oq_req_resp *request = new_req_resp();
00116 
00117         strncpy(request->type, type, MAX_NAME);
00118         request->node_id = node;
00119         request->sensor_id = sensor;
00120         strcpy(request->data, data);
00121         return request;
00122 }
00123 
00124 
00125 
00126 static inline struct oq_req_resp *new_response(unsigned long arg)
00127 {
00128         struct oq_req_resp *response = new_req_resp();
00129         memcpy(response, (oq_req_resp_t *) arg, sizeof(oq_req_resp_t));
00130         return response;
00131 }
00132 
00133 
00134 void sim_if_service(int nodes[], int num_nodes);
00135 
00136 
00137 struct sensor_stats {
00138         unsigned int id;
00139         unsigned long rx_bytes, rx_errors, rx_dropped, rx_overruns;
00140         unsigned long tx_bytes, tx_errors, tx_dropped, tx_overruns;
00141 };
00142 
00143 
00144 #endif                   /* _SIM_IF_H_ */


© 2007, Los Alamos National Security, LLC.