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/server/xen/sim_if-xen.cpp

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 #include <sys/ioctl.h>
00037 #include <sys/types.h>
00038 #include <sys/stat.h>
00039 #include <fcntl.h>
00040 #include <unistd.h>
00041 
00042 #include <configuration.h>
00043 #include <sensor_device.h>
00044 #include <virtual_time.h>
00045 #include <mac_lib.h>
00046 #include <sim_if.h>
00047 #include <daemon.h>
00048 
00049 
00050 
00051 static int radio_request(oq_req_resp_t *rr)
00052 {
00053         /* \todo  * determine connectivity (multiplexing skb)
00054                   * determine time of initial arrival & duration
00055                      based on local_virtual_time()
00056                       - propagation latency
00057                       - basic connectivity
00058                       - obstructions + multipath signal effects
00059         */
00060         return 0;
00061 }
00062 
00063 
00064 static int sense_request(oq_req_resp_t *rr)
00065 {
00066         return 0;
00067 }
00068 
00069 
00070 
00071 void sim_if_service(int nodes[], int num_nodes)
00072 {
00073         int ctl_fd, ctl, paused = 0, do_pause = 0;
00074         oq_req_resp_t *rr = new_req_resp();
00075 
00076         ctl_fd = open("/dev/orbisquartus0", O_RDONLY);
00077         ctl = ioctl(ctl_fd, OQ_RESP_INIT, rr);
00078 
00079         /* launch each node */
00080         struct avlnode *list;
00081         for (list = avl_find_min(&current_config.nodes); list != NULL; 
00082              list = list->next)
00083                 ((Sensor_node *) list->element)->launch();
00084 
00085 
00086         while (!oq_quitting() && !oq_shuttingdown()) {
00087                 if (do_pause) {
00088                         paused = 0;
00089                         ctl = ioctl(ctl_fd, OQ_RESP_PAUSE);
00090                         continue;
00091                 }
00092                 if (paused && !do_pause)
00093                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00094 
00095                 switch (ctl) {
00096                 case 0:
00097                         if (strcmp(rr->type, "radio") == 0) {
00098                                 node_t *node;
00099                                 if (radio_request(rr) < 0) {
00101                                 }
00102                                 if ((node = (node_t *) 
00103                                      avl_retrieve(rr->node_id, 
00104                                                   &current_config.nodes)) 
00105                                     == NULL) {
00107                                 }
00108                                 if (protocol_filter(node->radio.protocol, 
00109                                                     rr) < 0) {
00111                                 }
00112                                 if (rr == NULL) {
00114                                 }
00115                         } else {
00116                                 if (sense_request(rr) < 0) {
00118                                         rr->data[0] = 0;
00119                                         rr->timestamp.tv_sec = 0;
00120                                         rr->timestamp.tv_nsec = 0;
00121                                 }
00122                         }
00123                         ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00124                         break;
00125 
00126                 case OQ_REQ_REPEAT:
00127                         ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00128                         break;
00129 /*
00130                 case OQ_REQ_RECONFIG:
00131                         config_sim(&config);
00132                         free(rr);
00133                         rr = new_req_resp();
00134                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00135                         break;
00136 */
00137                 default:
00138                         free(rr);
00139                         rr = new_req_resp();
00140                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00141                         break;
00142                 }
00143         }
00144 
00145         close(ctl_fd);
00146 }


© 2007, Los Alamos National Security, LLC.