コード例 #1
0
ファイル: fdb.c プロジェクト: mq24705/apps
bool
update_fdb( hash_table *fdb, const uint8_t mac[ OFP_ETH_ALEN ], uint64_t dpid, uint16_t port ) {
    assert( fdb != NULL );
    assert( mac != NULL );
    assert( port != 0 );

    fdb_entry *entry = lookup_hash_entry( fdb, mac );

    debug( "Updating fdb ( mac = %02x:%02x:%02x:%02x:%02x:%02x, dpid = %#" PRIx64 ", port = %u ).",
           mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ], dpid, port );

    if ( entry != NULL ) {
        if ( ( entry->dpid == dpid ) && ( entry->port == port ) ) {
            entry->updated_at = time( NULL );

            return true;
        }

        if ( entry->created_at + HOST_MOVE_GUARD_SEC < time( NULL ) ) {
            // Poisoning when the terminal moves
            poison( entry->dpid, mac );

            entry->dpid = dpid;
            entry->port = port;
            entry->created_at = time( NULL );
            entry->updated_at = entry->created_at;

            return true;
        }

        warn( "Failed to update fdb because host move detected in %d sec "
              "( mac = %02x:%02x:%02x:%02x:%02x:%02x, "
              "dpid = %#" PRIx64 " -> %#" PRIx64 ", port = %u -> %u ).",
              HOST_MOVE_GUARD_SEC,
              mac[ 0 ], mac[ 1 ], mac[ 2 ], mac[ 3 ], mac[ 4 ], mac[ 5 ],
              entry->dpid, dpid, entry->port, port );

        return false;
    }

    entry = xmalloc( sizeof( fdb_entry ) );
    entry->dpid = dpid;
    memcpy( entry->mac, mac, OFP_ETH_ALEN );
    entry->port = port;
    entry->created_at = time( NULL );
    entry->updated_at = entry->created_at;
    insert_hash_entry( fdb, entry->mac, entry );

    return true;
}
コード例 #2
0
ファイル: dpid_table.c プロジェクト: axsh/trema-edge
void
insert_dpid_entry( uint64_t *dpid ) {
  assert( dpid_table != NULL );
  assert( dpid != NULL );

  if ( lookup_hash_entry( dpid_table, dpid ) != NULL ) {
    warn( "datapath %#" PRIx64 " is already registered.", *dpid );
    return;
  }

  uint64_t *new_entry = xmalloc( sizeof ( uint64_t ) );
  *new_entry = *dpid;
  insert_hash_entry( dpid_table, new_entry, new_entry );
}
コード例 #3
0
static void
handle_packet_in( uint64_t datapath_id, packet_in message ) {
  known_switch *sw = lookup_hash_entry(
    message.user_data,
    &datapath_id
  );
  if ( sw == NULL ) {
    warn( "Unknown switch (datapath ID = %#" PRIx64 ")", datapath_id );
    return;
  }
  
  packet_info packet_info = get_packet_info( message.data );
  learn( sw->forwarding_db, message.in_port, packet_info.eth_macsa );
  forwarding_entry *destination = lookup_hash_entry( sw->forwarding_db, 
                                                     packet_info.eth_macda );

  if ( destination == NULL ) {
    do_flooding( message );
  }
  else {
    send_packet( destination->port_no, message );
  }
}
コード例 #4
0
ファイル: stat_test.c プロジェクト: Milstein/trema
static void
test_increment_stat_succeeds_with_defined_key() {
  assert_true( init_stat() );

  const char *key = "key";
  assert_true( add_stat_entry( key ) );
  increment_stat( key );

  stat_entry *entry = lookup_hash_entry( stats, key );
  assert_string_equal( entry->key, key );
  uint64_t expected_value = 1;
  assert_memory_equal( &entry->value, &expected_value, sizeof( uint64_t ) );

  assert_true( finalize_stat() );
}
コード例 #5
0
ファイル: hash.c プロジェクト: Bracksun/netsniff-ng
/*
 * Removes a hash entry pointer from the table.
 *
 * If that hash does not exist, NULL is returned, or, if that hash
 * exists and is the first entry, ptr_next will be set to that entry
 * and NULL is returned. Otherwise the caller must maintain the
 * remaining list.
 */
