예제 #1
0
/*
 * A {QueueStatsRequest} object instance to request queue statistics.
 * Request queue statistics.
 *
 * @overload initialize(options={})
 *
 *   @example
 *     QueueStatsRequest.new(
 *       :port_no => port_no,
 *       :queue_id => queue_id
 *     )
 *
 *   @param [Hash] options
 *     the options to create a message with.
 *
 *   @option options [Number] :port_no
 *     request statistics for a specific port if specified, otherwise set port_no
 *     to +OFPP_ALL+ for all ports.
 *
 *   @option options [Number] :queue_id
 *     request statistics for a specific queue_id or set queue_id to +OFPQ_ALL+
 *     for all queues.
 *
 *   @return [QueueStatsRequest]
 *     an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_QUEUE)+ OpenFlow
 *     message.
 */
static VALUE
queue_stats_request_init( int argc, VALUE *argv, VALUE self ) {
  VALUE options;
  if ( !rb_scan_args( argc, argv, "01", &options )) {
    options = rb_hash_new();
  }
  rb_call_super( 1, &options );
  VALUE port_no = rb_hash_aref( options, ID2SYM( rb_intern( "port_no" ) ) );
  if ( port_no == Qnil ) {
    port_no = UINT2NUM( OFPP_ALL );
  }
  rb_iv_set( self, "@port_no", port_no );
  VALUE queue_id = rb_hash_aref( options, ID2SYM( rb_intern( "queue_id" ) ) );
  if ( queue_id == Qnil ) {
    queue_id = UINT2NUM( OFPQ_ALL );
  }
  rb_iv_set( self, "@queue_id", queue_id );


  buffer *message;
  Data_Get_Struct( self, buffer, message );
  ( ( 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;
  stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );

  stats_request = ( struct ofp_stats_request * ) message->data;
  struct ofp_queue_stats_request *queue_stats_request;
  queue_stats_request = ( struct ofp_queue_stats_request * ) stats_request->body;
  queue_stats_request->port_no = htons( get_stats_request_num2uint16( self, "@port_no" ) );
  queue_stats_request->queue_id = htonl( get_stats_request_num2uint( self, "@queue_id" ) );
  return self;
}
예제 #2
0
/*
 * A {VendorStatsRequest} object instance to request vendor statistics.
 * Request vendor specific statistics.
 *
 * @overload initialize(options={})
 *
 *   @example
 *     VendorStatsRequeset.new(
 *       :vendor_id => vendor_id
 *     )
 *
 *   @param [Hash] options
 *     the options to create a message with.
 *
 *   @option options [Number] :vendor_id
 *     request statistics for a specific vendor_id, otherwise set vendor_id
 *     to a default value of 0x00004cff.
 *
 *   @return [VendorStatsRequest]
 *     an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_VENDOR)+ openflow
 *     message.
 */
static VALUE
vendor_stats_request_init( int argc, VALUE *argv, VALUE self ) {
  VALUE options;

  if ( !rb_scan_args( argc, argv, "01", &options )) {
    options = rb_hash_new();
  }
  rb_call_super( 1, &options );
  VALUE vendor_id = rb_hash_aref( options, ID2SYM( rb_intern( "vendor_id" ) ) );
  if ( vendor_id == Qnil ) {
    vendor_id = UINT2NUM( 0x00004cff );
  }
  rb_iv_set( self, "@vendor_id", vendor_id );
  buffer *message;
  Data_Get_Struct( self, buffer, message );
  ( ( 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;
  stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
  uint32_t *vendor;
  vendor = ( uint32_t * ) stats_request->body;
  *vendor = htonl( get_stats_request_num2uint( self, "@vendor_id" ) );
  return self;
}
예제 #3
0
/*
 * A {TableStatsRequest} object instance to request table statistics.
 * Request table statistics. The table stats. request does not contain any data
 * in the body.
 *
 * @overload initialize(options={})
 *
 *   @example 
 *     TableStatsRequest.new(
 *       :transaction_id => 1234
 *     )
 *
 *   @param [Hash] options
 *     the options to create a message with.
 *
 *   @option options [Number] :transaction_id
 *     set the transaction_id as specified or auto-generate it.
 *
 *   @return [TableStatsRequest]
 *     an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_TABLE)+ openflow
 *     message.
 */
static VALUE
table_stats_request_init( int argc, VALUE *argv, VALUE self ) {
  VALUE options;
  if ( !rb_scan_args( argc, argv, "01", &options )) {
    options = rb_hash_new();
  }
  rb_call_super( 1, &options );
  buffer *message;
  Data_Get_Struct( self, buffer, message );
  ( ( 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;
  stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
  return self;
}
예제 #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;
}
예제 #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;
}