コード例 #1
0
void Close_segmented_infile (int map_fd, char* seg_name, int seg_fd, SEGMENT* seg)
{
  segment_release (seg);
  close (seg_fd);
  unlink (seg_name);
  G_close_cell (map_fd);
}
コード例 #2
0
void Close_segmented_tmpfile (char *seg_name, int seg_fd, SEGMENT *seg)
{
  /* Close files */
  segment_release (seg);
  close (seg_fd);
  unlink (seg_name);
}
コード例 #3
0
ファイル: interface.c プロジェクト: Jupotter/kaneton
t_status	interface_segment_release(o_syscall*	message)
{
  t_status error;

  error = segment_release(message->u.request.u.segment_release.arg1);

  message->u.reply.error = error;

  return (STATUS_OK);
}
コード例 #4
0
ファイル: cseg_close.c プロジェクト: AsherBond/MondocosmOS
int cseg_close(CSEG * cseg)
{
    segment_release(&(cseg->seg));
    close(cseg->fd);
    unlink(cseg->filename);
    if (cseg->name) {
	G_free(cseg->name);
	cseg->name = NULL;
    }
    if (cseg->mapset) {
	G_free(cseg->mapset);
	cseg->mapset = NULL;
    }
    return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: AsherBond/MondocosmOS
int main(int argc, char **argv)
{
    int n, verbose = 1,
	backrow, backcol,
	col, row,
	len, flag,
	srows, scols,
	backrow_fd, backcol_fd, path_fd, in_row_fd, in_col_fd, out_fd;
    const char *current_mapset,
	*search_mapset,
	*path_mapset,
	*backrow_mapset,
	*backcol_mapset, *in_row_file, *in_col_file, *out_file;
    CELL *cell;
    POINT *PRES_PT, *PRESENT_PT, *OLD_PT;
    struct Cell_head window;
    double east, north;
    struct Option *opt1, *opt2, *opt3, *opt4;
    struct Flag *flag1;
    struct GModule *module;

    G_gisinit(argv[0]);

    /* Set description */
    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("fire"));
    G_add_keyword(_("cumulative costs"));
    module->description =
	_("Recursively traces the least cost path backwards to "
	  "cells from which the cumulative cost was determined.");

    opt1 = G_define_option();
    opt1->key = "x_input";
    opt1->type = TYPE_STRING;
    opt1->required = YES;
    opt1->gisprompt = "old,cell,raster";
    opt1->description =
	_("Name of raster map containing back-path easting information");

    opt2 = G_define_option();
    opt2->key = "y_input";
    opt2->type = TYPE_STRING;
    opt2->required = YES;
    opt2->gisprompt = "old,cell,raster";
    opt2->description =
	_("Name of raster map containing back-path northing information");

    opt3 = G_define_option();
    opt3->key = "coordinate";
    opt3->type = TYPE_STRING;
    opt3->multiple = YES;
    opt3->key_desc = "x,y";
    opt3->description =
	_("The map E and N grid coordinates of starting points");

    opt4 = G_define_option();
    opt4->key = "output";
    opt4->type = TYPE_STRING;
    opt4->required = YES;
    opt4->gisprompt = "new,cell,raster";
    opt4->description = _("Name of spread path raster map");

    flag1 = G_define_flag();
    flag1->key = 'v';
    flag1->description = _("Run verbosely");

    /*   Do command line parsing    */
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    current_mapset = G_mapset();
    in_row_file = G_tempfile();
    in_col_file = G_tempfile();
    out_file = G_tempfile();

    /*  Get database window parameters      */
    G_get_window(&window);

    verbose = flag1->answer;

    /*  Check if backrow layer exists in data base  */
    search_mapset = "";

    strcpy(backrow_layer, opt2->answer);
    strcpy(backcol_layer, opt1->answer);

    backrow_mapset = G_find_raster(backrow_layer, search_mapset);
    backcol_mapset = G_find_raster(backcol_layer, search_mapset);

    if (backrow_mapset == NULL)
	G_fatal_error("%s - not found", backrow_layer);

    if (backcol_mapset == NULL)
	G_fatal_error("%s - not found", backcol_layer);

    search_mapset = "";

    strcpy(path_layer, opt4->answer);

    path_mapset = G_find_raster(path_layer, search_mapset);

    /*  find number of rows and cols in window    */
    nrows = Rast_window_rows();
    ncols = Rast_window_cols();

    cell = Rast_allocate_c_buf();

    /*  Open back cell layers for reading  */
    backrow_fd = Rast_open_old(backrow_layer, backrow_mapset);
    backcol_fd = Rast_open_old(backcol_layer, backcol_mapset);

    /*   Parameters for map submatrices   */
    len = sizeof(CELL);

    srows = nrows / 4 + 1;
    scols = ncols / 4 + 1;

    if (verbose)
	G_message
	    ("\nReading the input map -%s- and -%s- and creating some temporary files...",
	     backrow_layer, backcol_layer);

    /* Create segmented files for back cell and output layers  */
    in_row_fd = creat(in_row_file, 0666);
    segment_format(in_row_fd, nrows, ncols, srows, scols, len);
    close(in_row_fd);
    in_col_fd = creat(in_col_file, 0666);
    segment_format(in_col_fd, nrows, ncols, srows, scols, len);
    close(in_col_fd);

    out_fd = creat(out_file, 0666);
    segment_format(out_fd, nrows, ncols, srows, scols, len);
    close(out_fd);

    /*   Open initialize and segment all files  */
    in_row_fd = open(in_row_file, 2);
    segment_init(&in_row_seg, in_row_fd, 4);
    in_col_fd = open(in_col_file, 2);
    segment_init(&in_col_seg, in_col_fd, 4);

    out_fd = open(out_file, 2);
    segment_init(&out_seg, out_fd, 4);

    /*   Write the back cell layers in the segmented files, and  
     *   Change UTM coordinates to ROWs and COLUMNs */
    for (row = 0; row < nrows; row++) {
	Rast_get_c_row(backrow_fd, cell, row);

	for (col = 0; col < ncols; col++)
	    if (cell[col] > 0)
		cell[col] =
		    (window.north - cell[col]) / window.ns_res /* - 0.5 */ ;
	    else
		cell[col] = -1;
	segment_put_row(&in_row_seg, cell, row);
	Rast_get_c_row(backcol_fd, cell, row);

	for (col = 0; col < ncols; col++)
	    if (cell[col] > 0)
		cell[col] =
		    (cell[col] - window.west) / window.ew_res /* - 0.5 */ ;
	segment_put_row(&in_col_seg, cell, row);
    }

    /* Convert easting and northing from the command line to row and col */
    if (opt3->answer) {
	for (n = 0; opt3->answers[n] != NULL; n += 2) {
	    G_scan_easting(opt3->answers[n], &east, G_projection());
	    G_scan_northing(opt3->answers[n + 1], &north, G_projection());
	    row = (window.north - north) / window.ns_res;
	    col = (east - window.west) / window.ew_res;
	    /* ignore pt outside window */
	    if (east < window.west || east > window.east ||
		north < window.south || north > window.north) {
		G_warning("Ignoring point outside window: ");
		G_warning("   %.4f,%.4f", east, north);
		continue;
	    }

	    value = (char *)&backrow;
	    segment_get(&in_row_seg, value, row, col);
	    /* ignore pt in no-data area */
	    if (backrow < 0) {
		G_warning("Ignoring point in NO-DATA area :");
		G_warning("   %.4f,%.4f", east, north);
		continue;
	    }
	    value = (char *)&backcol;
	    segment_get(&in_col_seg, value, row, col);

	    insert(&PRESENT_PT, row, col, backrow, backcol);
	}
    }

    /*  Set flag according to input */
    if (path_mapset != NULL) {
	if (head_start_pt == NULL)
	    /*output layer exists and start pts are not given on cmd line */
	    flag = 1;

	/* output layer exists and starting pts are given on cmd line */
	else
	    flag = 2;
    }
    else
	flag = 3;		/* output layer does not previously exist */

    /* If the output layer containing the starting positions */
    /* create a linked list of of them  */
    if (flag == 1) {
	path_fd = Rast_open_old(path_layer, path_mapset);

	/*  Search for the marked starting pts and make list    */
	for (row = 0; row < nrows; row++) {
	    Rast_get_c_row(path_fd, cell, row);

	    for (col = 0; col < ncols; col++) {
		if (cell[col] > 0) {
		    value = (char *)&backrow;
		    segment_get(&in_row_seg, value, row, col);
		    /* ignore pt in no-data area */
		    if (backrow < 0) {
			G_warning("Ignoring point in NO-DATA area:");
			G_warning("   %.4f,%.4f\n",
				  window.west + window.ew_res * (col + 0.5),
				  window.north - window.ns_res * (row + 0.5));
			continue;
		    }
		    value = (char *)&backcol;
		    segment_get(&in_col_seg, value, row, col);
		    insert(&PRESENT_PT, row, col, backrow, backcol);
		}
	    }			/* loop over cols */
	}			/* loop over rows */

	Rast_close(path_fd);
    }

    /* loop over the starting points to find the least cost paths */
    if (verbose)
	G_message("\nFinding the least cost paths ...");

    PRES_PT = head_start_pt;
    while (PRES_PT != NULL) {
	path_finder(PRES_PT->row, PRES_PT->col, PRES_PT->backrow,
		    PRES_PT->backcol);

	OLD_PT = PRES_PT;
	PRES_PT = NEXT_PT;
	G_free(OLD_PT);
    }

    /* Write pending updates by segment_put() to outputmap */
    segment_flush(&out_seg);

    if (verbose)
	G_message("\nWriting the output map  -%s-...", path_layer);

    path_fd = Rast_open_c_new(path_layer);
    for (row = 0; row < nrows; row++) {
	segment_get_row(&out_seg, cell, row);
	Rast_put_row(path_fd, cell, CELL_TYPE);
    }

    if (verbose)
	G_message("finished.");

    segment_release(&in_row_seg);	/* release memory  */
    segment_release(&in_col_seg);
    segment_release(&out_seg);

    close(in_row_fd);		/* close all files */
    close(in_col_fd);
    close(out_fd);

    Rast_close(path_fd);
    Rast_close(backrow_fd);
    Rast_close(backcol_fd);

    unlink(in_row_file);	/* remove submatrix files  */
    unlink(in_col_file);
    unlink(out_file);

    exit(EXIT_SUCCESS);
}
コード例 #6
0
ファイル: rexmit.c プロジェクト: andreaaraldo/mytstat
static void
collapse_quad (quadrant * pquad)
{
  Bool freed;
  segment *pseg;
  segment *tmpseg;

  if ((pquad == NULL) || (pquad->seglist_head == NULL))
    return;

  pseg = pquad->seglist_head;
  while (pseg != NULL)
    {
      freed = FALSE;
      if (pseg->next == NULL)
        break;

      /* if this segment has not been ACKed, then neither have the */
      /* ones that follow, so no need to continue */
      if (!pseg->acked)
        break;

      /* if this segment and the next one have both been ACKed and they */
      /* "fit together", then collapse them into one (larger) segment   */
      if (pseg->acked && pseg->next->acked &&
          (pseg->seq_lastbyte + 1 == pseg->next->seq_firstbyte))
        {
          pseg->seq_lastbyte = pseg->next->seq_lastbyte;

          /* the new ACK count is the ACK count of the later segment */
          pseg->acked = pseg->next->acked;

          /* the new "transmit time" is the greater of the two */
          /* the new "ip_id" is the greater of the two */
          /* the new "type_of_segment" is the greater of the two */
          if (tv_gt (pseg->next->time, pseg->time))
            {
              pseg->time = pseg->next->time;
              pseg->ip_id = pseg->next->ip_id;
              pseg->type_of_segment = pseg->next->type_of_segment;
            }

          tmpseg = pseg->next;
          pseg->next = pseg->next->next;
          if (pseg->next != NULL)
            pseg->next->prev = pseg;
          if (tmpseg == pquad->seglist_tail)
            pquad->seglist_tail = pseg;
          //free (tmpseg);
          segment_release (tmpseg);
          pquad->no_of_segments--;
          //segment_list_info();
          freed = TRUE;
        }

      if (!freed)
        pseg = pseg->next;
      /* else, see if the next one also can be collapsed into me */
    }

  /* see if the quadrant is now "full" */
  if ((pquad->seglist_head->seq_lastbyte -
       pquad->seglist_head->seq_firstbyte + 1) == QUADSIZE)
    {
      pquad->full = TRUE;
    }
}
コード例 #7
0
ファイル: rexmit.c プロジェクト: andreaaraldo/mytstat
static int
addseg (tcb * ptcb,
        quadrant * pquad,
        seqnum thisseg_firstbyte, seglen len, Bool * pout_order,
        u_short this_ip_id)
{
  seqnum thisseg_lastbyte = thisseg_firstbyte + len - 1;
  segment *pseg;
  segment *pseg_new;
  int rexlen = 0;
  Bool split = FALSE;
  double recovery_time = 0;

  /* check each segment in the segment list */
  pseg = pquad->seglist_head;

  /* LM - all the segments are memorized in the seglist
     Here has been implemented the heuristic discussed in
     S. Jaiswal, G.Iannaccone, C. Diot, J.F. Kurose, D.Towsley
     Measurement and Classification of Out-of-Sequence Packets in a Tier-1 IP Backbone
     INFOCOM 2003 http://www.ieee-infocom.org/2003/technical_programs.htm
   */

  /* (optimize expected case, it just goes at the end) */
  if (pquad->seglist_tail &&
      (thisseg_firstbyte > pquad->seglist_tail->seq_lastbyte))
    pseg = NULL;
  for (; pseg != NULL; pseg = pseg->next)
    {

      if (thisseg_firstbyte > pseg->seq_lastbyte)
        {
          /* goes beyond this one */
          continue;
        }

      if (thisseg_firstbyte < pseg->seq_firstbyte)
        {
          /* starts BEFORE this recorded segment */

          /* if it also FINISHES before this segment, then it's */
          /* out of order (otherwise it's a resend the collapsed */
          /* multiple segments into one */
          if (thisseg_lastbyte < pseg->seq_lastbyte)
            *pout_order = TRUE;

          /* make a new segment record for it */
          pseg_new = create_seg (thisseg_firstbyte, len, this_ip_id);
          insert_seg_between (pquad, pseg_new, pseg->prev, pseg);

          /* see if we overlap the next segment in the list */
          if (thisseg_lastbyte <= pseg->seq_firstbyte)
            {
              /* we don't overlap, so we're done */
              // LM start
              rules_test (ptcb, pseg, len, pquad, this_ip_id, FALSE,
                          recovery_time);
              return (rexlen);
            }
          else
            {
              /* overlap him, split myself in 2 */
              //fprintf(fp_stdout, "split %lu %lu\n",
          //    len,  pseg_new->seq_lastbyte-pseg_new->seq_firstbyte);
              /* adjust new piece to mate with old piece */
              pseg_new->seq_lastbyte = pseg->seq_firstbyte - 1;

              // LM start
              rules_test (ptcb, pseg,
                          pseg_new->seq_lastbyte - pseg_new->seq_firstbyte,
                          pquad, this_ip_id, FALSE, recovery_time);

              /* pretend to be just the second half of this segment */
              thisseg_firstbyte = pseg->seq_firstbyte;
              len = thisseg_lastbyte - thisseg_firstbyte + 1;

              /* fall through */
            }
        }

      /* no ELSE, we might have fallen through */
      if (thisseg_firstbyte >= pseg->seq_firstbyte)
        {
          /* starts within this recorded sequence */
          ++pseg->retrans;
          recovery_time =
            time2double (current_time) - time2double (pseg->time);
          if (!split)
            rtt_retrans (ptcb, pseg);   /* must be a retransmission */
          if (thisseg_lastbyte <= pseg->seq_lastbyte)
            {
              /* entirely contained within this sequence */
              rexlen += len;
              // LM start
              rules_test (ptcb, pseg, len, pquad, this_ip_id, TRUE,
                          recovery_time);

              return (rexlen);
            }
          /* else */
          /* we extend beyond this sequence, split ourself in 2 */
          /* (pretend to be just the second half of this segment) */
          split = TRUE;
          rexlen += pseg->seq_lastbyte - thisseg_firstbyte + 1;
          thisseg_firstbyte = pseg->seq_lastbyte + 1;

          // LM start
          rules_test (ptcb, pseg, rexlen, pquad, this_ip_id, TRUE,
                      recovery_time);
          len = thisseg_lastbyte - thisseg_firstbyte + 1;
        }
    }
  /* if we got to the end, then it doesn't go BEFORE anybody, */
  /* tack it onto the end */

  pseg_new = create_seg (thisseg_firstbyte, len, this_ip_id);
  insert_seg_between (pquad, pseg_new, pquad->seglist_tail, NULL);

  /* MGM - management of the number of segments within this quadrant */

  if (pquad->no_of_segments > MAX_SEG_PER_QUAD)
    {
      /* free up the first segment in this quadrant */
      segment *tmp_pseg = pquad->seglist_head;

      /* rebuild the list */
      if (tmp_pseg->next != NULL)
        tmp_pseg->next->prev = tmp_pseg->prev;
      pquad->seglist_head = tmp_pseg->next;
      /* recall the initial segment byte */
      pquad->seglist_head->seq_firstbyte = tmp_pseg->seq_firstbyte;

      /* remove the segment */
      segment_release (tmp_pseg);
      pquad->no_of_segments--;
    }


  pseg_new->type_of_segment = IN_SEQUENCE;
  /* LM : This is an IN_SEQUENCE segment */
  if (internal_src && !internal_dst)
    {
      add_histo (tcp_anomalies_out, IN_SEQUENCE);
    }
  else if (!internal_src && internal_dst)
    {
      add_histo (tcp_anomalies_in, IN_SEQUENCE);
    }
#ifndef LOG_UNKNOWN
  else if (internal_src && internal_dst)
#else
  else
#endif
    {
      add_histo (tcp_anomalies_loc, IN_SEQUENCE);
    }

  if ((&(ptcb->ptp->c2s)) == ptcb)      //(dir == C2S)
    {
      add_histo (tcp_anomalies_c2s, IN_SEQUENCE);
    }
  else
    {
      add_histo (tcp_anomalies_s2c, IN_SEQUENCE);
    }
  return (rexlen);
}
コード例 #8
0
/* NULL cell handling added by Benjamin Ducke, May 2004 */
void Close_segmented_outfile (char* map_name, int map_fd,
			             char* seg_name, int seg_fd, SEGMENT* seg, 
                         CELL* cell_buf, int terse,
                         SEGMENT* elevation_seg, RASTER_MAP_TYPE data_type, int make_nulls)
{
  unsigned long row, nrows, col, ncols;
  void *value = NULL;
  char *null_flags;
  /* the following are used to store different raster map types */
  CELL c_value;
  FCELL f_value;
  DCELL d_value;  	

	
  /* Find number of rows and columns in elevation map */
  nrows = G_window_rows();
  ncols = G_window_cols();
	
  /* allocate memory for a NULL data row */	
  null_flags = G_calloc ((unsigned) ncols, sizeof (char));
    
  /* Write pending updates by segment_put() to output map */
  segment_flush(seg);
  
  if (!terse) {	
    fprintf (stdout, "\nWriting raster map '%s': \n", map_name);	
  }
	
  /* Convert output submatrices to full cell overlay */
  for(row=0; row< nrows; row++) {
    segment_get_row(seg, cell_buf, (signed) row);
	/* check for NULL values in the corresponding row of the */
	/* elevation input file. If there are any, set the CELLs */
	/* in the output file to NULL, as well */
	
	/* initialize null data row */
	for (col=0; col<ncols; col++) {
		null_flags[col] = 0;
	}
	
	/* convert all -1 cells to NULL, if user wants it so */
    if ( make_nulls == 1 ) {
	    for (col=0; col<ncols; col++) {
		   if ( cell_buf[col] == -1 ) {
		     null_flags[col] = 1;
		   }
		}
	}
	
	/* update NULL flags in row */
    for (col=0; col<ncols; col++) {
		if ( data_type == CELL_TYPE ) {
		    value = (CELL*) &c_value;
		}		  
		if ( data_type == FCELL_TYPE ) {
		    value = (FCELL*) &f_value;
		}		  
		if ( data_type == DCELL_TYPE ) {
		    value = (DCELL*) &d_value;
		}
		
        segment_get (elevation_seg, value, (signed) row, (signed) col);
		
		/* check for NULL value and record in null_flags row */
		if ( data_type == CELL_TYPE ) {
		    if (G_is_c_null_value (&c_value) ) {
			  null_flags[col] = 1; /* signal NULL value in null_flags row */
			}			
		}		  
		if ( data_type == FCELL_TYPE ) {
		    if (G_is_f_null_value (&f_value) ) {
			  null_flags[col] = 1; /* signal NULL value in null_flags row */
			}
		}		  
		if ( data_type == DCELL_TYPE ) {
		    if (G_is_d_null_value (&d_value) ) {
			  null_flags[col] = 1; /* signal NULL value in null_flags row */
			}						
		}
	}
    /* set all NULL cells according to null_flags row */
	G_insert_c_null_values (cell_buf, null_flags, (signed) ncols);
	
	/* now, write this row to disk */  
    if(G_put_raster_row (map_fd, cell_buf, CELL_TYPE) < 0) {
	  G_fatal_error ("Failed to convert output submatrices ");	  
	}
	
	/* progress display */
	if (! terse) {
		G_percent ((signed) row, (signed) nrows-1,2);
	}	
  }
  
  G_free (null_flags);
  
/* Close files */
  segment_release (seg);
  close (seg_fd);
  unlink (seg_name);
  G_close_cell (map_fd);
}