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/virtual_time.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 <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <avl.h>
00040 #include <daemon.h>
00041 #include <mini_mpi.h>
00042 #include <orbisquartus.h>
00043 #include <sensor_node.h>
00044 #include <mutex.h>
00045 #include "virtual_time.h"
00046 
00047 #define BIT_RATE 400 // FIXME: make this Sensor_node specific
00048 
00049 OrbisQuartus *oq;
00050 mutex_t vt_mutex;
00051 mutex_t vt_sync;
00052 
00053 AVL_tree<VT_timestamp> send_queue;
00054 AVL_tree<VT_timestamp> rcv_queue;
00055 AVL_tree<VT_timestamp> state_queue;   // FIXME: paths to fs snapshots
00056 
00057 extern int my_taskid;
00058 
00059 char *VT_timestamp::_format = "%lu,%lu";
00060 VT_timestamp VT_timestamp::_local_virtual_time = VT_timestamp(0L, 0L);
00061 VT_timestamp VT_timestamp::_global_virtual_time = VT_timestamp(0L, 0L);
00062 
00063 
00064 VT_message::VT_message(unsigned int to_whom, char *buf) :
00065   Comparable<VT_timestamp>(VT_timestamp())
00066 {
00067         msg_queue = OUT;
00068         sender = my_taskid;
00069         _svt = key = VT_timestamp();
00070         rcvr = to_whom;
00071         _rvt = VT_timestamp() + static_cast<int>(strlen(buf) * BIT_RATE);
00072         msg_sign = POSITIVE;
00073         content = buf;
00074 }
00075 
00076 
00077 VT_message::VT_message(char *string) :
00078   Comparable<VT_timestamp>(VT_timestamp())
00079 {
00080         int sign;
00081         char st[VT_timestamp::_strlen + 1];
00082         char rt[VT_timestamp::_strlen + 1];
00083         sscanf(string, "%s::%u::%s::%u::%d::%s",
00084                st, &sender, rt, &rcvr, &sign, content);
00085 
00086         _svt = VT_timestamp(st);
00087         _rvt = key = VT_timestamp(rt);
00088         msg_queue = IN;
00089         if (sign == POSITIVE)
00090                 msg_sign = POSITIVE;
00091         else
00092                 msg_sign = NEGATIVE;
00093 }
00094 
00095 
00096 
00097 int checkpoint(unsigned long node_id)
00098 {
00099         int error = 0;
00100 
00101         Sensor_node *node = dynamic_cast<Sensor_node*>
00102                 (oq->cfg.get_nodes()->find(node_id)->elt());
00103 
00104         if ((error = node->pause()) < 0)
00105                 return error;
00106         if ((error = node->save()) < 0)
00107                 return error;
00108 
00111 
00112         error = node->unpause();
00113 
00114         return error;
00115 }
00116 
00117 
00118 int chkpt_all(void)
00119 {
00120         int i, count, error = 0;
00121         unsigned long *assign = 0;
00122         oq->get_assignment(assign, &count);
00123 
00124         if (assign == 0)
00125                 return -1;
00126 
00127         for (i = 0; i < count; i ++) {
00128                 if ((error = checkpoint(assign[i])) < 0)
00129                         break;
00130         }
00131         return error;
00132 }
00133 
00134 
00135 int restore(unsigned long node_id)
00136 {
00137         int error = 0;
00138 /*
00139         Sensor_node *node = dynamic_cast<Sensor_node*>
00140                 (oq->cfg.get_nodes()->find(node_id)->elt());
00141 */
00143 
00144         return error;
00145 }
00146 
00147 
00148 void virtual_time_iterate(void)
00149 {
00150         VT_timestamp::tick();
00151 }


© 2007, Los Alamos National Security, LLC.