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/ruby/trema/command/kill.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema kill command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,8 +16,6 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
|
-
require "trema/dsl"
|
25
19
|
require "trema/util"
|
26
20
|
|
27
21
|
|
@@ -30,44 +24,45 @@ module Trema
|
|
30
24
|
include Trema::Util
|
31
25
|
|
32
26
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
options.on( "-h", "--help" ) do
|
38
|
-
puts options.to_s
|
39
|
-
exit 0
|
40
|
-
end
|
41
|
-
options.on( "-v", "--verbose" ) do
|
42
|
-
$verbose = true
|
27
|
+
def trema_kill name
|
28
|
+
unless maybe_kill( name )
|
29
|
+
exit_now! "unknown name: #{ name }"
|
43
30
|
end
|
31
|
+
end
|
44
32
|
|
45
|
-
options.parse! ARGV
|
46
33
|
|
47
|
-
|
34
|
+
############################################################################
|
35
|
+
private
|
36
|
+
############################################################################
|
48
37
|
|
49
|
-
# [FIXME] Trema apps does not appear in context.apps. why?
|
50
|
-
pid_file = File.join( Trema.pid, "#{ ARGV[ 0 ] }.pid" )
|
51
|
-
if FileTest.exist?( pid_file )
|
52
|
-
Trema::Process.read( pid_file ).kill!
|
53
|
-
return
|
54
|
-
end
|
55
38
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
39
|
+
def maybe_kill name
|
40
|
+
killed = maybe_kill_app( name ) || nil
|
41
|
+
killed ||= maybe_shutdown_host( name )
|
42
|
+
killed ||= maybe_shutdown_switch( name )
|
43
|
+
# [TODO] kill a link by its name. Needs a good naming convension for link.
|
44
|
+
killed
|
45
|
+
end
|
61
46
|
|
62
|
-
switch = context.switches[ ARGV[ 0 ] ]
|
63
|
-
if switch
|
64
|
-
switch.shutdown
|
65
|
-
return
|
66
|
-
end
|
67
47
|
|
68
|
-
|
48
|
+
def maybe_kill_app name
|
49
|
+
app = find_app_by_name( name )
|
50
|
+
app.kill! if app
|
51
|
+
app
|
52
|
+
end
|
69
53
|
|
70
|
-
|
54
|
+
|
55
|
+
def maybe_shutdown_host name
|
56
|
+
host = find_host_by_name( name )
|
57
|
+
host.shutdown! if host
|
58
|
+
host
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def maybe_shutdown_switch name
|
63
|
+
switch = find_switch_by_name( name )
|
64
|
+
switch.shutdown if switch
|
65
|
+
switch
|
71
66
|
end
|
72
67
|
end
|
73
68
|
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema killall command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,7 +16,6 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
19
|
require "trema/util"
|
25
20
|
|
26
21
|
|
@@ -29,20 +24,7 @@ module Trema
|
|
29
24
|
include Trema::Util
|
30
25
|
|
31
26
|
|
32
|
-
def
|
33
|
-
options = OptionParser.new
|
34
|
-
options.banner = "Usage: trema killall [OPTIONS ...]"
|
35
|
-
|
36
|
-
options.on( "-h", "--help" ) do
|
37
|
-
puts options.to_s
|
38
|
-
exit 0
|
39
|
-
end
|
40
|
-
options.on( "-v", "--verbose" ) do
|
41
|
-
$verbose = true
|
42
|
-
end
|
43
|
-
|
44
|
-
options.parse! ARGV
|
45
|
-
|
27
|
+
def trema_killall
|
46
28
|
cleanup_current_session
|
47
29
|
end
|
48
30
|
end
|
@@ -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,13 +16,23 @@
|
|
18
16
|
#
|
19
17
|
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
require "trema/util"
|
20
|
+
|
21
|
+
|
22
|
+
module Trema
|
23
|
+
module Command
|
24
|
+
include Trema::Util
|
25
|
+
|
26
|
+
|
27
|
+
def trema_netns netns
|
28
|
+
sh "sudo ip netns exec #{ netns } #{ ENV[ 'SHELL' ] }"
|
29
|
+
end
|
30
|
+
end
|
23
31
|
end
|
24
32
|
|
25
33
|
|
26
34
|
### Local variables:
|
27
35
|
### mode: Ruby
|
28
|
-
### coding: utf-8
|
36
|
+
### coding: utf-8
|
29
37
|
### indent-tabs-mode: nil
|
30
38
|
### End:
|
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema reset_stats command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,9 +16,7 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
19
|
require "trema/cli"
|
25
|
-
require "trema/dsl"
|
26
20
|
require "trema/util"
|
27
21
|
|
28
22
|
|
@@ -31,23 +25,9 @@ module Trema
|
|
31
25
|
include Trema::Util
|
32
26
|
|
33
27
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
options = OptionParser.new
|
38
|
-
options.banner = "Usage: trema reset_stats [OPTIONS ...]"
|
39
|
-
|
40
|
-
options.on( "-h", "--help" ) do
|
41
|
-
puts options.to_s
|
42
|
-
exit 0
|
43
|
-
end
|
44
|
-
options.on( "-v", "--verbose" ) do
|
45
|
-
$verbose = true
|
46
|
-
end
|
47
|
-
|
48
|
-
options.parse! ARGV
|
49
|
-
|
50
|
-
host = Trema::DSL::Context.load_current.hosts[ ARGV[ 0 ] ]
|
28
|
+
def trema_reset_stats name
|
29
|
+
host = find_host_by_name( name )
|
30
|
+
raise "unknown host: #{ name }" if host.nil?
|
51
31
|
Trema::Cli.new( host ).reset_stats
|
52
32
|
end
|
53
33
|
end
|
data/ruby/trema/command/ruby.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema ruby command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,7 +16,7 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "
|
19
|
+
require "trema/util"
|
24
20
|
|
25
21
|
|
26
22
|
module Trema
|
@@ -28,20 +24,7 @@ module Trema
|
|
28
24
|
include Trema::Util
|
29
25
|
|
30
26
|
|
31
|
-
def
|
32
|
-
options = OptionParser.new
|
33
|
-
options.banner = "Usage: trema ruby [OPTIONS ...]"
|
34
|
-
|
35
|
-
options.on( "-h", "--help" ) do
|
36
|
-
puts options.to_s
|
37
|
-
exit 0
|
38
|
-
end
|
39
|
-
options.on( "-v", "--verbose" ) do
|
40
|
-
$verbose = true
|
41
|
-
end
|
42
|
-
|
43
|
-
options.parse! ARGV
|
44
|
-
|
27
|
+
def trema_ruby
|
45
28
|
sh "x-www-browser http://rubydoc.info/github/trema/trema/master/frames"
|
46
29
|
end
|
47
30
|
end
|
data/ruby/trema/command/run.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema run command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,7 +16,6 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
19
|
require "trema/dsl"
|
25
20
|
require "trema/util"
|
26
21
|
|
@@ -30,34 +25,16 @@ module Trema
|
|
30
25
|
include Trema::Util
|
31
26
|
|
32
27
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
options = OptionParser.new
|
37
|
-
options.banner = "Usage: #{ $0 } run [OPTIONS ...]"
|
28
|
+
def trema_run options
|
29
|
+
@config_file = options[ :conf ] || nil
|
38
30
|
|
39
|
-
options
|
40
|
-
@config_file = v
|
41
|
-
end
|
42
|
-
options.on( "-d", "--daemonize" ) do
|
31
|
+
if options[ :daemonize ]
|
43
32
|
$run_as_daemon = true
|
44
33
|
end
|
45
|
-
options
|
34
|
+
if options[ :tremashark ]
|
46
35
|
$use_tremashark = true
|
47
36
|
end
|
48
37
|
|
49
|
-
options.separator ""
|
50
|
-
|
51
|
-
options.on( "-h", "--help" ) do
|
52
|
-
puts options.to_s
|
53
|
-
exit 0
|
54
|
-
end
|
55
|
-
options.on( "-v", "--verbose" ) do
|
56
|
-
$verbose = true
|
57
|
-
end
|
58
|
-
|
59
|
-
options.parse! ARGV
|
60
|
-
|
61
38
|
cleanup_current_session
|
62
39
|
|
63
40
|
if $run_as_daemon
|
@@ -65,6 +42,8 @@ module Trema
|
|
65
42
|
else
|
66
43
|
begin
|
67
44
|
Trema::DSL::Runner.new( load_config ).run
|
45
|
+
rescue SystemExit
|
46
|
+
# This is OK
|
68
47
|
ensure
|
69
48
|
cleanup_current_session
|
70
49
|
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema send_packets command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,7 +16,6 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
19
|
require "trema/cli"
|
25
20
|
require "trema/dsl"
|
26
21
|
require "trema/util"
|
@@ -31,93 +26,14 @@ module Trema
|
|
31
26
|
include Trema::Util
|
32
27
|
|
33
28
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
source = nil
|
38
|
-
dest = nil
|
39
|
-
cli_options = {}
|
40
|
-
|
41
|
-
dsl_parser = Trema::DSL::Parser.new
|
42
|
-
|
43
|
-
options = OptionParser.new
|
44
|
-
options.banner = "Usage: #{ $0 } send_packets --source HOSTNAME --dest HOSTNAME [OPTIONS ...]"
|
45
|
-
|
46
|
-
options.on( "-s", "--source HOSTNAME" ) do | v |
|
47
|
-
source = Trema::DSL::Context.load_current.hosts[ v ]
|
48
|
-
raise "Unknown host: #{ v }" if source.nil?
|
49
|
-
end
|
50
|
-
options.on( "--inc_ip_src [NUMBER]" ) do | v |
|
51
|
-
if v
|
52
|
-
cli_options[ :inc_ip_src ] = v
|
53
|
-
else
|
54
|
-
cli_options[ :inc_ip_src ] = true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
options.on( "-d", "--dest HOSTNAME" ) do | v |
|
58
|
-
dest = Trema::DSL::Context.load_current.hosts[ v ]
|
59
|
-
raise "Unknown host: #{ v }" if dest.nil?
|
60
|
-
end
|
61
|
-
options.on( "--inc_ip_dst [NUMBER]" ) do | v |
|
62
|
-
if v
|
63
|
-
cli_options[ :inc_ip_dst ] = v
|
64
|
-
else
|
65
|
-
cli_options[ :inc_ip_dst ] = true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
options.on( "--tp_src NUMBER" ) do | v |
|
69
|
-
cli_options[ :tp_src ] = v
|
70
|
-
end
|
71
|
-
options.on( "--inc_tp_src [NUMBER]" ) do | v |
|
72
|
-
if v
|
73
|
-
cli_options[ :inc_tp_src ] = v
|
74
|
-
else
|
75
|
-
cli_options[ :inc_tp_src ] = true
|
76
|
-
end
|
77
|
-
end
|
78
|
-
options.on( "--tp_dst NUMBER" ) do | v |
|
79
|
-
cli_options[ :tp_dst ] = v
|
80
|
-
end
|
81
|
-
options.on( "--inc_tp_dst [NUMBER]" ) do | v |
|
82
|
-
if v
|
83
|
-
cli_options[ :inc_tp_dst ] = v
|
84
|
-
else
|
85
|
-
cli_options[ :inc_tp_dst ] = true
|
86
|
-
end
|
87
|
-
end
|
88
|
-
options.on( "--pps NUMBER" ) do | v |
|
89
|
-
cli_options[ :pps ] = v
|
90
|
-
end
|
91
|
-
options.on( "--n_pkts NUMBER" ) do | v |
|
92
|
-
cli_options[ :n_pkts ] = v
|
93
|
-
end
|
94
|
-
options.on( "--duration NUMBER" ) do | v |
|
95
|
-
cli_options[ :duration ] = v
|
96
|
-
end
|
97
|
-
options.on( "--length NUMBER" ) do | v |
|
98
|
-
cli_options[ :length ] = v
|
99
|
-
end
|
100
|
-
options.on( "--inc_payload [NUMBER]" ) do | v |
|
101
|
-
if v
|
102
|
-
cli_options[ :inc_payload ] = v
|
103
|
-
else
|
104
|
-
cli_options[ :inc_payload ] = true
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
options.separator ""
|
109
|
-
|
110
|
-
options.on( "-h", "--help" ) do
|
111
|
-
puts options.to_s
|
112
|
-
exit 0
|
113
|
-
end
|
114
|
-
options.on( "-v", "--verbose" ) do
|
115
|
-
$verbose = true
|
116
|
-
end
|
29
|
+
def trema_send_packets source_name, dest_name, options
|
30
|
+
source = find_host_by_name( source_name )
|
31
|
+
raise "unknown host: #{ source_name }" if source.nil?
|
117
32
|
|
118
|
-
|
33
|
+
dest = find_host_by_name( dest_name )
|
34
|
+
raise "unknown host: #{ dest_name }" if dest.nil?
|
119
35
|
|
120
|
-
Trema::Cli.new( source ).send_packets( dest,
|
36
|
+
Trema::Cli.new( source ).send_packets( dest, options )
|
121
37
|
end
|
122
38
|
end
|
123
39
|
end
|
@@ -1,8 +1,4 @@
|
|
1
1
|
#
|
2
|
-
# trema show_stats command.
|
3
|
-
#
|
4
|
-
# Author: Yasuhito Takamiya <yasuhito@gmail.com>
|
5
|
-
#
|
6
2
|
# Copyright (C) 2008-2012 NEC Corporation
|
7
3
|
#
|
8
4
|
# This program is free software; you can redistribute it and/or modify
|
@@ -20,9 +16,7 @@
|
|
20
16
|
#
|
21
17
|
|
22
18
|
|
23
|
-
require "optparse"
|
24
19
|
require "trema/cli"
|
25
|
-
require "trema/dsl"
|
26
20
|
require "trema/util"
|
27
21
|
|
28
22
|
|
@@ -31,47 +25,34 @@ module Trema
|
|
31
25
|
include Trema::Util
|
32
26
|
|
33
27
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
stats = nil
|
28
|
+
def trema_show_stats hostname, tx, rx
|
29
|
+
cli = get_cli( hostname )
|
38
30
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
options.on( "-t", "--tx" ) do
|
43
|
-
stats = :tx
|
44
|
-
end
|
45
|
-
options.on( "-r", "--rx" ) do
|
46
|
-
stats = :rx
|
31
|
+
unless tx || rx
|
32
|
+
show_tx_and_rx cli
|
47
33
|
end
|
34
|
+
cli.show_tx_stats if tx
|
35
|
+
cli.show_rx_stats if rx
|
36
|
+
end
|
48
37
|
|
49
|
-
options.separator ""
|
50
38
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
options.on( "-v", "--verbose" ) do
|
56
|
-
$verbose = true
|
57
|
-
end
|
39
|
+
############################################################################
|
40
|
+
private
|
41
|
+
############################################################################
|
58
42
|
|
59
|
-
options.parse! ARGV
|
60
43
|
|
61
|
-
|
62
|
-
|
44
|
+
def show_tx_and_rx cli
|
45
|
+
puts "Sent packets:"
|
46
|
+
cli.show_tx_stats
|
47
|
+
puts "Received packets:"
|
48
|
+
cli.show_rx_stats
|
49
|
+
end
|
63
50
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
else
|
70
|
-
puts "Sent packets:"
|
71
|
-
Trema::Cli.new( host ).show_tx_stats
|
72
|
-
puts "Received packets:"
|
73
|
-
Trema::Cli.new( host ).show_rx_stats
|
74
|
-
end
|
51
|
+
|
52
|
+
def get_cli name
|
53
|
+
host = find_host_by_name( name )
|
54
|
+
exit_now! "unknown host: #{ name }" if host.nil?
|
55
|
+
Trema::Cli.new host
|
75
56
|
end
|
76
57
|
end
|
77
58
|
end
|