Пример #1
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;
}
Пример #2
0
int main(void)
{
   double floor[SIZE][SIZE] = { {0} };

   /* NOTE: don't use (for example) "5.9" but "5.09" and the 
    * 5.01 command do nothing: it write in the current position
    * which has been already written bye the previous command. */

   /* Don't forget '2' to write and '1', '6' and '9' to end */

   double cmds[CMD] = { 2, 5.25, 3, 5.12, 3, 5.25, 3, 5.12, 1, 6, 9 };

   /* Square (CMD = 11)
   double cmds[CMD] = { 2, 5.12, 3, 5.12, 3, 5.12, 3, 5.12, 1, 6, 9 };
   */

   /* C (CMD = 11)
   double cmds[CMD] = { 3, 3, 2, 5.09, 4, 5.06, 4, 5.09, 1, 6, 9 };
   */
   /* H (CMD = 16)
   double cmds[CMD] = {
      3, 2, 5.09, 4, 4, 5.05, 3, 5.08, 4, 5.05, 3, 3, 5.09, 1, 6, 9
   };
   */

   int pen = 0; /* 0 don't write */
   int route = 4, i, j;

   int r = 0, c = 0; /* rows and cols */
   r = c = SIZE/2-1; /* Logo start from middle of floor */

   /* loop all commands (cmds[]) */
   for(i = 0; i < CMD; i++) {
      /* check the command */
      switch( (int)cmds[i] ) {
	 case 1:
	    pen = 0;
	    break;
	 case 2:
	    pen = 1;
	    break;
	 case 3:
	 case 4:
	    route = getroute(route, (int)cmds[i]);
	    break;
         case 5:
	    j = (int)(cmds[i] * 100) % 100;

	    if(cmds[i] == 5.02 || cmds[i] == 5.06) /* fix 5.02 and 5.06 */
	       ++j;

	    /* Overflow check */
	    if( (route == 1 && r + j > SIZE) || (route == 2 && r - j < 0) ||
		(route == 3 && c - j < 0) || (route == 4 && c + j > SIZE)
  	    ) {
		printf("You can't go out of floor (%dx%d): 5.%d\n",
		SIZE, SIZE, j);
		return -1;
            }

	    for( ; j ; j--) {
               /* UP[1], DOWN[2], LEFT[3], RIGHT[4] */

               if(route > 2)
	          floor[r][route == 4 ? c++ : c--] = pen;
	       else
	          floor[route == 2 ? r-- : r++][c] = pen;

	    } /* end for (j) */

	    /* cursor in the current position */
	    if(route == 4) c--;
	    else if(route == 3) ++c;
	    else if(route == 2) ++r;
	    else --r;

	    break;
         case 6:
	    /* print the matrix */
	    pmatrix(floor, SIZE);
	    break; /* not required */
      } /* end switch (cmds[i]) */

   } /* end for (i) */
   printf("\n");

   return 0;
} /* E0F main */