trema 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (292) hide show
  1. data/.gitignore +1 -1
  2. data/Doxyfile +1 -1
  3. data/Gemfile +18 -6
  4. data/README.md +112 -5
  5. data/Rakefile +3 -1
  6. data/Rantfile +88 -1
  7. data/bin/trema +248 -0
  8. data/bin/trema-config +59 -0
  9. data/cruise.rb +1 -1
  10. data/features/example.dumper.feature +45 -65
  11. data/features/example.hello_trema.feature +21 -0
  12. data/features/example.learning_switch.feature +26 -28
  13. data/features/example.list_switches.feature +19 -33
  14. data/features/example.message.echo_reply.feature +10 -10
  15. data/features/example.message.echo_request.feature +2 -2
  16. data/features/example.message.features_request.feature +6 -5
  17. data/features/example.message.hello.feature +47 -13
  18. data/features/example.message.set_config.feature +4 -4
  19. data/features/example.message.vendor-action.feature +23 -0
  20. data/features/example.multi_learning_switch.feature +14 -42
  21. data/features/example.packet_in.feature +31 -0
  22. data/features/example.packetin_filter_config.feature +11 -7
  23. data/features/example.patch_panel.feature +29 -0
  24. data/features/example.repeater_hub.feature +43 -40
  25. data/features/example.switch_info.feature +51 -0
  26. data/features/example.switch_monitor.feature +24 -42
  27. data/features/packetin_filter.feature +28 -22
  28. data/features/step_definitions/misc_steps.rb +19 -8
  29. data/features/step_definitions/send_packets_steps.rb +1 -10
  30. data/features/step_definitions/stats_steps.rb +4 -4
  31. data/features/support/env.rb +2 -1
  32. data/features/support/hooks.rb +35 -2
  33. data/features/switch_manager.feature +18 -12
  34. data/features/trema-config.feature +26 -39
  35. data/features/trema.dump_flows.feature +26 -12
  36. data/features/trema.help.feature +26 -0
  37. data/features/trema.kill.feature +39 -41
  38. data/features/trema.killall.feature +23 -23
  39. data/features/trema.reset_stats.feature +50 -10
  40. data/features/trema.run.feature +28 -39
  41. data/features/trema.send_packets.feature +29 -40
  42. data/features/trema.show_stats.feature +30 -33
  43. data/features/trema.up.feature +33 -0
  44. data/features/trema.version.feature +9 -0
  45. data/ruby/extconf.rb +7 -0
  46. data/ruby/trema/aggregate-stats-reply.rb +3 -3
  47. data/ruby/trema/app.rb +5 -1
  48. data/ruby/trema/barrier-request.c +55 -30
  49. data/ruby/trema/cli.rb +8 -8
  50. data/ruby/trema/command.rb +1 -3
  51. data/ruby/trema/command/dump_flows.rb +5 -24
  52. data/ruby/trema/command/kill.rb +31 -36
  53. data/ruby/trema/command/killall.rb +1 -19
  54. data/{features/step_definitions/kill_steps.rb → ruby/trema/command/netns.rb} +13 -5
  55. data/ruby/trema/command/reset_stats.rb +3 -23
  56. data/ruby/trema/command/ruby.rb +2 -19
  57. data/ruby/trema/command/run.rb +6 -27
  58. data/ruby/trema/command/send_packets.rb +6 -90
  59. data/ruby/trema/command/show_stats.rb +21 -40
  60. data/ruby/trema/command/up.rb +5 -26
  61. data/ruby/trema/command/version.rb +1 -5
  62. data/ruby/trema/controller.c +14 -16
  63. data/ruby/trema/custom-switch.rb +56 -0
  64. data/ruby/trema/desc-stats-reply.rb +5 -5
  65. data/ruby/trema/dsl/configuration.rb +4 -0
  66. data/{features/step_definitions/up_steps.rb → ruby/trema/dsl/custom-switch.rb} +18 -4
  67. data/ruby/trema/dsl/netns.rb +78 -0
  68. data/ruby/trema/dsl/parser.rb +2 -0
  69. data/ruby/trema/dsl/runner.rb +8 -0
  70. data/ruby/trema/dsl/syntax.rb +18 -0
  71. data/ruby/trema/echo-reply.h +2 -2
  72. data/ruby/trema/echo-request.c +3 -5
  73. data/ruby/trema/enqueue.rb +2 -2
  74. data/ruby/trema/error.c +3 -3
  75. data/ruby/trema/executables.rb +26 -2
  76. data/ruby/trema/features-request.c +3 -5
  77. data/ruby/trema/flow-removed.c +6 -6
  78. data/ruby/trema/flow-stats-reply.rb +6 -8
  79. data/ruby/trema/flow.rb +12 -1
  80. data/ruby/trema/get-config-request.c +55 -28
  81. data/ruby/trema/hello.c +3 -5
  82. data/ruby/trema/host.rb +8 -0
  83. data/ruby/trema/list-switches-reply.c +1 -1
  84. data/ruby/trema/mac.rb +1 -1
  85. data/ruby/trema/match.c +15 -14
  86. data/ruby/trema/monkey-patch/module/deprecation.rb +0 -2
  87. data/ruby/trema/netns.rb +127 -0
  88. data/ruby/trema/ordered-hash.rb +5 -4
  89. data/ruby/trema/packet-in.c +136 -113
  90. data/ruby/trema/packet-queue.rb +9 -9
  91. data/ruby/trema/packetin-filter.rb +1 -1
  92. data/ruby/trema/phost.rb +16 -7
  93. data/ruby/trema/port-mod.c +6 -5
  94. data/ruby/trema/port-stats-reply.rb +2 -2
  95. data/ruby/trema/process.rb +29 -0
  96. data/ruby/trema/queue-stats-reply.rb +2 -4
  97. data/ruby/trema/send-out-port.rb +5 -3
  98. data/ruby/trema/set-eth-addr.rb +4 -0
  99. data/ruby/trema/set-ip-addr.rb +4 -2
  100. data/ruby/trema/set-ip-dst-addr.rb +2 -1
  101. data/ruby/trema/set-ip-src-addr.rb +2 -1
  102. data/ruby/trema/set-ip-tos.rb +3 -2
  103. data/ruby/trema/set-transport-port.rb +3 -2
  104. data/ruby/trema/set-vlan-priority.rb +3 -2
  105. data/ruby/trema/set-vlan-vid.rb +5 -4
  106. data/ruby/trema/shell/reset_stats.rb +2 -1
  107. data/ruby/trema/shell/run.rb +1 -1
  108. data/ruby/trema/shell/send_packets.rb +1 -1
  109. data/ruby/trema/shell/show_stats.rb +1 -1
  110. data/ruby/trema/stats-helper.rb +3 -3
  111. data/ruby/trema/stats-reply.c +26 -17
  112. data/ruby/trema/stats-request.c +39 -41
  113. data/ruby/trema/switch-daemon.rb +36 -31
  114. data/ruby/trema/switch.c +1 -1
  115. data/ruby/trema/table-stats-reply.rb +1 -1
  116. data/ruby/trema/timers.rb +13 -13
  117. data/ruby/trema/trema.c +3 -3
  118. data/ruby/trema/tremashark.rb +9 -2
  119. data/ruby/trema/util.rb +39 -15
  120. data/ruby/trema/vendor-action.rb +8 -3
  121. data/ruby/trema/vendor-stats-reply.rb +4 -6
  122. data/ruby/trema/vendor.c +1 -1
  123. data/ruby/trema/version.rb +1 -1
  124. data/spec/trema/barrier-request_spec.rb +47 -37
  125. data/spec/trema/controller_spec.rb +1 -0
  126. data/spec/trema/dsl/runner_spec.rb +8 -3
  127. data/spec/trema/dsl/vhost_spec.rb +8 -8
  128. data/spec/trema/echo-request_spec.rb +1 -0
  129. data/spec/trema/features-request_spec.rb +1 -0
  130. data/spec/trema/flow-removed_spec.rb +9 -9
  131. data/spec/trema/get-config-request_spec.rb +51 -39
  132. data/spec/trema/match_spec.rb +1 -1
  133. data/spec/trema/openflow-error_spec.rb +11 -11
  134. data/spec/trema/packet-out_spec.rb +5 -5
  135. data/spec/trema/queue-get-config-reply_spec.rb +1 -1
  136. data/spec/trema/queue-get-config-request_spec.rb +1 -1
  137. data/spec/trema/set-eth-dst-addr_spec.rb +1 -1
  138. data/spec/trema/set-eth-src-addr_spec.rb +1 -1
  139. data/spec/trema/set-ip-dst-addr_spec.rb +1 -0
  140. data/spec/trema/set-ip-src-addr_spec.rb +1 -0
  141. data/spec/trema/set-ip-tos_spec.rb +1 -0
  142. data/spec/trema/set-transport-dst-port_spec.rb +1 -0
  143. data/spec/trema/set-transport-src-port_spec.rb +1 -0
  144. data/spec/trema/set-vlan-priority_spec.rb +1 -0
  145. data/spec/trema/set-vlan-vid_spec.rb +2 -1
  146. data/spec/trema/stats-reply_spec.rb +38 -36
  147. data/spec/trema/stats-request_spec.rb +6 -6
  148. data/spec/trema/strip-vlan-header_spec.rb +1 -0
  149. data/spec/trema/util_spec.rb +3 -2
  150. data/spec/trema/vendor-action_spec.rb +9 -8
  151. data/src/examples/dumper/dumper.c +8 -6
  152. data/src/examples/dumper/dumper.rb +1 -1
  153. data/{features/step_definitions/killall_steps.rb → src/examples/hello_trema/hello-trema.rb} +6 -5
  154. data/src/examples/hello_trema/hello_trema.c +4 -4
  155. data/src/examples/learning_switch/learning_switch.c +1 -1
  156. data/src/examples/list_switches/list_switches.c +2 -2
  157. data/src/examples/match_compare/match-compare.rb +2 -2
  158. data/src/examples/multi_learning_switch/multi-learning-switch.rb +1 -1
  159. data/src/examples/multi_learning_switch/multi_learning_switch.c +3 -3
  160. data/src/examples/openflow_message/README +1 -1
  161. data/src/examples/openflow_message/echo-request.rb +1 -1
  162. data/src/examples/openflow_message/features_request.c +21 -21
  163. data/src/examples/openflow_message/hello.c +1 -3
  164. data/src/examples/openflow_message/hello.rb +9 -24
  165. data/src/examples/{hello_trema/hello_trema.rb → openflow_message/vendor-action.rb} +17 -7
  166. data/src/examples/openflow_message/vendor_action.c +105 -0
  167. data/src/examples/openflow_switch/hello_switch.c +81 -0
  168. data/src/examples/packet_in/packet-in.rb +9 -13
  169. data/src/examples/packetin_filter_config/packetin_filter_config.c +2 -2
  170. data/src/examples/patch_panel/network.conf +14 -0
  171. data/src/examples/patch_panel/patch-panel.conf +1 -0
  172. data/{features/step_definitions/show_stats_steps.rb → src/examples/patch_panel/patch-panel.rb} +29 -13
  173. data/src/examples/switch_info/{switch_info.rb → switch-info.rb} +2 -2
  174. data/src/examples/switch_info/switch_info.c +4 -4
  175. data/src/examples/switch_monitor/switch_monitor.c +3 -3
  176. data/src/examples/traffic_monitor/counter.c +9 -9
  177. data/src/examples/traffic_monitor/fdb.c +9 -9
  178. data/src/lib/arp.h +1 -1
  179. data/src/lib/buffer.c +4 -3
  180. data/src/lib/byteorder.c +31 -5
  181. data/src/lib/byteorder.h +2 -2
  182. data/src/lib/chibach.c +8 -6
  183. data/src/lib/daemon.c +29 -3
  184. data/src/lib/doubly_linked_list.c +6 -1
  185. data/src/lib/ether.c +1 -1
  186. data/src/lib/ether.h +1 -1
  187. data/src/lib/event_handler.c +3 -3
  188. data/src/lib/hash_table.c +1 -1
  189. data/src/lib/linked_list.c +50 -2
  190. data/src/lib/linked_list.h +2 -2
  191. data/src/lib/log.c +122 -22
  192. data/src/lib/log.h +13 -9
  193. data/src/lib/management_interface.c +361 -0
  194. data/src/lib/management_interface.h +42 -0
  195. data/src/lib/management_service_interface.c +104 -0
  196. data/src/lib/management_service_interface.h +136 -0
  197. data/src/lib/match_table.c +5 -5
  198. data/src/lib/message_queue.c +5 -3
  199. data/src/lib/message_queue.h +1 -1
  200. data/src/lib/messenger.c +73 -39
  201. data/src/lib/messenger.h +3 -2
  202. data/src/lib/openflow_application_interface.c +17 -17
  203. data/src/lib/openflow_message.c +175 -23
  204. data/src/lib/openflow_message.h +2 -1
  205. data/src/lib/openflow_switch_interface.c +12 -12
  206. data/src/lib/packet_parser.c +11 -32
  207. data/src/lib/packetin_filter_interface.c +5 -5
  208. data/src/lib/persistent_storage.c +7 -7
  209. data/src/lib/secure_channel.c +6 -6
  210. data/src/lib/secure_channel.h +1 -1
  211. data/src/lib/stat.c +54 -17
  212. data/src/lib/stat.h +9 -0
  213. data/src/lib/timer.c +11 -10
  214. data/src/lib/trema.c +38 -9
  215. data/src/lib/trema.h +1 -0
  216. data/src/lib/trema_private.h +6 -0
  217. data/src/lib/trema_wrapper.c +4 -4
  218. data/src/lib/trema_wrapper.h +10 -10
  219. data/src/lib/utility.c +6 -6
  220. data/src/management/application.c +224 -0
  221. data/src/management/echo.c +185 -0
  222. data/src/management/set_logging_level.c +153 -0
  223. data/src/management/show_stats.c +150 -0
  224. data/src/management/trema_manager +184 -0
  225. data/src/packetin_filter/packetin_filter.c +31 -29
  226. data/src/switch_manager/cookie_table.c +7 -7
  227. data/src/switch_manager/dpid_table.c +3 -3
  228. data/src/switch_manager/dpid_table.h +0 -1
  229. data/src/switch_manager/management_interface.h +0 -1
  230. data/src/switch_manager/ofpmsg_recv.c +3 -3
  231. data/src/switch_manager/ofpmsg_recv.h +0 -1
  232. data/src/switch_manager/ofpmsg_send.c +2 -2
  233. data/src/switch_manager/ofpmsg_send.h +0 -1
  234. data/src/switch_manager/secure_channel_listener.c +2 -2
  235. data/src/switch_manager/secure_channel_receiver.c +2 -2
  236. data/src/switch_manager/secure_channel_receiver.h +0 -1
  237. data/src/switch_manager/secure_channel_sender.c +8 -1
  238. data/src/switch_manager/service_interface.c +5 -4
  239. data/src/switch_manager/switch.c +79 -53
  240. data/src/switch_manager/switch_manager.c +24 -22
  241. data/src/switch_manager/xid_table.c +6 -6
  242. data/src/switch_manager/xid_table.h +0 -1
  243. data/src/tremashark/README +4 -3
  244. data/src/tremashark/packet_capture.c +11 -9
  245. data/src/tremashark/pcap_queue.c +2 -2
  246. data/src/tremashark/pcap_queue.h +2 -2
  247. data/src/tremashark/plugin/packet-trema/Makefile +1 -1
  248. data/src/tremashark/plugin/packet-trema/Makefile.common +1 -1
  249. data/src/tremashark/plugin/packet-trema/packet-trema.c +50 -37
  250. data/src/tremashark/queue.c +5 -4
  251. data/src/tremashark/queue.h +1 -1
  252. data/src/tremashark/stdin_relay.c +10 -8
  253. data/src/tremashark/syslog_relay.c +14 -12
  254. data/src/tremashark/tremashark.c +15 -18
  255. data/trema +2 -96
  256. data/trema-config +2 -52
  257. data/trema.gemspec +12 -1
  258. data/unittests/cmockery_trema.h +14 -13
  259. data/unittests/lib/buffer_test.c +1 -1
  260. data/unittests/lib/byteorder_test.c +108 -25
  261. data/unittests/lib/daemon_test.c +141 -5
  262. data/unittests/lib/doubly_linked_list_test.c +5 -1
  263. data/unittests/lib/ether_test.c +4 -4
  264. data/unittests/lib/hash_table_test.c +5 -3
  265. data/unittests/lib/linked_list_test.c +82 -4
  266. data/unittests/lib/log_test.c +96 -5
  267. data/unittests/lib/management_interface_test.c +240 -0
  268. data/unittests/lib/management_service_interface_test.c +319 -0
  269. data/unittests/lib/message_queue_test.c +6 -2
  270. data/unittests/lib/messenger_test.c +167 -2
  271. data/unittests/lib/openflow_application_interface_test.c +16 -22
  272. data/unittests/lib/openflow_message_test.c +721 -24
  273. data/unittests/lib/packet_info_test.c +2 -2
  274. data/unittests/lib/packet_parser_test.c +15 -16
  275. data/unittests/lib/packetin_filter_interface_test.c +6 -6
  276. data/unittests/lib/persistent_storage_test.c +11 -11
  277. data/unittests/lib/stat_test.c +151 -7
  278. data/unittests/lib/timer_test.c +1 -1
  279. data/unittests/lib/trema_private_test.c +2 -2
  280. data/unittests/lib/trema_test.c +40 -12
  281. data/unittests/lib/utility_test.c +3 -3
  282. data/unittests/lib/wrapper_test.c +3 -3
  283. data/unittests/packetin_filter/packetin_filter_test.c +12 -11
  284. data/unittests/switch_manager/switch_manager_test.c +29 -22
  285. metadata +99 -20
  286. data/features/step_definitions/log_steps.rb +0 -90
  287. data/features/step_definitions/run_steps.rb +0 -91
  288. data/features/trema.feature +0 -27
  289. data/features/tutorial.hello_trema.feature +0 -27
  290. data/features/tutorial.packet_in.feature +0 -47
  291. data/features/tutorial.switch_info.feature +0 -55
  292. data/ruby/trema/command/usage.rb +0 -63
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Management service interface.
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
+ #ifndef MANAGEMENT_SERVICE_INTERFACE_H
24
+ #define MANAGEMENT_SERVICE_INTERFACE_H
25
+
26
+
27
+ #include <inttypes.h>
28
+ #include <time.h>
29
+ #include "messenger.h"
30
+ #include "stat.h"
31
+
32
+
33
+ enum {
34
+ MESSENGER_MANAGEMENT_REQUEST = 0x0020,
35
+ MESSENGER_MANAGEMENT_REPLY,
36
+ };
37
+
38
+ enum {
39
+ MANAGEMENT_REQUEST_SUCCEEDED,
40
+ MANAGEMENT_REQUEST_FAILED,
41
+ };
42
+
43
+ enum {
44
+ MANAGEMENT_ECHO_REQUEST,
45
+ MANAGEMENT_ECHO_REPLY,
46
+ MANAGEMENT_SET_LOGGING_LEVEL_REQUEST,
47
+ MANAGEMENT_SET_LOGGING_LEVEL_REPLY,
48
+ MANAGEMENT_SHOW_STATS_REQUEST,
49
+ MANAGEMENT_SHOW_STATS_REPLY,
50
+ MANAGEMENT_APPLICATION_REQUEST,
51
+ MANAGEMENT_APPLICATION_REPLY,
52
+ };
53
+
54
+
55
+ typedef struct {
56
+ uint16_t type;
57
+ uint32_t length;
58
+ } __attribute__( ( packed ) ) management_request_header;
59
+
60
+ typedef struct {
61
+ uint32_t tv_sec;
62
+ uint32_t tv_nsec;
63
+ } timespec_n;
64
+
65
+ typedef struct {
66
+ management_request_header header;
67
+ timespec_n sent_at;
68
+ } __attribute__( ( packed ) ) management_echo_request;
69
+
70
+ typedef struct {
71
+ management_request_header header;
72
+ char level[ LOGGING_LEVEL_STR_LENGTH ];
73
+ } __attribute__( ( packed ) ) management_set_logging_level_request;
74
+
75
+ typedef struct {
76
+ management_request_header header;
77
+ } __attribute__( ( packed ) ) management_show_stats_request;
78
+
79
+ typedef struct {
80
+ management_request_header header;
81
+ uint32_t application_id;
82
+ uint8_t data[ 0 ];
83
+ } __attribute__( ( packed ) ) management_application_request;
84
+
85
+ typedef struct {
86
+ uint16_t type;
87
+ uint8_t status;
88
+ uint8_t flags;
89
+ uint32_t length;
90
+ } __attribute__( ( packed ) ) management_reply_header;
91
+
92
+ typedef struct {
93
+ management_reply_header header;
94
+ timespec_n sent_at;
95
+ timespec_n received_at;
96
+ } __attribute__( ( packed ) ) management_echo_reply;
97
+
98
+ typedef struct {
99
+ management_reply_header header;
100
+ } __attribute__( ( packed ) ) management_set_logging_level_reply;
101
+
102
+ typedef struct {
103
+ management_reply_header header;
104
+ stat_entry entries[ 0 ];
105
+ } __attribute__( ( packed ) ) management_show_stats_reply;
106
+
107
+ typedef struct {
108
+ management_reply_header header;
109
+ uint32_t application_id;
110
+ uint8_t data[ 0 ];
111
+ } __attribute__( ( packed ) ) management_application_reply;
112
+
113
+ typedef void ( *management_application_request_handler )(
114
+ const messenger_context_handle *handle,
115
+ uint32_t application_id,
116
+ void *data,
117
+ size_t data_length,
118
+ void *user_data
119
+ );
120
+
121
+
122
+ extern const char *( *get_management_service_name )( const char *service_name );
123
+ extern void ( *set_management_application_request_handler )( management_application_request_handler callback, void *user_data );
124
+ extern management_application_reply *( *create_management_application_reply )( uint8_t status, uint32_t application_id, void *data, size_t data_length );
125
+ extern bool ( *send_management_application_reply )( const messenger_context_handle *handle, const management_application_reply *reply );
126
+
127
+
128
+ #endif // MANAGEMENT_SERVICE_INTERFACE_H
129
+
130
+
131
+ /*
132
+ * Local variables:
133
+ * c-basic-offset: 2
134
+ * indent-tabs-mode: nil
135
+ * End:
136
+ */
@@ -19,10 +19,10 @@
19
19
 
