bool
dump_packetin_filter( struct ofp_match match, uint16_t priority, char *service_name, bool strict,
                      dump_packetin_filter_handler callback, void *user_data ) {
  maybe_init_packetin_filter_interface();

  handler_data *data = xmalloc( sizeof( handler_data ) );
  data->callback = callback;
  data->user_data = user_data;

  dump_packetin_filter_request request;
  memset( &request, 0, sizeof( dump_packetin_filter_request ) );
  hton_match( &request.criteria.match, &match );
  request.criteria.priority = htons( priority );
  if ( service_name != NULL ) {
    strncpy( request.criteria.service_name, service_name, sizeof( request.criteria.service_name ) );
    request.criteria.service_name[ sizeof( request.criteria.service_name ) - 1 ] = '\0';
  }
  if ( strict ) {
    request.flags = PACKETIN_FILTER_FLAG_MATCH_STRICT;
  }
  else {
    request.flags = PACKETIN_FILTER_FLAG_MATCH_LOOSE;
  }

  bool ret = send_request_message( PACKETIN_FILTER_MANAGEMENT_SERVICE,
                                   get_client_service_name(),
                                   MESSENGER_DUMP_PACKETIN_FILTER_REQUEST,
                                   &request, sizeof( dump_packetin_filter_request ), data );

  return ret;
}
bool
add_packetin_filter( struct ofp_match match, uint16_t priority, char *service_name,
                     add_packetin_filter_handler callback, void *user_data ) {
  if ( service_name == NULL || ( service_name != NULL && strlen( service_name ) == 0 ) ) {
    error( "Service name must be specified." );
    return false;
  }

  maybe_init_packetin_filter_interface();

  handler_data *data = xmalloc( sizeof( handler_data ) );
  data->callback = callback;
  data->user_data = user_data;

  add_packetin_filter_request request;
  memset( &request, 0, sizeof( add_packetin_filter_request ) );
  hton_match( &request.entry.match, &match );
  request.entry.priority = htons( priority );
  memcpy( request.entry.service_name, service_name, sizeof( request.entry.service_name ) );

  bool ret = send_request_message( PACKETIN_FILTER_MANAGEMENT_SERVICE,
                                   get_client_service_name(),
                                   MESSENGER_ADD_PACKETIN_FILTER_REQUEST,
                                   &request, sizeof( add_packetin_filter_request ), data );

  return ret;
}
Beispiel #3
0
static void
dump_filter_walker( struct ofp_match match, uint16_t priority, void *data, void *user_data ) {
  buffer *reply_buffer = user_data;
  assert( reply_buffer != NULL );

  dump_packetin_filter_reply *reply = reply_buffer->data;
  list_element *services = data;
  while ( services != NULL ) {
    reply->n_entries++;
    packetin_filter_entry *entry = append_back_buffer( reply_buffer, sizeof( packetin_filter_entry ) );
    hton_match( &entry->match, &match );
    entry->priority = htons( priority );
    strncpy( entry->service_name, services->data, sizeof( entry->service_name ) );
    entry->service_name[ sizeof( entry->service_name ) - 1 ] = '\0';
    services = services->next;
  }
}
Beispiel #4
0
/*
 * A {AggregateStatsRequest} object instance to request aggregate statistics.
 * @overload initialize(options={})
 *   @example
 *     AggregateStatsRequest.new(
 *       :match => Match
 *     )
 *
 *   @param [Hash] options
 *     the options to create a message with.
 *
 *   @option options [Match] :match
 *     a {Match} object to match flow fields with this request.
 *     This option is mandatory.
 *
 *   @option options [Number] :table_id
 *     a table id to match and restrict returned results.
 *     A value of 0xff would return all tables and is set to if not specified.
 *
 *   @option options [Number] :out_port
 *     a value of +OFPP_NONE+ would match all flow entries and is set to if not
 *     specified.
 *
 *   @raise [ArgumentError] if option[:match] is not specified.
 *
 *   @return [AggregateStatsRequest]
 *     an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_AGGREGATE)+ OpenFlow message.
 */
static VALUE
aggregate_stats_request_init( VALUE self, VALUE options ) {
  buffer *message;
  Data_Get_Struct( self, buffer, message );

  subclass_stats_request_init( self, options );

  ( ( struct ofp_header * ) ( message->data ) )->xid = htonl( get_stats_request_num2uint( self, "@transaction_id" ) );

  struct ofp_stats_request *stats_request;
  stats_request = ( struct ofp_stats_request * ) message->data;
  struct ofp_aggregate_stats_request *aggregate_stats_request;
  aggregate_stats_request = ( struct ofp_aggregate_stats_request * ) stats_request->body;

  stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );

  struct ofp_match m = get_stats_request_match( self );
  hton_match( &aggregate_stats_request->match, &m  ) ;
  aggregate_stats_request->table_id = get_stats_request_table_id( self );
  aggregate_stats_request->out_port = htons( get_stats_request_num2uint16( self, "@out_port" ) );
  return self;
}
Beispiel #5
0
/*
 * A {FlowStatsRequest} object instance to request flow statistics.
 *
 * @overload initialize(options={})
 *   @example
 *     FlowStatsRequest.new( :match => Match )
 *     FlowStatsRequest.new( :match => Match, :table_id => 1 )
 *     FlowStatsRequest.new( :match => Match, :table_id => 1, :out_port => 2 )
 *
 *   @param [Hash] options
 *     the options to create a message with.
 *
 *   @option options [Match] :match
 *     a {Match} object to match flow fields with this request.
 *     This option is mandatory.
 *
 *   @option options [Number] :table_id
 *     a table id to match and restrict returned results.
 *     A value of 0xff would return all tables and is set to if not specified.
 *
 *   @option options [Number] :out_port
 *     a value of +OFPP_NONE+ would match all flow entries and is set to if not
 *     specified.
 *
 *   @raise [ArgumentError] if option match is not specified.
 *   @raise [TypeError] if option match is not a Trema::Match object.
 *
 *   @return [FlowStatsRequest]
 *     an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_FLOW)+ OpenFlow message.
 */
static VALUE
flow_stats_request_init( VALUE self, VALUE options ) {
  buffer *message;
  Data_Get_Struct( self, buffer, message );

  subclass_stats_request_init( self, options );

  ( ( struct ofp_header * ) ( message->data ) )->xid = htonl( get_stats_request_num2uint( self, "@transaction_id" ) );

  struct ofp_stats_request *stats_request;
  stats_request = ( struct ofp_stats_request * ) message->data;
  struct ofp_flow_stats_request *flow_stats_request;
  flow_stats_request = ( struct ofp_flow_stats_request * ) stats_request->body;

  stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );

  const struct ofp_match *match;
  Data_Get_Struct( rb_iv_get( self, "@match" ), struct ofp_match, match );
  hton_match( &flow_stats_request->match, match );
  flow_stats_request->table_id = get_stats_request_table_id( self );
  flow_stats_request->out_port = htons( get_stats_request_num2uint16( self, "@out_port" ) );
  return self;
}