trema 0.2.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/.travis.yml +13 -0
- data/.yardopts +4 -0
- data/Gemfile +2 -3
- data/README.md +43 -97
- data/Rakefile +60 -4
- data/Rantfile +11 -10
- data/cruise.rb +4 -6
- data/features/example.packetin_filter_config.feature +10 -10
- data/features/example.switch_monitor.feature +14 -2
- data/features/step_definitions/kill_steps.rb +2 -2
- data/features/step_definitions/{off_steps.rb → killall_steps.rb} +2 -2
- data/features/step_definitions/misc_steps.rb +1 -1
- data/features/step_definitions/up_steps.rb +30 -0
- data/features/trema.feature +1 -0
- data/features/trema.run.feature +1 -0
- data/locale/README.ja.md +19 -0
- data/locale/ja/yard.po +3762 -0
- data/locale/yard.pot +3740 -0
- data/ruby/extconf.rb +4 -1
- data/ruby/trema/action-common.c +3 -17
- data/ruby/trema/action-common.h +3 -7
- data/ruby/trema/action.rb +33 -0
- data/ruby/trema/app.rb +1 -1
- data/ruby/trema/barrier-request.c +1 -0
- data/ruby/trema/command/run.rb +13 -9
- data/ruby/trema/command/usage.rb +1 -0
- data/ruby/trema/command/version.rb +1 -1
- data/ruby/trema/controller.c +133 -50
- data/ruby/trema/controller.rb +2 -2
- data/ruby/trema/desc-stats-reply.rb +77 -0
- data/ruby/trema/dsl/configuration.rb +3 -14
- data/ruby/trema/dsl/rswitch.rb +47 -0
- data/ruby/trema/dsl/runner.rb +4 -1
- data/ruby/trema/dsl/syntax.rb +11 -8
- data/ruby/trema/echo-reply.c +59 -45
- data/ruby/trema/echo-reply.h +1 -3
- data/ruby/trema/echo-request.c +49 -71
- data/ruby/trema/echo-request.h +0 -2
- data/ruby/trema/echo.c +99 -0
- data/ruby/trema/{action-enqueue.h → echo.h} +6 -7
- data/ruby/trema/enqueue.rb +87 -0
- data/ruby/trema/error.c +109 -104
- data/ruby/trema/error.h +0 -2
- data/ruby/trema/features-reply.c +89 -35
- data/ruby/trema/features-reply.h +0 -6
- data/ruby/trema/features-request.c +63 -37
- data/ruby/trema/features-request.h +0 -2
- data/ruby/trema/flow-mod.c +149 -0
- data/ruby/trema/{action-output.h → flow-mod.h} +6 -6
- data/ruby/trema/get-config-request.c +1 -0
- data/ruby/trema/hardware-switch.rb +88 -0
- data/ruby/trema/hello.c +55 -31
- data/ruby/trema/hello.h +0 -2
- data/ruby/trema/ip.rb +12 -2
- data/ruby/trema/logger.rb +29 -0
- data/ruby/trema/mac.rb +57 -36
- data/ruby/trema/match.c +7 -9
- data/ruby/trema/monkey-patch/integer/ranges.rb +0 -2
- data/ruby/trema/network-component.rb +1 -1
- data/ruby/trema/open-vswitch.rb +2 -2
- data/ruby/trema/openflow-switch.rb +3 -54
- data/ruby/trema/{packet_in.c → packet-in.c} +262 -175
- data/ruby/trema/{packet_in.h → packet-in.h} +0 -2
- data/ruby/trema/packet-queue.rb +4 -3
- data/ruby/trema/port-mod.c +8 -9
- data/ruby/trema/port-status-add.rb +60 -0
- data/ruby/trema/port-status-delete.rb +60 -0
- data/ruby/trema/port-status-modify.rb +60 -0
- data/ruby/trema/port-status.c +48 -15
- data/ruby/trema/port-status.h +6 -8
- data/ruby/trema/port.c +63 -8
- data/ruby/trema/queue-get-config-request.c +1 -0
- data/ruby/trema/ruby-switch.rb +62 -0
- data/ruby/trema/send-out-port.rb +97 -0
- data/ruby/trema/set-config.c +1 -0
- data/ruby/trema/set-eth-addr.rb +45 -0
- data/ruby/trema/set-eth-dst-addr.rb +54 -0
- data/ruby/trema/set-eth-src-addr.rb +54 -0
- data/ruby/trema/set-ip-addr.rb +47 -0
- data/ruby/trema/set-ip-dst-addr.rb +53 -0
- data/ruby/trema/set-ip-src-addr.rb +52 -0
- data/ruby/trema/set-ip-tos.rb +63 -0
- data/ruby/trema/set-transport-dst-port.rb +53 -0
- data/ruby/trema/set-transport-port.rb +52 -0
- data/ruby/trema/set-transport-src-port.rb +54 -0
- data/ruby/trema/set-vlan-priority.rb +65 -0
- data/ruby/trema/set-vlan-vid.rb +64 -0
- data/ruby/trema/shell/down.rb +1 -1
- data/ruby/trema/shell/link.rb +4 -4
- data/ruby/trema/shell/run.rb +8 -6
- data/ruby/trema/shell/up.rb +3 -3
- data/ruby/trema/stats-reply.c +27 -2
- data/ruby/trema/stats-request.c +64 -23
- data/ruby/trema/strip-vlan-header.rb +41 -0
- data/ruby/trema/switch.c +196 -0
- data/ruby/trema/{action-vendor.h → switch.h} +5 -7
- data/ruby/trema/switch.rb +28 -9
- data/ruby/trema/trema-ruby-utils.c +66 -0
- data/ruby/trema/{action-set-dl-src.h → trema-ruby-utils.h} +9 -11
- data/ruby/trema/trema.c +61 -61
- data/ruby/trema/vendor-action.rb +73 -0
- data/ruby/trema/vendor.c +121 -52
- data/ruby/trema/vendor.h +6 -10
- data/ruby/trema/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/action.rb +52 -0
- data/spec/support/mandatory-option.rb +56 -0
- data/spec/support/openflow-message.rb +91 -7
- data/spec/support/port-status.rb +38 -0
- data/spec/trema/controller_spec.rb +0 -26
- data/spec/trema/dsl/configuration_spec.rb +3 -3
- data/spec/trema/dsl/runner_spec.rb +12 -32
- data/spec/trema/dsl/syntax_spec.rb +2 -11
- data/spec/trema/echo-reply_spec.rb +49 -14
- data/spec/trema/echo-request_spec.rb +86 -34
- data/spec/trema/enqueue_spec.rb +76 -0
- data/spec/trema/error_spec.rb +43 -58
- data/spec/trema/features-reply_spec.rb +58 -24
- data/spec/trema/features-request_spec.rb +54 -28
- data/spec/trema/flow-mod_spec.rb +99 -0
- data/spec/trema/{openflow-switch_spec.rb → hardware-switch_spec.rb} +3 -3
- data/spec/trema/hello_spec.rb +28 -14
- data/spec/trema/ip_spec.rb +54 -0
- data/spec/trema/mac_spec.rb +49 -64
- data/spec/trema/match_spec.rb +1 -1
- data/spec/trema/open-vswitch_spec.rb +7 -7
- data/spec/trema/packet-in_spec.rb +73 -16
- data/spec/trema/port-status-add_spec.rb +32 -0
- data/spec/trema/port-status-delete_spec.rb +32 -0
- data/spec/trema/port-status-modify_spec.rb +71 -0
- data/spec/trema/port-status_spec.rb +5 -76
- data/spec/trema/{action-output_spec.rb → send-out-port_spec.rb} +20 -47
- data/spec/trema/set-eth-dst-addr_spec.rb +75 -0
- data/spec/trema/set-eth-src-addr_spec.rb +72 -0
- data/spec/trema/set-ip-dst-addr_spec.rb +58 -0
- data/spec/trema/set-ip-src-addr_spec.rb +58 -0
- data/spec/trema/set-ip-tos_spec.rb +65 -0
- data/spec/trema/set-transport-dst-port_spec.rb +65 -0
- data/spec/trema/set-transport-src-port_spec.rb +65 -0
- data/spec/trema/set-vlan-priority_spec.rb +65 -0
- data/spec/trema/set-vlan-vid_spec.rb +65 -0
- data/spec/trema/shell/vhost_spec.rb +4 -1
- data/spec/trema/shell/vswitch_spec.rb +11 -11
- data/spec/trema/stats-reply_spec.rb +59 -13
- data/spec/trema/stats-request_spec.rb +6 -0
- data/spec/trema/{action-strip-vlan_spec.rb → strip-vlan-header_spec.rb} +3 -17
- data/spec/trema/switch-daemon_spec.rb +39 -0
- data/spec/trema/vendor-action_spec.rb +81 -0
- data/spec/trema/vendor_spec.rb +76 -0
- data/spec/trema_spec.rb +56 -0
- data/src/examples/dumper/dumper.c +0 -8
- data/src/examples/dumper/dumper.rb +52 -52
- data/src/examples/hello_trema/hello_trema.c +0 -2
- data/src/examples/learning_switch/learning-switch.rb +3 -3
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +3 -3
- data/src/examples/openflow_message/features-request.rb +3 -3
- data/src/examples/packetin_filter_config/utils.c +4 -4
- data/src/examples/repeater_hub/repeater-hub.rb +3 -3
- data/src/examples/switch_info/switch_info.rb +2 -2
- data/src/examples/switch_monitor/switch_monitor.c +1 -1
- data/src/examples/traffic_monitor/traffic-monitor.rb +3 -3
- data/src/lib/arp.h +4 -1
- data/src/lib/chibach.c +391 -0
- data/src/lib/chibach.h +71 -0
- data/src/lib/chibach_private.c +170 -0
- data/src/lib/chibach_private.h +52 -0
- data/src/lib/ether.c +2 -1
- data/src/lib/ether.h +0 -1
- data/src/lib/ipv4.h +13 -14
- data/{ruby/trema/action-set-nw-src.h → src/lib/ipv6.h} +13 -9
- data/src/lib/log.c +161 -58
- data/src/lib/log.h +11 -16
- data/src/lib/messenger.c +36 -1
- data/src/lib/messenger.h +1 -0
- data/src/lib/openflow_application_interface.c +128 -28
- data/src/lib/openflow_application_interface.h +31 -6
- data/src/lib/openflow_message.c +2 -1
- data/src/lib/openflow_service_interface.h +1 -0
- data/src/lib/openflow_switch_interface.c +1380 -0
- data/src/lib/openflow_switch_interface.h +264 -0
- data/src/lib/packet_info.c +94 -11
- data/src/lib/packet_info.h +22 -3
- data/src/lib/packet_parser.c +38 -2
- data/src/lib/secure_channel.c +498 -0
- data/{ruby/trema/vendor-request.h → src/lib/secure_channel.h} +11 -10
- data/src/lib/tcp.h +0 -3
- data/src/lib/trema.c +38 -5
- data/{ruby/trema/action-set-nw-dst.h → src/lib/trema.hpp} +17 -8
- data/src/lib/trema_wrapper.c +5 -0
- data/src/lib/trema_wrapper.h +4 -0
- data/src/lib/utility.c +93 -4
- data/src/lib/utility.h +1 -0
- data/src/lib/wrapper.c +30 -7
- data/src/lib/wrapper.h +2 -0
- data/src/switch_manager/ofpmsg_recv.c +44 -30
- data/src/switch_manager/ofpmsg_send.c +40 -1
- data/src/switch_manager/ofpmsg_send.h +2 -0
- data/src/switch_manager/switch.c +153 -8
- data/src/switch_manager/switch.h +1 -0
- data/src/switch_manager/switchinfo.h +5 -0
- data/src/tremashark/README +2 -2
- data/src/tremashark/plugin/packet-trema/packet-trema.c +1 -0
- data/trema +1 -1
- data/unittests/lib/log_test.c +158 -34
- data/unittests/lib/openflow_application_interface_test.c +252 -69
- data/unittests/lib/openflow_message_test.c +3 -1
- data/unittests/lib/packet_parser_test.c +60 -15
- data/unittests/lib/test_packets/icmp6_echo_rep.cap +0 -0
- data/unittests/lib/test_packets/icmp6_echo_req.cap +0 -0
- data/unittests/lib/trema_test.c +2 -0
- data/unittests/lib/utility_test.c +65 -2
- data/unittests/lib/wrapper_test.c +29 -0
- data/vendor/{README → README.md} +2 -12
- data/vendor/packet-openflow.diff +13 -0
- metadata +86 -53
- data/GPL2 +0 -339
- data/ruby/trema/action-enqueue.c +0 -161
- data/ruby/trema/action-output.c +0 -169
- data/ruby/trema/action-set-dl-dst.c +0 -131
- data/ruby/trema/action-set-dl-dst.h +0 -44
- data/ruby/trema/action-set-dl-src.c +0 -131
- data/ruby/trema/action-set-nw-dst.c +0 -135
- data/ruby/trema/action-set-nw-src.c +0 -140
- data/ruby/trema/action-set-nw-tos.c +0 -124
- data/ruby/trema/action-set-nw-tos.h +0 -42
- data/ruby/trema/action-set-tp-dst.c +0 -122
- data/ruby/trema/action-set-tp-dst.h +0 -42
- data/ruby/trema/action-set-tp-src.c +0 -124
- data/ruby/trema/action-set-tp-src.h +0 -42
- data/ruby/trema/action-set-vlan-pcp.c +0 -128
- data/ruby/trema/action-set-vlan-pcp.h +0 -42
- data/ruby/trema/action-set-vlan-vid.c +0 -125
- data/ruby/trema/action-set-vlan-vid.h +0 -42
- data/ruby/trema/action-strip-vlan.c +0 -81
- data/ruby/trema/action-strip-vlan.h +0 -42
- data/ruby/trema/action-vendor.c +0 -121
- data/ruby/trema/vendor-request.c +0 -193
- data/spec/trema/action-enqueue_spec.rb +0 -100
- data/spec/trema/action-set-dl-dst_spec.rb +0 -95
- data/spec/trema/action-set-dl-src_spec.rb +0 -92
- data/spec/trema/action-set-nw-dst_spec.rb +0 -96
- data/spec/trema/action-set-nw-src_spec.rb +0 -97
- data/spec/trema/action-set-nw-tos_spec.rb +0 -88
- data/spec/trema/action-set-tp-dst_spec.rb +0 -88
- data/spec/trema/action-set-tp-src_spec.rb +0 -88
- data/spec/trema/action-set-vlan-pcp_spec.rb +0 -91
- data/spec/trema/action-set-vlan-vid_spec.rb +0 -91
- data/spec/trema/action-vendor_spec.rb +0 -90
- data/spec/trema/vendor-request_spec.rb +0 -79
data/ruby/trema/stats-request.c
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
|
25
25
|
extern VALUE mTrema;
|
26
26
|
VALUE cStatsRequest;
|
27
|
+
VALUE cDescStatsRequest;
|
27
28
|
VALUE cFlowStatsRequest;
|
28
29
|
VALUE cAggregateStatsRequest;
|
29
30
|
VALUE cTableStatsRequest;
|
@@ -119,6 +120,13 @@ subclass_stats_request_init( VALUE self, VALUE options ) {
|
|
119
120
|
}
|
120
121
|
|
121
122
|
|
123
|
+
static VALUE
|
124
|
+
desc_stats_request_alloc( VALUE klass ) {
|
125
|
+
buffer *desc_stats_request = create_desc_stats_request( MY_TRANSACTION_ID, NO_FLAGS );
|
126
|
+
return Data_Wrap_Struct( klass, NULL, free_buffer, desc_stats_request );
|
127
|
+
}
|
128
|
+
|
129
|
+
|
122
130
|
static VALUE
|
123
131
|
flow_stats_request_alloc( VALUE klass ) {
|
124
132
|
buffer *flow_stats_request = create_flow_stats_request( MY_TRANSACTION_ID, NO_FLAGS, MATCH, TABLE_ID, OUT_PORT );
|
@@ -226,7 +234,7 @@ stats_out_port( VALUE self ) {
|
|
226
234
|
/*
|
227
235
|
* Restrict port statistics to a specific port_no or to all ports.
|
228
236
|
*
|
229
|
-
|
237
|
+
@return [Number] the value of port_no.
|
230
238
|
*/
|
231
239
|
static VALUE
|
232
240
|
stats_port_no( VALUE self ) {
|
@@ -274,11 +282,47 @@ get_stats_request_table_id( VALUE self ) {
|
|
274
282
|
}
|
275
283
|
|
276
284
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
285
|
+
static VALUE
|
286
|
+
parse_common_arguments( int argc, VALUE *argv, VALUE self ) {
|
287
|
+
VALUE options;
|
288
|
+
if ( !rb_scan_args( argc, argv, "01", &options )) {
|
289
|
+
options = rb_hash_new();
|
290
|
+
}
|
291
|
+
rb_call_super( 1, &options );
|
292
|
+
buffer *message;
|
293
|
+
Data_Get_Struct( self, buffer, message );
|
294
|
+
( ( struct ofp_header * ) ( message->data ) )->xid = htonl( get_stats_request_num2uint( self, "@transaction_id" ) );
|
295
|
+
struct ofp_stats_request *stats_request;
|
296
|
+
stats_request = ( struct ofp_stats_request * ) message->data;
|
297
|
+
stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
|
298
|
+
return self;
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
/*
|
303
|
+
* A {DescStatsRequest} object instance to request descriptive information of vswitch.
|
304
|
+
* Such information includes switch manufacturer, hardware revision and serial number
|
305
|
+
*
|
306
|
+
* @overload initialize(options={})
|
307
|
+
*
|
308
|
+
* @example
|
309
|
+
* DescStatsRequest.new(
|
310
|
+
* :transaction_id => 1234
|
311
|
+
* )
|
312
|
+
*
|
313
|
+
* @param [Hash] options
|
314
|
+
* the options to create a message with.
|
315
|
+
*
|
316
|
+
* @option options [Number] :transaction_id
|
317
|
+
* set the transaction_id as specified or auto-generate it.
|
318
|
+
*
|
319
|
+
* @return [TableStatsRequest]
|
320
|
+
* an object that encapsulates the +OFPT_STATS_REQUEST(OFPST_DSST)+ openflow
|
321
|
+
* message.
|
322
|
+
*/
|
323
|
+
static VALUE
|
324
|
+
desc_stats_request_init( int argc, VALUE *argv, VALUE self ) {
|
325
|
+
return parse_common_arguments( argc, argv, self );
|
282
326
|
}
|
283
327
|
|
284
328
|
|
@@ -327,8 +371,9 @@ flow_stats_request_init( VALUE self, VALUE options ) {
|
|
327
371
|
|
328
372
|
stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
|
329
373
|
|
330
|
-
struct ofp_match
|
331
|
-
|
374
|
+
const struct ofp_match *match;
|
375
|
+
Data_Get_Struct( rb_iv_get( self, "@match" ), struct ofp_match, match );
|
376
|
+
hton_match( &flow_stats_request->match, match );
|
332
377
|
flow_stats_request->table_id = get_stats_request_table_id( self );
|
333
378
|
flow_stats_request->out_port = htons( get_stats_request_num2uint16( self, "@out_port" ) );
|
334
379
|
return self;
|
@@ -379,8 +424,9 @@ aggregate_stats_request_init( VALUE self, VALUE options ) {
|
|
379
424
|
|
380
425
|
stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
|
381
426
|
|
382
|
-
struct ofp_match
|
383
|
-
|
427
|
+
const struct ofp_match *match;
|
428
|
+
Data_Get_Struct( rb_iv_get( self, "@match" ), struct ofp_match, match );
|
429
|
+
hton_match( &aggregate_stats_request->match, match );
|
384
430
|
aggregate_stats_request->table_id = get_stats_request_table_id( self );
|
385
431
|
aggregate_stats_request->out_port = htons( get_stats_request_num2uint16( self, "@out_port" ) );
|
386
432
|
return self;
|
@@ -411,18 +457,7 @@ aggregate_stats_request_init( VALUE self, VALUE options ) {
|
|
411
457
|
*/
|
412
458
|
static VALUE
|
413
459
|
table_stats_request_init( int argc, VALUE *argv, VALUE self ) {
|
414
|
-
|
415
|
-
if ( !rb_scan_args( argc, argv, "01", &options )) {
|
416
|
-
options = rb_hash_new();
|
417
|
-
}
|
418
|
-
rb_call_super( 1, &options );
|
419
|
-
buffer *message;
|
420
|
-
Data_Get_Struct( self, buffer, message );
|
421
|
-
( ( struct ofp_header * ) ( message->data ) )->xid = htonl( get_stats_request_num2uint( self, "@transaction_id" ) );
|
422
|
-
struct ofp_stats_request *stats_request;
|
423
|
-
stats_request = ( struct ofp_stats_request * ) message->data;
|
424
|
-
stats_request->flags = htons ( get_stats_request_num2uint16( self, "@flags" ) );
|
425
|
-
return self;
|
460
|
+
return parse_common_arguments( argc, argv, self );
|
426
461
|
}
|
427
462
|
|
428
463
|
|
@@ -586,11 +621,17 @@ vendor_stats_request_init( int argc, VALUE *argv, VALUE self ) {
|
|
586
621
|
void
|
587
622
|
Init_stats_request(){
|
588
623
|
cStatsRequest = rb_define_class_under( mTrema, "StatsRequest", rb_cObject );
|
624
|
+
|
625
|
+
cDescStatsRequest = rb_define_class_under( mTrema, "DescStatsRequest", cStatsRequest );
|
626
|
+
rb_define_alloc_func( cDescStatsRequest, desc_stats_request_alloc );
|
627
|
+
rb_define_method( cDescStatsRequest, "initialize", desc_stats_request_init, -1 );
|
628
|
+
|
589
629
|
cFlowStatsRequest = rb_define_class_under( mTrema, "FlowStatsRequest", cStatsRequest );
|
590
630
|
rb_define_method( cStatsRequest, "initialize", stats_request_init, 1 );
|
591
631
|
rb_define_method( cStatsRequest, "transaction_id", stats_transaction_id, 0 );
|
632
|
+
rb_alias( cStatsRequest, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
592
633
|
rb_define_method( cStatsRequest, "flags", stats_flags, 0 );
|
593
|
-
|
634
|
+
|
594
635
|
rb_define_alloc_func( cFlowStatsRequest, flow_stats_request_alloc );
|
595
636
|
rb_define_method( cFlowStatsRequest, "initialize", flow_stats_request_init, 1 );
|
596
637
|
rb_define_method( cFlowStatsRequest, "match", stats_match, 0 );
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2008-2012 NEC Corporation
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License, version 2, as
|
6
|
+
# published by the Free Software Foundation.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
require "trema/action"
|
20
|
+
|
21
|
+
|
22
|
+
module Trema
|
23
|
+
#
|
24
|
+
# Strips the VLAN tag of a packet.
|
25
|
+
#
|
26
|
+
class StripVlanHeader < Action
|
27
|
+
#
|
28
|
+
# Creates an action that strips the VLAN tag of a packet.
|
29
|
+
#
|
30
|
+
def initialize
|
31
|
+
# Do nothing.
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
### Local variables:
|
38
|
+
### mode: Ruby
|
39
|
+
### coding: utf-8-unix
|
40
|
+
### indent-tabs-mode: nil
|
41
|
+
### End:
|
data/ruby/trema/switch.c
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2008-2012 NEC Corporation
|
3
|
+
*
|
4
|
+
* This program is free software; you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU General Public License, version 2, as
|
6
|
+
* published by the Free Software Foundation.
|
7
|
+
*
|
8
|
+
* This program is distributed in the hope that it will be useful,
|
9
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
* GNU General Public License for more details.
|
12
|
+
*
|
13
|
+
* You should have received a copy of the GNU General Public License along
|
14
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
16
|
+
*/
|
17
|
+
|
18
|
+
|
19
|
+
#include "chibach.h"
|
20
|
+
#include "flow-mod.h"
|
21
|
+
#include "logger.h"
|
22
|
+
#include "ruby.h"
|
23
|
+
#include "rubysig.h"
|
24
|
+
#include "switch.h"
|
25
|
+
|
26
|
+
|
27
|
+
VALUE mTrema;
|
28
|
+
VALUE cSwitch;
|
29
|
+
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
switch_send_message( VALUE self, VALUE message ) {
|
33
|
+
buffer *buf;
|
34
|
+
Data_Get_Struct( message, buffer, buf );
|
35
|
+
switch_send_openflow_message( buf );
|
36
|
+
return self;
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
static void
|
41
|
+
handle_controller_connected( void *rbswitch ) {
|
42
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "controller_connected" ) ) == Qtrue ) {
|
43
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "controller_connected" ), 0 );
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
static void
|
49
|
+
handle_hello( uint32_t transaction_id, uint8_t version, void *rbswitch ) {
|
50
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "hello" ) ) == Qtrue ) {
|
51
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "hello" ), 2, UINT2NUM( transaction_id ), UINT2NUM( version ) );
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
static void
|
57
|
+
handle_features_request( uint32_t transaction_id, void *rbswitch ) {
|
58
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "features_request" ) ) == Qtrue ) {
|
59
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "features_request" ), 1, UINT2NUM( transaction_id ) );
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static void
|
65
|
+
handle_set_config( uint32_t transaction_id, uint16_t flags, uint16_t miss_send_len, void *rbswitch ) {
|
66
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "set_config" ) ) == Qtrue ) {
|
67
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "set_config" ), 3, UINT2NUM( transaction_id ), UINT2NUM( flags ), UINT2NUM( miss_send_len ) );
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
static void
|
73
|
+
handle_flow_mod(
|
74
|
+
uint32_t transaction_id,
|
75
|
+
struct ofp_match match,
|
76
|
+
uint64_t cookie,
|
77
|
+
uint16_t command,
|
78
|
+
uint16_t idle_timeout,
|
79
|
+
uint16_t hard_timeout,
|
80
|
+
uint16_t priority,
|
81
|
+
uint32_t buffer_id,
|
82
|
+
uint16_t out_port,
|
83
|
+
uint16_t flags,
|
84
|
+
const openflow_actions *actions,
|
85
|
+
void *rbswitch
|
86
|
+
){
|
87
|
+
UNUSED( match );
|
88
|
+
UNUSED( cookie );
|
89
|
+
UNUSED( priority );
|
90
|
+
UNUSED( buffer_id );
|
91
|
+
UNUSED( out_port );
|
92
|
+
UNUSED( flags );
|
93
|
+
UNUSED( actions );
|
94
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "flow_mod" ) ) == Qtrue ) {
|
95
|
+
VALUE options = rb_hash_new();
|
96
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
|
97
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "command" ) ), UINT2NUM( command ) );
|
98
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "idle_timeout" ) ), UINT2NUM( idle_timeout ) );
|
99
|
+
rb_hash_aset( options, ID2SYM( rb_intern( "hard_timeout" ) ), UINT2NUM( hard_timeout ) );
|
100
|
+
VALUE flow_mod = rb_funcall( cFlowMod, rb_intern( "new" ), 1, options );
|
101
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "flow_mod" ), 2, UINT2NUM( transaction_id ), flow_mod );
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
static void
|
107
|
+
handle_echo_request( uint32_t transaction_id, const buffer *body, void *rbswitch ) {
|
108
|
+
if ( rb_respond_to( ( VALUE ) rbswitch, rb_intern( "echo_request" ) ) == Qtrue ) {
|
109
|
+
VALUE rbody = rb_str_new( body->data, ( long ) body->length );
|
110
|
+
rb_funcall( ( VALUE ) rbswitch, rb_intern( "echo_request" ), 2, UINT2NUM( transaction_id ), rbody );
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
static VALUE
|
116
|
+
switch_run( VALUE self ) {
|
117
|
+
setenv( "CHIBACH_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 );
|
118
|
+
|
119
|
+
VALUE name = rb_funcall( self, rb_intern( "name" ), 0 );
|
120
|
+
rb_gv_set( "$PROGRAM_NAME", name );
|
121
|
+
|
122
|
+
int argc = 6;
|
123
|
+
char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) );
|
124
|
+
argv[ 0 ] = STR2CSTR( name );
|
125
|
+
argv[ 1 ] = ( char * ) ( uintptr_t ) "--name";
|
126
|
+
argv[ 2 ] = STR2CSTR( name );
|
127
|
+
argv[ 3 ] = ( char * ) ( uintptr_t ) "--datapath_id";
|
128
|
+
argv[ 4 ] = STR2CSTR( rb_funcall( rb_iv_get( self, "@dpid" ), rb_intern( "to_hex" ), 0 ) );
|
129
|
+
argv[ 5 ] = ( char * ) ( uintptr_t ) "--daemonize";
|
130
|
+
argv[ 6 ] = NULL;
|
131
|
+
init_chibach( &argc, &argv );
|
132
|
+
xfree( argv );
|
133
|
+
|
134
|
+
set_controller_connected_handler( handle_controller_connected, ( void * ) self );
|
135
|
+
set_hello_handler( handle_hello, ( void * ) self );
|
136
|
+
set_features_request_handler( handle_features_request, ( void * ) self );
|
137
|
+
set_set_config_handler( handle_set_config, ( void * ) self );
|
138
|
+
set_flow_mod_handler( handle_flow_mod, ( void * ) self );
|
139
|
+
set_echo_request_handler( handle_echo_request, ( void * ) self );
|
140
|
+
|
141
|
+
if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) {
|
142
|
+
rb_funcall( self, rb_intern( "start" ), 0 );
|
143
|
+
}
|
144
|
+
|
145
|
+
rb_funcall( self, rb_intern( "start_chibach" ), 0 );
|
146
|
+
|
147
|
+
return self;
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
static void
|
152
|
+
thread_pass( void *user_data ) {
|
153
|
+
UNUSED( user_data );
|
154
|
+
CHECK_INTS;
|
155
|
+
rb_funcall( rb_cThread, rb_intern( "pass" ), 0 );
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
static VALUE
|
160
|
+
switch_start_chibach( VALUE self ) {
|
161
|
+
struct itimerspec interval;
|
162
|
+
interval.it_interval.tv_sec = 0;
|
163
|
+
interval.it_interval.tv_nsec = 1000000;
|
164
|
+
interval.it_value.tv_sec = 0;
|
165
|
+
interval.it_value.tv_nsec = 0;
|
166
|
+
add_timer_event_callback( &interval, thread_pass, NULL );
|
167
|
+
|
168
|
+
start_chibach();
|
169
|
+
|
170
|
+
return self;
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
/********************************************************************************
|
175
|
+
* Init Switch module.
|
176
|
+
********************************************************************************/
|
177
|
+
|
178
|
+
void
|
179
|
+
Init_switch() {
|
180
|
+
cSwitch = rb_define_class_under( mTrema, "Switch", rb_cObject );
|
181
|
+
rb_include_module( cSwitch, mLogger );
|
182
|
+
|
183
|
+
rb_define_method( cSwitch, "run!", switch_run, 0 );
|
184
|
+
rb_define_method( cSwitch, "send_message", switch_send_message, 1 );
|
185
|
+
rb_define_private_method( cSwitch, "start_chibach", switch_start_chibach, 0 );
|
186
|
+
|
187
|
+
rb_require( "trema/switch" );
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
/*
|
192
|
+
* Local variables:
|
193
|
+
* c-basic-offset: 2
|
194
|
+
* indent-tabs-mode: nil
|
195
|
+
* End:
|
196
|
+
*/
|
@@ -1,6 +1,4 @@
|
|
1
1
|
/*
|
2
|
-
* Author: Nick Karanatsios <nickkaranatsios@gmail.com>
|
3
|
-
*
|
4
2
|
* Copyright (C) 2008-2012 NEC Corporation
|
5
3
|
*
|
6
4
|
* This program is free software; you can redistribute it and/or modify
|
@@ -18,20 +16,20 @@
|
|
18
16
|
*/
|
19
17
|
|
20
18
|
|
21
|
-
#ifndef
|
22
|
-
#define
|
19
|
+
#ifndef SWITCH_H
|
20
|
+
#define SWITCH_H
|
23
21
|
|
24
22
|
|
25
23
|
#include "ruby.h"
|
26
24
|
|
27
25
|
|
28
|
-
extern VALUE
|
26
|
+
extern VALUE cSwitch;
|
29
27
|
|
30
28
|
|
31
|
-
void
|
29
|
+
void Init_switch( void );
|
32
30
|
|
33
31
|
|
34
|
-
#endif //
|
32
|
+
#endif // SWITCH_H
|
35
33
|
|
36
34
|
|
37
35
|
/*
|
data/ruby/trema/switch.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
3
|
-
#
|
4
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
5
3
|
#
|
6
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -18,20 +16,41 @@
|
|
18
16
|
#
|
19
17
|
|
20
18
|
|
21
|
-
|
19
|
+
module Trema
|
20
|
+
class Switch
|
21
|
+
attr_reader :dpid
|
22
|
+
alias :datapath_id :dpid
|
22
23
|
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def self.inherited subclass
|
26
|
+
at_exit { subclass.new( eval ARGV[ 0 ] ).run! }
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def initialize dpid
|
31
|
+
@dpid = dpid
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def name
|
36
|
+
self.class.to_s.split( "::" ).last
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def controller_connected
|
41
|
+
send_message Hello.new
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def features_request xid
|
46
|
+
send_message FeaturesReply.new( :datapath_id => @dpid, :transaction_id => xid )
|
47
|
+
end
|
29
48
|
end
|
30
49
|
end
|
31
50
|
|
32
51
|
|
33
52
|
### Local variables:
|
34
53
|
### mode: Ruby
|
35
|
-
### coding: utf-8
|
54
|
+
### coding: utf-8
|
36
55
|
### indent-tabs-mode: nil
|
37
56
|
### End:
|