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/l4/sim_if-l4.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 
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 <sim_if.h>
00043 #include <virtual_time.h>
00044 #include <mac_lib.h>
00045 #include <sensor_node.h>
00046 #include <daemon.h>
00047 #include <configuration.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 paused = 0, do_pause = 0;
00074         oq_req_resp_t *rr = new_req_resp();
00075 
00076         /* launch L4Linux for each node */
00077         AvlNode *list;
00078         for (list = avl_find_min(&current_config.nodes); list != NULL; 
00079              list = list->next)
00080                 launch((Sensor_node *) list->element);
00081 
00082 
00083         while (!oq_quitting() && !oq_shuttingdown()) {
00084                 if (do_pause) {
00085                         paused = 0;
00086                         ctl = ioctl(ctl_fd, OQ_RESP_PAUSE);
00087                         continue;
00088                 }
00089                 if (paused && !do_pause)
00090                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00091 
00092                 switch (ctl) {
00093                 case 0:
00094                         if (strcmp(rr->type, "radio") == 0) {
00095                                 Sensor_node *node;
00096                                 if (radio_request(rr) < 0) {
00098                                 }
00099                                 if ((node = (Sensor_node *) 
00100                                      avl_retrieve(rr->node_id, 
00101                                                   &current_config.nodes)) 
00102                                     == NULL) {
00104                                 }
00105                                 if (protocol_filter(node->radio.protocol, 
00106                                                     rr) < 0) {
00108                                 }
00109                                 if (rr == NULL) {
00111                                 }
00112                         } else {
00113                                 if (sense_request(rr) < 0) {
00115                                         rr->data[0] = 0;
00116                                         rr->timestamp.tv_sec = 0;
00117                                         rr->timestamp.tv_nsec = 0;
00118                                 }
00119                         }
00120                         ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00121                         break;
00122 
00123                 case OQ_REQ_REPEAT:
00124                         ctl = ioctl(ctl_fd, OQ_RESP_RESULT, rr);
00125                         break;
00126 /*
00127                 case OQ_REQ_RECONFIG:
00128                         config_sim(&config);
00129                         free(rr);
00130                         rr = new_req_resp();
00131                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00132                         break;
00133 */
00134                 default:
00135                         free(rr);
00136                         rr = new_req_resp();
00137                         ctl = ioctl(ctl_fd, OQ_RESP_REINIT, rr);
00138                         break;
00139                 }
00140         }
00141 }


© 2007, Los Alamos National Security, LLC.