~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/devel/sympathy_devel/sympathy_emview.c


  1 /* ex: set tabstop=2 expandtab shiftwidth=2 softtabstop=2: */
  2 /*
  3  *
  4  * Copyright (c) 2003 The Regents of the University of California.  All 
  5  * rights reserved.
  6  *
  7  * Redistribution and use in source and binary forms, with or without
  8  * modification, are permitted provided that the following conditions
  9  * are met:
 10  *
 11  * - Redistributions of source code must retain the above copyright
 12  *   notice, this list of conditions and the following disclaimer.
 13  *
 14  * - Neither the name of the University nor the names of its
 15  *   contributors may be used to endorse or promote products derived
 16  *   from this software without specific prior written permission.
 17  *
 18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 21  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29  *
 30  */
 31 
 32  /*
 33   *
 34   * Author: Nithya Ramanthan
 35   *
 36   */
 37 
 38 /* NR TODO:
 39  * cache data from nodes in addition to configuration */
 40 
 41 #include "sympathy.h"
 42 #include <emproxy/emproxy.h>
 43 #include <emrun/emrun.h>
 44 #include <routing/routing_table.h>
 45 
 46 buf_t* emview_cmd=NULL;
 47 buf_t* sink_cmd=NULL;
 48 static void sympathy_push_radio(sympathy_node_info_t* stat);
 49 
 50 void sympathy_update_emview(if_id_t node_id)
 51 {
 52   if ((node_id == my_node_id) && sink_cmd) {
 53     emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
 54       node_id, NULL, sink_cmd);
 55   }
 56   else if (emview_cmd) {
 57     emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
 58       node_id, NULL, emview_cmd);
 59   }
 60 }
 61 
 62 static
 63 int se_push_emview(void *data, int interval, g_event_t *ev)
 64 {
 65   int i;
 66   sympathy_node_info_t* stat;
 67 
 68   /* USe to test nodes that are added which don't necessarily exist
 69   static int ctr = 0;
 70   if (ctr == 5)  sympathy_update_emview(100);
 71   ctr++;
 72   */
 73 
 74   for (i=0; i<sink.num_srcs; i++) {
 75     stat = &sink.status_srcs[i];
 76 
 77     /* NR Even with caching - need to update this regularly? */
 78     sympathy_push_radio(stat);
 79     sympathy_emview_text(stat);
 80     sympathy_emview_route(stat);
 81     sympathy_emview_neighbors(stat);
 82   }
 83   return TIMER_RENEW;
 84 }
 85 
 86 
 87 static
 88 void sympathy_push_emview(char* device, if_id_t src, buf_t* buf)
 89 {
 90   struct timeval now;
 91   gettimeofday(&now, NULL);
 92   emproxy_emit_buf_to_gw(sim_path(device), src, &now, buf);
 93 }
 94 
 95 static
 96 void sympathy_push_radio(sympathy_node_info_t* stat)
 97 {
 98   buf_t* buf = buf_new();
 99   link_status_t info = {
100     if_id: (if_id_t) stat->addr,
101   };
102   bufcpy(buf, &info, sizeof(info));
103   sympathy_push_emview(SYMPATHY_EMVIEW_RADIO, stat->addr, buf);
104   buf_free(buf);
105 }
106 
107 
108 /* GLOBAL FUNCTIONS */
109 void sympathy_emview_text(sympathy_node_info_t* stat)
110 {
111   buf_t* buf = buf_new();
112   buf_t* buf2 = buf_new();
113 
114   /* If there is a failure, then set the node to a color, and print the
115    * text status. Otherwise, do not print anything */
116   if (stat->failure_type == SFL_OK) {
117     bufcpy(buf, "", 1);
118     bufprintf(buf2, "white");
119   }
120   else {
121     bufprintf(buf, "%s(%d pds)\n", decode_root_cause(stat->failure_root_cause,
122           stat->addr), sink.metric_pd - stat->period_root_caused);
123     bufprintf(buf2, "red");
124   }
125 
126   sympathy_push_emview(SYMPATHY_EMVIEW_TEXTSTATUS, stat->addr, buf);
127   sympathy_push_emview(SYMPATHY_EMVIEW_COLOR, stat->addr, buf2);
128 
129   buf_free(buf);
130   buf_free(buf2);
131 }
132 
133 void sympathy_emview_route(sympathy_node_info_t* stat)
134 {
135   buf_t* buf = buf_new();
136   route_entry_t null_r = {};
137   route_entry_t r = {
138     dst: stat->next_hop.sink,
139     next_hop: stat->next_hop.next_hop,
140     path_metric: stat->next_hop.quality
141   };
142 
143   if (route_valid(stat)) {
144     bufcpy(buf, (char*)&r, sizeof(route_entry_t));
145 
146     /* Add a "null" neighbor to the end in case they didnt */
147     bufcpy(buf, (char*)&null_r, sizeof(route_entry_t));
148   }
149   else bufcpy(buf, "", 1);
150 
151   sympathy_push_emview(SYMPATHY_EMVIEW_ROUTE, stat->addr, buf);
152   buf_free(buf);
153 }
154 
155 void sympathy_emview_neighbors(sympathy_node_info_t* stat)
156 {
157   buf_t* buf = buf_new();
158   neighbor_t null_n = {};
159 
160   if (neighbors_valid(stat)) {
161     bufcpy(buf, stat->neighbors, stat->num_neighbors*sizeof(neighbor_t));
162 
163     /* Add a "null" neighbor to the end in case they didnt */
164     bufcpy(buf, (char*)&null_n, sizeof(neighbor_t));
165   }
166   else bufcpy(buf, "", 1);
167 
168   sympathy_push_emview(SYMPATHY_EMVIEW_NEIGHBORS, stat->addr, buf);
169 
170   buf_free(buf);
171 }
172 
173 void sympathy_init_emview()
174 {
175   emview_cmd = buf_new();
176   sink_cmd = buf_new();
177   se_push_emview(NULL,0,NULL);
178   g_timer_add(10000, se_push_emview, NULL, NULL, NULL);
179 
180   /* Radio interface */
181   bufprintf(emview_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
182       SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);
183   bufprintf(sink_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
184       SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);
185 
186   /* Initialize neighbors device */
187   bufprintf(emview_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);
188   bufprintf(sink_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);
189 
190   /* Initialize routing device */
191   bufprintf(sink_cmd, "module=Routing/Trees:dev=%s,%s:dest-tree=blue,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);
192   bufprintf(emview_cmd, "module=Routing/Trees:dev=%s,%s:leaf\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);
193 
194   /* Initialize color box device */
195   bufprintf(sink_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
196       SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);
197   bufprintf(emview_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
198       SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);
199 
200   /* Initialize text-status device */
201   bufprintf(emview_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
202   bufprintf(sink_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
203 }
204 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.