Ejemplo n.º 1
0
Archivo: main.c Proyecto: nbastin/ivs
static void
del_port(const char *datapath, const char *interface)
{
    unsigned int dp_ifindex = if_nametoindex(datapath);
    if (dp_ifindex == 0) {
        fprintf(stderr, "Failed: no such datapath '%s'\n", datapath);
        exit(1);
    }

    struct nl_msg *msg = nlmsg_alloc();
    struct ovs_header *hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ,
                                         ovs_vport_family, sizeof(*hdr),
                                         NLM_F_ACK, OVS_VPORT_CMD_DEL,
                                         OVS_VPORT_VERSION);
    hdr->dp_ifindex = dp_ifindex;
    nla_put_string(msg, OVS_VPORT_ATTR_NAME, interface);
    int err = transact(sk, msg);

    /*
     * HACK the OVS kernel module had a bug (fixed by rlane in d5c9288d) which
     * returned random values on success. Work around this by assuming the
     * operation was successful if the kernel returned an invalid errno.
     */
    if (err > 0 || err < -1024) {
        err = 0;
    }

    if (err) {
        fprintf(stderr, "Failed: %s\n", strerror(-err));
        exit(1);
    }
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: Juankc125/ivs
static void
add_internal_port(const char *datapath, const char *interface)
{
    if (strlen(interface) > IFNAMSIZ) {
        fprintf(stderr, "Failed: Interface name too long\n");
        exit(1);
    }

    unsigned int dp_ifindex = if_nametoindex(datapath);
    if (dp_ifindex == 0) {
        fprintf(stderr, "Failed: no such datapath '%s'\n", datapath);
        exit(1);
    }

    struct nl_msg *msg = nlmsg_alloc();
    struct ovs_header *hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ,
                                         ovs_vport_family, sizeof(*hdr),
                                         NLM_F_ACK, OVS_VPORT_CMD_NEW,
                                         OVS_VPORT_VERSION);
    hdr->dp_ifindex = dp_ifindex;
    nla_put_u32(msg, OVS_VPORT_ATTR_TYPE, OVS_VPORT_TYPE_INTERNAL);
    nla_put_string(msg, OVS_VPORT_ATTR_NAME, interface);
    nla_put_u32(msg, OVS_VPORT_ATTR_UPCALL_PID, 0);
    int err = transact(sk, msg);
    if (err) {
        fprintf(stderr, "Failed: %s\n", strerror(-err));
        exit(1);
    }
}
status_t BpBinder::pingBinder()
{
    Parcel send;
    Parcel reply;
    status_t err = transact(PING_TRANSACTION, send, &reply);
    if (err != NO_ERROR) return err;
    if (reply.dataSize() < sizeof(status_t)) return NOT_ENOUGH_DATA;
    return (status_t)reply.readInt32();
}
status_t BpBinder::dump(int fd, const Vector<String16>& args)
{
    Parcel send;
    Parcel reply;
    send.writeFileDescriptor(fd);
    const size_t numArgs = args.size();
    send.writeInt32(numArgs);
    for (size_t i = 0; i < numArgs; i++) {
        send.writeString16(args[i]);
    }
    status_t err = transact(DUMP_TRANSACTION, send, &reply);
    return err;
}
Ejemplo n.º 5
0
	void run()
	{
		unsigned int ep;

		len_out = 0;
		len_in = bs->read(buf_in, BS_INSZ, &ep);
		if(len_in != -1)
		{
			transact();
			bs->write(buf_out, len_out);
		}
		else
		{
			if(ep == 0x47455420)
			{
				// "GET " as a 4-byte integer
				int r;
				len_in = 0;
				int left = BS_INSZ;
				char *bp;
				while(true)
				{
					bp = buf_in + len_in;
					r = bs->sock->readLine(bp, left);
					if(r == -1)
						break;
					Str::trim(bp);
					if(bp[0] == 0)
						break;
					Str::append(bp, "\n", strlen(bp) + 2);
					r = strlen(bp);
					len_in += r;
					left -= r;
				}
				if(r != -1)
				{
					transact_http_get();
					bs->sock->write(buf_out, len_out);
				}
			}
		}
		delete bs;		// dispose of socket
		bs = 0;
		done = 1;
	}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: nbastin/ivs
