trema 0.2.2.1 → 0.2.3
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/.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/error.h
CHANGED
data/ruby/trema/features-reply.c
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
|
|
@@ -28,56 +26,101 @@ extern VALUE mTrema;
|
|
|
28
26
|
VALUE cFeaturesReply;
|
|
29
27
|
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
29
|
+
static VALUE
|
|
30
|
+
features_reply_alloc( VALUE klass ) {
|
|
31
|
+
buffer *features_reply = create_features_reply( 0, 0, 0, 0, 0, 0, NULL );
|
|
32
|
+
return Data_Wrap_Struct( klass, NULL, free_buffer, features_reply );
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Creates a FeaturesReply message. A user would not explicitly
|
|
38
|
+
* instantiate a {FeaturesReply} object but would be created while
|
|
39
|
+
* parsing the +OFPT_FEATURES_REPLY+ message.
|
|
34
40
|
*
|
|
35
|
-
* @overload initialize(options
|
|
41
|
+
* @overload initialize(options)
|
|
36
42
|
* @example
|
|
37
|
-
* FeaturesReply.new(
|
|
43
|
+
* FeaturesReply.new(
|
|
38
44
|
* :datapath_id => 0xabc,
|
|
39
45
|
* :transaction_id => 1,
|
|
40
46
|
* :n_buffers => 256,
|
|
41
47
|
* :n_tables => 1,
|
|
42
48
|
* :capabilities => 135,
|
|
43
49
|
* :actions => 2048,
|
|
44
|
-
* :port => [
|
|
50
|
+
* :port => [ port1, port2, ... ]
|
|
45
51
|
* )
|
|
46
|
-
*
|
|
47
52
|
* @param [Hash] options
|
|
48
53
|
* the options to create a message with.
|
|
49
|
-
*
|
|
50
54
|
* @option options [Number] :datapath_id
|
|
51
|
-
* datapath unique id. Subsequent commands directed to switch should
|
|
55
|
+
* datapath unique id. Subsequent commands directed to switch should
|
|
52
56
|
* embed this id.
|
|
53
|
-
*
|
|
54
57
|
* @option options [Number] :transaction_id
|
|
55
58
|
* a positive number lower layers match this to ensure message integrity.
|
|
56
|
-
*
|
|
57
59
|
* @option options [Number] :n_buffers
|
|
58
60
|
* maximum number of packets that can be buffered at once.
|
|
59
|
-
*
|
|
60
61
|
* @option options [Number] :n_tables
|
|
61
|
-
* number of supported tables, number could vary according to
|
|
62
|
+
* number of supported tables, number could vary according to
|
|
62
63
|
* switch's implementation.
|
|
63
|
-
*
|
|
64
64
|
* @option options [Number] :capabilities
|
|
65
|
-
* supported capabilities expressed as a 32-bit bitmap. Ability of a switch
|
|
66
|
-
* to respond or perform a certain function for example flow statistics,
|
|
65
|
+
* supported capabilities expressed as a 32-bit bitmap. Ability of a switch
|
|
66
|
+
* to respond or perform a certain function for example flow statistics,
|
|
67
67
|
* IP address lookup in APR packets.
|
|
68
|
-
*
|
|
69
68
|
* @option options [Number] :actions
|
|
70
69
|
* supported actions expressed as a 32-bit bitmap.
|
|
71
|
-
*
|
|
72
70
|
* @option options [Port] :port
|
|
73
71
|
* an array of {Port} objects detailing physical port description and function.
|
|
74
|
-
*
|
|
75
72
|
* @return [FeaturesReply]
|
|
76
|
-
* an object that encapsulates the +OFPT_FEATURES_REPLY+ OpenFlow message.
|
|
77
73
|
*/
|
|
78
74
|
static VALUE
|
|
79
75
|
features_reply_init( VALUE self, VALUE options ) {
|
|
76
|
+
buffer *buf = NULL;
|
|
77
|
+
Data_Get_Struct( self, buffer, buf );
|
|
78
|
+
struct ofp_switch_features *features_reply = buf->data;
|
|
79
|
+
VALUE tmp = Qnil;
|
|
80
|
+
|
|
81
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "datapath_id" ) ) );
|
|
82
|
+
if ( tmp == Qnil ) {
|
|
83
|
+
rb_raise( rb_eArgError, ":datapath_id is a mandatory option" );
|
|
84
|
+
}
|
|
85
|
+
features_reply->datapath_id = htonll( NUM2ULL( tmp ) );
|
|
86
|
+
|
|
87
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
|
|
88
|
+
if ( tmp == Qnil ) {
|
|
89
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
|
|
90
|
+
if ( tmp == Qnil ) {
|
|
91
|
+
rb_raise( rb_eArgError, ":transaction_id is a mandatory option" );
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
features_reply->header.xid = htonl( NUM2UINT( tmp ) );
|
|
95
|
+
|
|
96
|
+
features_reply->n_buffers = 0;
|
|
97
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "n_buffers" ) ) );
|
|
98
|
+
if ( tmp != Qnil ) {
|
|
99
|
+
features_reply->n_buffers = htonl( NUM2UINT( tmp ) );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
features_reply->n_tables = 1;
|
|
103
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "n_tables" ) ) );
|
|
104
|
+
if ( tmp != Qnil ) {
|
|
105
|
+
features_reply->n_tables = ( uint8_t ) NUM2UINT( tmp );
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
features_reply->capabilities = 0;
|
|
109
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "capabilities" ) ) );
|
|
110
|
+
if ( tmp != Qnil ) {
|
|
111
|
+
features_reply->capabilities = htonl( NUM2UINT( tmp ) );
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
features_reply->actions = htonl( 1 << OFPAT_OUTPUT );
|
|
115
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "actions" ) ) );
|
|
116
|
+
if ( tmp != Qnil ) {
|
|
117
|
+
features_reply->actions = htonl( NUM2UINT( tmp ) );
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// TODO: ports
|
|
121
|
+
|
|
80
122
|
rb_iv_set( self, "@attribute", options );
|
|
123
|
+
|
|
81
124
|
return self;
|
|
82
125
|
}
|
|
83
126
|
|
|
@@ -100,7 +143,18 @@ features_reply_datapath_id( VALUE self ) {
|
|
|
100
143
|
*/
|
|
101
144
|
static VALUE
|
|
102
145
|
features_reply_transaction_id( VALUE self ) {
|
|
103
|
-
|
|
146
|
+
VALUE xid = Qnil;
|
|
147
|
+
|
|
148
|
+
xid = rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "transaction_id" ) ) );
|
|
149
|
+
if ( xid != Qnil ) {
|
|
150
|
+
return xid;
|
|
151
|
+
}
|
|
152
|
+
xid = rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "xid" ) ) );
|
|
153
|
+
if ( xid != Qnil ) {
|
|
154
|
+
return xid;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return Qnil;
|
|
104
158
|
}
|
|
105
159
|
|
|
106
160
|
|
|
@@ -162,9 +216,11 @@ features_reply_ports( VALUE self ) {
|
|
|
162
216
|
void
|
|
163
217
|
Init_features_reply() {
|
|
164
218
|
cFeaturesReply = rb_define_class_under( mTrema, "FeaturesReply", rb_cObject );
|
|
219
|
+
rb_define_alloc_func( cFeaturesReply, features_reply_alloc );
|
|
165
220
|
rb_define_method( cFeaturesReply, "initialize", features_reply_init, 1 );
|
|
166
221
|
rb_define_method( cFeaturesReply, "datapath_id", features_reply_datapath_id, 0 );
|
|
167
222
|
rb_define_method( cFeaturesReply, "transaction_id", features_reply_transaction_id, 0 );
|
|
223
|
+
rb_alias( cFeaturesReply, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
|
168
224
|
rb_define_method( cFeaturesReply, "n_buffers", features_reply_n_buffers, 0 );
|
|
169
225
|
rb_define_method( cFeaturesReply, "n_tables", features_reply_n_tables, 0 );
|
|
170
226
|
rb_define_method( cFeaturesReply, "capabilities", features_reply_capabilities, 0 );
|
|
@@ -173,13 +229,21 @@ Init_features_reply() {
|
|
|
173
229
|
}
|
|
174
230
|
|
|
175
231
|
|
|
232
|
+
void
|
|
233
|
+
handle_switch_ready( uint64_t datapath_id, void *controller ) {
|
|
234
|
+
if ( rb_respond_to( ( VALUE ) controller, rb_intern( "switch_ready" ) ) == Qtrue ) {
|
|
235
|
+
rb_funcall( ( VALUE ) controller, rb_intern( "switch_ready" ), 1, ULL2NUM( datapath_id ) );
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
176
240
|
/*
|
|
177
241
|
* Extract and map {Port} to +ofp_phy_port+ structure.
|
|
178
242
|
*/
|
|
179
243
|
static VALUE
|
|
180
244
|
ports_from( const list_element *phy_ports ) {
|
|
181
245
|
VALUE ports = rb_ary_new();
|
|
182
|
-
|
|
246
|
+
|
|
183
247
|
list_element *port_head = xmalloc( sizeof( list_element ) );
|
|
184
248
|
memcpy( port_head, phy_ports, sizeof( list_element ) );
|
|
185
249
|
list_element *port = NULL;
|
|
@@ -191,16 +255,6 @@ ports_from( const list_element *phy_ports ) {
|
|
|
191
255
|
}
|
|
192
256
|
|
|
193
257
|
|
|
194
|
-
void
|
|
195
|
-
handle_switch_ready( uint64_t datapath_id, void *controller ) {
|
|
196
|
-
if ( rb_respond_to( ( VALUE ) controller, rb_intern( "switch_ready" ) ) == Qtrue ) {
|
|
197
|
-
rb_funcall( ( VALUE ) controller, rb_intern( "switch_ready" ), 1, ULL2NUM( datapath_id ) );
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/*
|
|
202
|
-
* The handler that is called when an +OFPT_FEATURES_REPLY+ message is received.
|
|
203
|
-
*/
|
|
204
258
|
void
|
|
205
259
|
handle_features_reply(
|
|
206
260
|
uint64_t datapath_id,
|
|
@@ -226,7 +280,7 @@ handle_features_reply(
|
|
|
226
280
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "ports" ) ), ports_from( phy_ports ) );
|
|
227
281
|
|
|
228
282
|
VALUE features_reply = rb_funcall( cFeaturesReply, rb_intern( "new" ), 1, attributes );
|
|
229
|
-
rb_funcall( ( VALUE ) controller, rb_intern( "features_reply" ),
|
|
283
|
+
rb_funcall( ( VALUE ) controller, rb_intern( "features_reply" ), 2, ULL2NUM( datapath_id ), features_reply );
|
|
230
284
|
}
|
|
231
285
|
|
|
232
286
|
|
data/ruby/trema/features-reply.h
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Ruby wrapper class of OpenFlow features reply message.
|
|
3
3
|
*
|
|
4
|
-
* Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
|
5
|
-
*
|
|
6
4
|
* Copyright (C) 2008-2012 NEC Corporation
|
|
7
5
|
*
|
|
8
6
|
* This program is free software; you can redistribute it and/or modify
|
|
@@ -32,11 +30,7 @@ extern VALUE cFeaturesReply;
|
|
|
32
30
|
|
|
33
31
|
|
|
34
32
|
void Init_features_reply( void );
|
|
35
|
-
|
|
36
|
-
|
|
37
33
|
void handle_switch_ready( uint64_t datapath_id, void *controller );
|
|
38
|
-
|
|
39
|
-
|
|
40
34
|
void handle_features_reply(
|
|
41
35
|
uint64_t datapath_id,
|
|
42
36
|
uint32_t transaction_id,
|
|
@@ -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,8 +16,9 @@
|
|
|
18
16
|
*/
|
|
19
17
|
|
|
20
18
|
|
|
21
|
-
#include "trema.h"
|
|
22
19
|
#include "ruby.h"
|
|
20
|
+
#include "trema-ruby-utils.h"
|
|
21
|
+
#include "trema.h"
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
extern VALUE mTrema;
|
|
@@ -33,62 +32,88 @@ features_request_alloc( VALUE klass ) {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
|
|
36
|
-
/*
|
|
37
|
-
*
|
|
38
|
-
* switch's supported capabilities. Creates an object that encapsulates the
|
|
39
|
-
* +OFPT_FEATURES_REQUEST+ OpenFlow message.
|
|
35
|
+
/*
|
|
36
|
+
* Creates a FeaturesRequest OpenFlow message.
|
|
40
37
|
*
|
|
41
|
-
* @overload initialize(
|
|
38
|
+
* @overload initialize()
|
|
42
39
|
* @example
|
|
43
|
-
*
|
|
44
|
-
* FeaturesRequest.new( :transaction_id => 123 )
|
|
40
|
+
* FeaturesRequest.new
|
|
45
41
|
*
|
|
42
|
+
* @overload initialize(transaction_id)
|
|
43
|
+
* @example
|
|
44
|
+
* FeaturesRequest.new( 123 )
|
|
45
|
+
* @param [Integer] transaction_id
|
|
46
|
+
* An unsigned 32bit integer number associated with this message.
|
|
47
|
+
*
|
|
48
|
+
* @overload initialize(options)
|
|
49
|
+
* @example
|
|
50
|
+
* FeaturesRequest.new( :xid => 123 )
|
|
51
|
+
* FeaturesRequest.new( :transaction_id => 123 )
|
|
46
52
|
* @param [Hash] options
|
|
47
53
|
* the options to create a message with.
|
|
54
|
+
* @option options [Number] :xid
|
|
55
|
+
* @option options [Number] :transaction_id
|
|
56
|
+
* An unsigned 32bit integer number associated with this message.
|
|
57
|
+
* If not specified, an auto-generated value is set.
|
|
48
58
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @raise [ArgumentError] if transaction id is not an unsigned 32-bit integer.
|
|
54
|
-
* @raise [TypeError] if options is not a hash.
|
|
55
|
-
*
|
|
56
|
-
* @return [FeaturesRequest]
|
|
57
|
-
* an object that encapsulates the +OFPT_FEATURES_REQUEST+ OpenFlow message.
|
|
59
|
+
* @raise [ArgumentError] if transaction ID is not an unsigned 32-bit integer.
|
|
60
|
+
* @raise [TypeError] if argument is not a Integer or a Hash.
|
|
61
|
+
* @return [FeaturesRequest]
|
|
58
62
|
*/
|
|
59
63
|
static VALUE
|
|
60
64
|
features_request_init( int argc, VALUE *argv, VALUE self ) {
|
|
61
|
-
buffer *features_request;
|
|
65
|
+
buffer *features_request = NULL;
|
|
62
66
|
Data_Get_Struct( self, buffer, features_request );
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
VALUE options = Qnil;
|
|
68
|
+
|
|
69
|
+
if ( rb_scan_args( argc, argv, "01", &options ) == 0 ) {
|
|
70
|
+
set_xid( features_request, get_transaction_id() );
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if ( options == Qnil ) {
|
|
74
|
+
set_xid( features_request, get_transaction_id() );
|
|
75
|
+
}
|
|
76
|
+
else if ( rb_obj_is_kind_of( options, rb_cInteger ) == Qtrue ) {
|
|
77
|
+
validate_xid( options );
|
|
78
|
+
set_xid( features_request, ( uint32_t ) NUM2UINT( options ) );
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
Check_Type( options, T_HASH );
|
|
82
|
+
VALUE tmp = Qnil;
|
|
83
|
+
VALUE xid = Qnil;
|
|
84
|
+
|
|
85
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
|
|
86
|
+
if ( tmp != Qnil ) {
|
|
87
|
+
xid = tmp;
|
|
88
|
+
}
|
|
89
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
|
|
90
|
+
if ( tmp != Qnil ) {
|
|
91
|
+
xid = tmp;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( xid != Qnil ) {
|
|
95
|
+
validate_xid( xid );
|
|
96
|
+
set_xid( features_request, ( uint32_t ) NUM2UINT( xid ) );
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
set_xid( features_request, get_transaction_id() );
|
|
72
100
|
}
|
|
73
|
-
xid = ( uint32_t ) NUM2UINT( xid_ruby );
|
|
74
101
|
}
|
|
75
102
|
}
|
|
76
|
-
|
|
103
|
+
|
|
77
104
|
return self;
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
|
|
81
108
|
/*
|
|
82
|
-
* Transaction ids, message sequence numbers matching requests to
|
|
109
|
+
* Transaction ids, message sequence numbers matching requests to
|
|
110
|
+
* replies.
|
|
83
111
|
*
|
|
84
|
-
* @return [Number] the value of transaction
|
|
112
|
+
* @return [Number] the value of transaction ID.
|
|
85
113
|
*/
|
|
86
114
|
static VALUE
|
|
87
115
|
features_request_transaction_id( VALUE self ) {
|
|
88
|
-
|
|
89
|
-
Data_Get_Struct( self, buffer, features_request );
|
|
90
|
-
uint32_t xid = ntohl( ( ( struct ofp_header * ) ( features_request->data ) )->xid );
|
|
91
|
-
return UINT2NUM( xid );
|
|
116
|
+
return get_xid( self );
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
|
|
@@ -98,6 +123,7 @@ Init_features_request() {
|
|
|
98
123
|
rb_define_alloc_func( cFeaturesRequest, features_request_alloc );
|
|
99
124
|
rb_define_method( cFeaturesRequest, "initialize", features_request_init, -1 );
|
|
100
125
|
rb_define_method( cFeaturesRequest, "transaction_id", features_request_transaction_id, 0 );
|
|
126
|
+
rb_alias( cFeaturesRequest, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
|
101
127
|
}
|
|
102
128
|
|
|
103
129
|
|
|
@@ -0,0 +1,149 @@
|
|
|
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 "ruby.h"
|
|
20
|
+
#include "trema.h"
|
|
21
|
+
#include "trema-ruby-utils.h"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
extern VALUE mTrema;
|
|
25
|
+
VALUE cFlowMod;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
static VALUE
|
|
29
|
+
flow_mod_alloc( VALUE klass ) {
|
|
30
|
+
struct ofp_match match;
|
|
31
|
+
buffer *flow_mod = create_flow_mod(
|
|
32
|
+
0,
|
|
33
|
+
match,
|
|
34
|
+
0,
|
|
35
|
+
0,
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
UINT16_MAX,
|
|
39
|
+
UINT32_MAX,
|
|
40
|
+
OFPP_NONE,
|
|
41
|
+
0,
|
|
42
|
+
NULL
|
|
43
|
+
);
|
|
44
|
+
return Data_Wrap_Struct( klass, NULL, free_buffer, flow_mod );
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
static VALUE
|
|
49
|
+
flow_mod_init( int argc, VALUE *argv, VALUE self ) {
|
|
50
|
+
buffer *flow_mod = NULL;
|
|
51
|
+
Data_Get_Struct( self, buffer, flow_mod );
|
|
52
|
+
VALUE options = Qnil;
|
|
53
|
+
|
|
54
|
+
if ( rb_scan_args( argc, argv, "01", &options ) == 0 ) {
|
|
55
|
+
set_xid( flow_mod, get_transaction_id() );
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if ( options == Qnil ) {
|
|
59
|
+
set_xid( flow_mod, get_transaction_id() );
|
|
60
|
+
}
|
|
61
|
+
else if ( rb_obj_is_kind_of( options, rb_cInteger ) == Qtrue ) {
|
|
62
|
+
validate_xid( options );
|
|
63
|
+
set_xid( flow_mod, ( uint32_t ) NUM2UINT( options ) );
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
Check_Type( options, T_HASH );
|
|
67
|
+
VALUE tmp = Qnil;
|
|
68
|
+
VALUE xid = Qnil;
|
|
69
|
+
|
|
70
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
|
|
71
|
+
if ( tmp != Qnil ) {
|
|
72
|
+
xid = tmp;
|
|
73
|
+
}
|
|
74
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
|
|
75
|
+
if ( tmp != Qnil ) {
|
|
76
|
+
xid = tmp;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
tmp = rb_hash_aref( options, ID2SYM( rb_intern( "idle_timeout" ) ) );
|
|
80
|
+
if ( tmp != Qnil ) {
|
|
81
|
+
( ( struct ofp_flow_mod * ) ( flow_mod->data ) )->idle_timeout = ( uint16_t ) NUM2UINT( tmp );
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ( xid != Qnil ) {
|
|
85
|
+
validate_xid( xid );
|
|
86
|
+
set_xid( flow_mod, ( uint32_t ) NUM2UINT( xid ) );
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
set_xid( flow_mod, get_transaction_id() );
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return self;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
static VALUE
|
|
99
|
+
flow_mod_transaction_id( VALUE self ) {
|
|
100
|
+
return get_xid( self );
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
static VALUE
|
|
105
|
+
flow_mod_command( VALUE self ) {
|
|
106
|
+
buffer *flow_mod;
|
|
107
|
+
Data_Get_Struct( self, buffer, flow_mod );
|
|
108
|
+
uint32_t command = ntohl( ( ( struct ofp_flow_mod * ) ( flow_mod->data ) )->command );
|
|
109
|
+
return UINT2NUM( command );
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
static VALUE
|
|
114
|
+
flow_mod_idle_timeout( VALUE self ) {
|
|
115
|
+
buffer *flow_mod;
|
|
116
|
+
Data_Get_Struct( self, buffer, flow_mod );
|
|
117
|
+
uint32_t idle_timeout = ntohl( ( ( struct ofp_flow_mod * ) ( flow_mod->data ) )->idle_timeout );
|
|
118
|
+
return UINT2NUM( idle_timeout );
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
static VALUE
|
|
123
|
+
flow_mod_hard_timeout( VALUE self ) {
|
|
124
|
+
buffer *flow_mod;
|
|
125
|
+
Data_Get_Struct( self, buffer, flow_mod );
|
|
126
|
+
uint32_t hard_timeout = ntohl( ( ( struct ofp_flow_mod * ) ( flow_mod->data ) )->hard_timeout );
|
|
127
|
+
return UINT2NUM( hard_timeout );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
void
|
|
132
|
+
Init_flow_mod() {
|
|
133
|
+
cFlowMod = rb_define_class_under( mTrema, "FlowMod", rb_cObject );
|
|
134
|
+
rb_define_alloc_func( cFlowMod, flow_mod_alloc );
|
|
135
|
+
rb_define_method( cFlowMod, "initialize", flow_mod_init, -1 );
|
|
136
|
+
rb_define_method( cFlowMod, "transaction_id", flow_mod_transaction_id, 0 );
|
|
137
|
+
rb_define_method( cFlowMod, "command", flow_mod_command, 0 );
|
|
138
|
+
rb_define_method( cFlowMod, "idle_timeout", flow_mod_idle_timeout, 0 );
|
|
139
|
+
rb_define_method( cFlowMod, "hard_timeout", flow_mod_hard_timeout, 0 );
|
|
140
|
+
rb_alias( cFlowMod, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
* Local variables:
|
|
146
|
+
* c-basic-offset: 2
|
|
147
|
+
* indent-tabs-mode: nil
|
|
148
|
+
* End:
|
|
149
|
+
*/
|