Class: Trema::Error
- Inherits:
-
Object
- Object
- Trema::Error
- Defined in:
- ruby/trema/error.c
Instance Method Summary collapse
-
#code ⇒ Number
Reason of the failed type error.
-
#data ⇒ String?
An optional user data payload field, possibly detailed explanation of the error.
-
#error_type ⇒ Number
Indicates the command or action that failed.
- #initialize(options) ⇒ Error constructor
-
#transaction_id ⇒ Number
Transaction ids, message sequence numbers matching requests to replies.
Constructor Details
#initialize(options) ⇒ Error
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ruby/trema/error.c', line 72
static VALUE
error_init( int argc, VALUE *argv, VALUE self ) {
buffer *error = NULL;
Data_Get_Struct( self, buffer, error );
VALUE options;
if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
Check_Type( options, T_HASH );
VALUE tmp = Qnil;
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "type" ) ) );
if ( tmp != Qnil ) {
( ( struct ofp_error_msg * ) error->data )->type = htons( ( uint16_t ) NUM2UINT( tmp ) );
}
else {
rb_raise( rb_eArgError, "Type is a mandatory option" );
}
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "code" ) ) );
if ( tmp != Qnil ) {
( ( struct ofp_error_msg * ) error->data )->code = htons( ( uint16_t ) NUM2UINT( tmp ) );
}
else {
rb_raise( rb_eArgError, "Code is a mandatory option" );
}
VALUE xid = Qnil;
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
if ( tmp != Qnil ) {
xid = tmp;
}
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
if ( tmp != Qnil ) {
xid = tmp;
}
if ( xid != Qnil ) {
validate_xid( xid );
set_xid( error, ( uint32_t ) NUM2UINT( xid ) );
}
else {
set_xid( error, get_transaction_id() );
}
VALUE data = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
if ( data != Qnil ) {
Check_Type( data, T_STRING );
uint16_t length = ( uint16_t ) RSTRING_LEN( data );
append_back_buffer( error, length );
( ( struct ofp_header * ) ( error->data ) )->length = htons( ( uint16_t ) ( offsetof( struct ofp_error_msg, data ) + length ) );
memcpy( ( char * ) error->data + offsetof( struct ofp_error_msg, data ), RSTRING_PTR( data ), length );
}
}
else {
rb_raise( rb_eArgError, "Type and code are mandatory options" );
}
return self;
}
|
Instance Method Details
#code ⇒ Number
Reason of the failed type error.
189 190 191 192 193 |
# File 'ruby/trema/error.c', line 189
static VALUE
error_code( VALUE self ) {
struct ofp_error_msg *error = get_error( self );
return UINT2NUM( ntohs( error->code ) );
}
|
#data ⇒ String?
An optional user data payload field, possibly detailed explanation of the error.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'ruby/trema/error.c', line 159
static VALUE
error_data( VALUE self ) {
struct ofp_error_msg *error = get_error( self );
long length = ( long ) ( ntohs( error->header.length ) - sizeof( struct ofp_error_msg ) );
if ( length > 0 ) {
return rb_str_new( ( char * ) error->data, length );
}
else {
return Qnil;
}
}
|
#error_type ⇒ Number
Indicates the command or action that failed.
177 178 179 180 181 |
# File 'ruby/trema/error.c', line 177
static VALUE
error_type( VALUE self ) {
struct ofp_error_msg *error = get_error( self );
return UINT2NUM( ntohs( error->type ) );
}
|
#transaction_id ⇒ Number
Transaction ids, message sequence numbers matching requests to replies.
145 146 147 148 149 150 |
# File 'ruby/trema/error.c', line 145
static VALUE
error_transaction_id( VALUE self ) {
struct ofp_error_msg *error = get_error( self );
uint32_t xid = ntohl( error->header.xid );
return UINT2NUM( xid );
}
|