static void
del_dp(const char *datapath)
{
    unsigned int dp_ifindex = if_nametoindex(datapath);
    if (dp_ifindex == 0) {
        fprintf(stderr, "Failed: no such datapath '%s'\n", datapath);
        exit(1);
    }

    struct nl_msg *msg = nlmsg_alloc();
    struct ovs_header *hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ,
                                         ovs_datapath_family, sizeof(*hdr),
                                         NLM_F_ACK, OVS_DP_CMD_DEL,
                                         OVS_DATAPATH_VERSION);
    hdr->dp_ifindex = dp_ifindex;
    int err = transact(sk, msg);
    if (err) {
        fprintf(stderr, "Failed: %s\n", strerror(-err));
        exit(1);
    }
}
Ejemplo n.º 7
0
    LLRP_tSGET_READER_CONFIG get_reader_config = {
        .hdr.elementHdr.pType   = &LLRP_tdGET_READER_CONFIG,
        .eRequestedData = LLRP_GetReaderConfigRequestedData_GPIPortCurrentState,
        .GPIPortNum = 0,
        .listCustom = NULL
    };

    LLRP_tSMessage *pRspMsg;
    LLRP_tSGET_READER_CONFIG_RESPONSE *pRsp;

    LLRP_tSGPIPortCurrentState *pGPIPortCurrentState;


    // Send the message, expect the response of certain type
    pRspMsg = transact(&get_reader_config.hdr);
    if(pRspMsg == NULL) {
        g_warning("error with GetReaderConfig transaction to get GPIs");
        return -1;
    }

    // Check the LLRPStatus parameter
    pRsp = (LLRP_tSGET_READER_CONFIG_RESPONSE *)pRspMsg;
    if(checkLLRPStatus(pRsp->pLLRPStatus, "addROSpec") != 0) {
        g_warning("unexpected response in GetReaderConfig transaction to get GPIs");
        freeMessage(pRspMsg);
        return -1;
    }


    // handle each GPIPortCurrentState entry separately
