int biglist_locked_append(biglist_locked_t* bl, void* data) { biglist_lock(bl); bl->list = biglist_append(bl->list, data); biglist_unlock(bl); return 0; }
/**************************************************************************//** * * Parse a string based on the specified delimiter. * * *****************************************************************************/ biglist_t* vpi_parse_list(const char* string, char* delim, int* len) { biglist_t* bl = NULL; /* Internal token buffer */ char* _tokens = aim_strdup(string); char* arg; char* save_ptr; int count = 0; arg = aim_strtok_r(_tokens, delim, &save_ptr); while(arg) { bl = biglist_append(bl, aim_strdup(arg)); arg = aim_strtok_r(NULL, delim, &save_ptr); count++; } aim_free(_tokens); if(len) { *len = count; } return bl; }
int sff_tool(int argc, char* argv[]) { int rv = 0; int i; int c; int s = 0; int e = 0; int help = 0; int n = 0; int v = 0; biglist_t* fnames=NULL; while( (c = getopt(argc, argv, "sehnv")) != -1) { switch(c) { case 's': s = 1; break; case 'e': e = 1; break; case 'h': help=1; rv=0; break; case 'n': n=1; break; case 'v': v=1; break; default: help=1; rv = 1; break; } } if(help) { printf("Usage: %s [OPTIONS] [FILES]\n", argv[0]); printf(" -s Read filenames from stdin. \n"); printf(" -n Print the filename if successful.\n"); printf(" -v Print the filename always.\n"); printf(" -e Show the raw eeprom data.\n"); printf(" -h Help.\n"); return rv; } if(s) { /* Read filenames from stdin */ char b[PATH_MAX]; char* l; while((l = fgets(b, PATH_MAX, stdin))) { int len=SFF_STRLEN(l); if(len) { if(l[len-1] == '\n') { l[len-1] = 0; } fnames = biglist_append(fnames, aim_strdup(l)); } } } /* Read from command line. This can be used together with -s */ for(i = optind; i < argc; i++) { fnames = biglist_append(fnames, aim_strdup(argv[i])); } biglist_t* ble; char* f; BIGLIST_FOREACH_DATA(ble, fnames, char*, f) { sff_info_t info; memset(&info, 0, sizeof(info)); if( (rv = sff_info_init_file(&info, f)) >= 0) { if(n || v) { aim_printf(&aim_pvs_stdout, "%s\n", f); } if(e) { aim_printf(&aim_pvs_stdout, "eeprom:\n%{data}\n", info.eeprom, sizeof(info.eeprom)); } sff_info_show(&info, &aim_pvs_stdout); } else if(v) { aim_printf(&aim_pvs_stdout, "%s: failed.\n", f); } }
static void parse_options(int argc, char **argv) { while (1) { int option_index = 0; /* Options without short equivalents */ enum long_opts { OPT_START = 256, OPT_NAME, OPT_DPID, OPT_SYSLOG, OPT_TUNNEL, OPT_VERSION, OPT_MAX_FLOWS, OPT_PIPELINE, }; static struct option long_options[] = { {"verbose", no_argument, 0, 'v' }, {"trace", no_argument, 0, 't' }, {"interface", required_argument, 0, 'i' }, {"controller", required_argument, 0, 'c' }, {"listen", required_argument, 0, 'l' }, {"pipeline", optional_argument, 0, OPT_PIPELINE }, {"dpid", required_argument, 0, OPT_DPID }, {"syslog", no_argument, 0, OPT_SYSLOG }, {"tunnel", no_argument, 0, OPT_TUNNEL }, {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, OPT_VERSION }, /* Undocumented options */ {"name", required_argument, 0, OPT_NAME }, {"max-flows", required_argument, 0, OPT_MAX_FLOWS }, {"config-file", required_argument, 0, 'f' }, {"openflow-version", required_argument, 0, 'V' }, {0, 0, 0, 0 } }; int c = getopt_long(argc, argv, "vtl:i:c:f:hV:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 'v': loglevel = LOGLEVEL_VERBOSE; break; case 't': loglevel = LOGLEVEL_TRACE; break; case 'c': controllers = biglist_append(controllers, optarg); break; case 'l': listeners = biglist_append(listeners, optarg); break; case 'i': interfaces = biglist_append(interfaces, optarg); break; case 'f': config_filename = optarg; break; case 'V': openflow_version = optarg; break; case OPT_NAME: datapath_name = strdup(optarg); break; case OPT_DPID: dpid = strtoll(optarg, NULL, 16); break; case OPT_SYSLOG: use_syslog = 1; break; case OPT_TUNNEL: enable_tunnel = 1; break; case OPT_VERSION: printf("%s (%s)\n", program_version, AIM_STRINGIFY(BUILD_ID)); exit(0); break; case OPT_MAX_FLOWS: max_flows = strtoll(optarg, NULL, 0); core_cfg.max_flowtable_entries = max_flows; AIM_LOG_MSG("Setting max flows to %d", max_flows); break; case OPT_PIPELINE: pipeline = optarg ? optarg : "experimental"; break; case 'h': case '?': printf("ivs: Indigo Virtual Switch\n"); printf("Usage: ivs [OPTION]...\n"); printf("\n"); printf(" -v, --verbose Verbose logging\n"); printf(" -t, --trace Very verbose logging\n"); printf(" -c, --controller=IP:PORT Connect to a controller at startup\n"); printf(" -l, --listen=IP:PORT Listen for dpctl connections\n"); printf(" -i, --interface=INTERFACE Attach a network interface at startup\n"); printf(" --pipeline=NAME Set the default forwarding pipeline (standard-1.0 or standard-1.3)\n"); //printf(" -f, --config-file=FILE Read a configuration file\n"); //printf(" --name=NAME Set the name of the kernel datapath (default indigo)\n"); printf(" --dpid=DPID Set datapath ID (default autogenerated)\n"); printf(" --syslog Log to syslog instead of stderr\n"); printf(" --tunnel Enable flow-based GRE tunneling (requires controller support)\n"); printf(" -h,--help Display this help message and exit\n"); printf(" --version Display version information and exit\n"); exit(c == 'h' ? 0 : 1); break; } } }
static void parse_options(int argc, char **argv) { while (1) { int option_index = 0; /* Options without short equivalents */ enum long_opts { OPT_START = 256, OPT_DPID, OPT_PIPELINE }; static struct option long_options[] = { {"verbose", no_argument, 0, 'v'}, {"trace", no_argument, 0, 't'}, {"controller", required_argument, 0, 'c'}, {"openflow-version", required_argument, 0, 'V'}, {"dpid", required_argument, 0, OPT_DPID}, {"pipeline", optional_argument, 0, OPT_PIPELINE} }; int c = getopt_long(argc, argv, "vt:c:hV:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 'v': loglevel = LOGLEVEL_VERBOSE; break; case 't': loglevel = LOGLEVEL_TRACE; break; case 'c': controllers = biglist_append(controllers, optarg); break; case 'V': openflow_version = optarg; break; case OPT_PIPELINE: pipeline = optarg ? optarg : "experimental"; break; case OPT_DPID: AIM_ASSERT(optarg != NULL, "clang-analyzer workaround"); dpid = strtoll(optarg, NULL, 16); break; case 'h': case '?': printf("ofagent: Indigo OpenNSL Integration\n"); printf("Usage: ofagent [OPTION]...\n"); printf("\n"); printf(" -v, --verbose verbose\n"); printf(" -t, --trace Very verbose logging\n"); printf(" -c, --controller=IP:PORT Connect to a controller at startup\n"); printf(" --pipeline=NAME Set the default forwarding pipeline (standard-1.0 or standard-1.3)\n"); printf(" --dpid=DPID Set datapath ID (default autogenerated)\n"); printf(" --syslog Log to syslog instead of stderr\n"); printf(" -h,--help Display this help message and exit\n"); printf(" --version Display version information and exit\n"); exit(c == 'h' ? 0 : 1); break; } } }