20
20
 
21
21
  #include <assert.h>
22
+ #include <openflow.h>
22
23
  #include <pthread.h>
23
24
  #include <stdlib.h>
24
25
  #include <string.h>
25
- #include <openflow.h>
26
26
  #include "checks.h"
27
27
  #include "match.h"
28
28
  #include "match_table.h"
@@ -53,7 +53,7 @@ typedef struct {
53
53
 
54
54
  typedef struct {
55
55
  struct ofp_match *match;
56
- void ( * function )( struct ofp_match, uint16_t, void *, void * );
56
+ void ( *function )( struct ofp_match, uint16_t, void *, void * );
57
57
  void *user_data;
58
58
  } match_walker;
59
59
 
@@ -277,7 +277,7 @@ exact_match_table_walker( void *key, void *value, void *user_data ) {
277
277
  return;
278
278
  }
279
279
  }
280
- void ( * function )( struct ofp_match, uint16_t, void *, void * ) = walker->function;
280
+ void ( *function )( struct ofp_match, uint16_t, void *, void * ) = walker->function;
281
281
 
282
282
  function( entry->match, entry->priority, entry->data, walker->user_data );
283
283
  }
@@ -297,7 +297,7 @@ map_exact_match_table( hash_table *exact_table, struct ofp_match *match, void fu
297
297
 
298
298
  static void
299
299
  init_wildcards_match_table( list_element **wildcards_table ) {
300
- assert( wildcards_table != NULL);
300
+ assert( wildcards_table != NULL );
301
301
 
302
302
  create_list( wildcards_table );
303
303
  }
@@ -589,7 +589,7 @@ _map_match_table( struct ofp_match *match, void function( struct ofp_match match
589
589
 
590
590
 
591
591
  void
592
- foreach_match_table( void function( struct ofp_match, uint16_t, void *, void *), void *user_data ) {
592
+ foreach_match_table( void function( struct ofp_match, uint16_t, void *, void * ), void *user_data ) {
593
593
  _map_match_table( NULL, function, user_data );
594
594
  }
595
595
 
@@ -42,7 +42,7 @@ delete_message_queue( message_queue *queue ) {
42
42
  die( "queue must not be NULL" );
43
43
  }
44
44
 
45
- while( queue->head != NULL ) {
45
+ while ( queue->head != NULL ) {
46
46
  message_queue_element *element = queue->head;
47
47
  if ( queue->head->data != NULL ) {
48
48
  free_buffer( element->data );
@@ -122,7 +122,7 @@ peek_message( message_queue *queue ) {
122
122
  }
123
123
 
124
124
 
125
- void foreach_message_queue( message_queue *queue, void function( buffer *message, void *user_data ), void *user_data ) {
125
+ void foreach_message_queue( message_queue *queue, bool function( buffer *message, void *user_data ), void *user_data ) {
126
126
  if ( queue->divider == queue->tail ) {
127
127
  return;
128
128
  }
@@ -130,7 +130,9 @@ void foreach_message_queue( message_queue *queue, void function( buffer *message
130
130
  for ( element = queue->divider->next; element != NULL; element = element->next ) {
131
131
  buffer *message = element->data;
132
132
  assert( message != NULL );
133
- function( message, user_data );
133
+ if ( !function( message, user_data ) ) {
134
+ break;
135
+ }
134
136
  }
135
137
  }
136
138
 
@@ -47,7 +47,7 @@ bool delete_message_queue( message_queue *queue );
47
47
  bool enqueue_message( message_queue *queue, buffer *message );
48
48
  buffer *dequeue_message( message_queue *queue );
49
49
  buffer *peek_message( message_queue *queue );
50
- void foreach_message_queue( message_queue *queue, void function( buffer *message, void *user_data ), void *user_data );
50
+ void foreach_message_queue( message_queue *queue, bool function( buffer *message, void *user_data ), void *user_data );
51
51
 
52
52
 
53
53
  #endif // MESSAGE_QUEUE_H
data/src/lib/messenger.c CHANGED
@@ -303,7 +303,7 @@ free_message_buffer( message_buffer *buf ) {
303
303
  }
304
304
 
305
305
 
306
- static void*
306
+ static void *
307
307
  get_message_buffer_head( message_buffer *buf ) {
308
308
  return ( char * ) buf->buffer + buf->head_offset;
309
309
  }
@@ -419,7 +419,7 @@ send_dump_message( uint16_t dump_type, const char *service_name, const void *dat
419
419
  */
420
420
  static void
421
421
  delete_receive_queue( void *service_name, void *_rq, void *user_data ) {
422
- debug( "Deleting a receive queue ( service_name = %s, _rq = %p, user_data = %p ).", service_name, _rq, user_data );
422
+ debug( "Deleting a receive queue ( service_name = %s, _rq = %p, user_data = %p ).", ( char * ) service_name, _rq, user_data );
423
423
 
424
424
  receive_queue *rq = _rq;
425
425
  messenger_socket *client_socket;
@@ -533,7 +533,7 @@ create_receive_queue( const char *service_name ) {
533
533
  assert( service_name != NULL );
534
534
  assert( strlen( service_name ) < MESSENGER_SERVICE_NAME_LENGTH );
535
535
 
536
- debug( "Creating a receive queue (service_name = %s).", service_name );
536
+ debug( "Creating a receive queue ( service_name = %s ).", service_name );
537
537
 
538
538
  assert( receive_queues != NULL );
539
539
  receive_queue *rq = lookup_hash_entry( receive_queues, service_name );
@@ -553,7 +553,7 @@ create_receive_queue( const char *service_name ) {
553
553
 
554
554
  rq->listen_socket = socket( AF_UNIX, SOCK_SEQPACKET, 0 );
555
555
  if ( rq->listen_socket == -1 ) {
556
- error( "Failed to call socket (errno = %s [%d]).", strerror( errno ), errno );
556
+ error( "Failed to call socket ( errno = %s [%d] ).", strerror( errno ), errno );
557
557
  xfree( rq );
558
558
  return NULL;
559
559
  }
@@ -563,7 +563,7 @@ create_receive_queue( const char *service_name ) {
563
563
  int ret;
564
564
  ret = bind( rq->listen_socket, ( struct sockaddr * ) &rq->listen_addr, sizeof( struct sockaddr_un ) );
565
565
  if ( ret == -1 ) {
566
- error( "Failed to bind (fd = %d, sun_path = %s, errno = %s [%d]).",
566
+ error( "Failed to bind ( fd = %d, sun_path = %s, errno = %s [%d] ).",
567
567
  rq->listen_socket, rq->listen_addr.sun_path, strerror( errno ), errno );
568
568
  close( rq->listen_socket );
569
569
  xfree( rq );
@@ -572,7 +572,7 @@ create_receive_queue( const char *service_name ) {
572
572
 
573
573
  ret = listen( rq->listen_socket, SOMAXCONN );
574
574
  if ( ret == -1 ) {
575
- error( "Failed to listen (fd = %d, sun_path = %s, errno = %s [%d]).",
575
+ error( "Failed to listen ( fd = %d, sun_path = %s, errno = %s [%d] ).",
576
576
  rq->listen_socket, rq->listen_addr.sun_path, strerror( errno ), errno );
577
577
  close( rq->listen_socket );
578
578
  xfree( rq );
@@ -606,7 +606,7 @@ add_message_callback( const char *service_name, uint8_t message_type, void *call
606
606
  assert( service_name != NULL );
607
607
  assert( callback != NULL );
608
608
 
609
- debug( "Adding a message callback (service_name = %s, message_type = %#x, callback = %p).",
609
+ debug( "Adding a message callback ( service_name = %s, message_type = %#x, callback = %p ).",
610
610
  service_name, message_type, callback );
611
611
 
612
612
  receive_queue *rq = lookup_hash_entry( receive_queues, service_name );
@@ -619,6 +619,17 @@ add_message_callback( const char *service_name, uint8_t message_type, void *call
619
619
  }
620
620
  }
621
621
 
622
+ if ( message_type == MESSAGE_TYPE_REQUEST || message_type == MESSAGE_TYPE_REPLY ) {
623
+ for ( dlist_element *e = rq->message_callbacks->next; e; e = e->next ) {
624
+ receive_queue_callback *cb = e->data;
625
+ if ( cb->message_type == message_type ) {
626
+ warn( "Multiple message_requested/replied handler is not supported. ( service_name = %s, message_type = %#x, callback = %p )",
627
+ service_name, message_type, callback );
628
+ break;
629
+ }
630
+ }
631
+ }
632
+
622
633
  receive_queue_callback *cb = xmalloc( sizeof( receive_queue_callback ) );
623
634
  cb->message_type = message_type;
624
635
  cb->function = callback;
@@ -633,7 +644,7 @@ _add_message_received_callback( const char *service_name, const callback_message
633
644
  assert( service_name != NULL );
634
645
  assert( callback != NULL );
635
646
 
636
- debug( "Adding a message received callback (service_name = %s, callback = %p).",
647
+ debug( "Adding a message received callback ( service_name = %s, callback = %p ).",
637
648
  service_name, callback );
638
649
 
639
650
  return add_message_callback( service_name, MESSAGE_TYPE_NOTIFY, callback );
@@ -748,14 +759,11 @@ bool ( *delete_message_replied_callback )( const char *service_name, void ( *cal
748
759
 
749
760
 
750
761
  static bool
751
- _rename_message_received_callback( const char *old_service_name, const char *new_service_name ) {
762
+ rename_message_callback( const char *old_service_name, const char *new_service_name ) {
752
763
  assert( old_service_name != NULL );
753
764
  assert( new_service_name != NULL );
754
765
  assert( receive_queues != NULL );
755
766
 
756
- debug( "Renaming a message received callback ( old_service_name = %s, new_service_name = %s ).",
757
- old_service_name, new_service_name );
758
-
759
767
  receive_queue *old_rq = lookup_hash_entry( receive_queues, old_service_name );
760
768
  receive_queue *new_rq = lookup_hash_entry( receive_queues, new_service_name );
761
769
  dlist_element *element;
@@ -779,9 +787,35 @@ _rename_message_received_callback( const char *old_service_name, const char *new
779
787
 
780
788
  return true;
781
789
  }
790
+
791
+ static bool
792
+ _rename_message_received_callback( const char *old_service_name, const char *new_service_name ) {
793
+ assert( old_service_name != NULL );
794
+ assert( new_service_name != NULL );
795
+ assert( receive_queues != NULL );
796
+
797
+ debug( "Renaming a message received callback ( old_service_name = %s, new_service_name = %s ).",
798
+ old_service_name, new_service_name );
799
+
800
+ return rename_message_callback( old_service_name, new_service_name );
801
+ }
782
802
  bool ( *rename_message_received_callback )( const char *old_service_name, const char *new_service_name ) = _rename_message_received_callback;
783
803
 
784
804
 
805
+ static bool
806
+ _rename_message_requested_callback( const char *old_service_name, const char *new_service_name ) {
807
+ assert( old_service_name != NULL );
808
+ assert( new_service_name != NULL );
809
+ assert( receive_queues != NULL );
810
+
811
+ debug( "Renaming a message requested callback ( old_service_name = %s, new_service_name = %s ).",
812
+ old_service_name, new_service_name );
813
+
814
+ return rename_message_callback( old_service_name, new_service_name );
815
+ }
816
+ bool ( *rename_message_requested_callback )( const char *old_service_name, const char *new_service_name ) = _rename_message_requested_callback;
817
+
818
+
785
819
  static size_t
786
820
  message_buffer_remain_bytes( message_buffer *buf ) {
787
821
  assert( buf != NULL );
@@ -843,7 +877,7 @@ send_queue_connect( send_queue *sq ) {
843
877
  debug( "Connection established ( service_name = %s, sun_path = %s, fd = %d ).",
844
878
  sq->service_name, sq->server_addr.sun_path, sq->server_socket );
845
879
 
846
- socklen_t optlen = sizeof ( sq->socket_buffer_size );
880
+ socklen_t optlen = sizeof( sq->socket_buffer_size );
847
881
  if ( getsockopt( sq->server_socket, SOL_SOCKET, SO_SNDBUF, &sq->socket_buffer_size, &optlen ) == -1 ) {
848
882
  sq->socket_buffer_size = 0;
849
883
  }
@@ -872,7 +906,7 @@ send_queue_connect_timer( send_queue *sq ) {
872
906
  }
873
907
  if ( sq->running_timer ) {
874
908
  sq->running_timer = false;
875
- delete_timer_event( ( timer_callback )send_queue_connect_timeout, sq );
909
+ delete_timer_event( ( timer_callback ) send_queue_connect_timeout, sq );
876
910
  }
877
911
 
878
912
  int ret = send_queue_connect( sq );
@@ -893,10 +927,10 @@ send_queue_connect_timer( send_queue *sq ) {
893
927
  interval.it_interval.tv_sec = 0;
894
928
  interval.it_interval.tv_nsec = 0;
895
929
  interval.it_value = sq->reconnect_interval;
896
- add_timer_event_callback( &interval, ( void (*)(void *) )send_queue_connect_timeout, ( void * ) sq );
930
+ add_timer_event_callback( &interval, ( void ( * )( void * ) ) send_queue_connect_timeout, ( void * ) sq );
897
931
  sq->running_timer = true;
898
932
 
899
- debug( "refused_count = %d, reconnect_interval = %u.", sq->refused_count, sq->reconnect_interval.tv_sec );
933
+ debug( "refused_count = %d, reconnect_interval = %" PRIu64 ".", sq->refused_count, ( int64_t ) sq->reconnect_interval.tv_sec );
900
934
  return 0;
901
935
 
902
936
  case 1:
@@ -908,7 +942,7 @@ send_queue_connect_timer( send_queue *sq ) {
908
942
 
909
943
  default:
910
944
  die( "Got invalid value from send_queue_connect_timer( send_queue* )." );
911
- };
945
+ }
912
946
 
913
947
  return -1;
914
948
  }
@@ -1003,7 +1037,7 @@ static bool
1003
1037
  push_message_to_send_queue( const char *service_name, const uint8_t message_type, const uint16_t tag, const void *data, size_t len ) {
1004
1038
  assert( service_name != NULL );
1005
1039
 
1006
- debug( "Pushing a message to send queue ( service_name = %s, message_type = %#x, tag = %#x, data = %p, len = %u ).",
1040
+ debug( "Pushing a message to send queue ( service_name = %s, message_type = %#x, tag = %#x, data = %p, len = %zu ).",
1007
1041
  service_name, message_type, tag, data, len );
1008
1042
 
1009
1043
  message_header header;
@@ -1063,7 +1097,7 @@ static bool
1063
1097
  _send_message( const char *service_name, const uint16_t tag, const void *data, size_t len ) {
1064
1098
  assert( service_name != NULL );
1065
1099
 
1066
- debug( "Sending a message ( service_name = %s, tag = %#x, data = %p, len = %u ).",
1100
+ debug( "Sending a message ( service_name = %s, tag = %#x, data = %p, len = %zu ).",
1067
1101
  service_name, tag, data, len );
1068
1102
 
1069
1103
  return push_message_to_send_queue( service_name, MESSAGE_TYPE_NOTIFY, tag, data, len );
@@ -1096,7 +1130,7 @@ _send_request_message( const char *to_service_name, const char *from_service_nam
1096
1130
  assert( to_service_name != NULL );
1097
1131
  assert( from_service_name != NULL );
1098
1132
 
1099
- debug( "Sending a request message ( to_service_name = %s, from_service_name = %s, tag = %#x, data = %p, len = %u, user_data = %p ).",
1133
+ debug( "Sending a request message ( to_service_name = %s, from_service_name = %s, tag = %#x, data = %p, len = %zu, user_data = %p ).",
1100
1134
  to_service_name, from_service_name, tag, data, len, user_data );
1101
1135
 
1102
1136
  char *request_data, *p;
@@ -1130,7 +1164,7 @@ _send_reply_message( const messenger_context_handle *handle, const uint16_t tag,
1130
1164
  assert( handle != NULL );
1131
1165
 
1132
1166
  debug( "Sending a reply message ( handle = [ transaction_id = %#x, service_name_len = %u, service_name = %s ], "
1133
- "tag = %#x, data = %p, len = %u ).",
1167
+ "tag = %#x, data = %p, len = %zu ).",
1134
1168
  handle->transaction_id, handle->service_name_len, handle->service_name, tag, data, len );
1135
1169
 
1136
1170
  char *reply_data;
@@ -1255,7 +1289,7 @@ add_recv_queue_client_fd( receive_queue *rq, int fd ) {
1255
1289
 
1256
1290
  static void
1257
1291
  on_accept( int fd, void *data ) {
1258
- receive_queue *rq = ( receive_queue* )data;
1292
+ receive_queue *rq = ( receive_queue * ) data;
1259
1293
 
1260
1294
  assert( rq != NULL );
1261
1295
 
@@ -1357,7 +1391,7 @@ pull_from_recv_queue( receive_queue *rq, uint8_t *message_type, uint16_t *tag, v
1357
1391
  message_header *header;
1358
1392
 
1359
1393
  if ( rq->buffer->data_length < sizeof( message_header ) ) {
1360
- debug( "Queue length is smaller than a message header ( queue length = %u ).", rq->buffer->data_length );
1394
+ debug( "Queue length is smaller than a message header ( queue length = %zu ).", rq->buffer->data_length );
1361
1395
  return 0;
1362
1396
  }
1363
1397
 
@@ -1367,7 +1401,7 @@ pull_from_recv_queue( receive_queue *rq, uint8_t *message_type, uint16_t *tag, v
1367
1401
  assert( length != 0 );
1368
1402
  assert( length < messenger_recv_queue_length );
1369
1403
  if ( rq->buffer->data_length < length ) {
1370
- debug( "Queue length is smaller than message length ( queue length = %u, message length = %u ).",
1404
+ debug( "Queue length is smaller than message length ( queue length = %zu, message length = %u ).",
1371
1405
  rq->buffer->data_length, length );
1372
1406
  return 0;
1373
1407
  }
@@ -1378,7 +1412,7 @@ pull_from_recv_queue( receive_queue *rq, uint8_t *message_type, uint16_t *tag, v
1378
1412
  memcpy( data, header->value, *len > maxlen ? maxlen : *len );
1379
1413
  truncate_message_buffer( rq->buffer, length );
1380
1414
 
1381
- debug( "A message is retrieved from receive queue ( message_type = %#x, tag = %#x, len = %u, data = %p ).",
1415
+ debug( "A message is retrieved from receive queue ( message_type = %#x, tag = %#x, len = %zu, data = %p ).",
1382
1416
  *message_type, *tag, *len, data );
1383
1417
 
1384
1418
  return 1;
@@ -1400,7 +1434,7 @@ call_message_callbacks( receive_queue *rq, const uint8_t message_type, const uin
1400
1434
  dlist_element *element;
1401
1435
  receive_queue_callback *cb;
1402
1436
 
1403
- debug( "Calling message callbacks ( service_name = %s, message_type = %#x, tag = %#x, data = %p, len = %u ).",
1437
+ debug( "Calling message callbacks ( service_name = %s, message_type = %#x, tag = %#x, data = %p, len = %zu ).",
1404
1438
  rq->service_name, message_type, tag, data, len );
1405
1439
 
1406
1440
  for ( element = rq->message_callbacks->next; element; element = element->next ) {
@@ -1414,7 +1448,7 @@ call_message_callbacks( receive_queue *rq, const uint8_t message_type, const uin
1414
1448
  void ( *received_callback )( uint16_t tag, void *data, size_t len );
1415
1449
  received_callback = cb->function;
1416
1450
 
1417
- debug( "Calling a callback ( %p ) for MESSAGE_TYPE_NOTIFY (%#x) ( tag = %#x, data = %p, len = %u ).",
1451
+ debug( "Calling a callback ( %p ) for MESSAGE_TYPE_NOTIFY (%#x) ( tag = %#x, data = %p, len = %zu ).",
1418
1452
  cb->function, message_type, tag, data, len );
1419
1453
 
1420
1454
  received_callback( tag, data, len );
@@ -1434,7 +1468,7 @@ call_message_callbacks( receive_queue *rq, const uint8_t message_type, const uin
1434
1468
  header_len = sizeof( messenger_context_handle ) + handle->service_name_len;
1435
1469
  requested_data = ( ( char * ) data ) + header_len;
1436
1470
 
1437
- debug( "Calling a callback ( %p ) for MESSAGE_TYPE_REQUEST (%#x) ( handle = %p, tag = %#x, requested_data = %p, len = %u ).",
1471
+ debug( "Calling a callback ( %p ) for MESSAGE_TYPE_REQUEST (%#x) ( handle = %p, tag = %#x, requested_data = %p, len = %zu ).",
1438
1472
  cb->function, message_type, handle, tag, requested_data, len - header_len );
1439
1473
 
1440
1474
  requested_callback( handle, tag, ( void * ) requested_data, len - header_len );
@@ -1456,7 +1490,7 @@ call_message_callbacks( receive_queue *rq, const uint8_t message_type, const uin
1456
1490
  context = get_context( reply_handle->transaction_id );
1457
1491
 
1458
1492
  if ( NULL != context ) {
1459
- debug( "tag = %#x, data = %p, len = %u, user_data = %p.",
1493
+ debug( "tag = %#x, data = %p, len = %zu, user_data = %p.",
1460
1494
  tag, reply_handle->service_name, len - sizeof( messenger_context_handle ), context->user_data );
1461
1495
  replied_callback( tag, reply_handle->service_name, len - sizeof( messenger_context_handle ), context->user_data );
1462
1496
  delete_context( context );
@@ -1476,7 +1510,7 @@ call_message_callbacks( receive_queue *rq, const uint8_t message_type, const uin
1476
1510
 
1477
1511
  static void
1478
1512
  on_recv( int fd, void *data ) {
1479
- receive_queue *rq = ( receive_queue* )data;
1513
+ receive_queue *rq = ( receive_queue * ) data;
1480
1514
 
1481
1515
  assert( rq != NULL );
1482
1516
  assert( fd >= 0 );
@@ -1515,11 +1549,11 @@ on_recv( int fd, void *data ) {
1515
1549
  }
1516
1550
 
1517
1551
  if ( !write_message_buffer( rq->buffer, buf, ( size_t ) recv_len ) ) {
1518
- warn( "Could not write a message to receive queue due to overflow ( service_name = %s, len = %u ).", rq->service_name, recv_len );
1552
+ warn( "Could not write a message to receive queue due to overflow ( service_name = %s, len = %zd ).", rq->service_name, recv_len );
1519
1553
  send_dump_message( MESSENGER_DUMP_RECV_OVERFLOW, rq->service_name, buf, ( uint32_t ) recv_len );
1520
1554
  }
1521
1555
  else {
1522
- debug( "Pushing a message to receive queue ( service_name = %s, len = %u ).", rq->service_name, recv_len );
1556
+ debug( "Pushing a message to receive queue ( service_name = %s, len = %zd ).", rq->service_name, recv_len );
1523
1557
  send_dump_message( MESSENGER_DUMP_RECEIVED, rq->service_name, buf, ( uint32_t ) recv_len );
1524
1558
  }
1525
1559
  }
@@ -1540,9 +1574,9 @@ get_send_data( send_queue *sq, size_t offset ) {
1540
1574
  if ( ioctl( sq->server_socket, SIOCOUTQ, &used ) == 0 ) {
1541
1575
  if ( used < sq->socket_buffer_size ) {
1542
1576
  bucket_size = ( uint32_t ) ( sq->socket_buffer_size - used ) << 1;
1543
- if ( bucket_size > messenger_bucket_size ) {
1544
- bucket_size = messenger_bucket_size;
1545
- }
1577
+ if ( bucket_size > messenger_bucket_size ) {
1578
+ bucket_size = messenger_bucket_size;
1579
+ }
1546
1580
  }
1547
1581
  else {
1548
1582
  bucket_size = 1;
@@ -1575,7 +1609,7 @@ on_send_read( int fd, void *data ) {
1575
1609
  UNUSED( fd );
1576
1610
 
1577
1611
  char buf[ 256 ];
1578
- send_queue *sq = ( send_queue* )data;
1612
+ send_queue *sq = ( send_queue * ) data;
1579
1613
 
1580
1614
  if ( recv( sq->server_socket, buf, sizeof( buf ), 0 ) <= 0 ) {
1581
1615
  send_dump_message( MESSENGER_DUMP_SEND_CLOSED, sq->service_name, NULL, 0 );
@@ -1600,12 +1634,12 @@ on_send_read( int fd, void *data ) {
1600
1634
 
1601
1635
  static void
1602
1636
  on_send_write( int fd, void *data ) {
1603
- send_queue *sq = ( send_queue* )data;
1637
+ send_queue *sq = ( send_queue * ) data;
1604
1638
 
1605
1639
  assert( sq != NULL );
1606
1640
  assert( fd >= 0 );
1607
1641
 
1608
- debug( "Sending data to remote ( fd = %d, service_name = %s, buffer = %p, data_length = %u ).",
1642
+ debug( "Sending data to remote ( fd = %d, service_name = %s, buffer = %p, data_length = %zu ).",
1609
1643
  fd, sq->service_name, get_message_buffer_head( sq->buffer ), sq->buffer->data_length );
1610
1644
 
1611
1645
  if ( sq->buffer->data_length < sizeof( message_header ) ) {
@@ -1641,7 +1675,7 @@ on_send_write( int fd, void *data ) {
1641
1675
  }
1642
1676
  truncate_message_buffer( sq->buffer, sent_total );
1643
1677
  if ( err == EMSGSIZE || err == ENOBUFS || err == ENOMEM ) {
1644
- warn( "Dropping %u bytes data in send queue ( service_name = %s ).", sq->buffer->data_length, sq->service_name );
1678
+ warn( "Dropping %zu bytes data in send queue ( service_name = %s ).", sq->buffer->data_length, sq->service_name );
1645
1679
  truncate_message_buffer( sq->buffer, sq->buffer->data_length );
1646
1680
  }
1647
1681
  return;