trema 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Doxyfile +1 -1
- data/Gemfile +18 -6
- data/README.md +112 -5
- data/Rakefile +3 -1
- data/Rantfile +88 -1
- data/bin/trema +248 -0
- data/bin/trema-config +59 -0
- data/cruise.rb +1 -1
- data/features/example.dumper.feature +45 -65
- data/features/example.hello_trema.feature +21 -0
- data/features/example.learning_switch.feature +26 -28
- data/features/example.list_switches.feature +19 -33
- data/features/example.message.echo_reply.feature +10 -10
- data/features/example.message.echo_request.feature +2 -2
- data/features/example.message.features_request.feature +6 -5
- data/features/example.message.hello.feature +47 -13
- data/features/example.message.set_config.feature +4 -4
- data/features/example.message.vendor-action.feature +23 -0
- data/features/example.multi_learning_switch.feature +14 -42
- data/features/example.packet_in.feature +31 -0
- data/features/example.packetin_filter_config.feature +11 -7
- data/features/example.patch_panel.feature +29 -0
- data/features/example.repeater_hub.feature +43 -40
- data/features/example.switch_info.feature +51 -0
- data/features/example.switch_monitor.feature +24 -42
- data/features/packetin_filter.feature +28 -22
- data/features/step_definitions/misc_steps.rb +19 -8
- data/features/step_definitions/send_packets_steps.rb +1 -10
- data/features/step_definitions/stats_steps.rb +4 -4
- data/features/support/env.rb +2 -1
- data/features/support/hooks.rb +35 -2
- data/features/switch_manager.feature +18 -12
- data/features/trema-config.feature +26 -39
- data/features/trema.dump_flows.feature +26 -12
- data/features/trema.help.feature +26 -0
- data/features/trema.kill.feature +39 -41
- data/features/trema.killall.feature +23 -23
- data/features/trema.reset_stats.feature +50 -10
- data/features/trema.run.feature +28 -39
- data/features/trema.send_packets.feature +29 -40
- data/features/trema.show_stats.feature +30 -33
- data/features/trema.up.feature +33 -0
- data/features/trema.version.feature +9 -0
- data/ruby/extconf.rb +7 -0
- data/ruby/trema/aggregate-stats-reply.rb +3 -3
- data/ruby/trema/app.rb +5 -1
- data/ruby/trema/barrier-request.c +55 -30
- data/ruby/trema/cli.rb +8 -8
- data/ruby/trema/command.rb +1 -3
- data/ruby/trema/command/dump_flows.rb +5 -24
- data/ruby/trema/command/kill.rb +31 -36
- data/ruby/trema/command/killall.rb +1 -19
- data/{features/step_definitions/kill_steps.rb → ruby/trema/command/netns.rb} +13 -5
- data/ruby/trema/command/reset_stats.rb +3 -23
- data/ruby/trema/command/ruby.rb +2 -19
- data/ruby/trema/command/run.rb +6 -27
- data/ruby/trema/command/send_packets.rb +6 -90
- data/ruby/trema/command/show_stats.rb +21 -40
- data/ruby/trema/command/up.rb +5 -26
- data/ruby/trema/command/version.rb +1 -5
- data/ruby/trema/controller.c +14 -16
- data/ruby/trema/custom-switch.rb +56 -0
- data/ruby/trema/desc-stats-reply.rb +5 -5
- data/ruby/trema/dsl/configuration.rb +4 -0
- data/{features/step_definitions/up_steps.rb → ruby/trema/dsl/custom-switch.rb} +18 -4
- data/ruby/trema/dsl/netns.rb +78 -0
- data/ruby/trema/dsl/parser.rb +2 -0
- data/ruby/trema/dsl/runner.rb +8 -0
- data/ruby/trema/dsl/syntax.rb +18 -0
- data/ruby/trema/echo-reply.h +2 -2
- data/ruby/trema/echo-request.c +3 -5
- data/ruby/trema/enqueue.rb +2 -2
- data/ruby/trema/error.c +3 -3
- data/ruby/trema/executables.rb +26 -2
- data/ruby/trema/features-request.c +3 -5
- data/ruby/trema/flow-removed.c +6 -6
- data/ruby/trema/flow-stats-reply.rb +6 -8
- data/ruby/trema/flow.rb +12 -1
- data/ruby/trema/get-config-request.c +55 -28
- data/ruby/trema/hello.c +3 -5
- data/ruby/trema/host.rb +8 -0
- data/ruby/trema/list-switches-reply.c +1 -1
- data/ruby/trema/mac.rb +1 -1
- data/ruby/trema/match.c +15 -14
- data/ruby/trema/monkey-patch/module/deprecation.rb +0 -2
- data/ruby/trema/netns.rb +127 -0
- data/ruby/trema/ordered-hash.rb +5 -4
- data/ruby/trema/packet-in.c +136 -113
- data/ruby/trema/packet-queue.rb +9 -9
- data/ruby/trema/packetin-filter.rb +1 -1
- data/ruby/trema/phost.rb +16 -7
- data/ruby/trema/port-mod.c +6 -5
- data/ruby/trema/port-stats-reply.rb +2 -2
- data/ruby/trema/process.rb +29 -0
- data/ruby/trema/queue-stats-reply.rb +2 -4
- data/ruby/trema/send-out-port.rb +5 -3
- data/ruby/trema/set-eth-addr.rb +4 -0
- data/ruby/trema/set-ip-addr.rb +4 -2
- data/ruby/trema/set-ip-dst-addr.rb +2 -1
- data/ruby/trema/set-ip-src-addr.rb +2 -1
- data/ruby/trema/set-ip-tos.rb +3 -2
- data/ruby/trema/set-transport-port.rb +3 -2
- data/ruby/trema/set-vlan-priority.rb +3 -2
- data/ruby/trema/set-vlan-vid.rb +5 -4
- data/ruby/trema/shell/reset_stats.rb +2 -1
- data/ruby/trema/shell/run.rb +1 -1
- data/ruby/trema/shell/send_packets.rb +1 -1
- data/ruby/trema/shell/show_stats.rb +1 -1
- data/ruby/trema/stats-helper.rb +3 -3
- data/ruby/trema/stats-reply.c +26 -17
- data/ruby/trema/stats-request.c +39 -41
- data/ruby/trema/switch-daemon.rb +36 -31
- data/ruby/trema/switch.c +1 -1
- data/ruby/trema/table-stats-reply.rb +1 -1
- data/ruby/trema/timers.rb +13 -13
- data/ruby/trema/trema.c +3 -3
- data/ruby/trema/tremashark.rb +9 -2
- data/ruby/trema/util.rb +39 -15
- data/ruby/trema/vendor-action.rb +8 -3
- data/ruby/trema/vendor-stats-reply.rb +4 -6
- data/ruby/trema/vendor.c +1 -1
- data/ruby/trema/version.rb +1 -1
- data/spec/trema/barrier-request_spec.rb +47 -37
- data/spec/trema/controller_spec.rb +1 -0
- data/spec/trema/dsl/runner_spec.rb +8 -3
- data/spec/trema/dsl/vhost_spec.rb +8 -8
- data/spec/trema/echo-request_spec.rb +1 -0
- data/spec/trema/features-request_spec.rb +1 -0
- data/spec/trema/flow-removed_spec.rb +9 -9
- data/spec/trema/get-config-request_spec.rb +51 -39
- data/spec/trema/match_spec.rb +1 -1
- data/spec/trema/openflow-error_spec.rb +11 -11
- data/spec/trema/packet-out_spec.rb +5 -5
- data/spec/trema/queue-get-config-reply_spec.rb +1 -1
- data/spec/trema/queue-get-config-request_spec.rb +1 -1
- data/spec/trema/set-eth-dst-addr_spec.rb +1 -1
- data/spec/trema/set-eth-src-addr_spec.rb +1 -1
- data/spec/trema/set-ip-dst-addr_spec.rb +1 -0
- data/spec/trema/set-ip-src-addr_spec.rb +1 -0
- data/spec/trema/set-ip-tos_spec.rb +1 -0
- data/spec/trema/set-transport-dst-port_spec.rb +1 -0
- data/spec/trema/set-transport-src-port_spec.rb +1 -0
- data/spec/trema/set-vlan-priority_spec.rb +1 -0
- data/spec/trema/set-vlan-vid_spec.rb +2 -1
- data/spec/trema/stats-reply_spec.rb +38 -36
- data/spec/trema/stats-request_spec.rb +6 -6
- data/spec/trema/strip-vlan-header_spec.rb +1 -0
- data/spec/trema/util_spec.rb +3 -2
- data/spec/trema/vendor-action_spec.rb +9 -8
- data/src/examples/dumper/dumper.c +8 -6
- data/src/examples/dumper/dumper.rb +1 -1
- data/{features/step_definitions/killall_steps.rb → src/examples/hello_trema/hello-trema.rb} +6 -5
- data/src/examples/hello_trema/hello_trema.c +4 -4
- data/src/examples/learning_switch/learning_switch.c +1 -1
- data/src/examples/list_switches/list_switches.c +2 -2
- data/src/examples/match_compare/match-compare.rb +2 -2
- data/src/examples/multi_learning_switch/multi-learning-switch.rb +1 -1
- data/src/examples/multi_learning_switch/multi_learning_switch.c +3 -3
- data/src/examples/openflow_message/README +1 -1
- data/src/examples/openflow_message/echo-request.rb +1 -1
- data/src/examples/openflow_message/features_request.c +21 -21
- data/src/examples/openflow_message/hello.c +1 -3
- data/src/examples/openflow_message/hello.rb +9 -24
- data/src/examples/{hello_trema/hello_trema.rb → openflow_message/vendor-action.rb} +17 -7
- data/src/examples/openflow_message/vendor_action.c +105 -0
- data/src/examples/openflow_switch/hello_switch.c +81 -0
- data/src/examples/packet_in/packet-in.rb +9 -13
- data/src/examples/packetin_filter_config/packetin_filter_config.c +2 -2
- data/src/examples/patch_panel/network.conf +14 -0
- data/src/examples/patch_panel/patch-panel.conf +1 -0
- data/{features/step_definitions/show_stats_steps.rb → src/examples/patch_panel/patch-panel.rb} +29 -13
- data/src/examples/switch_info/{switch_info.rb → switch-info.rb} +2 -2
- data/src/examples/switch_info/switch_info.c +4 -4
- data/src/examples/switch_monitor/switch_monitor.c +3 -3
- data/src/examples/traffic_monitor/counter.c +9 -9
- data/src/examples/traffic_monitor/fdb.c +9 -9
- data/src/lib/arp.h +1 -1
- data/src/lib/buffer.c +4 -3
- data/src/lib/byteorder.c +31 -5
- data/src/lib/byteorder.h +2 -2
- data/src/lib/chibach.c +8 -6
- data/src/lib/daemon.c +29 -3
- data/src/lib/doubly_linked_list.c +6 -1
- data/src/lib/ether.c +1 -1
- data/src/lib/ether.h +1 -1
- data/src/lib/event_handler.c +3 -3
- data/src/lib/hash_table.c +1 -1
- data/src/lib/linked_list.c +50 -2
- data/src/lib/linked_list.h +2 -2
- data/src/lib/log.c +122 -22
- data/src/lib/log.h +13 -9
- data/src/lib/management_interface.c +361 -0
- data/src/lib/management_interface.h +42 -0
- data/src/lib/management_service_interface.c +104 -0
- data/src/lib/management_service_interface.h +136 -0
- data/src/lib/match_table.c +5 -5
- data/src/lib/message_queue.c +5 -3
- data/src/lib/message_queue.h +1 -1
- data/src/lib/messenger.c +73 -39
- data/src/lib/messenger.h +3 -2
- data/src/lib/openflow_application_interface.c +17 -17
- data/src/lib/openflow_message.c +175 -23
- data/src/lib/openflow_message.h +2 -1
- data/src/lib/openflow_switch_interface.c +12 -12
- data/src/lib/packet_parser.c +11 -32
- data/src/lib/packetin_filter_interface.c +5 -5
- data/src/lib/persistent_storage.c +7 -7
- data/src/lib/secure_channel.c +6 -6
- data/src/lib/secure_channel.h +1 -1
- data/src/lib/stat.c +54 -17
- data/src/lib/stat.h +9 -0
- data/src/lib/timer.c +11 -10
- data/src/lib/trema.c +38 -9
- data/src/lib/trema.h +1 -0
- data/src/lib/trema_private.h +6 -0
- data/src/lib/trema_wrapper.c +4 -4
- data/src/lib/trema_wrapper.h +10 -10
- data/src/lib/utility.c +6 -6
- data/src/management/application.c +224 -0
- data/src/management/echo.c +185 -0
- data/src/management/set_logging_level.c +153 -0
- data/src/management/show_stats.c +150 -0
- data/src/management/trema_manager +184 -0
- data/src/packetin_filter/packetin_filter.c +31 -29
- data/src/switch_manager/cookie_table.c +7 -7
- data/src/switch_manager/dpid_table.c +3 -3
- data/src/switch_manager/dpid_table.h +0 -1
- data/src/switch_manager/management_interface.h +0 -1
- data/src/switch_manager/ofpmsg_recv.c +3 -3
- data/src/switch_manager/ofpmsg_recv.h +0 -1
- data/src/switch_manager/ofpmsg_send.c +2 -2
- data/src/switch_manager/ofpmsg_send.h +0 -1
- data/src/switch_manager/secure_channel_listener.c +2 -2
- data/src/switch_manager/secure_channel_receiver.c +2 -2
- data/src/switch_manager/secure_channel_receiver.h +0 -1
- data/src/switch_manager/secure_channel_sender.c +8 -1
- data/src/switch_manager/service_interface.c +5 -4
- data/src/switch_manager/switch.c +79 -53
- data/src/switch_manager/switch_manager.c +24 -22
- data/src/switch_manager/xid_table.c +6 -6
- data/src/switch_manager/xid_table.h +0 -1
- data/src/tremashark/README +4 -3
- data/src/tremashark/packet_capture.c +11 -9
- data/src/tremashark/pcap_queue.c +2 -2
- data/src/tremashark/pcap_queue.h +2 -2
- data/src/tremashark/plugin/packet-trema/Makefile +1 -1
- data/src/tremashark/plugin/packet-trema/Makefile.common +1 -1
- data/src/tremashark/plugin/packet-trema/packet-trema.c +50 -37
- data/src/tremashark/queue.c +5 -4
- data/src/tremashark/queue.h +1 -1
- data/src/tremashark/stdin_relay.c +10 -8
- data/src/tremashark/syslog_relay.c +14 -12
- data/src/tremashark/tremashark.c +15 -18
- data/trema +2 -96
- data/trema-config +2 -52
- data/trema.gemspec +12 -1
- data/unittests/cmockery_trema.h +14 -13
- data/unittests/lib/buffer_test.c +1 -1
- data/unittests/lib/byteorder_test.c +108 -25
- data/unittests/lib/daemon_test.c +141 -5
- data/unittests/lib/doubly_linked_list_test.c +5 -1
- data/unittests/lib/ether_test.c +4 -4
- data/unittests/lib/hash_table_test.c +5 -3
- data/unittests/lib/linked_list_test.c +82 -4
- data/unittests/lib/log_test.c +96 -5
- data/unittests/lib/management_interface_test.c +240 -0
- data/unittests/lib/management_service_interface_test.c +319 -0
- data/unittests/lib/message_queue_test.c +6 -2
- data/unittests/lib/messenger_test.c +167 -2
- data/unittests/lib/openflow_application_interface_test.c +16 -22
- data/unittests/lib/openflow_message_test.c +721 -24
- data/unittests/lib/packet_info_test.c +2 -2
- data/unittests/lib/packet_parser_test.c +15 -16
- data/unittests/lib/packetin_filter_interface_test.c +6 -6
- data/unittests/lib/persistent_storage_test.c +11 -11
- data/unittests/lib/stat_test.c +151 -7
- data/unittests/lib/timer_test.c +1 -1
- data/unittests/lib/trema_private_test.c +2 -2
- data/unittests/lib/trema_test.c +40 -12
- data/unittests/lib/utility_test.c +3 -3
- data/unittests/lib/wrapper_test.c +3 -3
- data/unittests/packetin_filter/packetin_filter_test.c +12 -11
- data/unittests/switch_manager/switch_manager_test.c +29 -22
- metadata +99 -20
- data/features/step_definitions/log_steps.rb +0 -90
- data/features/step_definitions/run_steps.rb +0 -91
- data/features/trema.feature +0 -27
- data/features/tutorial.hello_trema.feature +0 -27
- data/features/tutorial.packet_in.feature +0 -47
- data/features/tutorial.switch_info.feature +0 -55
- data/ruby/trema/command/usage.rb +0 -63
data/.gitignore
CHANGED
@@ -27,7 +27,7 @@ callgrind.out.*
|
|
27
27
|
html
|
28
28
|
objects
|
29
29
|
|
30
|
-
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
30
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
31
31
|
#
|
32
32
|
# * Create a file at ~/.gitignore
|
33
33
|
# * Include files you want ignored
|
data/Doxyfile
CHANGED
@@ -616,7 +616,7 @@ INPUT_ENCODING = UTF-8
|
|
616
616
|
# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py
|
617
617
|
# *.f90 *.f *.for *.vhd *.vhdl
|
618
618
|
|
619
|
-
FILE_PATTERNS =
|
619
|
+
FILE_PATTERNS =
|
620
620
|
|
621
621
|
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
|
622
622
|
# should be searched for input files as well. Possible values are YES and NO.
|
data/Gemfile
CHANGED
@@ -1,23 +1,35 @@
|
|
1
|
-
source
|
1
|
+
source :rubygems
|
2
2
|
|
3
|
+
|
4
|
+
# Include dependencies from trema.gemspec. DRY!
|
3
5
|
gemspec
|
4
6
|
|
7
|
+
|
5
8
|
# Add dependencies required to use your gem here.
|
6
9
|
# Example:
|
7
10
|
# gem "activesupport", ">= 2.3.5"
|
8
11
|
|
12
|
+
|
9
13
|
# Add dependencies to develop your gem here.
|
10
14
|
# Include everything needed to run rake, tests, features, etc.
|
11
15
|
group :development do
|
16
|
+
gem "aruba", "~> 0.5.1"
|
12
17
|
gem "cucumber", "~> 1.2.1"
|
13
18
|
gem "flay", "~> 1.4.3"
|
14
19
|
gem "flog", "~> 2.5.3"
|
15
|
-
gem "rake", "~> 0.
|
20
|
+
gem "rake", "~> 10.0.2"
|
16
21
|
gem "rcov", "~> 1.0.0"
|
17
22
|
gem "rdoc", "~> 3.12"
|
18
|
-
gem "redcarpet", "~> 2.
|
19
|
-
gem "reek", "~> 1.2.
|
23
|
+
gem "redcarpet", "~> 2.2.2"
|
24
|
+
gem "reek", "~> 1.2.13"
|
20
25
|
gem "roodi", "~> 2.1.0"
|
21
|
-
gem "rspec", "~> 2.
|
22
|
-
gem "yard", "~> 0.
|
26
|
+
gem "rspec", "~> 2.12.0"
|
27
|
+
gem "yard", "~> 0.8.3"
|
23
28
|
end
|
29
|
+
|
30
|
+
|
31
|
+
### Local variables:
|
32
|
+
### mode: Ruby
|
33
|
+
### coding: utf-8-unix
|
34
|
+
### indent-tabs-mode: nil
|
35
|
+
### End:
|
data/README.md
CHANGED
@@ -22,19 +22,30 @@ Supported Platforms
|
|
22
22
|
|
23
23
|
Trema supports GNU/Linux only. And it has been tested on the following environments:
|
24
24
|
|
25
|
-
*
|
25
|
+
* Ruby 1.8.7 (1.9.x is NOT supported yet)
|
26
|
+
* Ubuntu 12.10, 12.04, 11.10, and 10.04 (i386/amd64, Desktop Edition)
|
26
27
|
* Debian GNU/Linux 6.0 (i386/amd64)
|
27
28
|
|
28
29
|
It may also run on other GNU/Linux distributions but is not tested and
|
29
30
|
NOT SUPPORTED at this moment.
|
30
31
|
|
31
32
|
|
33
|
+
Supported OpenFlow Protocol Versions
|
34
|
+
------------------------------------
|
35
|
+
|
36
|
+
Trema currently supports OpenFlow version 1.0 only.
|
37
|
+
|
38
|
+
|
32
39
|
Getting Started
|
33
40
|
---------------
|
34
41
|
|
35
42
|
1.Install the prerequisites at the command prompt:
|
36
43
|
|
37
|
-
|
44
|
+
(In Debian GNU/Linux or Ubuntu 12.04 and below)
|
45
|
+
$ sudo apt-get install gcc make ruby rubygems ruby-dev libpcap-dev libsqlite3-dev
|
46
|
+
|
47
|
+
(In Ubuntu 12.10)
|
48
|
+
$ sudo apt-get install gcc make ruby1.8 rubygems1.8 ruby1.8-dev libpcap-dev libsqlite3-dev
|
38
49
|
|
39
50
|
2.Install Trema at the command prompt:
|
40
51
|
|
@@ -51,7 +62,7 @@ Getting Started
|
|
51
62
|
Ruby API
|
52
63
|
--------
|
53
64
|
|
54
|
-
The following is an
|
65
|
+
The following is an excerpt from the Trema Ruby API.
|
55
66
|
The full documents are found here http://rubydoc.info/github/trema/trema/master/frames
|
56
67
|
|
57
68
|
### Event and Message Handlers
|
@@ -61,6 +72,22 @@ Subclass
|
|
61
72
|
and override some of the following methods to implement your own
|
62
73
|
controller.
|
63
74
|
|
75
|
+
```ruby
|
76
|
+
class MyController < Controller
|
77
|
+
# handle Packet-In messages here.
|
78
|
+
def packet_in datapath_id, message
|
79
|
+
# ...
|
80
|
+
end
|
81
|
+
|
82
|
+
# handle Flow-Removed messages here.
|
83
|
+
def flow_removed datapath_id, message
|
84
|
+
# ...
|
85
|
+
end
|
86
|
+
|
87
|
+
# ...
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
64
91
|
* [switch_ready(datapath_id)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:switch_ready)
|
65
92
|
* [switch_disconnected(datapath_id)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:switch_disconnected)
|
66
93
|
* [packet_in(datapath_id, message)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:packet_in)
|
@@ -80,6 +107,18 @@ For sending Flow-Mod and Packet-Out, there are some methods defined in
|
|
80
107
|
[Trema::Controller](http://rubydoc.info/github/trema/trema/master/Trema/Controller)
|
81
108
|
class.
|
82
109
|
|
110
|
+
```ruby
|
111
|
+
class MyController < Controller
|
112
|
+
def packet_in datapath_id, message
|
113
|
+
# ...
|
114
|
+
send_flow_mod_add( datapath_id, ... )
|
115
|
+
send_packet_out( datapath_id, ... )
|
116
|
+
end
|
117
|
+
|
118
|
+
# ...
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
83
122
|
* [send_flow_mod_add(datapath_id, options)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:send_flow_mod_add)
|
84
123
|
* [send_flow_mod_delete(datapath_id, options)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:send_flow_mod_delete)
|
85
124
|
* [send_flow_mod_modify(datapath_id, options)](http://rubydoc.info/github/trema/trema/master/Trema/Controller:send_flow_mod_modify)
|
@@ -90,6 +129,24 @@ class.
|
|
90
129
|
The following OpenFlow messages can be sent with
|
91
130
|
[Trema::Controller#send_message](http://rubydoc.info/github/trema/trema/master/Trema/Controller:send_message)
|
92
131
|
|
132
|
+
```ruby
|
133
|
+
class MyController < Controller
|
134
|
+
def switch_ready datapath_id
|
135
|
+
# send a FeaturesRequest message
|
136
|
+
send_message datapath_id, FeaturesRequest.new
|
137
|
+
end
|
138
|
+
|
139
|
+
def features_reply datapath_id, message
|
140
|
+
# ...
|
141
|
+
end
|
142
|
+
|
143
|
+
# ...
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
* [Trema::Hello](http://rubydoc.info/github/trema/trema/master/Trema/Hello)
|
148
|
+
* [Trema::EchoRequest](http://rubydoc.info/github/trema/trema/master/Trema/EchoRequest)
|
149
|
+
* [Trema::EchoReply](http://rubydoc.info/github/trema/trema/master/Trema/EchoReply)
|
93
150
|
* [Trema::FeaturesRequest](http://rubydoc.info/github/trema/trema/master/Trema/FeaturesRequest)
|
94
151
|
* [Trema::SetConfig](http://rubydoc.info/github/trema/trema/master/Trema/SetConfig)
|
95
152
|
* [Trema::GetConfigRequest](http://rubydoc.info/github/trema/trema/master/Trema/GetConfigRequest)
|
@@ -105,9 +162,57 @@ The following OpenFlow messages can be sent with
|
|
105
162
|
* [Trema::PortMod](http://rubydoc.info/github/trema/trema/master/Trema/PortMod)
|
106
163
|
* [Trema::Vendor](http://rubydoc.info/github/trema/trema/master/Trema/Vendor)
|
107
164
|
|
165
|
+
### Matching Rules
|
166
|
+
|
167
|
+
The matching rule of each flow table entry can be created with
|
168
|
+
[Match.new(options)](http://rubydoc.info/github/trema/trema/master/Trema/Match)
|
169
|
+
and passed as ":match =>" option when sending Flow-Mod or Packet-Out.
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
def packet_in datapath_id, message
|
173
|
+
# ...
|
174
|
+
|
175
|
+
send_flow_mod_add(
|
176
|
+
datapath_id,
|
177
|
+
:match => Match.new( :in_port => message.in_port, ...)
|
178
|
+
# ...
|
179
|
+
)
|
180
|
+
|
181
|
+
# ...
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
185
|
+
Also there is a utility method called
|
186
|
+
[ExactMatch.from(packetin)](http://rubydoc.info/github/trema/trema/master/Trema/ExactMatch)
|
187
|
+
for getting an exact match corresponding to a packet.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
def packet_in datapath_id, message
|
191
|
+
# ...
|
192
|
+
|
193
|
+
send_flow_mod_add(
|
194
|
+
datapath_id,
|
195
|
+
:match => ExactMatch.from( message )
|
196
|
+
# ...
|
197
|
+
)
|
198
|
+
|
199
|
+
# ...
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
108
203
|
### Actions
|
109
204
|
|
110
|
-
|
205
|
+
The actions list of each flow table entry can be set with ":actions
|
206
|
+
=>" when sending Flow-Mod or Packet-Out.
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
# Strip the VLAN tag of a packet then send it out to switch port #1
|
210
|
+
send_flow_mod_add(
|
211
|
+
datapath_id,
|
212
|
+
# ...
|
213
|
+
:actions => [ StripVlanHeader.new, SendOutPort.new( 1 ) ]
|
214
|
+
)
|
215
|
+
```
|
111
216
|
|
112
217
|
* [Trema::SendOutPort](http://rubydoc.info/github/trema/trema/master/Trema/SendOutPort)
|
113
218
|
* [Trema::SetEthSrcAddr](http://rubydoc.info/github/trema/trema/master/Trema/SetEthSrcAddr)
|
@@ -135,7 +240,8 @@ Meta
|
|
135
240
|
Contributors
|
136
241
|
------------
|
137
242
|
|
138
|
-
Special thanks to all contributors for submitting patches. A full list
|
243
|
+
Special thanks to all contributors for submitting patches. A full list
|
244
|
+
of contributors including their patches can be found at:
|
139
245
|
|
140
246
|
https://github.com/trema/trema/contributors
|
141
247
|
|
@@ -145,6 +251,7 @@ Project Status
|
|
145
251
|
|
146
252
|
* Build Status [![Build Status](https://secure.travis-ci.org/trema/trema.png?branch=develop)](http://travis-ci.org/trema/trema)
|
147
253
|
* Dependency Status [![Dependency Status](https://gemnasium.com/trema/trema.png)](https://gemnasium.com/trema/trema)
|
254
|
+
* Code Quality [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/trema/trema)
|
148
255
|
|
149
256
|
|
150
257
|
License
|
data/Rakefile
CHANGED
data/Rantfile
CHANGED
@@ -37,6 +37,7 @@ import "directedrule"
|
|
37
37
|
desc "Build trema."
|
38
38
|
task :default => [
|
39
39
|
:libtrema,
|
40
|
+
:management_commands,
|
40
41
|
:rubylib,
|
41
42
|
:switch_manager,
|
42
43
|
:switch,
|
@@ -57,6 +58,7 @@ task :examples => [
|
|
57
58
|
"examples:learning_switch",
|
58
59
|
"examples:list_switches",
|
59
60
|
"examples:multi_learning_switch",
|
61
|
+
"examples:openflow_switch",
|
60
62
|
"examples:openflow_message",
|
61
63
|
"examples:packet_in",
|
62
64
|
"examples:repeater_hub",
|
@@ -67,6 +69,14 @@ task :examples => [
|
|
67
69
|
]
|
68
70
|
|
69
71
|
|
72
|
+
task :management_commands => [
|
73
|
+
"management_commands:application",
|
74
|
+
"management_commands:echo",
|
75
|
+
"management_commands:set_logging_level",
|
76
|
+
"management_commands:show_stats",
|
77
|
+
]
|
78
|
+
|
79
|
+
|
70
80
|
import "clean"
|
71
81
|
|
72
82
|
desc "Cleanup generated files."
|
@@ -173,7 +183,7 @@ end
|
|
173
183
|
|
174
184
|
|
175
185
|
desc "Run the c cbench switch controller to benchmark"
|
176
|
-
task "cbench" => "cbench:
|
186
|
+
task "cbench" => "cbench:ruby"
|
177
187
|
|
178
188
|
|
179
189
|
desc "Run the c cbench switch controller to benchmark"
|
@@ -588,6 +598,45 @@ file Trema::Executables.stdin_relay => stdin_relay_objects + [ libtrema ] do | t
|
|
588
598
|
end
|
589
599
|
|
590
600
|
|
601
|
+
################################################################################
|
602
|
+
# Build management commands
|
603
|
+
################################################################################
|
604
|
+
|
605
|
+
management_commands = [
|
606
|
+
"application",
|
607
|
+
"echo",
|
608
|
+
"set_logging_level",
|
609
|
+
"show_stats",
|
610
|
+
]
|
611
|
+
|
612
|
+
management_source_dir = "src/management"
|
613
|
+
management_objects_dir = objects( "management" )
|
614
|
+
|
615
|
+
gen C::Dependencies, dependency( "management" ),
|
616
|
+
:search => [ Trema.include ], :sources => sys[ "#{ management_source_dir }/*.c" ]
|
617
|
+
|
618
|
+
gen Action do
|
619
|
+
source dependency( "management" )
|
620
|
+
end
|
621
|
+
|
622
|
+
gen Directory, management_objects_dir
|
623
|
+
|
624
|
+
|
625
|
+
gen DirectedRule, management_objects_dir => [ management_source_dir ], :o => :c do | t |
|
626
|
+
sys "gcc -I#{ Trema.include } -I#{ Trema.openflow } #{ var :CFLAGS } -c -o #{ t.name } #{ t.source }"
|
627
|
+
end
|
628
|
+
|
629
|
+
|
630
|
+
management_commands.each do | each |
|
631
|
+
target = File.join( management_objects_dir, each )
|
632
|
+
desc "Build #{ each } management command."
|
633
|
+
task "management_commands:#{ each }" => target
|
634
|
+
file target => [ File.join( management_objects_dir, "#{ each }.o" ), libtrema ] do | t |
|
635
|
+
sys "gcc -L#{ Trema.lib } -o #{ t.name } #{ t.source } -ltrema -lsqlite3 -ldl -lrt -lpthread"
|
636
|
+
end
|
637
|
+
end
|
638
|
+
|
639
|
+
|
591
640
|
################################################################################
|
592
641
|
# Build standalone examples
|
593
642
|
################################################################################
|
@@ -633,6 +682,41 @@ standalone_examples.each do | each |
|
|
633
682
|
end
|
634
683
|
|
635
684
|
|
685
|
+
########################################################################################
|
686
|
+
# Build openflow switches
|
687
|
+
################################################################################
|
688
|
+
|
689
|
+
openflow_switches = [
|
690
|
+
"hello_switch",
|
691
|
+
]
|
692
|
+
|
693
|
+
openflow_switch_source_dir = "src/examples/openflow_switch"
|
694
|
+
openflow_switch_objects_dir = objects( "examples/openflow_switch" )
|
695
|
+
|
696
|
+
gen C::Dependencies, dependency( "openflow_switch" ),
|
697
|
+
:search => [ Trema.include ], :sources => sys[ "#{ openflow_switch_source_dir }/*.c" ]
|
698
|
+
|
699
|
+
gen Action do
|
700
|
+
source dependency( "openflow_switch" )
|
701
|
+
end
|
702
|
+
|
703
|
+
gen Directory, openflow_switch_objects_dir
|
704
|
+
|
705
|
+
|
706
|
+
gen DirectedRule, openflow_switch_objects_dir => [ openflow_switch_source_dir ], :o => :c do | t |
|
707
|
+
sys "gcc -I#{ Trema.include } -I#{ Trema.openflow } #{ var :CFLAGS } -c -o #{ t.name } #{ t.source }"
|
708
|
+
end
|
709
|
+
|
710
|
+
|
711
|
+
openflow_switches.each do | each |
|
712
|
+
target = File.join( openflow_switch_objects_dir, each )
|
713
|
+
task "examples:openflow_switch" => target
|
714
|
+
file target => [ File.join( openflow_switch_objects_dir, "#{ each }.o" ), libtrema ] do | t |
|
715
|
+
sys "gcc -L#{ Trema.lib } -o #{ t.name } #{ t.source } -ltrema -lsqlite3 -ldl -lrt -lpthread"
|
716
|
+
end
|
717
|
+
end
|
718
|
+
|
719
|
+
|
636
720
|
################################################################################
|
637
721
|
# Build openflow messages
|
638
722
|
################################################################################
|
@@ -643,6 +727,7 @@ openflow_messages = [
|
|
643
727
|
"features_request",
|
644
728
|
"hello",
|
645
729
|
"set_config",
|
730
|
+
"vendor_action",
|
646
731
|
]
|
647
732
|
|
648
733
|
openflow_message_source_dir = "src/examples/openflow_message"
|
@@ -794,6 +879,8 @@ tests = [
|
|
794
879
|
"objects/unittests/wrapper_test",
|
795
880
|
"objects/unittests/match_table_test",
|
796
881
|
"objects/unittests/message_queue_test",
|
882
|
+
"objects/unittests/management_interface_test",
|
883
|
+
"objects/unittests/management_service_interface_test",
|
797
884
|
]
|
798
885
|
|
799
886
|
|
data/bin/trema
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Trema command-line tool.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2008-2012 NEC Corporation
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License, version 2, as
|
9
|
+
# published by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
18
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19
|
+
#
|
20
|
+
|
21
|
+
|
22
|
+
$LOAD_PATH.unshift File.expand_path( File.join File.dirname( __FILE__ ), "..", "ruby" )
|
23
|
+
|
24
|
+
|
25
|
+
require "rubygems"
|
26
|
+
|
27
|
+
require "gli"
|
28
|
+
require "trema/command"
|
29
|
+
require "trema/util"
|
30
|
+
require "trema/version"
|
31
|
+
|
32
|
+
|
33
|
+
include GLI::App
|
34
|
+
include Trema::Util
|
35
|
+
include Trema::Command
|
36
|
+
|
37
|
+
|
38
|
+
program_desc "Trema command-line tool"
|
39
|
+
|
40
|
+
|
41
|
+
desc "Displays the current runtime version"
|
42
|
+
version Trema::VERSION
|
43
|
+
|
44
|
+
|
45
|
+
desc "Be verbose"
|
46
|
+
switch [ :v, :verbose ], :negatable => false
|
47
|
+
|
48
|
+
|
49
|
+
desc "Runs a trema application"
|
50
|
+
arg_name "controller"
|
51
|
+
command :run do | c |
|
52
|
+
c.desc "Runs as a daemon"
|
53
|
+
c.switch [ :d, :daemonize ], :negatable => false
|
54
|
+
|
55
|
+
c.desc "Enables Trema wireshark plugin"
|
56
|
+
c.switch [ :s, :tremashark ], :negatable => false
|
57
|
+
|
58
|
+
c.desc "Specifies emulated network configuration"
|
59
|
+
c.flag [ :c, :conf ]
|
60
|
+
|
61
|
+
c.action do | global_options, options, args |
|
62
|
+
trema_run options
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
desc "Terminates a trema process"
|
68
|
+
arg_name "name"
|
69
|
+
command :kill do | c |
|
70
|
+
c.action do | global_options, options, args |
|
71
|
+
help_now!( "name is required" ) if args.empty?
|
72
|
+
args.each do | each |
|
73
|
+
trema_kill each
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
desc "Starts a killed trema process again"
|
80
|
+
arg_name "name"
|
81
|
+
command :up do | c |
|
82
|
+
c.action do | global_options, options, args |
|
83
|
+
trema_up args[ 0 ]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
desc "Terminates all trema processes"
|
89
|
+
command :killall do | c |
|
90
|
+
c.action do
|
91
|
+
trema_killall
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
desc "Sends UDP packets to destination host"
|
97
|
+
command :send_packets do | c |
|
98
|
+
c.desc "host that sends packets"
|
99
|
+
c.flag [ :s, :source ]
|
100
|
+
|
101
|
+
c.desc "host that receives packets"
|
102
|
+
c.flag [ :d, :dest ]
|
103
|
+
|
104
|
+
c.desc "number of times to increment the IP source address"
|
105
|
+
c.default_value nil
|
106
|
+
c.flag [ :inc_ip_src ]
|
107
|
+
|
108
|
+
c.desc "number of times to increment the IP destination address"
|
109
|
+
c.default_value nil
|
110
|
+
c.flag [ :inc_ip_dst ]
|
111
|
+
|
112
|
+
c.desc "set the initial UDP source port"
|
113
|
+
c.flag [ :tp_src ]
|
114
|
+
|
115
|
+
c.desc "number of times to increment the UDP source port"
|
116
|
+
c.default_value nil
|
117
|
+
c.flag [ :inc_tp_src ]
|
118
|
+
|
119
|
+
c.desc "set the initial UDP destination port"
|
120
|
+
c.flag [ :tp_dst ]
|
121
|
+
|
122
|
+
c.desc "number of times to increment the UDP destination port"
|
123
|
+
c.default_value nil
|
124
|
+
c.flag [ :inc_tp_dst ]
|
125
|
+
|
126
|
+
c.desc "send packet rate - packets per second"
|
127
|
+
c.flag [ :pps ]
|
128
|
+
|
129
|
+
c.desc "number of packets to send"
|
130
|
+
c.flag [ :n_pkts ]
|
131
|
+
|
132
|
+
c.desc "time duration to send packets"
|
133
|
+
c.flag [ :duration ]
|
134
|
+
|
135
|
+
c.desc "length of UDP payload"
|
136
|
+
c.flag [ :length ]
|
137
|
+
|
138
|
+
c.desc "increment UDP payload"
|
139
|
+
c.default_value nil
|
140
|
+
c.flag [ :inc_payload ]
|
141
|
+
|
142
|
+
c.action do | global_options, options, args |
|
143
|
+
raise "--source option is mandatory" if options[ :source ].nil?
|
144
|
+
raise "--dest option is mandatory" if options[ :dest ].nil?
|
145
|
+
|
146
|
+
trema_send_packets options[ :source ], options[ :dest ], options
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
desc "Shows stats of packets"
|
152
|
+
arg_name "host"
|
153
|
+
command :show_stats do | c |
|
154
|
+
c.desc "Show stats of packets sent"
|
155
|
+
c.switch [ :t, :tx ], :negatable => false
|
156
|
+
c.desc "Show stats of packets received"
|
157
|
+
c.switch [ :r, :rx ], :negatable => false
|
158
|
+
|
159
|
+
c.action do | global_options, options, args |
|
160
|
+
help_now!( "host is required" ) if args.empty?
|
161
|
+
trema_show_stats args[ 0 ], options[ :tx ], options[ :rx ]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
desc "Resets stats of packets"
|
167
|
+
arg_name "hosts..."
|
168
|
+
command :reset_stats do | c |
|
169
|
+
c.action do | global_options, options, args |
|
170
|
+
hosts = args
|
171
|
+
if hosts.empty?
|
172
|
+
hosts = Trema::DSL::Context.load_current.hosts.keys
|
173
|
+
end
|
174
|
+
hosts.each do | each |
|
175
|
+
trema_reset_stats each
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
desc "Print all flow entries"
|
182
|
+
arg_name "switches..."
|
183
|
+
command :dump_flows do | c |
|
184
|
+
c.action do | global_options, options, args |
|
185
|
+
help_now!( "switches is required" ) if args.empty?
|
186
|
+
trema_dump_flows args
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
desc "Opens a new shell in the specified network namespace"
|
192
|
+
arg_name "name"
|
193
|
+
command :netns do | c |
|
194
|
+
c.action do | global_options, options, args |
|
195
|
+
trema_netns args[ 0 ]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
desc "Opens in your browser Trema's Ruby API documentation"
|
201
|
+
command :ruby do | c |
|
202
|
+
c.action do
|
203
|
+
trema_ruby
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
desc "Displays the current runtime version"
|
209
|
+
command :version do | c |
|
210
|
+
c.action do
|
211
|
+
trema_version
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
pre do | global, command, options, args |
|
217
|
+
$verbose = global[ :verbose ]
|
218
|
+
|
219
|
+
assert_trema_is_built
|
220
|
+
|
221
|
+
if FileTest.exist?( Trema.tmp ) and not FileTest.writable?( Trema.tmp )
|
222
|
+
# Trema is system widely installed with gem command
|
223
|
+
sh "sudo chmod o+w -R #{ Trema.tmp }"
|
224
|
+
end
|
225
|
+
|
226
|
+
FileUtils.mkdir_p Trema.log
|
227
|
+
FileUtils.mkdir_p Trema.pid
|
228
|
+
FileUtils.mkdir_p Trema.sock
|
229
|
+
|
230
|
+
true
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
on_error do | exception |
|
235
|
+
# Error logic here
|
236
|
+
# return false to skip default error handling
|
237
|
+
true
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
exit run( ARGV )
|
242
|
+
|
243
|
+
|
244
|
+
### Local variables:
|
245
|
+
### mode: Ruby
|
246
|
+
### coding: utf-8
|
247
|
+
### indent-tabs-mode: nil
|
248
|
+
### End:
|