/* * collisions.cpp * serp++ * * Created by Victor Grishchenko on 3/15/09. * Copyright 2009 Delft Technical University. All rights reserved. * */ #include "bin.h" #include "sbit.h" #include #include using namespace std; #define NUMPEERS 40 #define QUEUE_LEN 32 #define WIDTH 20 #define TOP (bin(WIDTH,0)) sbit bigpic; // common knowledge struct Peer { deque packets; // packets in flight & unacknowledged feye map; int peerno; bin focus; Peer () : map(bigpic,bin(0,rand()%(1<6) map.refocus(focus); if (labs(map.focus-focus)>=129) printf("bred!\n"); map |= focus; // sanity check if (bigpic.get(focus)) printf("zhopa: peer %i redid %x after jumped %i\n", peerno,focus.offset(),oldfoc.commonParent(focus).layer()); assert(focus.layer()==0 && focus=QUEUE_LEN) { // round trip, acks reach senders bin packet = peers[i].packets.front(); peers[i].packets.pop_front(); if (packet==0) continue; bool collision = bigpic.get(packet); bin round = bigpic.set(packet); printf("peer %i arrived %x filled %i coll %i\n", i,packet.offset(),round.layer(),collision); for(int j=0; j