Class: Trema::FeaturesReply

Inherits:
Object
  • Object
show all
Defined in:
ruby/trema/features-reply.c

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ FeaturesReply

Creates a FeaturesReply message. A user would not explicitly instantiate a Trema::FeaturesReply object but would be created while parsing the OFPT_FEATURES_REPLY message.

Examples:

FeaturesReply.new(
  :datapath_id => 0xabc,
  :transaction_id => 1,
  :n_buffers => 256,
  :n_tables => 1,
  :capabilities => 135,
  :actions => 2048,
  :port => [ port1, port2, ... ]
)

Parameters:

  • options (Hash)

    the options to create a message with.

Options Hash (options):

  • :datapath_id (Number)

    datapath unique id. Subsequent commands directed to switch should embed this id.

  • :transaction_id (Number)

    a positive number lower layers match this to ensure message integrity.

  • :n_buffers (Number)

    maximum number of packets that can be buffered at once.

  • :n_tables (Number)

    number of supported tables, number could vary according to switch’s implementation.

  • :capabilities (Number)

    supported capabilities expressed as a 32-bit bitmap. Ability of a switch to respond or perform a certain function for example flow statistics, IP address lookup in APR packets.

  • :actions (Number)

    supported actions expressed as a 32-bit bitmap.

  • :port (Port)

    an array of Port objects detailing port description and function.



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'ruby/trema/features-reply.c', line 74

static VALUE
features_reply_init( VALUE self, VALUE options ) {
  buffer *buf = NULL;
  Data_Get_Struct( self, buffer, buf );
  struct ofp_switch_features *features_reply = buf->data;
  VALUE tmp = Qnil;

  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "datapath_id" ) ) );
  if ( tmp == Qnil ) {
    rb_raise( rb_eArgError, ":datapath_id is a mandatory option" );
  }
  features_reply->datapath_id = htonll( NUM2ULL( tmp ) );

  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
  if ( tmp == Qnil ) {
    tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
    if ( tmp == Qnil ) {
      rb_raise( rb_eArgError, ":transaction_id is a mandatory option" );
    }
  }
  features_reply->header.xid = htonl( ( uint32_t ) NUM2UINT( tmp ) );

  features_reply->n_buffers = 0;
  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "n_buffers" ) ) );
  if ( tmp != Qnil ) {
    features_reply->n_buffers = htonl( ( uint32_t ) NUM2UINT( tmp ) );
  }

  features_reply->n_tables = 1;
  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "n_tables" ) ) );
  if ( tmp != Qnil ) {
    features_reply->n_tables = ( uint8_t ) NUM2UINT( tmp );
  }

  features_reply->capabilities = 0;
  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "capabilities" ) ) );
  if ( tmp != Qnil ) {
    features_reply->capabilities = htonl( ( uint32_t ) NUM2UINT( tmp ) );
  }

  features_reply->actions = htonl( 1 << OFPAT_OUTPUT );
  tmp = rb_hash_aref( options, ID2SYM( rb_intern( "actions" ) ) );
  if ( tmp != Qnil ) {
    features_reply->actions = htonl( ( uint32_t ) NUM2UINT( tmp ) );
  }

  rb_iv_set( self, "@attribute", options );

  return self;
}

Instance Method Details

#actionsNumber

Supported actions expressed as a 32-bit bitmap.

Returns:

  • (Number)

    the value of actions.



197
198
199
200
# File 'ruby/trema/features-reply.c', line 197

static VALUE
features_reply_actions( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "actions" ) ) );
}

#capabilitiesNumber

Supported capabilities expressed as a 32-bit bitmap.

Returns:

  • (Number)

    the value of capabilities.



186
187
188
189
# File 'ruby/trema/features-reply.c', line 186

static VALUE
features_reply_capabilities( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "capabilities" ) ) );
}

#datapath_idNumber

Message originator identifier.

Returns:

  • (Number)

    the value of datapath_id



131
132
133
134
# File 'ruby/trema/features-reply.c', line 131

static VALUE
features_reply_datapath_id( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "datapath_id" ) ) );
}

#n_buffersNumber

Maximum number of packets that can be buffered at once.

Returns:

  • (Number)

    the value of n_buffers.



164
165
166
167
# File 'ruby/trema/features-reply.c', line 164

static VALUE
features_reply_n_buffers( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "n_buffers" ) ) );
}

#n_tablesNumber

Number of supported tables.

Returns:

  • (Number)

    the value of n_tables.



175
176
177
178
# File 'ruby/trema/features-reply.c', line 175

static VALUE
features_reply_n_tables( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "n_tables" ) ) );
}

#physical_portsArray<Port>

An array of Port objects detailing physical port description and function.

Returns:

  • (Array<Port>)

    the value of ports.



219
220
221
222
# File 'ruby/trema/features-reply.c', line 219

static VALUE
features_reply_physical_ports( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "physical_ports" ) ) );
}

#portsArray<Port>

An array of Port objects detailing port description and function.

Returns:

  • (Array<Port>)

    the value of ports.



208
209
210
211
# File 'ruby/trema/features-reply.c', line 208

static VALUE
features_reply_ports( VALUE self ) {
  return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "ports" ) ) );
}

#transaction_idNumber

Transaction ids, message sequence numbers matching requests to replies.

Returns:

  • (Number)

    the value of transaction id.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ruby/trema/features-reply.c', line 142

static VALUE
features_reply_transaction_id( VALUE self ) {
  VALUE xid = Qnil;

  xid = rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "transaction_id" ) ) );
  if ( xid != Qnil ) {
    return xid;
  }
  xid = rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "xid" ) ) );
  if ( xid != Qnil ) {
    return xid;
  }

  return Qnil;
}