Exemple #1
0
	/*
	 * Create and send new boundary particle
	 */
tw_event	*
rm_particle_send(tw_lpid gid, tw_stime offset, tw_lp * src_lp)
{
	tw_event	*e;
	//tw_memory	*b;

	rm_message	*m;
	//rm_particle	*p;

	//printf("%ld: sending particle to cell %ld \n", src_lp->id, gid);

	if(gid == 0)
		tw_error(TW_LOC, "here");
	e = tw_event_new(gid, offset, src_lp);
	m = tw_event_data(e);

	m->type = RM_PARTICLE;

#if DWB
	b = tw_memory_alloc(src_lp, g_rm_fd);
	tw_event_memory_set(e, b, g_rm_fd);

	p = tw_memory_data(b);
	p->user_lp = src_lp;
#endif

	tw_event_send(e);

	return e;
}
Exemple #2
0
tw_event	*
forward(ip_state * state, tw_bf * bf, rn_message * msg, tw_lp * lp)
{
	tw_memory	*b;
	tw_event	*e;
	tw_stime	 ts = 0.0;

	rn_link		*l;

	ip_message	*ip;

	state->stats->s_nforward++;

	if(NULL == (l = getroute(state, msg, lp)))
		return NULL;

	b = tw_memory_alloc(lp, g_ip_fd);
	b->ts = tw_now(lp);
	tw_memoryq_push(state->link_q, b);

	ip = tw_memory_data(b);

	ip->link = l;
	ip->last_sent = l->last_sent;

	if(tw_now(lp) > l->last_sent)
		l->last_sent = tw_now(lp);
	else
		ts = l->last_sent - tw_now(lp);

	l->last_sent += (msg->size / l->bandwidth);
	ts += ((msg->size / l->bandwidth) + l->delay);

	l->avg_delay += msg->size;

	e = rn_event_new(l->addr, ts, lp, DOWNSTREAM, msg->size);

#if 0
	if((bf->c31 = (e == lp->pe->abort_event && e->recv_ts <= g_tw_ts_end)))
	{
		tw_error(TW_LOC, "Got abort event ...");
		state->stats->s_nnet_failures++;
		msg->ttl++;
	}
#endif

#if VERIFY_IP
	printf("\t\t%lld IP FWD: to %lld at ts %lf (sz %d bw %lf del %lf)\n", 
		lp->gid, l->addr, e->recv_ts, msg->size, l->bandwidth, l->delay);
#endif

	return e;
}
Exemple #3
0
/*
 * tcp_timer_reset: reset the RTO timer properly
 */
