(file) Return to sympathy_emview.c CVS log (file) Jump to this file's LXR Page (dir) Up to [CENS] / emstar / devel / sympathy_devel

File: [CENS] / emstar / devel / sympathy_devel / sympathy_emview.c (download) / (as text)
Revision: 1.11, Sat Sep 3 00:15:56 2005 UTC (4 years, 2 months ago) by nithya
Branch: MAIN
CVS Tags: pregeonet, acoustic-05-18-06, PRE_TOSNIC_FIX, PRE_64BIT, HEAD, ESS_RELEASE_3_5, ESS_RELEASE_3_4, ESS_RELEASE_3_2, ESS_RELEASE_3_1, ESS_RELEASE_3_0, ESS_CONNECTIVITY, ESS_CENTROUTE_TESTING, EMSTAR_RELEASE_2_5, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, BG_1_0, BANGLADESH_ARSENIC_1_2, BANGLADESH_ARSENIC_1_1, AMARSS_JR_DEPLOYMENT_6_05_07
Changes since 1.10: +10 -5 lines
Added Boilerplate

/* ex: set tabstop=2 expandtab shiftwidth=2 softtabstop=2: */
/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

 /*
  *
  * Author: Nithya Ramanthan
  *
  */

/* NR TODO:
 * cache data from nodes in addition to configuration */

#include "sympathy.h"
#include <emproxy/emproxy.h>
#include <emrun/emrun.h>
#include <routing/routing_table.h>

buf_t* emview_cmd=NULL;
buf_t* sink_cmd=NULL;
static void sympathy_push_radio(sympathy_node_info_t* stat);

void sympathy_update_emview(if_id_t node_id)
{
  if ((node_id == my_node_id) && sink_cmd) {
    emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
      node_id, NULL, sink_cmd);
  }
  else if (emview_cmd) {
    emproxy_emit_buf_to_gw(EMRUN_EMVIEW_CONFIG_DEVNAME,
      node_id, NULL, emview_cmd);
  }
}

static
int se_push_emview(void *data, int interval, g_event_t *ev)
{
  int i;
  sympathy_node_info_t* stat;

  /* USe to test nodes that are added which don't necessarily exist
  static int ctr = 0;
  if (ctr == 5)  sympathy_update_emview(100);
  ctr++;
  */

  for (i=0; i<sink.num_srcs; i++) {
    stat = &sink.status_srcs[i];

    /* NR Even with caching - need to update this regularly? */
    sympathy_push_radio(stat);
    sympathy_emview_text(stat);
    sympathy_emview_route(stat);
    sympathy_emview_neighbors(stat);
  }
  return TIMER_RENEW;
}


static
void sympathy_push_emview(char* device, if_id_t src, buf_t* buf)
{
  struct timeval now;
  gettimeofday(&now, NULL);
  emproxy_emit_buf_to_gw(sim_path(device), src, &now, buf);
}

static
void sympathy_push_radio(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  link_status_t info = {
    if_id: (if_id_t) stat->addr,
  };
  bufcpy(buf, &info, sizeof(info));
  sympathy_push_emview(SYMPATHY_EMVIEW_RADIO, stat->addr, buf);
  buf_free(buf);
}


/* GLOBAL FUNCTIONS */
void sympathy_emview_text(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  buf_t* buf2 = buf_new();

  /* If there is a failure, then set the node to a color, and print the
   * text status. Otherwise, do not print anything */
  if (stat->failure_type == SFL_OK) {
    bufcpy(buf, "", 1);
    bufprintf(buf2, "white");
  }
  else {
    bufprintf(buf, "%s(%d pds)\n", decode_root_cause(stat->failure_root_cause,
          stat->addr), sink.metric_pd - stat->period_root_caused);
    bufprintf(buf2, "red");
  }

  sympathy_push_emview(SYMPATHY_EMVIEW_TEXTSTATUS, stat->addr, buf);
  sympathy_push_emview(SYMPATHY_EMVIEW_COLOR, stat->addr, buf2);

  buf_free(buf);
  buf_free(buf2);
}

void sympathy_emview_route(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  route_entry_t null_r = {};
  route_entry_t r = {
    dst: stat->next_hop.sink,
    next_hop: stat->next_hop.next_hop,
    path_metric: stat->next_hop.quality
  };

  if (route_valid(stat)) {
    bufcpy(buf, (char*)&r, sizeof(route_entry_t));

    /* Add a "null" neighbor to the end in case they didnt */
    bufcpy(buf, (char*)&null_r, sizeof(route_entry_t));
  }
  else bufcpy(buf, "", 1);

  sympathy_push_emview(SYMPATHY_EMVIEW_ROUTE, stat->addr, buf);
  buf_free(buf);
}

void sympathy_emview_neighbors(sympathy_node_info_t* stat)
{
  buf_t* buf = buf_new();
  neighbor_t null_n = {};

  if (neighbors_valid(stat)) {
    bufcpy(buf, stat->neighbors, stat->num_neighbors*sizeof(neighbor_t));

    /* Add a "null" neighbor to the end in case they didnt */
    bufcpy(buf, (char*)&null_n, sizeof(neighbor_t));
  }
  else bufcpy(buf, "", 1);

  sympathy_push_emview(SYMPATHY_EMVIEW_NEIGHBORS, stat->addr, buf);

  buf_free(buf);
}

void sympathy_init_emview()
{
  emview_cmd = buf_new();
  sink_cmd = buf_new();
  se_push_emview(NULL,0,NULL);
  g_timer_add(10000, se_push_emview, NULL, NULL, NULL);

  /* Radio interface */
  bufprintf(emview_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);
  bufprintf(sink_cmd, "module=Link/Radio:dev=%s,%s:core\n", 
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_RADIO);

  /* Initialize neighbors device */
  bufprintf(emview_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);
  bufprintf(sink_cmd, "module=Link/Neighbors:dev=%s,%s:links=alive,0,1,black,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_NEIGHBORS);

  /* Initialize routing device */
  bufprintf(sink_cmd, "module=Routing/Trees:dev=%s,%s:dest-tree=blue,show-notes\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);
  bufprintf(emview_cmd, "module=Routing/Trees:dev=%s,%s:leaf\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_ROUTE);

  /* Initialize color box device */
  bufprintf(sink_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);
  bufprintf(emview_cmd, "module=ColorStatus:dev=%s,%s:core:component=Link/Radio/%s\n",
      SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_COLOR, SYMPATHY_EMVIEW_INTERFACE);

  /* Initialize text-status device */
  bufprintf(emview_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
  bufprintf(sink_cmd, "module=TextStatus:dev=%s,%s:core\n", SYMPATHY_EMVIEW_INTERFACE, SYMPATHY_EMVIEW_TEXTSTATUS);
}

CENS CVS Mailing List
Powered by
ViewCVS 0.9.2