static void *remove_hash_entry(unsigned int hash, void *ptr, void *ptr_next,
			       struct hash_table *table)
{
	struct hash_table_entry *entry = lookup_hash_entry(hash, table);
	if (!entry->ptr)
		return NULL;
	else if (entry->ptr == ptr) {
		entry->ptr = ptr_next;
		entry->hash = hash;
		if (!ptr_next)
			table->nr--;
		return NULL;
	} else
		return entry->ptr;
}
コード例 #6
0
ファイル: hash_table_test.c プロジェクト: aigamo/trema
static void
test_insert_twice_overwrites_old_value() {
  char *prev;
  char key[] = "key";
  table = create_hash( compare_string, hash_string );

  char old_value[] = "old value";
  char new_value[] = "new value";

  insert_hash_entry( table, key, old_value );
  prev = insert_hash_entry( table, key, new_value );

  assert_string_equal( lookup_hash_entry( table, key ), "new value" );
  assert_string_equal( prev, "old value" );

  delete_hash( table );
}
コード例 #7
0
ファイル: match_table.c プロジェクト: n-tada/trema
void
insert_match_entry( struct ofp_match *ofp_match, uint16_t priority, const char *service_name, const char *entry_name ) {
  match_entry *new_entry, *entry;
  list_element *list;

  pthread_mutex_lock( match_table_head.mutex );

  new_entry = allocate_match_entry( ofp_match, priority, service_name, entry_name );

  if ( !ofp_match->wildcards ) {
    entry = lookup_hash_entry( match_table_head.exact_table, ofp_match );
    if ( entry != NULL ) {
      warn( "insert entry exits" );
      free_match_entry( new_entry );
      pthread_mutex_unlock( match_table_head.mutex );
      return;
    }
    insert_hash_entry( match_table_head.exact_table, &new_entry->ofp_match, new_entry );
    pthread_mutex_unlock( match_table_head.mutex );
    return;
  }

  // wildcard flags are set
  for ( list = match_table_head.wildcard_table; list != NULL; list = list->next ) {
    entry = list->data;
    if ( entry->priority <= new_entry->priority ) {
      break;
    }
  }
  if ( list == NULL ) {
    // wildcard_table is null or tail
    append_to_tail( &match_table_head.wildcard_table, new_entry );
    pthread_mutex_unlock( match_table_head.mutex );
    return;
  }
  if ( list == match_table_head.wildcard_table ) {
    // head
    insert_in_front( &match_table_head.wildcard_table, new_entry );
    pthread_mutex_unlock( match_table_head.mutex );
    return;
  }

  // insert brefore
  insert_before( &match_table_head.wildcard_table, list->data, new_entry );
  pthread_mutex_unlock( match_table_head.mutex );
}
コード例 #8
0
ファイル: http_client.c プロジェクト: deadcafe/trash
static http_transaction *
lookup_http_transaction( CURL *easy_handle ) {
  debug( "Looking up a HTTP transaction ( easy_handle = %p, transactions = %p ).", easy_handle, transactions );

  assert( easy_handle != NULL );
  assert( transactions != NULL );

  http_transaction *transaction = lookup_hash_entry( transactions, easy_handle );
  if ( transaction == NULL ) {
    debug( "Failed to lookup a transaction ( transactions = %p, easy_handle = %p ).", transactions, easy_handle );
    return NULL;
  }

  debug( "Transaction found ( transaction = %p, transactions = %p, easy_handle = %p ).", transaction, transactions, easy_handle );

  return transaction;
}
コード例 #9
0
ファイル: match_table.c プロジェクト: Milstein/trema
static bool
insert_exact_match_entry( hash_table *exact_table, struct ofp_match *match, void *data ) {
  assert( exact_table != NULL );
  assert( match != NULL );

  match_entry *entry = lookup_hash_entry( exact_table, match );
  if ( entry != NULL ) {
    char match_string[ MATCH_STRING_LENGTH ];
    match_to_string( match, match_string, sizeof( match_string ) );
    warn( "exact match entry already exists ( match = [%s] )", match_string );
    return false;
  }
  match_entry *new_entry = allocate_match_entry( match, 0 /* dummy priority */, data );
  match_entry *conflict_entry = insert_hash_entry( exact_table, &new_entry->match, new_entry );
  assert( conflict_entry == NULL );
  return true;
}
コード例 #10
0
ファイル: match_table.c プロジェクト: Milstein/trema
static void *
delete_exact_match_strict_entry( hash_table *exact_table, struct ofp_match *match ) {
  assert( exact_table != NULL );
  assert( match != NULL );

  match_entry *entry = lookup_hash_entry( exact_table, match );
  if ( entry == NULL ) {
    char match_string[ MATCH_STRING_LENGTH ];
    match_to_string( match, match_string, sizeof( match_string ) );
    warn( "exact match entry not found ( match = [%s] )",
          match_string );
    return NULL;
  }
  void *data = entry->data;
  delete_hash_entry( exact_table, match );
  free_match_entry( entry );
  return data;
}
コード例 #11
0
static transaction_entry *
lookup_transaction_entry_by_barrier_xid( uint32_t transaction_id ) {
  debug( "Looking up a transaction entry by barrier transaction id ( transaction_db = %p, transaction_id = %#x ).", transaction_db, transaction_id );

  assert( transaction_db != NULL );
  assert( transaction_db->barrier_xid != NULL );

  transaction_entry *entry = lookup_hash_entry( transaction_db->barrier_xid, &transaction_id );
  if ( entry != NULL ) {
    debug( "A transaction entry found." );
    dump_transaction_entry( debug, entry );
  }
  else {
    debug( "Failed to lookup a transaction entry by barrier transaction id ( transaction_db = %p, transaction_id = %#x ).", transaction_db, transaction_id );
  }

  return entry;
}
コード例 #12
0
void
print_with_graph_easy_format( void *param, size_t entries, const topology_link_status *s ) {
  size_t i;

  UNUSED( param );

  debug( "topology: entries %d", entries );

  hash_table *link_hash = create_hash( compare_link, hash_link );
  // show_topology graph-easy | graph-easy
  // Graph-Easy:
  //   http://search.cpan.org/~shlomif/Graph-Easy/bin/graph-easy
  printf("#! /usr/bin/env graph-easy\n" );

  for ( i = 0; i < entries; i++ ) {
    if ( s[ i ].status != TD_LINK_UP ) {
      continue;
    }
    topology_link_status r;
    r.from_dpid = s[ i ].to_dpid;
    r.from_portno = s[ i ].to_portno;
    r.to_dpid = s[ i ].from_dpid;
    r.to_portno = s[ i ].from_portno;

    topology_link_status *e = lookup_hash_entry( link_hash, &r );
    if ( e != NULL ) {
      delete_hash_entry( link_hash, e );
      print_link_status( e, true );
    } else {
      insert_hash_entry( link_hash, ( void * ) ( intptr_t ) &s[ i ], ( void *) ( intptr_t ) &s[ i ] );
    }
  }
  hash_iterator iter;
  init_hash_iterator( link_hash, &iter );
  hash_entry *e;
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
    topology_link_status *le = e->value;
    print_link_status( le, false );
  }

  delete_hash( link_hash );

  stop_trema();
}
コード例 #13
0
static transaction_entry *
lookup_transaction( uint64_t datapath_id, uint32_t vni ) {
  debug( "Looking up a transaction record ( datapath_id = %#" PRIx64 ", vni = %#x ).", datapath_id, vni );

  if ( !valid_vni( vni ) ) {
    return NULL;
  }

  transaction_entry key = { datapath_id, vni, 0, 0, 0, 0, NULL, NULL };
  transaction_entry *entry = lookup_hash_entry( transactions, &key );
  if ( entry != NULL ) {
    debug( "Transaction record found ( datapath_id = %#" PRIx64 ", vni = %#x, operation = %#x, port_wait_count = %d, callback = %p, user_data = %p ).",
           entry->datapath_id, entry->vni, entry->operation, entry->port_wait_count, entry->callback, entry->user_data );
  }
  else {
    debug( "Failed to lookup a transaction record ( datapath_id = %#" PRIx64 ", vni = %#x ).", datapath_id, vni );
  }

  return entry;
}
コード例 #14
0
ファイル: messenger_test.c プロジェクト: Epictetus/trema
static void
test_send_then_message_received_callback_is_called() {
  init_messenger( "/tmp" );

  const char service_name[] = "Say HELLO";

  expect_value( callback_hello, tag, 43556 );
  expect_string( callback_hello, data, "HELLO" );
  expect_value( callback_hello, len, 6 );

  add_message_received_callback( service_name, callback_hello );
  send_message( service_name, 43556, "HELLO", strlen( "HELLO" ) + 1 );
  start_messenger();
  start_event_handler();

  delete_message_received_callback( service_name, callback_hello );
  delete_send_queue( lookup_hash_entry( send_queues, service_name ) );

  finalize_messenger();
}
コード例 #15
0
static void
handle_port_desc_reply( uint64_t datapath_id, uint32_t transaction_id,
                        uint16_t type, uint16_t flags, const buffer *data,
                       void *user_data ) {
  UNUSED( transaction_id );
  UNUSED( type );
  UNUSED( flags );
  show_desc *show_desc = user_data;

  desc_entry *desc = lookup_hash_entry( show_desc->db, &datapath_id );
  if ( desc == NULL ) {
    return;
  }
  append_to_tail( &desc->port_desc, duplicate_buffer( data ) );

  if ( more_requests( flags ) ) {
    return;
  }

  display_desc( &desc->desc_stats );
  display_datapath_id( datapath_id );
  for ( list_element *e = desc->port_desc; e != NULL; e = e->next ) {
    buffer *data = e->data;
    struct ofp_port *port = ( struct ofp_port  * ) data->data;
    size_t length = data->length;
    while ( length >= sizeof( struct ofp_port ) ) {
      display_port( port );
      length -= ( uint16_t ) sizeof( struct ofp_port );
      port++;
    }
    free_buffer( e->data );
  }
  delete_list( desc->port_desc );
  delete_hash_entry( show_desc->db, &datapath_id );
  show_desc->count--;
  xfree( desc );

  if ( show_desc->count == 0 ) {
    stop_trema();
  }
}
コード例 #16
0
void *
lookup_datapath_entry( hash_table *db, uint64_t datapath_id ) {
  datapath_entry *entry = lookup_hash_entry( db, &datapath_id );
  debug( "lookup datapath: %#" PRIx64 " ( entry = %p )", datapath_id, entry );
  return entry != NULL ? entry->user_data : NULL;
}
コード例 #17
0
ファイル: fdb.c プロジェクト: Milstein/trema
uint16_t
lookup_fdb( hash_table *db, uint8_t *mac ) {
  fdb *entry = lookup_hash_entry( db, mac );
  return ( uint16_t ) ( entry == NULL ? ENTRY_NOT_FOUND_IN_FDB : entry->port_number );

}
コード例 #18
0
ファイル: xid_table.c プロジェクト: Darma/trema
xid_entry_t *
lookup_xid_entry( uint32_t xid ) {
  return lookup_hash_entry( xid_table.hash, &xid );
}
コード例 #19
0
ファイル: switch_port.c プロジェクト: axsh/trema-edge
switch_port *
lookup_switch_port( uint32_t port_no ) {
  assert( switch_ports != NULL );

  return lookup_hash_entry( switch_ports, &port_no );
}
コード例 #20
0
ファイル: hash.c プロジェクト: Bracksun/netsniff-ng
void *lookup_hash(unsigned int hash, const struct hash_table *table)
{
	if (!table->array)
		return NULL;
	return lookup_hash_entry(hash, table)->ptr;
}