Statistics
| Branch: | Tag: | Revision:

sssimulator / core.h @ master

History | View | Annotate | Download (1.56 KB)

1 86681e55 luca
/*
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 52770a8f Luca Baldesi
#ifndef __CORE_H__
11
#define __CORE_H__ 1
12 86681e55 luca
13 91dc88f2 luca
#include <stdio.h>
14
15 86681e55 luca
struct peer {
16
  struct chunk_instance **chunks;
17
  struct chunk_instance **recv_chunks;
18
  int key;
19
  int id;
20
  int latest_not_needed;
21
  struct peer **neighbour;
22
  int neigh_size;
23
  int num_chunks;
24
  int buf_size;
25
  int buf_mask;
26 91dc88f2 luca
  double offer_rate;
27
  double * neighbour_prob;
28 86681e55 luca
};
29
30
struct chunk {
31
  int received;
32
  float avg_delay;
33 52770a8f Luca Baldesi
  float max_delay;
34 86681e55 luca
};
35
36
struct chunk_instance {
37
  int chunk;
38 52770a8f Luca Baldesi
  float dl;
39 86681e55 luca
  int key;
40 52770a8f Luca Baldesi
  float completed;
41 86681e55 luca
};
42
43
44
#define min(X, Y)  ((X) < (Y) ? (X) : (Y))
45
#define max(X, Y)  ((X) > (Y) ? (X) : (Y))
46
47
int comp(int chunk);
48
49
extern FILE *trace;    //trace file
50
extern int PO_DELAY;
51
52
static inline int win_right(struct peer *p, int t)
53
{
54
  return min(t, p->num_chunks);
55
}
56
57
#ifdef NO_BUFFER
58
static inline int win_left(struct peer *p, int t)
59
{
60
  return 0;
61
}
62
63
static inline int win_idx(struct peer *p, int i)
64
{
65
  return i;
66
}
67
68
static inline int in_buffer(struct peer *p, int c, int t)
69
{
70
  return 1;
71
}
72
#else
73
static inline int win_left(struct peer *p, int t)
74
{
75
  return max(0, min(t + 1, p->num_chunks) - p->buf_size);
76
}
77
78
static inline int win_idx(struct peer *p, int i)
79
{
80
  return i & p->buf_mask;
81
}
82
83 4136f032 Luca Baldesi
// the chunk is not in buffer if the playout delay elapsed.
84
// the playout delay is represented by buf_size.
85 86681e55 luca
static inline int in_buffer(struct peer *p, int i, int t)
86
{
87
  return p->chunks[win_idx(p, i)]->chunk > t - p->buf_size;
88
}
89
#endif
90 91dc88f2 luca
91 52770a8f Luca Baldesi
#endif