Statistics
| Branch: | Tag: | Revision:

sssimulator / sssim.c @ 743e659d

History | View | Annotate | Download (5.8 KB)

1
/*
2
 * This is SSSim: the Simple & Stupid Simulator
3
 *
4
 *  Copyright (c) 2008 Luca Abeni
5
 *  Copyright (c) 2008 Csaba Kiraly
6
 *
7
 *  This is free software; see gpl-3.0.txt
8
 */
9

    
10
#include <unistd.h>
11
#include <stdlib.h>
12
#include <getopt.h>
13
#include <stdio.h>
14
#include <string.h>
15
#include <time.h>
16
#include <math.h>
17

    
18
#include "config.h"
19
#include "core.h"
20
#include "graph.h"
21
#include "sched.h"
22
#include "stats.h"
23
#include "td.h"
24
#include "ed.h"
25
#include "overlay.h"
26

    
27
static struct peer *peers;
28
extern FILE *resfile;
29
extern FILE *delayfile;
30
extern FILE *statusfile;
31
static FILE *statsfile;
32
static FILE *graphfile;
33
char inputgraph[200] = {'\0'};;
34

    
35
int PO_DELAY;    // playout delay
36
float netload = 1;
37
static int num_peers = N;   //number of nodes
38
static int num_chunks = K;   //number of chunks
39
static int nn;
40
float convergence_precision = 0;
41
uint32_t analysis_window = 0;
42
static unsigned int seed = 1;
43
static int buf_size;
44
static int ts = 2;
45
static int event_driven = 0;
46
static int display_neighbourhood;
47

    
48
static void show_usage(char *argv[])
49
{
50
  printf("Usage: %s [options]\n", argv[0]);
51

    
52
  printf("Options:\n");
53
  printf("\t-s <seed>:\t\t\tSet the seed for the random numbers generator\n");
54
  printf("\t-c <number of chunks>:\t\tSet the number of chunks\n");
55
  printf("\t-o <neighbourhood size>:\tSet the neighbourhood size (outdegree)\n");
56
  printf("\t-n <number of peers>:\t\tSet the number of peers\n");
57
  printf("\t-t <trace file>\n");
58
  printf("\t-l <netload>:\t\t\tSet the net load factor, the ratio of packages sent over the number of peers per chunk time (default=1).\n");
59
  printf("\t-r <results file>:\t\t(dynamically generated during simulation)\n");
60
  printf("\t-d <delay file>:\t\t(dynamically generated during simulation)\n");
61
  printf("\t-p <status file>\n");
62
  printf("\t-P:\t\t\t\tPrint the neighbourhoods\n");
63
  printf("\t-S <stats file>\n");
64
  printf("\t-b <chunks buffer size>:\t(playout delay)\n");
65
  printf("\t-T <Server Period>:\t\tSet the deadline postponing amount\n");
66
  printf("\t-g <Graph file name>:\t\tSave the overlay as a DOT file\n");
67
  printf("\t-e:\t\t\t\tSwitch to event-driven mode\n");
68
  printf("\t-G <Edge Graph file name>:\tImport the overlay from an '.edges' file. Options: [,optimize|,wuli][,random_source]\n");
69
  printf("\t-a <precision>:\t\t\tStops if convergence is reached.\n");
70
  printf("\t-w <analysis window size>:\tDefine the analysis chunk window.\n");
71
  exit(0);
72
}
73

    
74
static int opts_parse(int argc, char *argv[])
75
{
76
  int o;
77
  
78
  while ((o = getopt(argc, argv, "w:a:d:c:eo:n:t:r:s:p:S:b:T:g:G:l:hP")) != -1) {
79
    switch(o) {
80
      case 'a':
81
        convergence_precision = atof(optarg);
82
        break;
83
      case 'w':
84
        analysis_window = atoi(optarg);
85
        break;
86
      case 'e':
87
        event_driven = 1;
88
        break;
89
      case 'n':
90
        num_peers = atoi(optarg);
91
        break;
92
      case 'c':
93
        num_chunks = atoi(optarg);
94
        break;
95
      case 'o':
96
        nn = atoi(optarg);
97
        break;
98
      case 'l':
99
        netload = atof(optarg);
100
        break;
101
      case 'b':
102
        buf_size = pow(2, ilogb(2 * atoi(optarg) - 1));
103
        break;
104
      case 't':
105
        if (strcmp(optarg, "-") == 0) {
106
          trace = stdout;
107
        } else {
108
          trace = fopen(optarg, "w");
109
        }
110
        break;
111
      case 'r':
112
        resfile = fopen(optarg, "w");
113
        break;
114
      case 'd':
115
        delayfile = fopen(optarg, "w");
116
        break;
117
      case 'p':
118
        statusfile = fopen(optarg, "w");
119
        break;
120
      case 'P':
121
        display_neighbourhood = 1;
122
        break;
123
      case 'S':
124
        statsfile = fopen(optarg, "w");
125
        break;
126
      case 's':
127
        seed = atoi(optarg);
128
        if (seed == 0) {
129
          seed = time(NULL);
130
        }
131
        break;
132
      case 'T':
133
        ts = atoi(optarg);
134
        if (ts <= 1) {
135
          fprintf(stderr, "Invalid Server Period %d\n", ts);
136
          exit(-1);
137
        }
138
        break;
139
      case 'g':
140
        graphfile = fopen(optarg, "w");
141
        break;
142
      case 'G':
143
        strcpy(inputgraph, optarg);;
144
        break;
145
      case 'h':
146
        show_usage(argv);
147
      default:
148
        fprintf(stderr, "Error: unknown option %c\n", o);
149

    
150
        exit(-1);
151
      }
152
  }
153
  if (nn == 0) {
154
    nn = num_peers - 1;
155
  }
156

    
157
  return optind - 1;
158
}
159

    
160

    
161

    
162

    
163
///==========================================================
164
///     main
165
///==========================================================
166

    
167
int main(int argc, char *argv[])
168
{
169
  int n;
170
  struct chunk *ch;
171
  struct peer source;
172

    
173
  n = opts_parse(argc, argv);
174
  argc -= n;
175
  argv += n;
176

    
177
  srand(seed);
178
  if (strlen(inputgraph) > 0)
179
          peers = overlay_from_edgefile(inputgraph, &num_peers, &nn, num_chunks, &buf_size, &PO_DELAY, &source);
180
  else
181
          peers = overlay_from_parameters(&num_peers, &nn, num_chunks, &buf_size, &PO_DELAY, &source);
182
  if (!peers)
183
          return -1;
184
 
185
 
186

    
187
    if (display_neighbourhood) {
188
      for (n = 0; n < num_peers; n++) {
189
        printf("Peer %d Neighbourhood: ", n);
190
        neighbourhood_print(peers[n].neighbour, peers[n].neigh_size);
191
        printf("\n");
192
      }
193
    }
194
    if (graphfile) {
195
      graph_dotprint(graphfile, &source, peers, n);
196
    }
197
    if (delayfile) {
198
        fprintf(delayfile, "Time,Receiver,Chunk,Delay\n");
199
        fflush(delayfile);
200
    }
201
    printf("Buf Size: %d\n", buf_size);
202
    if(event_driven)
203
                        ch = ed_loop(peers, num_peers, num_chunks, ts);
204
    else
205
                        ch = td_loop(peers, num_peers, num_chunks, ts);
206

    
207

    
208
    if (!per_chunk_delay_analysis(NULL, ch, num_chunks, num_peers)){
209
      printf("sub-optimal distribution!!!\n");
210
    }
211
    if (trace){
212
      per_chunk_delay_analysis(trace, ch, num_chunks, num_peers);
213
      per_node_delay_analysis(trace,  ch, num_chunks);
214
    }
215

    
216
    if (statsfile) {
217
      fprintf(statsfile, "Seed: %u\n", seed);
218
      per_chunk_delay_analysis(statsfile, ch, num_chunks, num_peers);
219
      per_node_delay_analysis(statsfile,  ch, num_chunks);
220
    }
221

    
222
    if (delayfile)
223
            fclose(delayfile);
224

    
225
  return 0;
226
}