Revision 6405ff89

View differences:

topology.c
33 33
#define MIN(A,B) (((A) < (B)) ? (A) : (B))
34 34
#define MAX(A,B) (((A) > (B)) ? (A) : (B))
35 35

  
36
#define MODULE  2147483647
37
#define A       16807
38
#define LASTXN  127773
39
#define UPTOMOD -2836
40
#define RATIO   0.46566128e-9
41

  
36 42
double alpha_target = 0.5;
37 43
double topo_mem = 0;
38 44

  
......
277 283
  return NAN;
278 284
}
279 285

  
280
// //get the declared capacity of a node
281
// static double get_capacity_of_newid(const struct nodeID* n){
282
//   int i = 0;
283
//   for (i = 0; i < newids_size; i++){
284
// 	  if (strcmp(node_addr(n), node_addr(newids[i]))) {
285
// 		  return metas[i].capacity;
286
// 	  }
287
//   }
288
//   return NAN;
289
// }
290

  
291

  
292
// FF//get the declared capacity of a node
293
// static double get_offers_threads_of(const struct nodeID* n){
294
//   struct peer *p = peerset_get_peer(pset, n);
295
//   if (p) {
296
//     return p->offers_threads;
297
//   }
298
// 
299
//   return NAN;
300
// }
301

  
302

  
303 286
static double get_rx_bytes_chunks_of(const struct nodeID* n){
304 287
#ifdef MONL
305 288
  return get_rx_bytes_chunks(n);
......
355 338
	return (double) (((1-alpha) + (2*alpha_target*uniform)) * to_return) ; 
356 339
	}
357 340

  
341
long rnd32(long gSeed)
342
{
343
  long times, rest, prod1, prod2;
344

  
345
  times = gSeed / LASTXN;
346
  rest = gSeed - times * LASTXN;
347
  prod1 = times * UPTOMOD;
348
  prod2 = rest * A;
349
  gSeed = prod1 + prod2;
350
  if (gSeed < 0)
351
    gSeed = gSeed + MODULE;
352
  return gSeed;
353
}
354

  
355
double negexp (double mean, long *gSeed)
356
{
357
  double u;
358
  *gSeed = rnd32 (*gSeed);
359
  u = (*gSeed) * RATIO;
360
  return (-mean * log (u));
361
}
362

  
358 363
int cmp_rtt(const struct nodeID** a, const struct nodeID** b) {
359 364
  double ra, rb;
360 365
  ra = add_noise(get_rtt_of(*a), alpha_target);
......
456 461
	differencea = ra - mine;
457 462
	differenceb = rb - mine;
458 463
	// Both greater than mine
459
	fprintf(stderr, "AFFINITY: %s ra %f diffa %f, %s rb %f diffb %f mine %f\n", node_addr(*a), ra, differencea,  node_addr(*b), rb, differenceb, mine);
460 464
	if (differenceb > 0 && differencea > 0) {
461 465
		if (differencea > differenceb)
462 466
			return 1;
......
487 491
  return cmp_affinity((const struct nodeID**) a, (const struct nodeID**) b);
488 492
}
489 493

  
494
int cmp_bw_weight(const struct nodeID** a, const struct nodeID** b) {
495
  double bwa, bwb, ra, rb, vca, vcb, seeda, seedb;
496
  bwa = get_metadata_for_peer(*a).capacity;
497
  bwb = get_metadata_for_peer(*b).capacity;
498
  if (!isnan(ra)) {
499
	ra = 1/(bwa/1000000);
500
	seeda = rand()/(RAND_MAX + 1.0);
501
	vca = negexp(ra, &seeda);
502
  }
503
  else { 
504
	vca = NAN;
505
  }
506
  if (!isnan(rb)) {
507
	rb = 1/(bwb/1000000);
508
	seedb = rand()/(RAND_MAX + 1.0);
509
	vcb = negexp(rb, &seedb);
510
  }
511
  else {
512
	vcb = NAN;
513
  }
514
  
515
  if ((isnan(vca) && isnan(vcb)) || vca == vcb) 
516
	return 0;
517
  else if (isnan(vcb) || vca < vcb) 
518
	return -1;
519
  else 
520
	return 1;
521
}
522

  
523
int vcmp_bw_weight(const void* a, const void* b) {
524
  return cmp_bw_weight((const struct nodeID**) a, (const struct nodeID**) b);
525
}
526

  
490 527
// Use add best policy specified at command line
491 528
int vcmp_add_best(const void* a, const void* b) {
492 529
  if (strcmp(topo_add_best_policy, "OFFERS") == 0) {
......
499 536
	  return vcmp_rtt_bw( a,  b);
500 537
  } else if (strcmp(topo_add_best_policy, "AFFINITY") == 0) {
501 538
	  return vcmp_affinity( a,  b);
539
  } else if (strcmp(topo_add_best_policy, "BW_WEIGHT") == 0) {
540
	  return vcmp_bw_weight( a,  b);
502 541
  } else if (strcmp(topo_add_best_policy, "") == 0){ // defualt behaviuor
503 542
	  return vcmp_rtt_bw( a, b);
504 543
  } else {
......
517 556
	  return vcmp_rx_bytes_chunks(a, b);
518 557
  } else if (strcmp(topo_keep_best_policy, "PACKET_LOSS") == 0) {
519 558
	  return vcmp_packet_loss( a, b);
520
  } else if (strcmp(topo_add_best_policy, "AFFINITY") == 0) {
559
  } else if (strcmp(topo_keep_best_policy, "AFFINITY") == 0) {
521 560
	  return vcmp_affinity( a,  b);
561
  } else if (strcmp(topo_keep_best_policy, "BW_WEIGHT") == 0) {
562
	  return vcmp_bw_weight( a,  b);
522 563
  } else if (strcmp(topo_keep_best_policy, "") == 0) { // Default behaviuor
523 564
	  return vcmp_rx_bytes_chunks( a, b);
524 565
  } else {
......
527 568
  }  
528 569
}
529 570

  
571

  
530 572
// currently it just makes the peerset grow
531 573
void update_peers(struct nodeID *from, const uint8_t *buff, int len)
532 574
{

Also available in: Unified diff