struct datapath *
dp_new(void) {
    struct datapath *dp;
    dp = xmalloc(sizeof(struct datapath));

    dp->mfr_desc   = strncpy(xmalloc(DESC_STR_LEN), MFR_DESC, DESC_STR_LEN);
    dp->mfr_desc[DESC_STR_LEN-1]     = 0x00;
    dp->hw_desc    = strncpy(xmalloc(DESC_STR_LEN), HW_DESC, DESC_STR_LEN);
    dp->hw_desc[DESC_STR_LEN-1]      = 0x00;
    dp->sw_desc    = strncpy(xmalloc(DESC_STR_LEN), SW_DESC, DESC_STR_LEN);
    dp->sw_desc[DESC_STR_LEN-1]      = 0x00;
    dp->dp_desc    = strncpy(xmalloc(DESC_STR_LEN), DP_DESC, DESC_STR_LEN);
    dp->dp_desc[DESC_STR_LEN-1]      = 0x00;
    dp->serial_num = strncpy(xmalloc(SERIAL_NUM_LEN), SERIAL_NUM, SERIAL_NUM_LEN);
    dp->serial_num[SERIAL_NUM_LEN-1] = 0x00;


    dp->id = gen_datapath_id();

    dp->generation_id = -1;

    dp->last_timeout = time_now();
    list_init(&dp->remotes);
    dp->listeners = NULL;
    dp->n_listeners = 0;
    dp->listeners_aux = NULL;
    dp->n_listeners_aux = 0;

    memset(dp->ports, 0x00, sizeof (dp->ports));
    dp->local_port = NULL;

    dp->buffers = dp_buffers_create(dp);
    dp->pipeline = pipeline_create(dp);
    dp->groups = group_table_create(dp);
    dp->meters = meter_table_create(dp);
    dp->bundles = bundle_table_create(dp);

    list_init(&dp->port_list);
    dp->ports_num = 0;
    dp->max_queues = NETDEV_MAX_QUEUES;

    dp->exp = &dp_exp;

    dp->config.flags         = OFPC_FRAG_NORMAL;
    dp->config.miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;

    if(strlen(dp->dp_desc) == 0) {
        /* just use "$HOSTNAME pid=$$" */
        char hostnametmp[DESC_STR_LEN];
	    gethostname(hostnametmp,sizeof hostnametmp);
        snprintf(dp->dp_desc, sizeof dp->dp_desc,"%s pid=%u",hostnametmp, getpid());
    }

    /* FIXME: Should not depend on udatapath_as_lib */
    #if defined(OF_HW_PLAT) && (defined(UDATAPATH_AS_LIB) || defined(USE_NETDEV))
        dp_hw_drv_init(dp);
    #endif

    return dp;
}
示例#2
0
int egress_pipeline_init(void) {
  egress_pipeline_instances = malloc(NB_THREADS_PER_PIPELINE * sizeof(void *));
  write_atomic_int(&USEC_INTERVAL, 2400); // roughly 5Mbps with 1.5KB packets
  //write_atomic_int(&USEC_INTERVAL, 1200); // roughly 10Mbps with 1.5KB packets
  write_atomic_int(&EGRESS_CB_SIZE, 15);
  int i;
  for (i = 0; i < NB_THREADS_PER_PIPELINE; i++) {
    egress_pipeline_instances[i] = pipeline_create(i);
  }

  return 0;
}
示例#3
0
文件: read.c 项目: digideskio/bwa
void pixz_read(bool verify, size_t nspecs, char **specs) {
    decode_index();
    if (verify)
        gFileIndexOffset = read_file_index(0);
    wanted_files(nspecs, specs);
    set_block_sizes();

#if DEBUG
    for (wanted_t *w = gWantedFiles; w; w = w->next)
        debug("want: %s", w->name);
#endif
    
    pipeline_create(block_create, block_free, read_thread, decode_thread);
    if (verify && gFileIndexOffset) {
        gArWanted = gWantedFiles;
        wanted_t *w = gWantedFiles, *wlast = NULL;
        bool lastmulti = false;
        off_t lastoff = 0;
        
        struct archive *ar = archive_read_new();
        archive_read_support_compression_none(ar);
        archive_read_support_format_tar(ar);
        archive_read_open(ar, NULL, tar_ok, tar_read, tar_ok);
        struct archive_entry *entry;
        while (true) {
            int aerr = archive_read_next_header(ar, &entry);
            if (aerr == ARCHIVE_EOF) {
                break;
            } else if (aerr != ARCHIVE_OK && aerr != ARCHIVE_WARN) {
                fprintf(stderr, "%s\n", archive_error_string(ar));
                die("Error reading archive entry");
            }
            
            off_t off = archive_read_header_position(ar);
            const char *path = archive_entry_pathname(entry);
            if (!lastmulti) {
                if (wlast && wlast->size != off - lastoff)
                    die("Index and archive show differing sizes for %s: %d vs %d",
                        wlast->name, wlast->size, off - lastoff);
                lastoff = off;
            }
            
            lastmulti = is_multi_header(path);
            if (lastmulti)
                continue;
            
            if (!w)
                die("File %s missing in index", path);
            if (strcmp(path, w->name) != 0)
                die("Index and archive differ as to next file: %s vs %s",
                    w->name, path);
            
            wlast = w;
            w = w->next;
        }
        if (w && w->name)
            die("File %s missing in archive", w->name);
        tar_write_last(); // write whatever's left
    } else {
        pipeline_item_t *pi;
        while ((pi = pipeline_merged())) {
            io_block_t *ib = (io_block_t*)(pi->data);
            fwrite(ib->output, ib->outsize, 1, gOutFile);
            queue_push(gPipelineStartQ, PIPELINE_ITEM, pi);
        }
    }
    
    pipeline_destroy();
    wanted_free(gWantedFiles);
}
示例#4
0
文件: read.c 项目: blue119/pixz
void pixz_read(bool verify, size_t nspecs, char **specs) {
    if (decode_index()) {
	    if (verify)
	        gFileIndexOffset = read_file_index();
	    wanted_files(nspecs, specs);
		gExplicitFiles = nspecs;
    }

#if DEBUG
    for (wanted_t *w = gWantedFiles; w; w = w->next)
        debug("want: %s", w->name);
#endif
    
    pipeline_create(block_create, block_free,
		gIndex ? read_thread : read_thread_noindex, decode_thread);
    if (verify && gFileIndexOffset) {
        gArWanted = gWantedFiles;
        wanted_t *w = gWantedFiles, *wlast = NULL;
        bool lastmulti = false;
        off_t lastoff = 0;
        
        struct archive *ar = archive_read_new();
        archive_read_support_compression_none(ar);
        archive_read_support_format_tar(ar);
        archive_read_open(ar, NULL, tar_ok, tar_read, tar_ok);
        struct archive_entry *entry;
        while (true) {
            int aerr = archive_read_next_header(ar, &entry);
            if (aerr == ARCHIVE_EOF) {
                break;
            } else if (aerr != ARCHIVE_OK && aerr != ARCHIVE_WARN) {
                fprintf(stderr, "%s\n", archive_error_string(ar));
                die("Error reading archive entry");
            }
            
            off_t off = archive_read_header_position(ar);
            const char *path = archive_entry_pathname(entry);
            if (!lastmulti) {
                if (wlast && wlast->size != off - lastoff)
                    die("Index and archive show differing sizes for %s: %d vs %d",
                        wlast->name, wlast->size, off - lastoff);
                lastoff = off;
            }
            
            lastmulti = is_multi_header(path);
            if (lastmulti)
                continue;
            
            if (!w)
                die("File %s missing in index", path);
            if (strcmp(path, w->name) != 0)
                die("Index and archive differ as to next file: %s vs %s",
                    w->name, path);
            
            wlast = w;
            w = w->next;
        }
		archive_read_finish(ar);
        if (w && w->name)
            die("File %s missing in archive", w->name);
        tar_write_last(); // write whatever's left
    }
	if (!gExplicitFiles) {
		/* Heuristics for detecting pixz file index:
		 *    - Input must be streaming (otherwise read_thread does this) 
		 *    - Data must look tar-like
		 *    - Must have all sized blocks, followed by unsized file index */
		bool start = !gIndex && verify,
			 tar = false, all_sized = true, skipping = false;
		
		pipeline_item_t *pi;
        while ((pi = pipeline_merged())) {
            io_block_t *ib = (io_block_t*)(pi->data);
			if (skipping && ib->btype != BLOCK_CONTINUATION) {
				fprintf(stderr,
					"Warning: File index heuristic failed, use -t flag.\n");
				skipping = false;
			}
			if (!skipping && tar && !start && all_sized
					&& ib->btype == BLOCK_UNSIZED && taste_file_index(ib))
				skipping = true;
			if (start) {
				tar = taste_tar(ib);
				start = false;
			}
			if (ib->btype == BLOCK_UNSIZED)
				all_sized = false;
			
			if (!skipping)
				fwrite(ib->output, ib->outsize, 1, gOutFile);
            queue_push(gPipelineStartQ, PIPELINE_ITEM, pi);
        }
    }
    
    pipeline_destroy();
    wanted_free(gWantedFiles);
}
示例#5
0
int
main(int argc, char **argv)
{
  pipeline_t                *pl;
  char                       line[1024];
  int                        n;
  int                        i;
  int                        stages;
  pipeline_stage_process_pf *stages_proc;
  int                        max_random;
  struct timeval             start;
  struct timeval             end;
  int                        start_num = 0;

  stages = atoi(argv[1]);
  max_random = atoi(argv[2]);
  if (argc == 4) {
    start_num = atoi(argv[3]);
    if (start_num <= 0) {
      printf("    usage: test_pipeline <stage_num> <max_random> [start_num]\n");
      return 1;
    }
  }

  if (stages<1 || max_random<1) {
    printf("    usage: test_pipeline <stage_num> <max_random> [start_num]\n");
    return 1;
  }

  stages_proc = malloc(stages * sizeof(pipeline_stage_process_pf));

  for (i = 0; i < stages-1; ++i)
    stages_proc[i] = _stage;
  stages_proc[stages-1] = _stage_tail;

  pl = pipeline_create(stages, stages_proc);
  free(stages_proc);

  if (start_num == 0)
    printf("input an integer, and end with a command named 'q'\n");

  while (1) {
    if (start_num == 0) {
      printf("data> ");
      if (fgets(line, sizeof(line), stdin) == NULL)
        break;

      line[strlen(line)-1] = 0;
      if (strcmp(line, "q") == 0)
        break;

      if (sscanf(line, "%d", &n) != 1) {
        printf("please input valid integer\n");
        continue;
      }
    }

//    int num = random() % max_random;
    g_random_count += max_random;

    gettimeofday(&start, NULL);

    for (i = max_random; i > 0; --i)
      pipeline_start(pl, (void *) (long) (n + i));

    pipeline_wait(pl, 0);

    gettimeofday(&end, NULL);
    test_time("pipeline", &start, &end);
    if (start_num != 0)
      break;
  }

  printf("\n\n---------------count is: %d[%d]\n\n", g_count, g_random_count);
  assert(g_count == g_random_count);

  pipeline_wait(pl, 1);
  pipeline_destroy(pl);
  return EXIT_SUCCESS;
}