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/packet-queue.rb
CHANGED
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
class Queue
|
|
22
22
|
class << self
|
|
23
|
-
#
|
|
24
|
-
#
|
|
23
|
+
#
|
|
24
|
+
# The {PacketQueue} to append to the list.
|
|
25
|
+
#
|
|
25
26
|
attr_accessor :queues
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -175,4 +176,4 @@ end
|
|
|
175
176
|
### mode: Ruby
|
|
176
177
|
### coding: utf-8-unix
|
|
177
178
|
### indent-tabs-mode: nil
|
|
178
|
-
### End:
|
|
179
|
+
### End:
|
data/ruby/trema/port-mod.c
CHANGED
|
@@ -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
|
|
@@ -46,7 +44,7 @@ port_mod_alloc( VALUE kclass ) {
|
|
|
46
44
|
* @overload initialize(options={})
|
|
47
45
|
* @example
|
|
48
46
|
* PortMod.new(
|
|
49
|
-
* :port_no => 1,
|
|
47
|
+
* :port_no => 1,
|
|
50
48
|
* :hw_addr => "11:22:33:44:55:66",
|
|
51
49
|
* :config => 1,
|
|
52
50
|
* :mask => 1,
|
|
@@ -56,7 +54,7 @@ port_mod_alloc( VALUE kclass ) {
|
|
|
56
54
|
* @param [Hash] options
|
|
57
55
|
* the options to create a message with.
|
|
58
56
|
*
|
|
59
|
-
* @param [Number] :port_no
|
|
57
|
+
* @param [Number] :port_no
|
|
60
58
|
* an index into datapath's ports list.
|
|
61
59
|
*
|
|
62
60
|
* @param [String,Number,Trema::Mac] :hw_addr
|
|
@@ -64,10 +62,10 @@ port_mod_alloc( VALUE kclass ) {
|
|
|
64
62
|
* Unique for each port. Obtained from +OFPT_FEATURES_REPLY+ message.
|
|
65
63
|
* Can be supplied as a string, number or as a Mac object.
|
|
66
64
|
*
|
|
67
|
-
* @param [Number] :config
|
|
65
|
+
* @param [Number] :config
|
|
68
66
|
* a bitmap that can be set to configure a port.
|
|
69
67
|
*
|
|
70
|
-
* @param [Number] :mask
|
|
68
|
+
* @param [Number] :mask
|
|
71
69
|
* set the bits of the +config+ flag to change.
|
|
72
70
|
*
|
|
73
71
|
* @param [Number] :advertise
|
|
@@ -98,7 +96,7 @@ port_mod_init( int argc, VALUE *argv, VALUE self ) {
|
|
|
98
96
|
} else if ( rb_obj_is_instance_of( hw_addr, rb_eval_string( "Trema::Mac" ) ) == Qfalse ) {
|
|
99
97
|
rb_raise( rb_eArgError, "hw_addr must be a string or an integer or Mac object" );
|
|
100
98
|
}
|
|
101
|
-
ptr = ( uint8_t* )
|
|
99
|
+
ptr = ( uint8_t* ) dl_addr_to_a( mac, haddr );
|
|
102
100
|
rb_iv_set( self, "@hw_addr", mac );
|
|
103
101
|
}
|
|
104
102
|
VALUE port_no;
|
|
@@ -171,7 +169,7 @@ port_mod_hw_addr( VALUE self ) {
|
|
|
171
169
|
|
|
172
170
|
|
|
173
171
|
/*
|
|
174
|
-
* A port can be administratively brought down, disable flooding or packet
|
|
172
|
+
* A port can be administratively brought down, disable flooding or packet
|
|
175
173
|
* forwarding or any other options as per +ofp_port_config+. flags.
|
|
176
174
|
*
|
|
177
175
|
* @return [Number] the value of config.
|
|
@@ -196,7 +194,7 @@ port_mod_mask( VALUE self ) {
|
|
|
196
194
|
/*
|
|
197
195
|
* Set to zero to prevent any changes.
|
|
198
196
|
*
|
|
199
|
-
* @return [Number] the value of advertise.
|
|
197
|
+
* @return [Number] the value of advertise.
|
|
200
198
|
*/
|
|
201
199
|
static VALUE
|
|
202
200
|
port_mod_advertise( VALUE self ) {
|
|
@@ -210,6 +208,7 @@ Init_port_mod() {
|
|
|
210
208
|
rb_define_alloc_func( cPortMod, port_mod_alloc );
|
|
211
209
|
rb_define_method( cPortMod, "initialize", port_mod_init, -1 );
|
|
212
210
|
rb_define_method( cPortMod, "transaction_id", port_mod_transaction_id, 0 );
|
|
211
|
+
rb_alias( cPortMod, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
|
213
212
|
rb_define_method( cPortMod, "port_no", port_mod_port_no, 0 );
|
|
214
213
|
rb_define_method( cPortMod, "hw_addr", port_mod_hw_addr, 0 );
|
|
215
214
|
rb_define_method( cPortMod, "config", port_mod_config, 0 );
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
module Trema
|
|
20
|
+
#
|
|
21
|
+
# As physical ports are added to the datapath, the controller needs
|
|
22
|
+
# to be informed with this message.
|
|
23
|
+
#
|
|
24
|
+
class PortStatusAdd < PortStatus
|
|
25
|
+
#
|
|
26
|
+
# Creates a port-added message.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# PortStatusAdd.new(
|
|
30
|
+
# :datapath_id => 0xabc,
|
|
31
|
+
# :transaction_id => 123,
|
|
32
|
+
# :phy_port => port
|
|
33
|
+
# )
|
|
34
|
+
#
|
|
35
|
+
# @param [Hash] options
|
|
36
|
+
# the options to create a message with.
|
|
37
|
+
#
|
|
38
|
+
# @option options [Number] :datapath_id
|
|
39
|
+
# message originator identifier.
|
|
40
|
+
#
|
|
41
|
+
# @option options [Number] :transaction_id
|
|
42
|
+
# unsolicited message transaction_id is zero.
|
|
43
|
+
#
|
|
44
|
+
# @option options [Port] :phy_port
|
|
45
|
+
# a {Port} object describing the properties of the port.
|
|
46
|
+
#
|
|
47
|
+
# @return [PortStatusAdd]
|
|
48
|
+
#
|
|
49
|
+
def initialize options
|
|
50
|
+
super options.merge( :reason => OFPPR_ADD )
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Local variables:
|
|
57
|
+
### mode: Ruby
|
|
58
|
+
### coding: utf-8
|
|
59
|
+
### indent-tabs-mode: nil
|
|
60
|
+
### End:
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
module Trema
|
|
20
|
+
#
|
|
21
|
+
# As physical ports are deleted from the datapath, the controller
|
|
22
|
+
# needs to be informed with this message.
|
|
23
|
+
#
|
|
24
|
+
class PortStatusDelete < PortStatus
|
|
25
|
+
#
|
|
26
|
+
# Creates a port-deleted message.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# PortStatusDelete.new(
|
|
30
|
+
# :datapath_id => 0xabc,
|
|
31
|
+
# :transaction_id => 123,
|
|
32
|
+
# :phy_port => port
|
|
33
|
+
# )
|
|
34
|
+
#
|
|
35
|
+
# @param [Hash] options
|
|
36
|
+
# the options to create a message with.
|
|
37
|
+
#
|
|
38
|
+
# @option options [Number] :datapath_id
|
|
39
|
+
# message originator identifier.
|
|
40
|
+
#
|
|
41
|
+
# @option options [Number] :transaction_id
|
|
42
|
+
# unsolicited message transaction_id is zero.
|
|
43
|
+
#
|
|
44
|
+
# @option options [Port] :phy_port
|
|
45
|
+
# a {Port} object describing the properties of the port.
|
|
46
|
+
#
|
|
47
|
+
# @return [PortStatusDelete]
|
|
48
|
+
#
|
|
49
|
+
def initialize options
|
|
50
|
+
super options.merge( :reason => OFPPR_DELETE )
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Local variables:
|
|
57
|
+
### mode: Ruby
|
|
58
|
+
### coding: utf-8
|
|
59
|
+
### indent-tabs-mode: nil
|
|
60
|
+
### End:
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
module Trema
|
|
20
|
+
#
|
|
21
|
+
# As physical ports of the datapath are modified, the controller
|
|
22
|
+
# needs to be informed with this message.
|
|
23
|
+
#
|
|
24
|
+
class PortStatusModify < PortStatus
|
|
25
|
+
#
|
|
26
|
+
# Creates a port-modified message.
|
|
27
|
+
#
|
|
28
|
+
# @example
|
|
29
|
+
# PortStatusModify.new(
|
|
30
|
+
# :datapath_id => 0xabc,
|
|
31
|
+
# :transaction_id => 123,
|
|
32
|
+
# :phy_port => port
|
|
33
|
+
# )
|
|
34
|
+
#
|
|
35
|
+
# @param [Hash] options
|
|
36
|
+
# the options to create a message with.
|
|
37
|
+
#
|
|
38
|
+
# @option options [Number] :datapath_id
|
|
39
|
+
# message originator identifier.
|
|
40
|
+
#
|
|
41
|
+
# @option options [Number] :transaction_id
|
|
42
|
+
# unsolicited message transaction_id is zero.
|
|
43
|
+
#
|
|
44
|
+
# @option options [Port] :phy_port
|
|
45
|
+
# a {Port} object describing the properties of the port.
|
|
46
|
+
#
|
|
47
|
+
# @return [PortStatusModify]
|
|
48
|
+
#
|
|
49
|
+
def initialize options
|
|
50
|
+
super options.merge( :reason => OFPPR_MODIFY )
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Local variables:
|
|
57
|
+
### mode: Ruby
|
|
58
|
+
### coding: utf-8
|
|
59
|
+
### indent-tabs-mode: nil
|
|
60
|
+
### End:
|
data/ruby/trema/port-status.c
CHANGED
|
@@ -28,17 +28,15 @@ VALUE cPortStatus;
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
/*
|
|
31
|
-
*
|
|
32
|
-
* asynchronous message. This message is sent when a state transition on any
|
|
33
|
-
* physical port is detected.
|
|
31
|
+
* Creates a port status message.
|
|
34
32
|
*
|
|
35
|
-
* @overload initialize(options
|
|
33
|
+
* @overload initialize(options)
|
|
36
34
|
* @example
|
|
37
35
|
* PortStatus.new(
|
|
38
|
-
* :datapath_id =>
|
|
39
|
-
* :transaction_id =>
|
|
40
|
-
* :reason =>
|
|
41
|
-
* :phy_port =>
|
|
36
|
+
* :datapath_id => 0xabc,
|
|
37
|
+
* :transaction_id => 123,
|
|
38
|
+
* :reason => PortStatus::OFPPR_ADD,
|
|
39
|
+
* :phy_port => port
|
|
42
40
|
* )
|
|
43
41
|
*
|
|
44
42
|
* @param [Hash] options
|
|
@@ -57,10 +55,22 @@ VALUE cPortStatus;
|
|
|
57
55
|
* a {Port} object describing the properties of the port.
|
|
58
56
|
*
|
|
59
57
|
* @return [PortStatus]
|
|
60
|
-
* an object that encapsulates the +OFPT_PORT_STATUS+ OpenFlow message.
|
|
61
58
|
*/
|
|
62
59
|
static VALUE
|
|
63
60
|
port_status_init( VALUE self, VALUE options ) {
|
|
61
|
+
if ( rb_hash_aref( options, ID2SYM( rb_intern( "datapath_id" ) ) ) == Qnil ) {
|
|
62
|
+
rb_raise( rb_eArgError, ":datapath_id is a mandatory option" );
|
|
63
|
+
}
|
|
64
|
+
if ( rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) ) == Qnil ) {
|
|
65
|
+
rb_raise( rb_eArgError, ":transaction_id is a mandatory option" );
|
|
66
|
+
}
|
|
67
|
+
if ( rb_hash_aref( options, ID2SYM( rb_intern( "reason" ) ) ) == Qnil ) {
|
|
68
|
+
rb_raise( rb_eArgError, ":reason is a mandatory option" );
|
|
69
|
+
}
|
|
70
|
+
if ( rb_hash_aref( options, ID2SYM( rb_intern( "phy_port" ) ) ) == Qnil ) {
|
|
71
|
+
rb_raise( rb_eArgError, ":phy_port is a mandatory option" );
|
|
72
|
+
}
|
|
73
|
+
|
|
64
74
|
rb_iv_set( self, "@attribute", options );
|
|
65
75
|
return self;
|
|
66
76
|
}
|
|
@@ -113,15 +123,27 @@ port_status_phy_port( VALUE self ) {
|
|
|
113
123
|
void
|
|
114
124
|
Init_port_status() {
|
|
115
125
|
cPortStatus = rb_define_class_under( mTrema, "PortStatus", rb_cObject );
|
|
126
|
+
|
|
127
|
+
rb_define_const( cPortStatus, "OFPPR_ADD", INT2NUM( OFPPR_ADD ) );
|
|
128
|
+
rb_define_const( cPortStatus, "OFPPR_DELETE", INT2NUM( OFPPR_DELETE ) );
|
|
129
|
+
rb_define_const( cPortStatus, "OFPPR_MODIFY", INT2NUM( OFPPR_MODIFY ) );
|
|
130
|
+
|
|
116
131
|
rb_define_method( cPortStatus, "initialize", port_status_init, 1 );
|
|
117
132
|
rb_define_method( cPortStatus, "datapath_id", port_status_datapath_id, 0 );
|
|
133
|
+
rb_alias( cPortStatus, rb_intern( "dpid" ), rb_intern( "datapath_id" ) );
|
|
118
134
|
rb_define_method( cPortStatus, "transaction_id", port_status_transaction_id, 0 );
|
|
135
|
+
rb_alias( cPortStatus, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
|
|
119
136
|
rb_define_method( cPortStatus, "reason", port_status_reason, 0 );
|
|
120
137
|
rb_define_method( cPortStatus, "phy_port", port_status_phy_port, 0 );
|
|
138
|
+
|
|
139
|
+
rb_require( "trema/port-status-add" );
|
|
140
|
+
rb_require( "trema/port-status-delete" );
|
|
141
|
+
rb_require( "trema/port-status-modify" );
|
|
121
142
|
}
|
|
122
143
|
|
|
144
|
+
|
|
123
145
|
/*
|
|
124
|
-
* Handler called when
|
|
146
|
+
* Handler called when a port status message is received.
|
|
125
147
|
*/
|
|
126
148
|
void
|
|
127
149
|
handle_port_status(
|
|
@@ -132,19 +154,30 @@ handle_port_status(
|
|
|
132
154
|
void *user_data
|
|
133
155
|
) {
|
|
134
156
|
VALUE controller = ( VALUE ) user_data;
|
|
157
|
+
|
|
135
158
|
if ( rb_respond_to( controller, rb_intern( "port_status" ) ) == Qfalse ) {
|
|
136
159
|
return;
|
|
137
160
|
}
|
|
138
|
-
VALUE attributes = rb_hash_new();
|
|
139
161
|
|
|
162
|
+
VALUE attributes = rb_hash_new();
|
|
140
163
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "datapath_id" ) ), ULL2NUM( datapath_id ) );
|
|
141
164
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
|
|
142
|
-
rb_hash_aset( attributes, ID2SYM( rb_intern( "reason" ) ), UINT2NUM( reason ) );
|
|
143
|
-
|
|
144
165
|
rb_hash_aset( attributes, ID2SYM( rb_intern( "phy_port" ) ), port_from( &phy_port ) );
|
|
145
166
|
|
|
146
|
-
VALUE port_status =
|
|
147
|
-
|
|
167
|
+
VALUE port_status = Qnil;
|
|
168
|
+
if ( reason == OFPPR_ADD ) {
|
|
169
|
+
port_status = rb_funcall( rb_eval_string( "Trema::PortStatusAdd" ), rb_intern( "new" ), 1, attributes );
|
|
170
|
+
}
|
|
171
|
+
else if ( reason == OFPPR_DELETE ) {
|
|
172
|
+
port_status = rb_funcall( rb_eval_string( "Trema::PortStatusDelete" ), rb_intern( "new" ), 1, attributes );
|
|
173
|
+
}
|
|
174
|
+
else if ( reason == OFPPR_MODIFY ) {
|
|
175
|
+
port_status = rb_funcall( rb_eval_string( "Trema::PortStatusModify" ), rb_intern( "new" ), 1, attributes );
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
rb_raise( rb_eArgError, "Unknown port-status reason." );
|
|
179
|
+
}
|
|
180
|
+
rb_funcall( controller, rb_intern( "port_status" ), 2, ULL2NUM( datapath_id ), port_status );
|
|
148
181
|
}
|
|
149
182
|
|
|
150
183
|
|
data/ruby/trema/port-status.h
CHANGED
|
@@ -26,15 +26,13 @@ extern VALUE cPortStatus;
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
void Init_port_status( void );
|
|
29
|
-
|
|
30
|
-
|
|
31
29
|
void handle_port_status(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
uint64_t datapath_id,
|
|
31
|
+
uint32_t transaction_id,
|
|
32
|
+
uint8_t reason,
|
|
33
|
+
struct ofp_phy_port phy_port,
|
|
34
|
+
void *user_data
|
|
35
|
+
);
|
|
38
36
|
|
|
39
37
|
|
|
40
38
|
/*
|
data/ruby/trema/port.c
CHANGED
|
@@ -87,7 +87,7 @@ port_init( VALUE self, VALUE options ) {
|
|
|
87
87
|
|
|
88
88
|
VALUE name = rb_hash_aref( options, ID2SYM( rb_intern( "name" ) ) );
|
|
89
89
|
rb_iv_set( self, "@name", name );
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
VALUE config = rb_hash_aref( options, ID2SYM( rb_intern( "config" ) ) );
|
|
92
92
|
rb_iv_set( self, "@config", config );
|
|
93
93
|
|
|
@@ -191,7 +191,7 @@ port_advertised( VALUE self ) {
|
|
|
191
191
|
*
|
|
192
192
|
* @return [Number] the value of supported.
|
|
193
193
|
*/
|
|
194
|
-
static VALUE
|
|
194
|
+
static VALUE
|
|
195
195
|
port_supported( VALUE self ) {
|
|
196
196
|
return rb_iv_get( self, "@supported" );
|
|
197
197
|
}
|
|
@@ -219,10 +219,6 @@ port_up( VALUE self ) {
|
|
|
219
219
|
if ( ( config & OFPPC_PORT_DOWN ) == OFPPC_PORT_DOWN ) {
|
|
220
220
|
return Qfalse;
|
|
221
221
|
}
|
|
222
|
-
uint32_t state = ( uint16_t ) NUM2UINT( rb_iv_get( self, "@state" ) );
|
|
223
|
-
if ( ( state & OFPPS_LINK_DOWN ) == OFPPS_LINK_DOWN ) {
|
|
224
|
-
return Qfalse;
|
|
225
|
-
}
|
|
226
222
|
return Qtrue;
|
|
227
223
|
}
|
|
228
224
|
|
|
@@ -238,6 +234,57 @@ port_down( VALUE self ) {
|
|
|
238
234
|
}
|
|
239
235
|
|
|
240
236
|
|
|
237
|
+
/*
|
|
238
|
+
* Tests if the link is up.
|
|
239
|
+
*
|
|
240
|
+
* @return [Boolean] true if link is up otherwise false.
|
|
241
|
+
*/
|
|
242
|
+
static VALUE
|
|
243
|
+
link_up( VALUE self ) {
|
|
244
|
+
uint32_t state = ( uint16_t ) NUM2UINT( rb_iv_get( self, "@state" ) );
|
|
245
|
+
if ( ( state & OFPPS_LINK_DOWN ) == OFPPS_LINK_DOWN ) {
|
|
246
|
+
return Qfalse;
|
|
247
|
+
}
|
|
248
|
+
return Qtrue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* Tests if the link is down.
|
|
254
|
+
*
|
|
255
|
+
* @return [Boolean] true if link is down otherwise false.
|
|
256
|
+
*/
|
|
257
|
+
static VALUE
|
|
258
|
+
link_down( VALUE self ) {
|
|
259
|
+
return link_up( self ) == Qfalse ? Qtrue : Qfalse;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
/*
|
|
264
|
+
* Tests if the link and port are both up.
|
|
265
|
+
*
|
|
266
|
+
* @return [Boolean] true if link is up otherwise false.
|
|
267
|
+
*/
|
|
268
|
+
static VALUE
|
|
269
|
+
port_and_link_up( VALUE self ) {
|
|
270
|
+
if ( port_up( self ) == Qtrue && link_up( self ) == Qtrue ) {
|
|
271
|
+
return Qtrue;
|
|
272
|
+
}
|
|
273
|
+
return Qfalse;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
/*
|
|
278
|
+
* Tests if the link or port is down.
|
|
279
|
+
*
|
|
280
|
+
* @return [Boolean] true if link is up otherwise false.
|
|
281
|
+
*/
|
|
282
|
+
static VALUE
|
|
283
|
+
port_or_link_down( VALUE self ) {
|
|
284
|
+
return port_and_link_up( self ) == Qfalse ? Qtrue : Qfalse;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
241
288
|
/*
|
|
242
289
|
* Compares two ports by substracting their unique numbers.
|
|
243
290
|
*
|
|
@@ -254,6 +301,10 @@ port_compare( VALUE self, VALUE other ) {
|
|
|
254
301
|
void
|
|
255
302
|
Init_port() {
|
|
256
303
|
cPort = rb_define_class_under( mTrema, "Port", rb_cObject );
|
|
304
|
+
|
|
305
|
+
rb_define_const( cPort, "OFPPC_PORT_DOWN", INT2NUM( OFPPC_PORT_DOWN ) );
|
|
306
|
+
rb_define_const( cPort, "OFPPS_LINK_DOWN", INT2NUM( OFPPS_LINK_DOWN ) );
|
|
307
|
+
|
|
257
308
|
rb_define_method( cPort, "initialize", port_init, 1 );
|
|
258
309
|
rb_define_method( cPort, "number", port_number, 0 );
|
|
259
310
|
rb_define_method( cPort, "hw_addr", port_hw_addr, 0 );
|
|
@@ -264,8 +315,12 @@ Init_port() {
|
|
|
264
315
|
rb_define_method( cPort, "advertised", port_advertised, 0 );
|
|
265
316
|
rb_define_method( cPort, "supported", port_supported, 0 );
|
|
266
317
|
rb_define_method( cPort, "peer", port_peer, 0 );
|
|
267
|
-
rb_define_method( cPort, "
|
|
268
|
-
rb_define_method( cPort, "
|
|
318
|
+
rb_define_method( cPort, "port_up?", port_up, 0 );
|
|
319
|
+
rb_define_method( cPort, "port_down?", port_down, 0 );
|
|
320
|
+
rb_define_method( cPort, "link_up?", link_up, 0 );
|
|
321
|
+
rb_define_method( cPort, "link_down?", link_down, 0 );
|
|
322
|
+
rb_define_method( cPort, "up?", port_and_link_up, 0 );
|
|
323
|
+
rb_define_method( cPort, "down?", port_or_link_down, 0 );
|
|
269
324
|
rb_define_method( cPort, "<=>", port_compare, 1 );
|
|
270
325
|
}
|
|
271
326
|
|