Statistics
| Branch: | Tag: | Revision:

sssimulator / core.h @ master

History | View | Annotate | Download (1.56 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
#ifndef __CORE_H__
11
#define __CORE_H__ 1
12

    
13
#include <stdio.h>
14

    
15
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
  double offer_rate;
27
  double * neighbour_prob;
28
};
29

    
30
struct chunk {
31
  int received;
32
  float avg_delay;
33
  float max_delay;
34
};
35

    
36
struct chunk_instance {
37
  int chunk;
38
  float dl;
39
  int key;
40
  float completed;
41
};
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
// the chunk is not in buffer if the playout delay elapsed.
84
// the playout delay is represented by buf_size.
85
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

    
91
#endif