Code Search for Developers
 
 
  

generate.c from EmStar at Krugle


Show generate.c syntax highlighted

/*
 *
 * 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.
 *
 */
 
/*
 *  Generates randomized workload to be applied via "workload"
 */

#include <libmisc/misc.h>

void usage()
{
  fprintf(stderr, 
	  "generate -1 -P <probability> -L <length> -T <total> -n <numnodes>\n"
	  "   Generates sequence of events, each L seconds, with prob. P of\n"
	  "   occurring at each node.  The trace continues until the requested\n"
	  "   total 'T' number of events is reached\n\n");
  fprintf(stderr, 
	  "generate -2 -E <exp num events> -D <data-amt> -L <sec> -T <total-sec> -n <numnodes>\n"
	  "   Generates a sequence of events, L seconds apart, for a total time of T secs\n"
	  "   A total of D bytes of data is sent, divided among the events so that the\n"
	  "   expected number of submissions during any event time is E.\n\n");
  exit(1);
}

int main(int argc, char **argv)
{
  float L;
  int N;
  
  if (misc_parse_option_as_float(&argc, argv, "length", 'L', &L) < 0) {
    elog(LOG_ERR, "Missing required parameter --length");
    usage();
  }
  
  if (misc_parse_option_as_int(&argc, argv, "nodes", 'n', &N) < 0) {
    elog(LOG_ERR, "Missing required parameter --nodes");
    usage();
  }

  if (misc_parse_out_switch(&argc, argv, "", '2')) {
    
    float E, T;
    int D, D_e, N_e, max_bins, i;
        
    if (misc_parse_option_as_float(&argc, argv, "total", 'T', &T) < 0) {
      elog(LOG_ERR, "Missing required parameter --total");
      usage();
    }
    
    if (misc_parse_option_as_float(&argc, argv, "exp", 'E', &E) < 0) {
      elog(LOG_ERR, "Missing required parameter --exp");
      usage();
    }
    
    if (misc_parse_option_as_int(&argc, argv, "data", 'D', &D) < 0) {
      elog(LOG_ERR, "Missing required parameter --data");
      usage();
    }
    
    misc_init(&argc, argv, CVSTAG);

    /* determine number of events and amount of data per event */
    max_bins = T / L;
    N_e = E * max_bins;
    if (N_e < 1) N_e = 1;
    D_e = D / N_e;

    printf("# E=%f, L=%f, T=%f, D=%d, n=%d\n",
	   E, L, T, D, N);
    printf("# => %d events, %d bytes each, %d bytes total (%d short)\n",
	   N_e, D_e, D_e*N_e, D - D_e*N_e);

    printf("default_size=%d\n", D_e);
    
    char bins[max_bins][N];
    memset(bins, 0, sizeof(bins));
    
    for (i=0; i<N_e; i++) {
      int failcount = 0;

    again:
      failcount++;
      if (failcount > 100) {
	elog(LOG_CRIT, "not enough room for all those events!");
	exit(1);
      }
     
      int index = random_range(0,max_bins-1);
      int node = random_range(0,N-1);
      
      if (bins[index][node]) goto again;
      bins[index][node] = 1;
    }
    
    for (i=0; i<max_bins; i++) {
      int j;
      int do_header = 1;

      for (j=0; j<N; j++) {

	if (bins[i][j] == 0)
	  continue;
      
	if (do_header) {
	  printf("time=%d:nodes=", (int)(L * 1000.0 * (float)i));
	  do_header = 0;
	}

	printf("%d,", j+1);
      }
		 
      if (do_header == 0)
	printf("\n");
    }
    
    printf("time=%d:halt\n\n", (int)(T*1000));
  }
    
  else if (misc_parse_out_switch(&argc, argv, "", '1')) {
    
    float P;
    int T;
    int count=0;
    int i=0;
    
    if (misc_parse_option_as_int(&argc, argv, "total", 'T', &T) < 0) {
      elog(LOG_ERR, "Missing required parameter --total");
      usage();
    }
    
    if (misc_parse_option_as_float(&argc, argv, "prob", 'P', &P) < 0) {
      elog(LOG_ERR, "Missing required parameter --prob");
      usage();
    }
    
    misc_init(&argc, argv, CVSTAG);
    
    printf("# P=%f, L=%f, N=%d, T=%d\n", P, L, N, T);
    
    while (1) {
      int j;
      int header=0;
      i++;
      for (j=0; j<N; j++) {
	if ((random() / (float)RAND_MAX) < P) {
	  if (!header) {
	    header = 1;
	    printf("time=%d:nodes=", (int)(L*i*1000));
	  }
	  else
	  printf(",");
	  printf("%d", j+1);
	  count++;
	  if (count >= T) {
	    printf("\n\n");
	    fflush(stdout);
	    exit(0);
	  }
	}
      }
      if (header)
	printf("\n");
    }
  }

  else
    elog(LOG_CRIT, "Please select mode 1 or 2 **********");

  return 0;
}




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  generate.c
  wl_i.h
  wl_main.c
  wl_plugin_random_rate.c
  wl_plugin_scenario_file.c
  wl_structs.c