trema 0.2.5 → 0.2.6
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/.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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Management command to check if a specified application/service is alive or not.
|
|
3
|
+
*
|
|
4
|
+
* Author: Yasunobu Chiba
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2012 NEC Corporation
|
|
7
|
+
*
|
|
8
|
+
* This program is free software; you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License, version 2, as
|
|
10
|
+
* published by the Free Software Foundation.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License along
|
|
18
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <assert.h>
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <string.h>
|
|
27
|
+
#include <time.h>
|
|
28
|
+
#include "trema.h"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#define SUB_TIMESPEC( _a, _b, _return ) \
|
|
32
|
+
do { \
|
|
33
|
+
( _return )->tv_sec = ( _a )->tv_sec - ( _b )->tv_sec; \
|
|
34
|
+
( _return )->tv_nsec = ( _a )->tv_nsec - ( _b )->tv_nsec; \
|
|
35
|
+
if ( ( _return )->tv_nsec < 0 ) { \
|
|
36
|
+
( _return )->tv_sec--; \
|
|
37
|
+
( _return )->tv_nsec += 1000000000; \
|
|
38
|
+
} \
|
|
39
|
+
} \
|
|
40
|
+
while ( 0 )
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
static char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
void
|
|
47
|
+
usage( void ) {
|
|
48
|
+
printf( "Usage: echo SERVICE_NAME\n" );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
static void
|
|
53
|
+
print_usage_and_exit( void ) {
|
|
54
|
+
usage();
|
|
55
|
+
exit( EXIT_FAILURE );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
static void
|
|
60
|
+
parse_arguments( int argc, char **argv ) {
|
|
61
|
+
assert( argv != NULL );
|
|
62
|
+
|
|
63
|
+
if ( argc != 2 ) {
|
|
64
|
+
print_usage_and_exit();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if ( argv[ 1 ] == NULL || ( argv[ 1 ] != NULL && strlen( argv[ 1 ] ) == 0 ) ) {
|
|
68
|
+
print_usage_and_exit();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
memset( service_name, '\0', MESSENGER_SERVICE_NAME_LENGTH );
|
|
72
|
+
snprintf( service_name, MESSENGER_SERVICE_NAME_LENGTH, "%s", get_management_service_name( argv[ 1 ] ) );
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
static void
|
|
77
|
+
timeout( void *user_data ) {
|
|
78
|
+
UNUSED( user_data );
|
|
79
|
+
|
|
80
|
+
printf( "Timeout.\n" );
|
|
81
|
+
|
|
82
|
+
delete_timer_event( timeout, NULL );
|
|
83
|
+
|
|
84
|
+
stop_trema();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
static void
|
|
89
|
+
handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
|
|
90
|
+
UNUSED( user_data );
|
|
91
|
+
|
|
92
|
+
assert( tag == MESSENGER_MANAGEMENT_REPLY );
|
|
93
|
+
assert( data != NULL );
|
|
94
|
+
assert( length == sizeof( management_echo_reply ) );
|
|
95
|
+
|
|
96
|
+
management_echo_reply *reply = data;
|
|
97
|
+
assert( ntohs( reply->header.type ) == MANAGEMENT_ECHO_REPLY );
|
|
98
|
+
assert( ntohl( reply->header.length ) == sizeof( management_echo_reply ) );
|
|
99
|
+
|
|
100
|
+
if ( reply->header.status != MANAGEMENT_REQUEST_SUCCEEDED ) {
|
|
101
|
+
printf( "Failed to execute echo request/reply transaction.\n" );
|
|
102
|
+
stop_trema();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
struct timespec sent_at = { 0, 0 };
|
|
107
|
+
sent_at.tv_sec = ( time_t ) ntohl( reply->sent_at.tv_sec );
|
|
108
|
+
sent_at.tv_nsec = ( long ) ntohl( reply->sent_at.tv_nsec );
|
|
109
|
+
|
|
110
|
+
struct timespec received_at = { 0, 0 };
|
|
111
|
+
received_at.tv_sec = ( time_t ) ntohl( reply->received_at.tv_sec );
|
|
112
|
+
received_at.tv_nsec = ( long ) ntohl( reply->received_at.tv_nsec );
|
|
113
|
+
|
|
114
|
+
struct timespec now = { 0, 0 };
|
|
115
|
+
clock_gettime( CLOCK_REALTIME, &now );
|
|
116
|
+
|
|
117
|
+
struct timespec roundtrip = { 0, 0 };
|
|
118
|
+
SUB_TIMESPEC( &now, &sent_at, &roundtrip );
|
|
119
|
+
|
|
120
|
+
long double roundtrip_msec = roundtrip.tv_sec * 1000 + ( long double ) roundtrip.tv_nsec / 1000000;
|
|
121
|
+
|
|
122
|
+
printf( "Reqeust sent at: %d.%09d\n", ( int ) sent_at.tv_sec, ( int ) sent_at.tv_nsec );
|
|
123
|
+
printf( "Reqeust received at: %d.%09d\n", ( int ) received_at.tv_sec, ( int ) received_at.tv_nsec );
|
|
124
|
+
printf( "Reply received at: %d.%09d\n", ( int ) now.tv_sec, ( int ) now.tv_nsec );
|
|
125
|
+
printf( "Roundtrip time: %Lf [msec]\n", roundtrip_msec );
|
|
126
|
+
|
|
127
|
+
stop_trema();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
static void
|
|
132
|
+
send_echo_request() {
|
|
133
|
+
management_echo_request request;
|
|
134
|
+
memset( &request, 0, sizeof( management_echo_request ) );
|
|
135
|
+
request.header.type = MANAGEMENT_ECHO_REQUEST;
|
|
136
|
+
request.header.length = htonl( sizeof( management_echo_request ) );
|
|
137
|
+
|
|
138
|
+
struct timespec now = { 0, 0 };
|
|
139
|
+
int retval = clock_gettime( CLOCK_REALTIME, &now );
|
|
140
|
+
if ( retval < 0 ) {
|
|
141
|
+
printf( "Failed to retrieve clock ( errno = %s [%d] ).\n", strerror( errno ), errno );
|
|
142
|
+
exit( EXIT_FAILURE );
|
|
143
|
+
}
|
|
144
|
+
request.sent_at.tv_sec = htonl( ( uint32_t ) now.tv_sec );
|
|
145
|
+
request.sent_at.tv_nsec = htonl( ( uint32_t ) now.tv_nsec );
|
|
146
|
+
|
|
147
|
+
bool ret = send_request_message( service_name, get_trema_name(), MESSENGER_MANAGEMENT_REQUEST,
|
|
148
|
+
&request, sizeof( management_echo_request ), NULL );
|
|
149
|
+
if ( !ret ) {
|
|
150
|
+
printf( "Failed to send an echo request to %s.\n", service_name );
|
|
151
|
+
exit( EXIT_FAILURE );
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
int
|
|
157
|
+
main( int argc, char *argv[] ) {
|
|
158
|
+
// Initialize the Trema world
|
|
159
|
+
init_trema( &argc, &argv );
|
|
160
|
+
|
|
161
|
+
// Parse arguments
|
|
162
|
+
parse_arguments( argc, argv );
|
|
163
|
+
|
|
164
|
+
// Set a handler to handle echo reply
|
|
165
|
+
add_message_replied_callback( get_trema_name(), handle_reply );
|
|
166
|
+
|
|
167
|
+
// Send an echo request
|
|
168
|
+
send_echo_request();
|
|
169
|
+
|
|
170
|
+
// Set timeout
|
|
171
|
+
add_periodic_event_callback( 5, timeout, NULL );
|
|
172
|
+
|
|
173
|
+
// Main loop
|
|
174
|
+
start_trema();
|
|
175
|
+
|
|
176
|
+
return EXIT_SUCCESS;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
/*
|
|
181
|
+
* Local variables:
|
|
182
|
+
* c-basic-offset: 2
|
|
183
|
+
* indent-tabs-mode: nil
|
|
184
|
+
* End:
|
|
185
|
+
*/
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Management command to change logging level in operation.
|
|
3
|
+
*
|
|
4
|
+
* Author: Yasunobu Chiba
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2012 NEC Corporation
|
|
7
|
+
*
|
|
8
|
+
* This program is free software; you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License, version 2, as
|
|
10
|
+
* published by the Free Software Foundation.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License along
|
|
18
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <assert.h>
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <string.h>
|
|
27
|
+
#include "trema.h"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
static char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
|
31
|
+
static char logging_level[ LOGGING_LEVEL_STR_LENGTH ];
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
void
|
|
35
|
+
usage( void ) {
|
|
36
|
+
printf( "Usage: set_logging_level SERVICE_NAME LEVEL\n" );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
static void
|
|
41
|
+
print_usage_and_exit( void ) {
|
|
42
|
+
usage();
|
|
43
|
+
exit( EXIT_FAILURE );
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
static void
|
|
48
|
+
parse_arguments( int argc, char **argv ) {
|
|
49
|
+
assert( argv != NULL );
|
|
50
|
+
|
|
51
|
+
if ( argc != 3 ) {
|
|
52
|
+
print_usage_and_exit();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if ( argv[ 1 ] == NULL || ( argv[ 1 ] != NULL && strlen( argv[ 1 ] ) == 0 ) ) {
|
|
56
|
+
print_usage_and_exit();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if ( argv[ 2 ] == NULL ||
|
|
60
|
+
( argv[ 2 ] != NULL && ( strlen( argv[ 2 ] ) == 0 || strlen( argv[ 2 ] ) >= LOGGING_LEVEL_STR_LENGTH ) ) ) {
|
|
61
|
+
print_usage_and_exit();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
memset( service_name, '\0', MESSENGER_SERVICE_NAME_LENGTH );
|
|
65
|
+
snprintf( service_name, MESSENGER_SERVICE_NAME_LENGTH, "%s", get_management_service_name( argv[ 1 ] ) );
|
|
66
|
+
|
|
67
|
+
memset( logging_level, '\0', LOGGING_LEVEL_STR_LENGTH );
|
|
68
|
+
snprintf( logging_level, LOGGING_LEVEL_STR_LENGTH, "%s", argv[ 2 ] );
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
static void
|
|
73
|
+
timeout( void *user_data ) {
|
|
74
|
+
UNUSED( user_data );
|
|
75
|
+
|
|
76
|
+
printf( "Timeout.\n" );
|
|
77
|
+
|
|
78
|
+
delete_timer_event( timeout, NULL );
|
|
79
|
+
|
|
80
|
+
stop_trema();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
static void
|
|
85
|
+
handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
|
|
86
|
+
UNUSED( user_data );
|
|
87
|
+
|
|
88
|
+
assert( tag == MESSENGER_MANAGEMENT_REPLY );
|
|
89
|
+
assert( data != NULL );
|
|
90
|
+
assert( length == sizeof( management_set_logging_level_reply ) );
|
|
91
|
+
|
|
92
|
+
management_set_logging_level_reply *reply = data;
|
|
93
|
+
assert( ntohs( reply->header.type ) == MANAGEMENT_SET_LOGGING_LEVEL_REPLY );
|
|
94
|
+
assert( ntohl( reply->header.length ) == sizeof( management_set_logging_level_reply ) );
|
|
95
|
+
|
|
96
|
+
if ( reply->header.status == MANAGEMENT_REQUEST_SUCCEEDED ) {
|
|
97
|
+
printf( "Logging level is set to %s.\n", logging_level );
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
printf( "Failed to set logging level.\n" );
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
stop_trema();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
static void
|
|
108
|
+
send_set_logging_level_request() {
|
|
109
|
+
management_set_logging_level_request request;
|
|
110
|
+
memset( &request, 0, sizeof( management_set_logging_level_request ) );
|
|
111
|
+
request.header.type = htons( MANAGEMENT_SET_LOGGING_LEVEL_REQUEST );
|
|
112
|
+
request.header.length = htonl( sizeof( management_set_logging_level_request ) );
|
|
113
|
+
strncpy( request.level, logging_level, sizeof( request.level ) );
|
|
114
|
+
|
|
115
|
+
bool ret = send_request_message( service_name, get_trema_name(), MESSENGER_MANAGEMENT_REQUEST,
|
|
116
|
+
&request, sizeof( management_set_logging_level_request ), NULL );
|
|
117
|
+
if ( !ret ) {
|
|
118
|
+
printf( "Failed to send a set logging level request to %s.\n", service_name );
|
|
119
|
+
exit( EXIT_FAILURE );
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
int
|
|
125
|
+
main( int argc, char *argv[] ) {
|
|
126
|
+
// Initialize the Trema world
|
|
127
|
+
init_trema( &argc, &argv );
|
|
128
|
+
|
|
129
|
+
// Parse arguments
|
|
130
|
+
parse_arguments( argc, argv );
|
|
131
|
+
|
|
132
|
+
// Set a handler to handle set logging level reply
|
|
133
|
+
add_message_replied_callback( get_trema_name(), handle_reply );
|
|
134
|
+
|
|
135
|
+
// Send a set logging level request
|
|
136
|
+
send_set_logging_level_request();
|
|
137
|
+
|
|
138
|
+
// Set timeout
|
|
139
|
+
add_periodic_event_callback( 5, timeout, NULL );
|
|
140
|
+
|
|
141
|
+
// Main loop
|
|
142
|
+
start_trema();
|
|
143
|
+
|
|
144
|
+
return EXIT_SUCCESS;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/*
|
|
149
|
+
* Local variables:
|
|
150
|
+
* c-basic-offset: 2
|
|
151
|
+
* indent-tabs-mode: nil
|
|
152
|
+
* End:
|
|
153
|
+
*/
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Management command to show statistics.
|
|
3
|
+
*
|
|
4
|
+
* Author: Yasunobu Chiba
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2012 NEC Corporation
|
|
7
|
+
*
|
|
8
|
+
* This program is free software; you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License, version 2, as
|
|
10
|
+
* published by the Free Software Foundation.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License along
|
|
18
|
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
|
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <assert.h>
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <string.h>
|
|
27
|
+
#include "trema.h"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
static char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
void
|
|
34
|
+
usage( void ) {
|
|
35
|
+
printf( "Usage: show_stats SERVICE_NAME\n" );
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
static void
|
|
40
|
+
print_usage_and_exit( void ) {
|
|
41
|
+
usage();
|
|
42
|
+
exit( EXIT_FAILURE );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
static void
|
|
47
|
+
parse_arguments( int argc, char **argv ) {
|
|
48
|
+
assert( argv != NULL );
|
|
49
|
+
|
|
50
|
+
if ( argc != 2 ) {
|
|
51
|
+
print_usage_and_exit();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ( argv[ 1 ] == NULL || ( argv[ 1 ] != NULL && strlen( argv[ 1 ] ) == 0 ) ) {
|
|
55
|
+
print_usage_and_exit();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
memset( service_name, '\0', MESSENGER_SERVICE_NAME_LENGTH );
|
|
59
|
+
snprintf( service_name, MESSENGER_SERVICE_NAME_LENGTH, "%s", get_management_service_name( argv[ 1 ] ) );
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
static void
|
|
64
|
+
timeout( void *user_data ) {
|
|
65
|
+
UNUSED( user_data );
|
|
66
|
+
|
|
67
|
+
printf( "Timeout.\n" );
|
|
68
|
+
|
|
69
|
+
delete_timer_event( timeout, NULL );
|
|
70
|
+
|
|
71
|
+
stop_trema();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
static void
|
|
76
|
+
handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
|
|
77
|
+
UNUSED( user_data );
|
|
78
|
+
|
|
79
|
+
assert( tag == MESSENGER_MANAGEMENT_REPLY );
|
|
80
|
+
assert( data != NULL );
|
|
81
|
+
assert( length >= offsetof( management_show_stats_reply, entries ) );
|
|
82
|
+
|
|
83
|
+
management_show_stats_reply *reply = data;
|
|
84
|
+
assert( ntohs( reply->header.type ) == MANAGEMENT_SHOW_STATS_REPLY );
|
|
85
|
+
assert( ntohl( reply->header.length ) == length );
|
|
86
|
+
|
|
87
|
+
if ( reply->header.status == MANAGEMENT_REQUEST_FAILED ) {
|
|
88
|
+
printf( "Failed to show statistics.\n" );
|
|
89
|
+
stop_trema();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
size_t entries_length = length - offsetof( management_show_stats_reply, entries );
|
|
94
|
+
unsigned int n_entries = ( unsigned int ) entries_length / sizeof( stat_entry );
|
|
95
|
+
stat_entry *entry = reply->entries;
|
|
96
|
+
for ( unsigned int i = 0; i < n_entries; i++ ) {
|
|
97
|
+
printf( "%s: %" PRIu64 "\n", entry->key, ntohll( entry->value ) );
|
|
98
|
+
entry++;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
stop_trema();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
static void
|
|
106
|
+
send_show_stats_request() {
|
|
107
|
+
management_show_stats_request request;
|
|
108
|
+
memset( &request, 0, sizeof( management_show_stats_request ) );
|
|
109
|
+
request.header.type = htons( MANAGEMENT_SHOW_STATS_REQUEST );
|
|
110
|
+
request.header.length = htonl( sizeof( management_show_stats_request ) );
|
|
111
|
+
|
|
112
|
+
bool ret = send_request_message( service_name, get_trema_name(), MESSENGER_MANAGEMENT_REQUEST,
|
|
113
|
+
&request, sizeof( management_show_stats_request ), NULL );
|
|
114
|
+
if ( !ret ) {
|
|
115
|
+
printf( "Failed to send a show stats request to %s.\n", service_name );
|
|
116
|
+
exit( EXIT_FAILURE );
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
int
|
|
122
|
+
main( int argc, char *argv[] ) {
|
|
123
|
+
// Initialize the Trema world
|
|
124
|
+
init_trema( &argc, &argv );
|
|
125
|
+
|
|
126
|
+
// Parse arguments
|
|
127
|
+
parse_arguments( argc, argv );
|
|
128
|
+
|
|
129
|
+
// Set a handler to handle show stats reply
|
|
130
|
+
add_message_replied_callback( get_trema_name(), handle_reply );
|
|
131
|
+
|
|
132
|
+
// Send a show stats request
|
|
133
|
+
send_show_stats_request();
|
|
134
|
+
|
|
135
|
+
// Set timeout
|
|
136
|
+
add_periodic_event_callback( 5, timeout, NULL );
|
|
137
|
+
|
|
138
|
+
// Main loop
|
|
139
|
+
start_trema();
|
|
140
|
+
|
|
141
|
+
return EXIT_SUCCESS;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* Local variables:
|
|
147
|
+
* c-basic-offset: 2
|
|
148
|
+
* indent-tabs-mode: nil
|
|
149
|
+
* End:
|
|
150
|
+
*/
|