Exemplo n.º 1
0
Arquivo: main.c Projeto: py-qiu/linux
int main(int argc, char *argv[])
{
	int i;
	data_t a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
	
	dlinklist_t list;
	
	list = CreateEmptyDLinklist();
	
	if (NULL == list) return -1;

	printf("insert each elment\n");
	for (i = 0; i < 10; i++) {
		if (InsertDLinklist(list, i, a[i]) < 0)
			break;
	}
	iterate_list(list);

	printf("removed list[4]\n");
	DeleteDLinklist(list, 4);
	iterate_list(list);

	printf("insert \"1\" at the %dth position of the list\n", 0);
	InsertDLinklist(list, 0, 1);
	iterate_list(list);

	ClearDLinklist(list);
	printf("after clear, total number of list is %d and ", LengthDLinklist(list));
	iterate_list(list);
		
	DestroyDLinklist(list);
	
	return 0;
}
Exemplo n.º 2
0
static void
stop_switch() {
  if ( switch_info.secure_channel_fd >= 0 ) {
    close( switch_info.secure_channel_fd );
    switch_info.secure_channel_fd = -1;
  }
  uint8_t state = MESSENGER_OPENFLOW_DISCONNECTED;
  if ( switch_info.state == SWITCH_STATE_CONNECTION_FAILED ) {
    state = MESSENGER_OPENFLOW_FAILD_TO_CONNECT;
  }
  service_send_state( &switch_info, &switch_info.datapath_id, state );
  flush_messenger();

  // free service name list
  iterate_list( switch_info.vendor_service_name_list, xfree_data, NULL );
  delete_list( switch_info.vendor_service_name_list );
  switch_info.vendor_service_name_list = NULL;
  iterate_list( switch_info.packetin_service_name_list, xfree_data, NULL );
  delete_list( switch_info.packetin_service_name_list );
  switch_info.packetin_service_name_list = NULL;
  iterate_list( switch_info.portstatus_service_name_list, xfree_data, NULL );
  delete_list( switch_info.portstatus_service_name_list );
  switch_info.portstatus_service_name_list = NULL;
  iterate_list( switch_info.state_service_name_list, xfree_data, NULL );
  delete_list( switch_info.state_service_name_list );
  switch_info.state_service_name_list = NULL;

  stop_trema();
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: py-qiu/linux
int main(int argc, char *argv[])
{
	int i;
	data_t a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
	data_t x;
	
	seqlist_t *list;
	
	list = CreateEmptySqlist();
	
	if (NULL == list) return -1;
		
	for (i = 0; i < 10; i++) {
		if (InsertSqlist(list, i, a[i]) < 0)
			break;
	}
	iterate_list(list);
	
	GetSqlist(list, 4, &x);
	printf("list[4] = %d\n", x);
	printf("updated list[4] to 100\n");
	SetSqlist(list, 4, 100);
	GetSqlist(list, 4, &x);
	printf("now list[4] = %d\n", x);
	iterate_list(list);
		
	printf("removed list[4]\n");
	DeleteSqlist(list, 4);
	GetSqlist(list, 4, &x);
	printf("now list[4] = %d\n", x);
	printf("and total number of list is %d\n", LengthSqlist(list));
	
	iterate_list(list);
	
	ClearSqlist(list);
	printf("after clear, total number of list is %d\n", LengthSqlist(list));

	iterate_list(list);
		
	DestroySqlist(list);
	
	return 0;
}
void
management_event_forward_entries_set( list_element **service_list,
                                const event_forward_operation_request *request, size_t request_len ) {
  const size_t service_name_list_len = request_len - offsetof( event_forward_operation_request, service_list );

  const char **service_name_list = xcalloc( request->n_services, sizeof( char * ) );

  // split null terminated string list.
  unsigned int n_services = 0;
  const char *name_begin = request->service_list;
  for ( size_t i = 0 ; i < service_name_list_len ; ++i ) {
    if ( request->service_list[ i ] == '\0' ) {
      service_name_list[ n_services++ ] = name_begin;
      if ( n_services == request->n_services ) {
        if ( i + 1 != service_name_list_len ) {
          warn( "Expecting %d name(s) for EVENT_FWD_ENTRY_SET, but more exist. Ignoring.", request->n_services );
        }
        break;
      }
      name_begin = &request->service_list[ i + 1 ];
    }
  }
  if ( n_services != request->n_services ) {
    warn( "Expected %d name(s) for EVENT_FWD_ENTRY_SET, but found %d.", request->n_services, n_services );
  }

  info( "Resetting event filter(s)." );
  // clear current list
  iterate_list( *service_list, xfree_data, NULL );
  delete_list( *service_list );
  create_list( service_list );

  // set new list
  for ( unsigned int i = 0 ; i < n_services ; ++i ) {
    const size_t service_name_len = strlen( service_name_list[ i ] );
    if ( service_name_len == 0 ) {
      warn( "Ignoring 0 length service name in EVENT_FWD_ENTRY_SET" );
      continue;
    }
    info( " Adding '%s' to event filter.", service_name_list[ i ] );
    append_to_tail( service_list, xstrdup( service_name_list[ i ] ) );
  }

  xfree( service_name_list );
}
Exemplo n.º 5
0
void
handle_features_reply(
  uint64_t datapath_id,
  uint32_t transaction_id,
  uint32_t n_buffers,
  uint8_t n_tables,
  uint32_t capabilities,
  uint32_t actions,
  const list_element *ports,
  void *controller
) {
  if ( rb_respond_to( ( VALUE ) controller, rb_intern( "features_reply" ) ) == Qfalse ) {
    return;
  }

  VALUE attributes = rb_hash_new();
  rb_hash_aset( attributes, ID2SYM( rb_intern( "datapath_id" ) ), ULL2NUM( datapath_id ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "n_buffers" ) ), UINT2NUM( n_buffers ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "n_tables" ) ), UINT2NUM( n_tables ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "capabilities" ) ), UINT2NUM( capabilities ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "actions" ) ), UINT2NUM( actions ) );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "ports" ) ), ports_from( ports ) );

  list_element *tmp_ports = xmalloc( sizeof( list_element ) );
  memcpy( tmp_ports, ports, sizeof( list_element ) );
  list_element *physical_ports = xmalloc( sizeof( list_element ) );
  create_list( &physical_ports );
  iterate_list( tmp_ports, append_physical_port, &physical_ports );
  rb_hash_aset( attributes, ID2SYM( rb_intern( "physical_ports" ) ), ports_from( physical_ports ) );
  xfree( physical_ports );
  xfree( tmp_ports );

  VALUE features_reply = rb_funcall( cFeaturesReply, rb_intern( "new" ), 1, attributes );
  rb_funcall( ( VALUE ) controller, rb_intern( "features_reply" ), 2, ULL2NUM( datapath_id ), features_reply );
}