tw_event	*
tcp_timer_reset(tw_event * timer, tw_bf * bf, tcp_message * old, 
		tw_stime ts, int sn, tw_lp * lp)
{
	tcp_message	*m;

	if(timer && timer->recv_ts == ts)
	{
		tw_error(TW_LOC, "%ld: attempt to reset timer to cur ts %lf!", 
			 lp->gid, ts);

		m = tw_memory_data(timer->memory);
		m->src = old->src;
		m->seq_num = sn;

		return timer;
	}

	// if this IS the timer firing, then do create new timer!
	if((bf->c14 = (!timer || timer == lp->pe->cur_event)))
	{
		//old->RC.timer = timer;
		timer = NULL;
		timer = rn_timer_init(lp, ts);
	} else
	{
		//old->RC.timer_ts = timer->recv_ts;
		rn_timer_reset(lp, &timer, ts);
	}

	if((bf->c13 = (timer != NULL)))
	{
		if(!timer->memory)
			timer->memory = tw_memory_alloc(lp, g_tcp_fd);

#if TCP_DEBUG
		printf("\t%lld: reset RTO to %lf (%ld)\n", lp->id, ts, (long int)timer);
#endif

		m = tw_memory_data(timer->memory);

		// do I need this?
		//old->RC.timer_seq = m->seq_num;

		m->src = old->src;
		m->seq_num = sn;
	}

	if(timer && !timer->memory)
		tw_error(TW_LOC, "no membuf here!");

	return timer;
}
Exemple #4
0
tw_event	*
tcp_rc_timer_reset(tw_event * timer, tw_bf * bf, tcp_message * old, tw_lp * lp)
{
	if(bf->c14)
	{
		// If I init'd a timer, cancel it.
		if(timer)
		{
			tw_memory_alloc_rc(lp, timer->memory, g_tcp_fd);
			timer->memory = NULL;

#if TCP_DEBUG
			printf("\t%lld: cancel timer at %lf (%ld)\n", 
				lp->id, timer->recv_ts, (long int) timer);
#endif

			rn_timer_cancel(lp, &timer);
		}

		// restore pointer to previous timer
		//timer = old->RC.timer;
		//old->RC.timer = NULL;
	} else
	{
		//rn_timer_reset(lp, &timer, old->RC.timer_ts);
	}

	if(bf->c13 == 0)
		return timer;

	if(timer)
	{
		tcp_message	*m;

#if TCP_DEBUG
		printf("\t%lld: new RTO at %lf (%ld)\n", 
			lp->id, tw_now(lp), (long int) timer);
#endif

		if(NULL == timer->memory)
			timer->memory = tw_memory_alloc(lp, g_tcp_fd);

		m = tw_memory_data(timer->memory);
		//m->seq_num = old->RC.timer_seq;
		m->src = old->src;
	}

	if(timer && !timer->memory)
		tw_error(TW_LOC, "no membuf here!");

	return timer;
}
Exemple #5
0
/*
 * tcp_timer_reset: reset the RTO timer properly
 */
