Class: Trema::Vendor
- Inherits:
-
Object
- Object
- Object
- Trema::Vendor
- Defined in:
- ruby/trema/vendor.c
Instance Method Summary (collapse)
-
- (Array?) data
Vendor specific data payload.
-
- (Vendor) initialize
constructor
Creates a Vendor Request message.
-
- (Number) transaction_id
Transaction ids, message sequence numbers matching requests to replies.
-
- (Number) vendor
A 32-bit value that uniquely identifies the vendor.
Constructor Details
- (Vendor) initialize - (Vendor) initialize(options)
Creates a Vendor Request message. This message can be used to facilitate sending of vendor-defined arbitrary data.
67 68 69 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ruby/trema/vendor.c', line 67
static VALUE
vendor_init( int argc, VALUE *argv, VALUE self ) {
buffer *vendor = NULL;
Data_Get_Struct( self, buffer, vendor );
VALUE options = Qnil;
if ( rb_scan_args( argc, argv, "01", &options ) == 0 ) {
set_xid( vendor, get_transaction_id() );
}
else {
if ( options == Qnil ) {
set_xid( vendor, get_transaction_id() );
}
else {
if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
Check_Type( options, T_HASH );
VALUE tmp = Qnil;
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( vendor, ( uint32_t ) NUM2UINT( xid ) );
}
else {
set_xid( vendor, get_transaction_id() );
}
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "vendor" ) ) );
if ( tmp != Qnil ) {
( ( struct ofp_vendor_header * ) ( vendor->data ) )->vendor = htonl( ( uint32_t ) NUM2UINT( tmp ) );
}
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
if ( tmp != Qnil ) {
Check_Type( tmp, T_ARRAY );
uint16_t length = ( uint16_t ) RARRAY_LEN( tmp );
append_back_buffer( vendor, length );
set_length( vendor, ( uint16_t ) ( sizeof( struct ofp_vendor_header ) + length ) );
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
int i;
for ( i = 0; i < length; i++ ) {
data[ i ] = ( uint8_t ) FIX2INT( RARRAY_PTR( tmp )[ i ] );
}
}
}
}
}
return self;
}
|
Instance Method Details
- (Array?) data
Vendor specific data payload.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'ruby/trema/vendor.c', line 159
static VALUE
vendor_data( VALUE self ) {
buffer *vendor;
Data_Get_Struct( self, buffer, vendor );
uint16_t length = get_length( vendor );
if ( length > 0 ) {
VALUE data_array = rb_ary_new2( length );
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
long i;
for ( i = 0; i < length; i++ ) {
rb_ary_push( data_array, INT2FIX( data[ i ] ) );
}
return data_array;
}
return Qnil;
}
|
- (Number) transaction_id
Transaction ids, message sequence numbers matching requests to replies.
133 134 135 136 |
# File 'ruby/trema/vendor.c', line 133 static VALUE vendor_transaction_id( VALUE self ) { return get_xid( self ); } |
- (Number) vendor
A 32-bit value that uniquely identifies the vendor.
144 145 146 147 148 149 150 |
# File 'ruby/trema/vendor.c', line 144
static VALUE
vendor_vendor( VALUE self ) {
buffer *vendor_message;
Data_Get_Struct( self, buffer, vendor_message );
uint32_t vendor = ntohl( ( ( struct ofp_vendor_header * ) ( vendor_message->data ) )->vendor );
return UINT2NUM( vendor );
}
|