Skip to content

Commit

Permalink
Add event filter operation. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-higuchi committed Feb 22, 2013
1 parent 317f5bb commit a0c7d9a
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 71 deletions.
48 changes: 35 additions & 13 deletions src/topology/discovery_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,27 @@ start_discovery_management( void ){


static void
send_flow_mod_receiving_lldp( const sw_entry *sw, uint16_t hard_timeout, uint16_t priority, bool add ) {
struct ofp_match match;
memset( &match, 0, sizeof( struct ofp_match ) );
set_match_for_lldp( struct ofp_match *match ) {
assert( match != NULL );
memset( match, 0, sizeof( struct ofp_match ) );
if ( !options.lldp.lldp_over_ip ) {
match.wildcards = OFPFW_ALL & ~OFPFW_DL_TYPE;
match.dl_type = ETH_ETHTYPE_LLDP;
match->wildcards = OFPFW_ALL & ~OFPFW_DL_TYPE;
match->dl_type = ETH_ETHTYPE_LLDP;
}
else {
match.wildcards = OFPFW_ALL & ~( OFPFW_DL_TYPE | OFPFW_NW_PROTO | OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK );
match.dl_type = ETH_ETHTYPE_IPV4;
match.nw_proto = IPPROTO_ETHERIP;
match.nw_src = options.lldp.lldp_ip_src;
match.nw_dst = options.lldp.lldp_ip_dst;
match->wildcards = OFPFW_ALL & ~( OFPFW_DL_TYPE | OFPFW_NW_PROTO | OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK );
match->dl_type = ETH_ETHTYPE_IPV4;
match->nw_proto = IPPROTO_ETHERIP;
match->nw_src = options.lldp.lldp_ip_src;
match->nw_dst = options.lldp.lldp_ip_dst;
}
}


static void
send_flow_mod_receiving_lldp( const sw_entry *sw, uint16_t hard_timeout, uint16_t priority, bool add ) {
struct ofp_match match;
set_match_for_lldp( &match );

openflow_actions *actions = create_actions();
const uint16_t max_len = UINT16_MAX;
Expand Down Expand Up @@ -223,9 +230,17 @@ handle_packet_in( uint64_t dst_datapath_id,
probe_request( entry, PROBE_TIMER_EVENT_RECV_LLDP, &dst_datapath_id, dst_port_no );
}

static char PACKET_IN[] = "packet_in";
static void
handle_event_forward_entry_to_all_result( enum efi_result result, void *user_data ) {
if ( result == EFI_OPERATION_FAILED ) {
warn( "Registering/Unregistering topology to switch event '%s' failed.", ( const char * ) user_data );
}
}


void
enable_discovery( void ) {
_enable_discovery( void ) {
info( "Enabling topology discovery." );
if ( g_discovery_enabled ) {
warn( "Topology Discovery is already enabled." );
Expand All @@ -237,16 +252,19 @@ enable_discovery( void ) {
// start receiving packet-in
set_packet_in_handler( handle_packet_in, NULL );

// get event from all switches (directly)
add_event_forward_entry_to_all_switches( EVENT_FORWARD_TYPE_PACKET_IN, get_trema_name(), handle_event_forward_entry_to_all_result, PACKET_IN );

set_switch_status_updated_hook( handle_switch_status_updated_callback, NULL );
set_port_status_updated_hook( handle_port_status_updated_callback, NULL );

// update all port status
foreach_port_entry( port_entry_walker, NULL );

}
void (* enable_discovery )( void ) = _enable_discovery;

void
disable_discovery( void ) {
_disable_discovery( void ) {
if ( options.always_enabled ) return;
info( "Disabling topology discovery." );
if ( !g_discovery_enabled ) {
Expand All @@ -257,11 +275,15 @@ disable_discovery( void ) {
// stop receiving packet-in
set_packet_in_handler( ignore_packet_in, NULL );

// stop getting event from all switches (directly)
delete_event_forward_entry_to_all_switches( EVENT_FORWARD_TYPE_PACKET_IN, get_trema_name(), handle_event_forward_entry_to_all_result, PACKET_IN );

// ignore switch/port events
set_switch_status_updated_hook( NULL, NULL );
set_port_status_updated_hook( NULL, NULL );

// remove LLDP flow entry
foreach_sw_entry( switch_del_LLDP_flow_mods, NULL );
}
void (* disable_discovery )( void ) = _disable_discovery;

4 changes: 2 additions & 2 deletions src/topology/discovery_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ bool start_discovery_management( void );
/**
* Enable discovery.
*/
void enable_discovery( void );
void disable_discovery( void );
extern void (* enable_discovery )( void );
extern void (* disable_discovery )( void );

// TODO Future work: port masking API etc.

Expand Down
4 changes: 4 additions & 0 deletions src/topology/topology_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ main( int argc, char *argv[] ) {

init_openflow_application_interface( get_trema_name() );

init_event_forward_interface();

info( "Initializing topology services");
init_topology_table();

Expand All @@ -66,6 +68,8 @@ main( int argc, char *argv[] ) {

finalize_topology_table();

finalize_event_forward_interface();

return 0;
}

Expand Down
34 changes: 33 additions & 1 deletion src/topology/topology_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ static void
handle_switch_ready( uint64_t datapath_id, void *user_data ) {
UNUSED( user_data );

sw_entry *sw = update_sw_entry( &datapath_id );
sw_entry *sw = lookup_sw_entry( &datapath_id );
if ( sw != NULL ) {
warn( "Received switch-ready event, but switch(%#" PRIx64 ") already exists.", datapath_id );
} else {
sw = update_sw_entry( &datapath_id );
}
sw->up = true;
info( "Switch(%#" PRIx64 ") is connected.", datapath_id );

Expand Down Expand Up @@ -261,6 +266,30 @@ handle_port_status( uint64_t datapath_id, uint32_t transaction_id, uint8_t reaso
}


static char PORT_STATUS[] = "port_status";
static char STATE_NOTIFY[] = "state_notify";
static void
handle_event_forward_entry_to_all_result( enum efi_result result, void *user_data ) {
if ( result == EFI_OPERATION_FAILED ) {
error( "Registering topology to switch event '%s' failed.", ( const char * ) user_data );
}
}


static void
emulate_initial_switch_ready( uint64_t* dpids, size_t n_dpids, void *user_data ) {
UNUSED( user_data );
if( dpids == NULL ) {
error( "Failed to get initial switch lists" );
return;
}

for ( size_t i = 0 ; i < n_dpids ; ++i ) {
handle_switch_ready( dpids[i], NULL );
}
}


bool
init_topology_management( void ) {
bool result = true;
Expand All @@ -281,6 +310,9 @@ finalize_topology_management( void ) {

bool
start_topology_management( void ) {
add_event_forward_entry_to_all_switches( EVENT_FORWARD_TYPE_PORT_STATUS, get_trema_name(), handle_event_forward_entry_to_all_result, PORT_STATUS );
add_event_forward_entry_to_all_switches( EVENT_FORWARD_TYPE_STATE_NOTIFY, get_trema_name(), handle_event_forward_entry_to_all_result, STATE_NOTIFY );
send_efi_switch_list_request( emulate_initial_switch_ready, NULL );
return true;
}

Expand Down
Loading

0 comments on commit a0c7d9a

Please sign in to comment.