tw_event	*
tcp_timer_reset(tw_event * timer, tw_bf * bf, tcp_message * old, 
		tw_stime ts, int sn, tw_lp * lp)
{
	tcp_message	*m;

	// this can happen because sometimes we rollback more events
	// than we need to when nkp < nlp.  So, sometimes our events
	// our rolled back that do NOT reset the RTO, and therefore
	// it might seem that we need to RC reset the timer, when in fact
	// we do not.
	if(timer && timer->recv_ts == ts)
		tw_error(TW_LOC, "%ld: bad timer reset: cur ts %lf!", lp->gid, ts);

	// if this IS the timer firing, then init new timer
	if((bf->c14 = (!timer || timer == lp->pe->cur_event)))
	{
		old->RC.timer = timer;
		timer = rn_timer_init(lp, ts);

#if TCP_DEBUG
		printf("\t%lld: init RTO to %lf (%ld)\n", lp->gid, ts, (long int) timer);
#endif
		
	} else
	{
#if TCP_DEBUG
		printf("\t%lld: reset RTO to %lf (was %lf)\n", 
			lp->gid, ts, timer->recv_ts);
#endif

		old->RC.timer_ts = timer->recv_ts;
		rn_timer_reset(lp, &timer, ts);
	}

	if((bf->c13 = (timer != NULL)))
	{
		if(!timer->memory)
			timer->memory = tw_memory_alloc(lp, g_tcp_fd);

		m = tw_memory_data(timer->memory);

		old->RC.timer_seq = m->seq_num;
		m->src = old->src;
		m->seq_num = sn;
	}

	return timer;
}
Exemple #6
0
tw_memory	*
mem_alloc(tw_lp * lp)
{
    tw_memory	*m;

    m = tw_memory_alloc(lp, my_fd);

    if(m->next)
        tw_error(TW_LOC, "Next pointer is set!");

    if(m->prev)
        tw_error(TW_LOC, "Prev pointer is set!");

    return m;
};
Exemple #7
0
void
bgp_notify_send(bgp_state * state, bgp_nbr * n, tw_lp * lp)
{
	tw_event	*e;
	tw_memory	*hdr;

	bgp_message	*m;

	state->stats->s_nnotify_sent++;
	e = rn_event_new(n->id, 0.0, lp, DOWNSTREAM, BGP_NOTIFY);

	hdr = tw_memory_alloc(lp, g_bgp_fd);
	m = tw_memory_data(hdr);

	m->b.type = NOTIFICATION;

	tw_event_memory_set(e, hdr, g_bgp_fd);
	rn_event_send(e);

#if VERIFY_BGP
	fprintf(state->log, "\tsent notify to nbr %d at %f\n", n->id, tw_now(lp));
#endif
}
void
ospf_random_weights(ospf_state * state, tw_lp * lp)
{
	tw_memory	*b;
	tw_event	*e;
	tw_stime	 next_status;

	ospf_message	*m;

	int	 	 percent;
	long int	 i;

	for(i = 0; i < state->m->nlinks; i++)
	{
		percent = tw_rand_integer(lp->rng, 0, 100);

		if(percent > 10 + 1)
			return;

		next_status = tw_rand_integer(lp->rng, 1, g_tw_ts_end);

		if(next_status >= g_tw_ts_end)
			continue;

		e = NULL;
		e = rn_timer_simple(lp, next_status);

		b = tw_memory_alloc(lp, g_ospf_fd);
		m = tw_memory_data(b);

		m->type = OSPF_WEIGHT_CHANGE;
		m->data = (void *) i;

		tw_event_memory_set(e, b, g_ospf_fd);
	}
}
Exemple #9
0
void
epi_init_agent_default(void)
{
    tw_memory	*b;

    epi_agent	*a;

    int		 i;
    int		 j;

    int		 id;
    int		 lid;
    int		 rid;

    if(!g_epi_nagents)
        tw_error(TW_LOC, "No agents specified!");

    if(!g_tw_nlp)
        tw_error(TW_LOC, "No locations specified!");

    if(!g_epi_nregions)
        tw_error(TW_LOC, "No regions specified!");

    g_epi_regions = tw_calloc(TW_LOC, "", sizeof(unsigned int *), g_epi_nregions);

    // create reporting tables for each region, for each disease
    for(i = 0; i < g_epi_nregions; i++)
    {
        g_epi_regions[i] = tw_calloc(TW_LOC, "", sizeof(*g_epi_regions[i]),
                                     g_epi_ndiseases);

        for(j = 0; j < g_epi_ndiseases; j++)
            g_epi_regions[i][j] = tw_calloc(TW_LOC, "",
                                            sizeof(*g_epi_regions[i][j]),
                                            g_epi_diseases[j].nstages);
    }

    // allocate the location priority queues for this node
    g_epi_pq = tw_calloc(TW_LOC, "", sizeof(*g_epi_pq), g_tw_nlp);

    for(i = 0; i < g_tw_nlp; i++)
        g_epi_pq[i] = pq_create();

    // round-robin mapping of agents to locations, and locations to regions
    for(i = 0; i < g_epi_nagents; i++)
    {
        lid = i % g_tw_nlp;
        rid = lid % g_epi_nregions;

        b = tw_memory_alloc(g_tw_lp[lid], g_epi_fd);
        a = tw_memory_data(b);

        a->id = id++;
        a->region = rid;

        a->pathogens = NULL;
        a->curr = 0;
        a->nloc = tw_rand_integer(g_tw_lp[lid]->rng, 0, 10);

        // setup "home" location
        a->loc[0] = lid;
        a->dur[0] = tw_rand_exponential(g_tw_lp[lid]->rng, g_epi_mean);
        a->ts_next = a->ts_remove = a->dur[0];
        pq_enqueue(g_epi_pq[a->loc[0]], b);

        printf("A %d nloc %d: (%d, %lf) ",
               a->id, a->nloc, a->loc[0], a->dur[0]);

        for(j = 1; j < a->nloc; j++)
        {
            a->loc[j] = tw_rand_integer(g_tw_lp[lid]->rng, 0,
                                        (g_tw_nlp * tw_nnodes()) - 2);
            a->dur[j] = tw_rand_exponential(g_tw_lp[lid]->rng,
                                            g_epi_mean);

            printf("(%d %lf) ", a->loc[j], a->dur[j]);
        }

        printf("\n");
        ga = a;
    }
}
Exemple #10
0
/*
 * epi_init - initialize node LPs state variables
 * 
 * state	- our node LP state space
 * lp		- our node LP
 */
