Sha256: 28415bb04270bc11b3b4d378416b39297c1d69b64885fe7092b7eb96fcd79cce

Contents?: true

Size: 1.72 KB

Versions: 13

Compression:

Stored size: 1.72 KB

Contents

/*
 * Traffic counter.
 *
 * Author: Kazushi SUGYO
 *
 * Copyright (C) 2008-2012 NEC Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#include "trema.h"
#include "fdb.h"


hash_table *
create_fdb() {
  return create_hash( compare_mac, hash_mac );
}


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 );

}


void
learn_fdb( hash_table *db, uint8_t *mac, uint16_t port_number ) {
  fdb *entry = lookup_hash_entry( db, mac );
  if ( entry == NULL ) {
    entry = xmalloc( sizeof( fdb ) );
    memcpy( entry->mac, mac, ETH_ADDRLEN );
    entry->port_number = port_number;
    insert_hash_entry( db, entry->mac, entry );
  }
  else {
    entry->port_number = port_number;
  }
}


static void
free_each_value( void *key, void *value, void *user_data ) {
  UNUSED( key );
  UNUSED( user_data );
  xfree( value );
}


void
delete_fdb( hash_table *db ) {
  foreach_hash( db, free_each_value, NULL );
  delete_hash( db );
}


/*
 * Local variables:
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * End:
 */

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
trema-0.3.9 src/examples/traffic_monitor/fdb.c
trema-0.3.8 src/examples/traffic_monitor/fdb.c
trema-0.3.7 src/examples/traffic_monitor/fdb.c
trema-0.3.6 src/examples/traffic_monitor/fdb.c
trema-0.3.5 src/examples/traffic_monitor/fdb.c
trema-0.3.4 src/examples/traffic_monitor/fdb.c
trema-0.3.3 src/examples/traffic_monitor/fdb.c
trema-0.3.2 src/examples/traffic_monitor/fdb.c
trema-0.3.1 src/examples/traffic_monitor/fdb.c
trema-0.3.0 src/examples/traffic_monitor/fdb.c
trema-0.2.8 src/examples/traffic_monitor/fdb.c
trema-0.2.7 src/examples/traffic_monitor/fdb.c
trema-0.2.6 src/examples/traffic_monitor/fdb.c