trema 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ruby/trema/command/run.rb +2 -2
- data/ruby/trema/controller.c +1 -1
- data/ruby/trema/dsl/runner.rb +3 -0
- data/ruby/trema/echo.c +2 -2
- data/ruby/trema/error.c +1 -1
- data/ruby/trema/features-reply.c +4 -4
- data/ruby/trema/packet-in.c +53 -10
- data/ruby/trema/trema-ruby-utils.c +1 -1
- data/ruby/trema/util.rb +5 -0
- data/ruby/trema/vendor.c +9 -4
- data/ruby/trema/version.rb +1 -1
- data/src/lib/openflow_message.c +1 -1
- metadata +4 -4
data/ruby/trema/command/run.rb
CHANGED
@@ -35,7 +35,7 @@ module Trema
|
|
35
35
|
$use_tremashark = true
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
need_cleanup = ( not running? )
|
39
39
|
|
40
40
|
if $run_as_daemon
|
41
41
|
Trema::DSL::Runner.new( load_config ).daemonize
|
@@ -45,7 +45,7 @@ module Trema
|
|
45
45
|
rescue SystemExit
|
46
46
|
# This is OK
|
47
47
|
ensure
|
48
|
-
cleanup_current_session
|
48
|
+
cleanup_current_session if need_cleanup
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/ruby/trema/controller.c
CHANGED
@@ -488,7 +488,7 @@ controller_send_packet_out( int argc, VALUE *argv, VALUE self ) {
|
|
488
488
|
VALUE opt_data = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
|
489
489
|
if ( opt_data != Qnil ) {
|
490
490
|
Check_Type( opt_data, T_STRING );
|
491
|
-
uint16_t length = (
|
491
|
+
uint16_t length = ( uint16_t ) RSTRING_LEN( opt_data );
|
492
492
|
allocated_data = alloc_buffer_with_length( length );
|
493
493
|
memcpy( append_back_buffer( allocated_data, length ), RSTRING_PTR( opt_data ), length );
|
494
494
|
data = allocated_data;
|
data/ruby/trema/dsl/runner.rb
CHANGED
@@ -44,6 +44,9 @@ module Trema
|
|
44
44
|
|
45
45
|
|
46
46
|
def maybe_run_switch_manager
|
47
|
+
# FIXME
|
48
|
+
return if FileTest.exists? File.join( Trema.pid, "switch_manager.pid" )
|
49
|
+
|
47
50
|
switch_manager =
|
48
51
|
if @context.switch_manager and @context.apps.values.size > 0
|
49
52
|
last_app = @context.apps.values.last.name
|
data/ruby/trema/echo.c
CHANGED
@@ -61,9 +61,9 @@ echo_init( int argc, VALUE *argv, VALUE self ) {
|
|
61
61
|
VALUE user_data = rb_hash_aref( options, ID2SYM( rb_intern( "user_data" ) ) );
|
62
62
|
if ( user_data != Qnil ) {
|
63
63
|
Check_Type( user_data, T_STRING );
|
64
|
-
uint16_t length = (
|
64
|
+
uint16_t length = ( uint16_t ) RSTRING_LEN( user_data );
|
65
65
|
append_back_buffer( echo, length );
|
66
|
-
set_length( echo, length );
|
66
|
+
set_length( echo, ( uint16_t ) ( sizeof( struct ofp_header ) + length ) );
|
67
67
|
memcpy( ( char * ) echo->data + sizeof( struct ofp_header ), RSTRING_PTR( user_data ), length );
|
68
68
|
}
|
69
69
|
}
|
data/ruby/trema/error.c
CHANGED
@@ -115,7 +115,7 @@ error_init( int argc, VALUE *argv, VALUE self ) {
|
|
115
115
|
VALUE data = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
|
116
116
|
if ( data != Qnil ) {
|
117
117
|
Check_Type( data, T_STRING );
|
118
|
-
uint16_t length = (
|
118
|
+
uint16_t length = ( uint16_t ) RSTRING_LEN( data );
|
119
119
|
append_back_buffer( error, length );
|
120
120
|
( ( struct ofp_header * ) ( error->data ) )->length = htons( ( uint16_t ) ( offsetof( struct ofp_error_msg, data ) + length ) );
|
121
121
|
memcpy( ( char * ) error->data + offsetof( struct ofp_error_msg, data ), RSTRING_PTR( data ), length );
|
data/ruby/trema/features-reply.c
CHANGED
@@ -91,12 +91,12 @@ features_reply_init( VALUE self, VALUE options ) {
|
|
91
91
|
rb_raise( rb_eArgError, ":transaction_id is a mandatory option" );
|
92
92
|
}
|
93
93
|
}
|
94
|
-
features_reply->header.xid = htonl( NUM2UINT( tmp ) );
|
94
|
+
features_reply->header.xid = htonl( ( uint32_t ) NUM2UINT( tmp ) );
|
95
95
|
|
96
96
|
features_reply->n_buffers = 0;
|
97
97
|
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "n_buffers" ) ) );
|
98
98
|
if ( tmp != Qnil ) {
|
99
|
-
features_reply->n_buffers = htonl( NUM2UINT( tmp ) );
|
99
|
+
features_reply->n_buffers = htonl( ( uint32_t ) NUM2UINT( tmp ) );
|
100
100
|
}
|
101
101
|
|
102
102
|
features_reply->n_tables = 1;
|
@@ -108,13 +108,13 @@ features_reply_init( VALUE self, VALUE options ) {
|
|
108
108
|
features_reply->capabilities = 0;
|
109
109
|
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "capabilities" ) ) );
|
110
110
|
if ( tmp != Qnil ) {
|
111
|
-
features_reply->capabilities = htonl( NUM2UINT( tmp ) );
|
111
|
+
features_reply->capabilities = htonl( ( uint32_t ) NUM2UINT( tmp ) );
|
112
112
|
}
|
113
113
|
|
114
114
|
features_reply->actions = htonl( 1 << OFPAT_OUTPUT );
|
115
115
|
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "actions" ) ) );
|
116
116
|
if ( tmp != Qnil ) {
|
117
|
-
features_reply->actions = htonl( NUM2UINT( tmp ) );
|
117
|
+
features_reply->actions = htonl( ( uint32_t ) NUM2UINT( tmp ) );
|
118
118
|
}
|
119
119
|
|
120
120
|
// TODO: ports
|
data/ruby/trema/packet-in.c
CHANGED
@@ -49,25 +49,62 @@ VALUE cPacketIn;
|
|
49
49
|
}
|
50
50
|
|
51
51
|
|
52
|
+
typedef struct rb_packet_in {
|
53
|
+
packet_in packet_in;
|
54
|
+
buffer *data;
|
55
|
+
} rb_packet_in;
|
56
|
+
|
57
|
+
|
58
|
+
static void
|
59
|
+
packet_in_free( rb_packet_in *_packet_in ) {
|
60
|
+
free_buffer( _packet_in->data );
|
61
|
+
xfree( _packet_in );
|
62
|
+
}
|
63
|
+
|
64
|
+
|
52
65
|
static VALUE
|
53
66
|
packet_in_alloc( VALUE klass ) {
|
54
|
-
|
55
|
-
|
67
|
+
rb_packet_in *_packet_in = xmalloc( sizeof( rb_packet_in ) );
|
68
|
+
memset( &_packet_in->packet_in, 0, sizeof( packet_in ) );
|
69
|
+
_packet_in->data = alloc_buffer_with_length( 1 );
|
70
|
+
parse_packet( _packet_in->data );
|
71
|
+
_packet_in->packet_in.data = _packet_in->data;
|
72
|
+
return Data_Wrap_Struct( klass, 0, packet_in_free, _packet_in );
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
static VALUE
|
77
|
+
packet_in_init_copy( VALUE self, VALUE orig ) {
|
78
|
+
if ( self == orig ) {
|
79
|
+
return self;
|
80
|
+
}
|
81
|
+
|
82
|
+
rb_packet_in *self_pin, *orig_pin;
|
83
|
+
Data_Get_Struct( self, rb_packet_in, self_pin );
|
84
|
+
Data_Get_Struct( self, rb_packet_in, orig_pin );
|
85
|
+
|
86
|
+
memcpy( &self_pin->packet_in, &orig_pin->packet_in, sizeof( packet_in ) );
|
87
|
+
free_buffer( self_pin->data );
|
88
|
+
self_pin->data = duplicate_buffer( orig_pin->data );
|
89
|
+
parse_packet( self_pin->data );
|
90
|
+
self_pin->packet_in.data = self_pin->data;
|
91
|
+
|
92
|
+
return self;
|
56
93
|
}
|
57
94
|
|
58
95
|
|
59
96
|
static packet_in *
|
60
97
|
get_packet_in( VALUE self ) {
|
61
|
-
|
62
|
-
Data_Get_Struct( self,
|
63
|
-
return cpacket;
|
98
|
+
rb_packet_in *cpacket;
|
99
|
+
Data_Get_Struct( self, rb_packet_in, cpacket );
|
100
|
+
return &cpacket->packet_in;
|
64
101
|
}
|
65
102
|
|
66
103
|
|
67
104
|
static packet_info *
|
68
105
|
get_packet_in_info( VALUE self ) {
|
69
|
-
|
70
|
-
Data_Get_Struct( self,
|
106
|
+
rb_packet_in *cpacket;
|
107
|
+
Data_Get_Struct( self, rb_packet_in, cpacket );
|
71
108
|
return ( packet_info * ) cpacket->data->user_data;
|
72
109
|
}
|
73
110
|
|
@@ -1046,6 +1083,8 @@ Init_packet_in() {
|
|
1046
1083
|
cPacketIn = rb_define_class_under( mTrema, "PacketIn", rb_cObject );
|
1047
1084
|
rb_define_alloc_func( cPacketIn, packet_in_alloc );
|
1048
1085
|
|
1086
|
+
rb_define_method( cPacketIn, "initialize_copy", packet_in_init_copy, 1 );
|
1087
|
+
|
1049
1088
|
rb_define_method( cPacketIn, "datapath_id", packet_in_datapath_id, 0 );
|
1050
1089
|
rb_define_method( cPacketIn, "transaction_id", packet_in_transaction_id, 0 );
|
1051
1090
|
rb_define_method( cPacketIn, "buffer_id", packet_in_buffer_id, 0 );
|
@@ -1142,9 +1181,13 @@ handle_packet_in( uint64_t datapath_id, packet_in message ) {
|
|
1142
1181
|
}
|
1143
1182
|
|
1144
1183
|
VALUE r_message = rb_funcall( cPacketIn, rb_intern( "new" ), 0 );
|
1145
|
-
|
1146
|
-
Data_Get_Struct( r_message,
|
1147
|
-
memcpy( tmp, &message, sizeof( packet_in ) );
|
1184
|
+
rb_packet_in *tmp = NULL;
|
1185
|
+
Data_Get_Struct( r_message, rb_packet_in, tmp );
|
1186
|
+
memcpy( &tmp->packet_in, &message, sizeof( packet_in ) );
|
1187
|
+
free_buffer( tmp->data );
|
1188
|
+
tmp->data = duplicate_buffer( message.data );
|
1189
|
+
parse_packet( tmp->data );
|
1190
|
+
tmp->packet_in.data = tmp->data;
|
1148
1191
|
|
1149
1192
|
rb_funcall( controller, rb_intern( "packet_in" ), 2, ULL2NUM( datapath_id ), r_message );
|
1150
1193
|
}
|
@@ -37,7 +37,7 @@ get_xid( VALUE self ) {
|
|
37
37
|
|
38
38
|
void
|
39
39
|
set_length( const buffer *openflow_message, uint16_t length ) {
|
40
|
-
( ( struct ofp_header * ) ( openflow_message->data ) )->length = htons(
|
40
|
+
( ( struct ofp_header * ) ( openflow_message->data ) )->length = htons( length );
|
41
41
|
}
|
42
42
|
|
43
43
|
|
data/ruby/trema/util.rb
CHANGED
data/ruby/trema/vendor.c
CHANGED
@@ -110,7 +110,7 @@ vendor_init( int argc, VALUE *argv, VALUE self ) {
|
|
110
110
|
Check_Type( tmp, T_ARRAY );
|
111
111
|
uint16_t length = ( uint16_t ) RARRAY_LEN( tmp );
|
112
112
|
append_back_buffer( vendor, length );
|
113
|
-
set_length( vendor, length );
|
113
|
+
set_length( vendor, ( uint16_t ) ( sizeof( struct ofp_vendor_header ) + length ) );
|
114
114
|
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
|
115
115
|
int i;
|
116
116
|
for ( i = 0; i < length; i++ ) {
|
@@ -165,7 +165,7 @@ vendor_data( VALUE self ) {
|
|
165
165
|
if ( length > 0 ) {
|
166
166
|
VALUE data_array = rb_ary_new2( length );
|
167
167
|
uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
|
168
|
-
|
168
|
+
long i;
|
169
169
|
for ( i = 0; i < length; i++ ) {
|
170
170
|
rb_ary_push( data_array, INT2FIX( data[ i ] ) );
|
171
171
|
}
|
@@ -205,8 +205,13 @@ handle_vendor(
|
|
205
205
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
|
206
206
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "vendor" ) ), UINT2NUM( vendor ) );
|
207
207
|
|
208
|
-
if ( data->length ) {
|
209
|
-
|
208
|
+
if ( data != NULL && data->length > 0 ) {
|
209
|
+
VALUE data_array = rb_ary_new2( ( long ) data->length );
|
210
|
+
long i;
|
211
|
+
for ( i = 0; i < data->length; i++ ) {
|
212
|
+
rb_ary_push( data_array, INT2FIX( ( ( uint8_t * ) data->data)[ i ] ) );
|
213
|
+
}
|
214
|
+
rb_hash_aset( attributes, ID2SYM( rb_intern( "data" ) ), data_array );
|
210
215
|
}
|
211
216
|
VALUE vendor_r = rb_funcall( cVendor, rb_intern( "new" ), 1, attributes );
|
212
217
|
rb_funcall( controller, rb_intern( "vendor" ), 2, ULL2NUM( datapath_id ), vendor_r );
|
data/ruby/trema/version.rb
CHANGED
data/src/lib/openflow_message.c
CHANGED
@@ -2752,7 +2752,7 @@ validate_port_stats_reply( const buffer *message ) {
|
|
2752
2752
|
assert( message != NULL );
|
2753
2753
|
|
2754
2754
|
ret = validate_header( message, OFPT_STATS_REPLY,
|
2755
|
-
offsetof( struct ofp_stats_reply, body )
|
2755
|
+
offsetof( struct ofp_stats_reply, body ),
|
2756
2756
|
UINT16_MAX );
|
2757
2757
|
if ( ret < 0 ) {
|
2758
2758
|
return ret;
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yasuhito Takamiya
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: .
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-12-
|
18
|
+
date: 2012-12-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|