void
epi_init(epi_state * state, tw_lp * lp)
{
	tw_memory	*b;
	tw_memory	*agent = NULL;
	tw_stime	 ts_min_tran = DBL_MAX;

	epi_agent	*a;
	epi_pathogen	*p;
	epi_ic_stage	*s;

	double		 x;

	int		 i;
	int		 j;
	int		 sz;

	// hard-coded, single hospital LP
	if(lp->id == g_tw_nlp-1)
	{
		fprintf(g_epi_hospital_f, "0 0 %u %u %u\n", 
			g_epi_hospital[0][0], g_epi_hospital_ww[0][0], 
			g_epi_hospital_wws[0][0]);

		g_epi_hospital[0][0] = 0;
		g_epi_hospital_ww[0][0] = 0;
		g_epi_hospital_wws[0][0] = 0;

		return;
	}

	// ID of the hospital I go to (or nearest if office/school)
	state->hospital = 0;
	state->stats = tw_calloc(TW_LOC, "", sizeof(epi_statistics), 1);
	state->ncontagious = tw_calloc(TW_LOC, "", sizeof(unsigned int), g_epi_ndiseases);
	state->ts_seir = tw_calloc(TW_LOC, "", sizeof(tw_stime), g_epi_ndiseases);

	for(i = 0; i < g_epi_ndiseases; i++)
		state->ts_seir[i] = DBL_MAX;

	// if no agents initially at this location, then we are done!
	if(0 == (sz = pq_get_size(g_epi_pq[lp->id])))
		return;

	// determine agents initial parameters / configuration
	for(i = 0; i < sz; i++)
	{
		agent = pq_next(g_epi_pq[lp->id], i);
		a = tw_memory_data(agent);

		for(j = 0; j < g_epi_ndiseases; j++)
		{
			if(!a->id && !j)
			{
				// ALLOCATE PATHOGEN AND FILL IT IN
				b = tw_memory_alloc(lp, g_epi_pathogen_fd);
				p = tw_memory_data(b);

				b->next = a->pathogens;
				a->pathogens = b;

				p->index = j;
				p->stage = EPI_SUSCEPTIBLE;
				p->ts_stage_tran = DBL_MAX;

				g_epi_regions[a->region][p->index][p->stage]--;
				p->stage = EPI_EXPOSED;
				g_epi_regions[a->region][p->index][p->stage]++;
				g_epi_exposed_today[j]++;
	
				// determine if agents start out sick.
				if(tw_rand_unif(lp->rng) < g_epi_sick_rate)
				{

				s = &g_epi_diseases[p->index].stages[p->stage];

				x = ((double) tw_rand_integer(lp->rng, 0, INT_MAX) / 
						(double) INT_MAX);

				p->ts_stage_tran = (s->min_duration + 
						(x * (s->max_duration - s->min_duration)));

				if(0.0 >= p->ts_stage_tran)
					tw_error(TW_LOC, "Immediate stage transition?!");

				//state->stats->s_ninfected++;
				state->ncontagious[p->index]++;
				state->ncontagious_tot++;
				//g_epi_hospital[0][0]++;
				g_epi_sick_init_pop[j]++;

				ts_min_tran = min(ts_min_tran, p->ts_stage_tran);

				if(!a->id)
					printf("%ld: agent exposed %d: %s, transition at %lf\n", 
					lp->id, a->id, g_epi_diseases[j].name, 
					p->ts_stage_tran);
				}
			}
		}

		// reflect ts_next change in PQ ordering
		if(ts_min_tran < a->ts_next)
		{
			a->ts_next = ts_min_tran;
			pq_delete_any(g_epi_pq[lp->id], &agent);
			pq_enqueue(g_epi_pq[lp->id], agent);
		}

		// determine if agents are a part of worried well population.
		if(g_epi_ww_rate)
		{
			if(tw_rand_unif(lp->rng) < g_epi_ww_rate)
			{
				a->behavior_flags = 1;
				g_epi_hospital_ww[0][0]++;
				g_epi_ww_init_pop++;
			}
		} else if(g_epi_wws_rate)
		{
			if(tw_rand_unif(lp->rng) < g_epi_wws_rate)
			{
				a->behavior_flags = 2;
				g_epi_hospital_wws[0][0]++;
				g_epi_wws_init_pop++;
			}
		}

		// define agent's at work contact population
		//g_epi_regions[a->region][a->stage]++;
	}

	epi_location_timer(state, lp);
}
Exemple #11
0
static void
recv_finish(tw_pe *me, tw_event *e, char * buffer)
{
  tw_pe		*dest_pe;
  tw_clock start;

#if ROSS_MEMORY
  tw_memory	*memory;
  tw_memory	*last;

  tw_fd		 mem_fd;

  size_t		 mem_size;

  unsigned	 position = 0;

  memcpy(e, buffer, g_tw_event_msg_sz);
  position += g_tw_event_msg_sz;
#endif

  me->stats.s_nread_network++;
  me->s_nwhite_recv++;

  //  printf("recv_finish: remote event [cancel %u] FROM: LP %lu, PE %lu, TO: LP %lu, PE %lu at TS %lf \n",
  //	 e->state.cancel_q, (tw_lpid)e->src_lp, e->send_pe, (tw_lpid)e->dest_lp, me->id, e->recv_ts);

  e->dest_lp = tw_getlocal_lp((tw_lpid) e->dest_lp);
  dest_pe = e->dest_lp->pe;
  // instrumentation
  e->dest_lp->kp->kp_stats->s_nread_network++;
  e->dest_lp->lp_stats->s_nread_network++;

  if(e->send_pe > tw_nnodes()-1)
    tw_error(TW_LOC, "bad sendpe_id: %d", e->send_pe);

  e->cancel_next = NULL;
  e->caused_by_me = NULL;
  e->cause_next = NULL;



  if(e->recv_ts < me->GVT)
    tw_error(TW_LOC, "%d: Received straggler from %d: %lf (%d)",
	     me->id,  e->send_pe, e->recv_ts, e->state.cancel_q);

  if(tw_gvt_inprogress(me))
    me->trans_msg_ts = ROSS_MIN(me->trans_msg_ts, e->recv_ts);

  // if cancel event, retrieve and flush
  // else, store in hash table
  if(e->state.cancel_q)
    {
      tw_event *cancel = tw_hash_remove(me->hash_t, e, e->send_pe);

      // NOTE: it is possible to cancel the event we
      // are currently processing at this PE since this
      // MPI module lets me read cancel events during
      // event sends over the network.

      cancel->state.cancel_q = 1;
      cancel->state.remote = 0;

      cancel->cancel_next = dest_pe->cancel_q;
      dest_pe->cancel_q = cancel;

      tw_event_free(me, e);

      return;
    }

  if (g_tw_synchronization_protocol == OPTIMISTIC ||
      g_tw_synchronization_protocol == OPTIMISTIC_DEBUG ||
      g_tw_synchronization_protocol == OPTIMISTIC_REALTIME ) {
    tw_hash_insert(me->hash_t, e, e->send_pe);
    e->state.remote = 1;
  }

#if ROSS_MEMORY
  mem_size = (size_t) e->memory;
  mem_fd = (tw_fd) e->prev;

  last = NULL;
  while(mem_size)
    {
      memory = tw_memory_alloc(e->dest_lp, mem_fd);

      if(last)
	last->next = memory;
      else
	e->memory = memory;

      memcpy(memory, &buffer[position], mem_size);
      position += mem_size;

      memory->fd = mem_fd;
      memory->nrefs = 1;

      mem_size = (size_t) memory->next;
      mem_fd = memory->fd;

      last = memory;
    }
#endif

  /* NOTE: the final check in the if conditional below was added to make sure
   * that we do not execute the fast case unless the cancellation queue is
   * empty on the destination PE.  Otherwise we need to invoke the normal
   * scheduling routines to make sure that a forward event doesn't bypass a
   * cancellation event with an earlier timestamp.  This is helpful for
   * stateful models that produce incorrect results when presented with
   * duplicate messages with no rollback between them.
   */
  if(me == dest_pe && e->dest_lp->kp->last_time <= e->recv_ts && !dest_pe->cancel_q) {
    /* Fast case, we are sending to our own PE and
     * there is no rollback caused by this send.
     */
    start = tw_clock_read();
    tw_pq_enqueue(dest_pe->pq, e);
    dest_pe->stats.s_pq += tw_clock_read() - start;
    return;
  }

  if (me->node == dest_pe->node) {
    /* Slower, but still local send, so put into top
     * of dest_pe->event_q.
     */
    e->state.owner = TW_pe_event_q;
    tw_eventq_push(&dest_pe->event_q, e);
    return;
  }

  /* Never should happen; MPI should have gotten the
   * message to the correct node without needing us
   * to redirect the message there for it.  This is
   * probably a serious bug with the event headers
   * not being formatted right.
   */
  tw_error(
	   TW_LOC,
	   "Event recived by PE %u but meant for PE %u",
	   me->id,
	   dest_pe->id);
}
Exemple #12
0
tw_event       *
tw_socket_read_event(tw_pe * me)
{
	tw_net_node	*node = g_tw_net_node[me->id];

	tw_event       *recv_event;
	tw_event       *cancel_event;

#ifdef ROSS_MEMORY_LIB
	tw_memory	*last;
	tw_memory	*memory;
#endif

	//tw_message     *temp_message;
	void           *temp_data;

	//tw_pe          *send_pe;
	tw_peid		send_peid;
	tw_pe          *dest_pe;

	int             rv;
	unsigned int             i;

#ifdef ROSS_MEMORY_LIB
	void           *temp_mem_data;

	size_t		mem_size;
	tw_fd		mem_fd;
#endif

	rv = 0;

	/*
	 * Get a free event from our freeq and save the pointers
	 * to the message and the data for later use.
	 */
	if(me->abort_event == (recv_event = tw_event_grab(me)))
		return NULL;

	//temp_message = recv_event->message;
	//temp_data = recv_event->message->data;
	temp_data = recv_event + 1;

	/*
	 * Attempt to read an event, and return NULL if no more events to recv.
	 */
	for (i = 0; i < nnet_nodes - g_tw_npe; i++)
	{
		rv = tw_socket_read(node->clients[i],
			(char *) recv_event, sizeof(tw_event) + g_tw_msg_sz, 100);

		if (rv > 0)
			break;
	}

	/*
	 * Check to see if we actually read an event
	 */
	if (1 > rv)
	{
		if(recv_event != me->abort_event)
		{
			recv_event->event_id = 0;
			tw_eventq_unshift(&me->free_q, recv_event);
		}

		return NULL;
	}

	if (recv_event == me->abort_event)
		tw_error(TW_LOC, "Out of memory!  Allocate more events!");

	if(recv_event->recv_ts < me->GVT)
		tw_error(TW_LOC, "Received straggler event!");

	/*
	 * Restore recv'ed event's pointers
	 *
	 * on recv'rs side: have dest_lp ptr, not src_lp ptr
	 */
	//recv_event->dest_lp = tw_getlp((tw_lpid)recv_event->dest_lp);
	//recv_event->src_lp = tw_getlp((tw_lpid)recv_event->src_lp);
	//recv_event->message = temp_message;
	//recv_event->message->data = temp_data;
	recv_event->dest_lp = tw_getlocal_lp((tw_lpid) recv_event->dest_lp);

	//send_pe = recv_event->src_lp->pe;
	send_peid = (recv_event->dest_lp->type.map)
				((tw_lpid) recv_event->src_lp);

	if(send_peid == me->id)
		tw_error(TW_LOC, "Sent event over network to self?");

	if (recv_event->recv_ts > g_tw_ts_end)
		tw_error(TW_LOC, "%d: Received remote event at %d, end=%d!", 
				recv_event->dest_lp->id,
				recv_event->recv_ts, g_tw_ts_end);

	if(recv_event->dest_lp->pe != me)
		tw_error(TW_LOC, "Not destination PE!");

	/*
	 * If a CANCEL message, just get the event out of hash table * and call 
	 * tw_event_cancel() on it, which rolls it back if nec 
	 */
	if(recv_event->state.owner == TW_net_acancel)
	{
#if VERIFY_SOCKET_TCP
		printf
			("\t\t\t\t\t\t\t\tREAD CANCEL: dest p%d l%d: ts=%f sn=%d\n",
			 recv_event->dest_lp->pe->id,
			 recv_event->dest_lp->id,
			 recv_event->recv_ts, recv_event->event_id);
#endif

		cancel_event = NULL;

		cancel_event = tw_hash_remove(me->hash_t, recv_event, send_peid);
		dest_pe = cancel_event->dest_lp->pe;
		cancel_event->state.cancel_q = 1;
		cancel_event->state.remote = 0;

		if(cancel_event == recv_event)
			tw_error(TW_LOC, "cancel_event == recv_event!");

		if(cancel_event->state.owner == 0 ||
			cancel_event->state.owner == TW_pe_free_q)
			tw_error(TW_LOC, "cancel_event no owner!");

		tw_mutex_lock(&dest_pe->cancel_q_lck);
		cancel_event->cancel_next = dest_pe->cancel_q;
		dest_pe->cancel_q = cancel_event;
		tw_mutex_unlock(&dest_pe->cancel_q_lck);

		recv_event->event_id = recv_event->state.cancel_q = 0;
		recv_event->state.remote = 0;

		tw_event_free(me, recv_event);

		return cancel_event;
	}

	recv_event->next = NULL;
	//recv_event->lp_state = NULL;
	recv_event->cancel_next = NULL;
	recv_event->caused_by_me = NULL;
	recv_event->cause_next = NULL;

	// signals for on-the-fly fossil collection
	recv_event->state.remote = 1;

	tw_hash_insert(me->hash_t, recv_event, send_peid);

#if VERIFY_SOCKET_TCP
	printf
		("\t\t\t\t\t\t\t\tREAD NORMAL: dest p%d l%d: ts=%f sn=%d src p%d l%d \n",
		 recv_event->dest_lp->pe->id,
		 recv_event->dest_lp->id,
		 recv_event->recv_ts, recv_event->seq_num,
		 recv_event->src_lp->pe->id,
		 recv_event->src_lp->id);
#endif

#ifdef ROSS_MEMORY_LIB
	mem_size = (size_t) recv_event->memory;
	mem_fd = (tw_fd) recv_event->prev;
	last = NULL;
	while(mem_size)
	{
		memory = tw_memory_alloc(recv_event->src_lp, mem_fd);
		temp_mem_data = memory->data;

		if(last)
			last->next = memory;
		else
			recv_event->memory = memory;

		rv = 0;
		while(rv != mem_size)
		{
			rv = tw_socket_read(node->clients[i],
					(char *) memory, mem_size, 100);
		}

		memory->data = temp_mem_data;
		memory->prev = (tw_memory *) mem_fd;

#if VERIFY_SOCKET_TCP
		printf("recv\'d mem buf of size %d on event %f\n", rv, recv_event->recv_ts);
#endif

		mem_size = (size_t) memory->next;
		mem_fd = (tw_fd) memory->prev;
		last = memory;
	}
#endif

	recv_event->prev = NULL;

	return recv_event;
}
Exemple #13
0
void
ospf_db_read(ospf_state * state, tw_lp * lp)
{
	tw_memory	*b;
	//tw_stime	 db_last_ts;

	ospf_db_entry	*dbe;
	ospf_lsa	*lsa;
	ospf_lsa_link	*l;

	FILE		*fp;
	int		 age;
	int		 free;
	int		 entry;
	int	 	 id;
	int		 size;
	int		 i;
	int		 j;

	fp = g_ospf_lsa_input;

	state->db = (ospf_db_entry *) 
			calloc(sizeof(ospf_db_entry), state->ar->g_ospf_nlsa);

	if(!state->db)
		tw_error(TW_LOC, "Out of memory for local LSA database!");

	fscanf(fp, "%lf", &state->db_last_ts);

	if(!state->db_last_ts)
		state->db_last_ts = 1;

	if(state->ar->low == lp->gid)
	{
		//printf("%ld: Reading in LSAs for area: %d \n", lp->gid, state->ar->id);
		state->ar->g_ospf_lsa = (tw_memory **) calloc(sizeof(tw_memory *) *
						state->ar->g_ospf_nlsa, 1);

		if(!state->ar->g_ospf_lsa)
			tw_error(TW_LOC, "Unable to allocate global LSA table!");

		fscanf(fp, "%d", &id);
		for(i = 0; i < state->ar->g_ospf_nlsa; i++)
		{
			state->ar->g_ospf_lsa[i] = tw_memory_alloc(lp, g_ospf_lsa_fd);
			lsa = tw_memory_data(state->ar->g_ospf_lsa[i]);

			while(id == i)
			{
				lsa->type = ospf_lsa_router;
				lsa->id = id;

				fscanf(fp, "%d %d", &lsa->adv_r, &size);

				for(j = 0; j < size; j++)
				{
					b = tw_memory_alloc(lp, g_ospf_ll_fd);
					l = tw_memory_data(b);

					fscanf(fp, "%d %d", &l->dst, &l->metric);
					tw_memoryq_push(&lsa->links, b);
				}

				fscanf(fp, "%d", &id);

				if(id == i)
				{
#if VERIFY_OSPF_READ
					printf("\t");
					ospf_lsa_print(stdout, lsa);
#endif
					lsa->next = tw_memory_alloc(lp, g_ospf_lsa_fd);
					lsa = tw_memory_data(lsa->next);
				} else
				{
#if VERIFY_OSPF_READ
					printf("\t");
					ospf_lsa_print(stdout, lsa);
#endif
				}
			}
		}
	}

#if VERIFY_OSPF_READ || 1
	printf("%lld: Database: %lf \n", lp->gid, state->db_last_ts);
#endif

	for(i = 0; i < state->ar->g_ospf_nlsa; i++)
	{
		dbe = &state->db[i];

		fscanf(fp, "%d %d %d %d %d %c %c",
			&free, &age, &entry, &dbe->lsa, &dbe->seqnum, 
			&dbe->cause_bgp, &dbe->cause_ospf);

		dbe->b.free = free;
		//dbe->b.age = age;
		dbe->b.age = 0;
		dbe->b.entry = entry;
		dbe->cause_bgp = dbe->cause_ospf = 0;

#if VERIFY_OSPF_READ
		printf("\t%d %d %d %d %d %c %c \n",
			dbe->b.free, dbe->b.age, dbe->b.entry,
			dbe->lsa, dbe->seqnum, dbe->cause_bgp, dbe->cause_ospf);
#endif
	}
}