Class: Trema::SetConfig

Inherits:
Object
  • Object
show all
Defined in:
ruby/trema/set-config.c

Constant Summary collapse

OFPC_FRAG_NORMAL =
INT2NUM( OFPC_FRAG_NORMAL )
OFPC_FRAG_DROP =
INT2NUM( OFPC_FRAG_DROP )
OFPC_FRAG_REASM =
INT2NUM( OFPC_FRAG_REASM )
OFPC_FRAG_MASK =
INT2NUM( OFPC_FRAG_MASK )

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SetConfig

A Trema::SetConfig object instance represents a set of attributes which allow tuning the behavior of the openflow protocol in some way.

Returns an object that encapsulates the OFPT_SET_CONFIG OpenFlow message.

Examples:

SetConfig.new
SetConfig.new(
  :flags => OFPC_FRAG_DROP,
  :miss_send_len => 256
)
SetConfig.new(
  :flags => OFPC_FRAG_DROP,
  :miss_send_len => 256,
  :transaction_id => 123
)

Parameters:

  • options (Hash) (defaults to: {})

    the options to create a message with.

Options Hash (options):

  • :flags (Number)

    flags defaults to 0 (no special handling for IP fragments) if not specified.

  • :miss_send_len (Number)

    miss_send_len defaults to 128 bytes if not specified.

  • :transaction_id (Number)

    transaction_id auto-generated if not specified.

Raises:

  • (ArgumentError)

    if transaction id is not an unsigned 32-bit integer.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'ruby/trema/set-config.c', line 70

static VALUE
set_config_init( int argc, VALUE *argv, VALUE self ) {
  buffer *set_config;
  Data_Get_Struct( self, buffer, set_config );

  uint32_t xid = get_transaction_id();
  uint16_t flags =  OFPC_FRAG_NORMAL;
  uint16_t miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
  VALUE options;

  if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
    Check_Type( options, T_HASH );
    VALUE flags_ruby;
    if ( ( flags_ruby = rb_hash_aref( options, ID2SYM( rb_intern( "flags" ) ) ) ) != Qnil ) {
      flags = ( uint16_t ) NUM2UINT( flags_ruby );
    }
    VALUE miss_send_len_ruby;
    if ( ( miss_send_len_ruby = rb_hash_aref( options, ID2SYM( rb_intern( "miss_send_len" ) ) ) ) != Qnil ) {
      miss_send_len = ( uint16_t ) NUM2UINT( miss_send_len_ruby );
    }
    VALUE xid_ruby;
    if ( ( xid_ruby = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) ) ) != Qnil ) {
      if ( rb_funcall( xid_ruby, rb_intern( "unsigned_32bit?" ), 0 ) == Qfalse ) {
        rb_raise( rb_eArgError, "Transaction ID must be an unsigned 32-bit integer" );
      }
      xid = ( uint32_t ) NUM2UINT( xid_ruby );
    }
  }
  ( ( struct ofp_header * ) ( set_config->data ) )->xid = htonl( xid );
  ( ( struct ofp_switch_config * ) ( set_config->data ) )->flags = htons( flags );
  ( ( struct ofp_switch_config * ) ( set_config->data ) )->miss_send_len = htons( miss_send_len );
  return self;
}

Instance Method Details

#flagsNumber

A 2-bit value that can be set to indicate no special handling, drop or reassemble IP fragments.

Returns:

  • (Number)

    the value of flags.



125
126
127
128
129
130
131
# File 'ruby/trema/set-config.c', line 125

static VALUE
set_config_flags( VALUE self ) {
  buffer *set_config;
  Data_Get_Struct( self, buffer, set_config );
  uint16_t flags = ntohs( ( ( struct ofp_switch_config * ) ( set_config->data ) )->flags );
  return UINT2NUM( flags );
}

#miss_send_lenNumber

The maximum number of bytes to send on flow table miss or flow destined to controller.

Returns:

  • (Number)

    the value of miss_send_len.



139
140
141
142
143
144
145
# File 'ruby/trema/set-config.c', line 139

static VALUE
set_config_miss_send_len( VALUE self ) {
  buffer *set_config;
  Data_Get_Struct( self, buffer, set_config );
  uint16_t miss_send_len = ntohs( ( ( struct ofp_switch_config * ) ( set_config->data ) )->miss_send_len );
  return UINT2NUM( miss_send_len );
}

#transaction_idNumber

Transaction ids, message sequence numbers matching requests to replies.

Returns:

  • (Number)

    the value of transaction id.



110
111
112
113
114
115
116
# File 'ruby/trema/set-config.c', line 110

static VALUE
set_config_transaction_id( VALUE self ) {
  buffer *set_config;
  Data_Get_Struct( self, buffer, set_config );
  uint32_t xid = ntohl( ( ( struct ofp_header * ) ( set_config->data ) )->xid );
  return UINT2NUM( xid );
}