Revision 4123e0f7

View differences:

ed.c
14 14
FILE *statusfile;
15 15
extern float convergence_precision;
16 16
extern uint32_t analysis_window;
17
extern int per_link_events;
17 18

  
18 19
struct ed_simulator {
19 20
	struct chunk * chunks;
......
151 152

  
152 153
void ed_simulator_gen_events(struct ed_simulator *eds)
153 154
{
154
	int i;
155
	int i, j;
155 156

  
156 157
	if(eds)
157 158
	{
158 159
		ed_simulator_schedule(eds, source_event_new(eds), 0);
159 160
		for (i = 0; i < eds->num_peers; i++) 
160
		{
161
			ed_simulator_schedule(eds, peer_offer_event_new(eds, &(eds->peers[i])), 0 );
162
		}
161
			if (per_link_events)
162
				for (j = 0; j < eds->peers[i].neigh_size; j++) 
163
					ed_simulator_schedule(eds, link_offer_event_new(eds, &(eds->peers[i]), j), 0 );
164
			else
165
				ed_simulator_schedule(eds, peer_offer_event_new(eds, &(eds->peers[i])), 0 );
163 166
	}
164 167
}
165 168

  
overlay.c
217 217
      for(c = 0; c < *neigh_size; c++)
218 218
      {
219 219
	      (peers[n].neighbour_prob)[c] = 1.0/(*neigh_size);
220
	//fprintf(stderr, "[DEBUG]: loading prob for peer %d -> %f\n", peers[n].id, (peers[n].neighbour_prob)[c]);
220
		//fprintf(stderr, "[DEBUG]: loading prob for peer %d (%d of %d) -> %f\n", peers[n].id, c, *neigh_size, (peers[n].neighbour_prob)[c]);
221 221
      }
222 222
      peers[n].neigh_size = *neigh_size;
223 223
    }
peer_event.c
54 54
	return (struct action_event *) po;