Ejemplo n.º 8
0
int main( int argc, char* argv[] )
{
    int ret = 1;
    WSADATA wsd;
    SOCKADDR_IN sa_local;
    DWORD tid;
    HANDLE hThread = NULL;

    if( WSAStartup( MAKEWORD( 2, 2 ), &wsd ) )
    {
        fprintf( stderr, "WSAStartup() failed, error %d\n", WSAGetLastError() );
        return 1;
    }
    
    hRxEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
    if( !hRxEvent )
    {
        fprintf( stderr, "CreateEvent() failed, error %lu\n", GetLastError() );
        goto done;
    }

    hAckEvent = CreateEvent( NULL, FALSE, TRUE, NULL );
    if( !hAckEvent )
    {
        fprintf( stderr, "CreateEvent() failed, error %lu\n", GetLastError() );
        goto done;
    }

    rxsock = socket( AF_INET, SOCK_DGRAM, 0 );
    if( INVALID_SOCKET == sock )
    {
        fprintf( stderr, "socket() failed, error %d\n", WSAGetLastError() );
        goto done;
    }

    memset( &sa_local, 0, sizeof(SOCKADDR_IN) );
    sa_local.sin_family = AF_INET;
    sa_local.sin_addr.S_un.S_addr = htonl( 0x7F000001 );
    sa_local.sin_port = htons( SYSLOG_PORT );
    if( bind( rxsock, (SOCKADDR*) &sa_local, sizeof(SOCKADDR_IN) ) )
    {
        fprintf( stderr, "bind() failed, error %d\n", WSAGetLastError() );
        goto done;
    }

    hThread = CreateThread( NULL, 0, listener, NULL, 0, &tid );
    if( !hThread )
    {
        fprintf( stderr, "CreateThread() failed, error %lu\n", GetLastError() );
        goto done;
    }

    openlog( "test_ident", 0, LOG_USER );
    if( !initialized )
    {
        fprintf( stderr, "openlog() failed\n" );
        goto done;
    }
    
    if( transact( LOG_DEBUG, "test message %d", 1 ) )
        goto done;

    setlogmask( LOG_MASK( LOG_EMERG ) );

    if( !transact( LOG_DEBUG, "test message %d", 2 ) )
        goto done;

    if( transact( LOG_EMERG, "test message %d", 3 ) )
        goto done;

    closelog();
    openlog( "test_ident", LOG_PID, LOG_USER );
    if( !initialized )
    {
        fprintf( stderr, "openlog() failed\n" );
        goto done;
    }

    setlogmask( LOG_MASK( LOG_DEBUG ) );

    if( transact( LOG_DEBUG, "test message %d with pid", 4 ) )
        goto done;

    if( transact( LOG_DEBUG, "long test message %d 1234567890 1234567890 1234567890 1234567890 1234567890", 5 ) )
        goto done;

    ret = 0;

done:
    if( rxsock != INVALID_SOCKET ) closesocket( rxsock );
    if( hAckEvent )
    {
        if( hThread )
        {
            SetEvent( hAckEvent );
            puts( "waiting for thread shutdown" );
            WaitForSingleObject( hThread, INFINITE );
        }
        CloseHandle( hAckEvent );
    }
    if( hThread ) CloseHandle( hThread );
    if( hRxEvent ) CloseHandle( hRxEvent );
    WSACleanup();
    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
  // make sure the number of arguments is odd (including the program name)
  if (!(argc == 1 || argc == 3 || argc == 5 || argc == 7)) {
    fprintf(stderr, "usage: %s [-a <accts>] [-i <transactions>] [-t <think-time>]\n", argv[0]);
    exit(-1);
  }

  // look at each runtime argument and see which value it's attempting to set
  int i;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-a")) {
      num_accts = atoi(argv[i+1]);
      i++;
    } else if (!strcmp(argv[i], "-i")) {
      num_trans = atoi(argv[i+1]);
      i++;
    } else if (!strcmp(argv[i], "-t")) {
      think_time = atoi(argv[i+1]);
      i++;
    } else {
      fprintf(stderr, "usage: %s [-a <accts>] [-i <transactions>] [-t <think-time>]\n", argv[0]);
      exit(-1);
    }
  }

  // display the parameters that will be used for this test run
  fprintf(stderr, "%s: -a %d -i %d -t %d\n", argv[0], num_accts, num_trans, think_time);

  // initialize the random number generator
  srand(1);

  // create the bank accounts
  accts = (struct acct_t *)malloc(num_accts * sizeof(struct acct_t));

  // initialize the bank accounts' values and keep track of the total sum in all accounts
  int original_sum = 0;
  for (i = 0; i < num_accts; i++) {
    accts[i].bal = rand() % 1000;
    original_sum += accts[i].bal;
  }

  // call the transact function to do the transfers
  transact(NULL);

  // find the total sum of all accounts after the transfers are done
  int sum = 0;
  for (i = 0; i < num_accts; i++) {
    sum += accts[i].bal;
  }

  // if the sum is not equal to the original sum, then we had a race condition!!
  if (sum != original_sum) {
    fprintf(stderr, "ERROR! original_sum = %d, sum = %d\n", original_sum, sum);
  }
  else {
    fprintf(stderr, "Values are still consistent\n");
  }

  return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    static const struct option long_options[] = {
        /* Target options must come first. */
        {"all", no_argument, NULL, 'a'},
        {"target", required_argument, NULL, 't'},
        {"help", no_argument, NULL, 'h'},

        /* Action options come afterward. */
        {"list", no_argument, NULL, 'l'},
        {"set", required_argument, NULL, 's'},
        {"reopen", no_argument, NULL, 'r'},
        {0, 0, 0, 0},
    };
    char *short_options;

    /* Determine targets. */
    bool ok = true;
    int n_actions = 0;
    struct vlog_client **clients = NULL;
    size_t n_clients = 0;

    set_program_name(argv[0]);
    time_init();

    short_options = long_options_to_short_options(long_options);
    for (;;) {
        int option;
        size_t i;

        option = getopt_long(argc, argv, short_options, long_options, NULL);
        if (option == -1) {
            break;
        }
        if (!strchr("ath", option) && n_clients == 0) {
            ofp_fatal(0, "no targets specified (use --help for help)");
        } else {
            ++n_actions;
        }
        switch (option) {
        case 'a':
            add_all_targets(&clients, &n_clients, &ok);
            break;

        case 't':
            add_target(&clients, &n_clients, optarg, &ok);
            break;

        case 'l':
            for (i = 0; i < n_clients; i++) {
                struct vlog_client *client = clients[i];
                char *reply;

                printf("%s:\n", vlog_client_target(client));
                reply = transact(client, "list", &ok);
                fputs(reply, stdout);
                free(reply);
            }
            break;

        case 's':
            for (i = 0; i < n_clients; i++) {
                struct vlog_client *client = clients[i];
                char *request = xasprintf("set %s", optarg);
                transact_ack(client, request, &ok);
                free(request);
            }
            break;

        case 'r':
            for (i = 0; i < n_clients; i++) {
                struct vlog_client *client = clients[i];
                char *request = xstrdup("reopen");
                transact_ack(client, request, &ok);
                free(request);
            }
            break;

        case 'h':
            usage(argv[0], EXIT_SUCCESS);
            break;

        case '?':
            exit(EXIT_FAILURE);

        default:
            NOT_REACHED();
        }
    }
    if (!n_actions) {
        fprintf(stderr,
                "warning: no actions specified (use --help for help)\n");
    }
    exit(ok ? 0 : 1);
}