55 55
}
56 56

  
57
/********************LINK OFFER******************************/
58
struct link_offer_event{
59
	struct action_event ae;
60
	struct ed_simulator * eds;
61
	struct peer * src;
62
	int dst_idx;
63
};
64

  
65
void link_offer_event_destroy(struct action_event ** ae)
66
{
67
	struct link_offer_event * po;
68
	po = (struct link_offer_event *) *ae;
69
	free(po);
70
	*ae = NULL;
71
}
72

  
73
int link_offer_event_trigger(struct action_event * ae)
74
{
75
	int chunk, t;
76
	struct peer * dst;
77
	struct link_offer_event * po;
78

  
79
	po = (struct link_offer_event *) ae;
80
//	fprintf(stderr,"[DEBUG] peer %d is offering\n", (po->src)->id);
81
	t = (int) ed_simulator_time(po->eds);
82
	dst = (po->src)->neighbour[po->dst_idx];
83
	peer_send_chunk(po->src, t, &chunk, dst);
84
	if (chunk >= 0)
85
	{
86
		//fprintf(stderr,"[DEBUG] %d: peer %d send chunk %d to %d\n", t, (po->src)->id, chunk, dst->id);
87
		(po->src)->chunks[win_idx(po->src, chunk)]->dl += ed_simulator_server_period(po->eds);
88
		ed_simulator_send_chunk(po->eds, chunk, dst, (po->src)->chunks[win_idx(po->src, chunk)]->dl);
89
	}
90
	//fprintf(stderr,"[DEBUG] offer rate: %f, prob: %f, interval: %f\n", (po->src)->offer_rate,  (po->src)->neighbour_prob[po->dst_idx], (po->src)->offer_rate * 1/((po->src)->neighbour_prob[po->dst_idx]));
91
	ed_simulator_schedule(po->eds, ae, (po->src)->offer_rate * 1/((po->src)->neighbour_prob[po->dst_idx]));
92
	return chunk >= 0 ? 0 : -1;
93
}
94

  
95
struct action_event * link_offer_event_new(struct ed_simulator * eds, struct peer *src, int dst_idx)
96
{
97
	struct link_offer_event * po;
98
	po = (struct link_offer_event *) malloc (sizeof(struct link_offer_event));
99
	action_event_init((struct action_event *)&(po->ae), link_offer_event_trigger, link_offer_event_destroy);
100
	po->eds = eds;
101
	po->src = src;
102
	po->dst_idx = dst_idx;
103
	return (struct action_event *) po;
104
}
57 105
/********************PEER RECEPTION******************************/
58 106
struct peer_reception_event{
59 107
	struct action_event ae;
peer_event.h
23 23

  
24 24
struct action_event * source_event_new(struct ed_simulator * eds);
25 25

  
26
struct action_event * link_offer_event_new(struct ed_simulator * eds, struct peer *src, int dst_idx);
27

  
26 28
#endif
sched.c
738 738
  if (trace) fprintf(trace, "\tPeer %d: %d ---> %d\n", p->id, *chunk, (*target)->id);
739 739
}
740 740

  
741
void peer_send_chunk(struct peer *p, int t, int *chunk, struct peer *target)
742
{
743
  *chunk = chunk_sched(p, t, target);
744
  if (*chunk < 0) {
745
    if (trace) fprintf(trace, "\tPeer %d: Idle (no chunk that %d needs)\n", p->id, (target)->id);
746
    return;
747
  }
748
  
749
  if (trace) fprintf(trace, "\tPeer %d: %d ---> %d\n", p->id, *chunk, (target)->id);
750
}
751

  
741 752
/* Should be probably merged with peer_send_c_p */
742 753
void peer_send_utility(struct peer *p, int t, int *chunk, struct peer **target)
743 754
{
sched.h
10 10
#define __SCHED_H__ 1
11 11

  
12 12
void peer_send(struct peer *p, int t, int *chunk, struct peer **target);
13
void peer_send_chunk(struct peer *p, int t, int *chunk, struct peer *target);
13 14
void source_set(struct peer **neigh, int size, double * probs, int num_chunks);
14 15
void source_send(int t, struct peer **target);
15 16

  
sssim.c
43 43
static int buf_size;
44 44
static int ts = 2;
45 45
static int event_driven = 0;
46
int per_link_events = 0;
46 47
static int display_neighbourhood;
47 48

  
48 49
static void show_usage(char *argv[])
......
65 66
  printf("\t-T <Server Period>:\t\tSet the deadline postponing amount\n");
66 67
  printf("\t-g <Graph file name>:\t\tSave the overlay as a DOT file\n");
67 68
  printf("\t-e:\t\t\t\tSwitch to event-driven mode\n");
69
  printf("\t-E:\t\t\t\tSwitch to event-driven mode and generate per-link events\n");
68 70
  printf("\t-G <Edge Graph file name>:\tImport the overlay from an '.edges' file. Options: [,optimize][,random_source]\n");
69 71
  printf("\t-a <precision>:\t\t\tStops if convergence is reached.\n");
70 72
  printf("\t-w <analysis window size>:\tDefine the analysis chunk window.\n");
......
75 77
{
76 78
  int o;
77 79
  
78
  while ((o = getopt(argc, argv, "w:a:d:c:eo:n:t:r:s:p:S:b:T:g:G:l:hP")) != -1) {
80
  while ((o = getopt(argc, argv, "w:a:d:c:eEo:n:t:r:s:p:S:b:T:g:G:l:hP")) != -1) {
79 81
    switch(o) {
80 82
      case 'a':
81 83
        convergence_precision = atof(optarg);
......
83 85
      case 'w':
84 86
        analysis_window = atoi(optarg);
85 87
        break;
88
      case 'E':
89
	per_link_events = 1;
86 90
      case 'e':
87 91
        event_driven = 1;
88 92
        break;

Also available in: Unified diff