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
@@ -69,7 +69,7 @@ buffer *create_flow_removed( const uint32_t transaction_id, const struct ofp_mat
69
69
  const uint32_t duration_nsec, const uint16_t idle_timeout,
70
70
  const uint64_t packet_count, const uint64_t byte_count );
71
71
  buffer *create_port_status( const uint32_t transaction_id, const uint8_t reason,
72
- const struct ofp_phy_port desc);
72
+ const struct ofp_phy_port desc );
73
73
  buffer *create_packet_out( const uint32_t transaction_id, const uint32_t buffer_id,
74
74
  const uint16_t in_port, const openflow_actions *actions,
75
75
  const buffer *data );
@@ -275,6 +275,7 @@ bool get_error_type_and_code( const uint8_t type, const int error_no,
275
275
  uint16_t *error_type, uint16_t *error_code );
276
276
  void set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
277
277
  const uint32_t wildcards, const buffer *packet );
278
+ void normalize_match( struct ofp_match *match );
278
279
 
279
280
 
280
281
  #endif // OPENFLOW_MESSAGE_H
@@ -18,9 +18,9 @@
18
18
  */
19
19
 
20
20
 
21
+ #include <arpa/inet.h>
21
22
  #include <assert.h>
22
23
  #include <inttypes.h>
23
- #include <arpa/inet.h>
24
24
  #include <syslog.h>
25
25
  #include "chibach_private.h"
26
26
  #include "hash_table.h"
@@ -458,7 +458,7 @@ handle_error( buffer *data ) {
458
458
  buffer *body = duplicate_buffer( data );
459
459
  remove_front_buffer( body, offsetof( struct ofp_error_msg, data ) );
460
460
 
461
- debug( "An error message is received ( transaction_id = %#x, type = %u, code = %u, data length = %u ).",
461
+ debug( "An error message is received ( transaction_id = %#x, type = %#x, code = %#x, data length = %zu ).",
462
462
  transaction_id, type, code, body->length );
463
463
 
464
464
  if ( event_handlers.error_callback == NULL ) {
@@ -506,7 +506,7 @@ handle_echo_request( buffer *data ) {
506
506
  body,
507
507
  event_handlers.echo_request_user_data );
508
508
 
509
- event_handlers.echo_request_callback( transaction_id, body, event_handlers.set_config_user_data );
509
+ event_handlers.echo_request_callback( transaction_id, body, event_handlers.echo_request_user_data );
510
510
 
511
511
  if ( body != NULL ) {
512
512
  free_buffer( body );
@@ -540,7 +540,7 @@ handle_echo_reply( buffer *data ) {
540
540
  body,
541
541
  event_handlers.echo_reply_user_data );
542
542
 
543
- event_handlers.echo_reply_callback( transaction_id, body, event_handlers.set_config_user_data );
543
+ event_handlers.echo_reply_callback( transaction_id, body, event_handlers.echo_reply_user_data );
544
544
 
545
545
  if ( body != NULL ) {
546
546
  free_buffer( body );
@@ -701,7 +701,7 @@ handle_packet_out( buffer *data ) {
701
701
  }
702
702
 
703
703
  debug( "A packet-out is received ( transaction_id = %#x, buffer_id = %#x, in_port = %u, "
704
- "actions_len = %u, frame_length = %u ).",
704
+ "actions_len = %zu, frame_length = %zu ).",
705
705
  transaction_id, buffer_id, in_port, actions_len, frame_length );
706
706
 
707
707
  if ( event_handlers.packet_out_callback == NULL ) {
@@ -820,7 +820,7 @@ handle_port_mod( buffer *data ) {
820
820
  event_handlers.port_mod_user_data );
821
821
 
822
822
  event_handlers.port_mod_callback( transaction_id, port_no, hw_addr, config, mask, advertise,
823
- event_handlers.barrier_request_user_data );
823
+ event_handlers.port_mod_user_data );
824
824
 
825
825
  }
826
826
 
@@ -855,7 +855,7 @@ handle_stats_request( buffer *data ) {
855
855
  {
856
856
  struct ofp_aggregate_stats_request *aggregate = p;
857
857
  ntoh_match( &aggregate->match, &aggregate->match );
858
- aggregate->out_port = ntohs( aggregate->out_port );
858
+ aggregate->out_port = ntohs( aggregate->out_port );
859
859
  }
860
860
  break;
861
861
 
@@ -980,7 +980,7 @@ handle_openflow_message( buffer *message ) {
980
980
 
981
981
  int ret = validate_openflow_message( message );
982
982
  if ( ret < 0 ) {
983
- error( "Failed to validate an OpenFlow message ( code = %d, length = %u ).", ret, message->length );
983
+ error( "Failed to validate an OpenFlow message ( code = %d, length = %zu ).", ret, message->length );
984
984
  return false;
985
985
  }
986
986
 
@@ -1031,7 +1031,7 @@ handle_openflow_message( buffer *message ) {
1031
1031
  handle_queue_get_config_request( message );
1032
1032
  break;
1033
1033
  default:
1034
- error( "Unhandled OpenFlow message ( type = %u ).", header->type );
1034
+ error( "Unhandled OpenFlow message ( type = %#x ).", header->type );
1035
1035
  ret = false;
1036
1036
  break;
1037
1037
  }
@@ -1080,7 +1080,7 @@ switch_send_openflow_message( buffer *message ) {
1080
1080
 
1081
1081
  bool
1082
1082
  handle_secure_channel_message( buffer *message ) {
1083
- debug( "An OpenFlow message is received from remove." );
1083
+ debug( "An OpenFlow message is received from remote." );
1084
1084
 
1085
1085
  assert( message != NULL );
1086
1086
  assert( message->length >= sizeof( struct ofp_header ) );
@@ -1098,7 +1098,7 @@ handle_local_message( uint16_t tag, void *data, size_t length ) {
1098
1098
  assert( data != NULL );
1099
1099
  assert( length >= sizeof( openflow_service_header_t ) );
1100
1100
 
1101
- debug( "A message is received from remote ( tag = %u, data = %p, length = %u ).", tag, data, length );
1101
+ debug( "A message is received from remote ( tag = %#x, data = %p, length = %zu ).", tag, data, length );
1102
1102
 
1103
1103
  switch ( tag ) {
1104
1104
  case MESSENGER_OPENFLOW_MESSAGE:
@@ -1261,7 +1261,7 @@ send_error_message( uint32_t transaction_id, uint16_t type, uint16_t code ) {
1261
1261
  case OFPBAC_BAD_ARGUMENT:
1262
1262
  case OFPBAC_EPERM:
1263
1263
  case OFPBAC_TOO_MANY:
1264
- case OFPBAC_BAD_QUEUE:
1264
+ case OFPBAC_BAD_QUEUE:
1265
1265
  {
1266
1266
  const buffer *original_message = get_openflow_message( transaction_id );
1267
1267
  if ( original_message != NULL ) {
@@ -16,11 +16,11 @@
16
16
  */
17
17
 
18
18
 
19
- #include <assert.h>
20
- #include <stdint.h>
21
19
  #include <arpa/inet.h>
20
+ #include <assert.h>
22
21
  #include <net/ethernet.h>
23
22
  #include <netinet/ip.h>
23
+ #include <stdint.h>
24
24
  #include "packet_info.h"
25
25
  #include "log.h"
26
26
  #include "wrapper.h"
@@ -63,7 +63,7 @@ parse_ether( buffer *buf ) {
63
63
 
64
64
  packet_info->vlan_tci = ntohs( vlantag_header->tci );
65
65
  packet_info->vlan_tpid = packet_info->eth_type;
66
- packet_info->vlan_prio =TCI_GET_PRIO( packet_info->vlan_tci );
66
+ packet_info->vlan_prio = TCI_GET_PRIO( packet_info->vlan_tci );
67
67
  packet_info->vlan_cfi = TCI_GET_CFI( packet_info->vlan_tci );
68
68
  packet_info->vlan_vid = TCI_GET_VID( packet_info->vlan_tci );
69
69
 
@@ -76,7 +76,7 @@ parse_ether( buffer *buf ) {
76
76
  }
77
77
 
78
78
  // Skip nested vlan headers.
79
- while ( packet_info->eth_type == ETH_ETHTYPE_TPID ) {
79
+ while ( packet_info->eth_type == ETH_ETHTYPE_TPID ) {
80
80
  // Check the length of remained buffer
81
81
  length = REMAINED_BUFFER_LENGTH( buf, ptr );
82
82
  if ( length < sizeof( vlantag_header_t ) ) {
@@ -115,8 +115,6 @@ parse_ether( buffer *buf ) {
115
115
  packet_info->l2_payload = ptr;
116
116
  packet_info->l2_payload_length = payload_length;
117
117
  }
118
-
119
- return;
120
118
  }
121
119
 
122
120
 
@@ -147,9 +145,7 @@ parse_arp( buffer *buf ) {
147
145
  packet_info->arp_tpa = ntohl( arp_header->tip );
148
146
 
149
147
  packet_info->format |= NW_ARP;
150
-
151
- return;
152
- };
148
+ }
153
149
 
154
150
 
155
151
  static void
@@ -196,8 +192,6 @@ parse_ipv4( buffer *buf ) {
196
192
  }
197
193
 
198
194
  packet_info->format |= NW_IPV4;
199
-
200
- return;
201
195
  }
202
196
 
203
197
 
@@ -218,8 +212,8 @@ parse_ipv6( buffer *buf ) {
218
212
  // Parses IPv6 header
219
213
  ipv6_header_t *ipv6_header = ptr;
220
214
  uint32_t hdrctl = ntohl( ipv6_header->hdrctl );
221
- packet_info->ipv6_version = ( uint8_t )( hdrctl >> 28 );
222
- packet_info->ipv6_tc = ( uint8_t )( hdrctl >> 20 & 0xFF );
215
+ packet_info->ipv6_version = ( uint8_t ) ( hdrctl >> 28 );
216
+ packet_info->ipv6_tc = ( uint8_t ) ( hdrctl >> 20 & 0xFF );
223
217
  packet_info->ipv6_flowlabel = hdrctl & 0xFFFFF;
224
218
  packet_info->ipv6_plen = ntohs( ipv6_header->plen );
225
219
  packet_info->ipv6_nexthdr = ipv6_header->nexthdr;
@@ -228,8 +222,6 @@ parse_ipv6( buffer *buf ) {
228
222
  memcpy( packet_info->ipv6_daddr, ipv6_header->daddr, IPV6_ADDRLEN );
229
223
 
230
224
  packet_info->format |= NW_IPV6;
231
-
232
- return;
233
225
  }
234
226
 
235
227
 
@@ -248,8 +240,6 @@ parse_lldp( buffer *buf ) {
248
240
  }
249
241
 
250
242
  packet_info->format |= NW_LLDP;
251
-
252
- return;
253
243
  }
254
244
 
255
245
 
@@ -296,9 +286,7 @@ parse_icmp( buffer *buf ) {
296
286
  }
297
287
 
298
288
  packet_info->format |= NW_ICMPV4;
299
-
300
- return;
301
- };
289
+ }
302
290
 
303
291
 
304
292
  static void
@@ -330,9 +318,7 @@ parse_udp( buffer *buf ) {
330
318
  }
331
319
 
332
320
  packet_info->format |= TP_UDP;
333
-
334
- return;
335
- };
321
+ }
336
322
 
337
323
 
338
324
  static void
@@ -377,10 +363,7 @@ parse_tcp( buffer *buf ) {
377
363
  }
378
364
 
379
365
  packet_info->format |= TP_TCP;
380
-
381
- return;
382
- };
383
-
366
+ }
384
367
 
385
368
 
386
369
  static void
@@ -404,8 +387,6 @@ parse_igmp( buffer *buf ) {
404
387
  packet_info->igmp_group = ntohl( igmp->group );
405
388
 
406
389
  packet_info->format |= NW_IGMP;
407
-
408
- return;
409
390
  }
410
391
 
411
392
 
@@ -433,12 +414,10 @@ parse_etherip( buffer *buf ) {
433
414
  if ( payload_length > 0 ) {
434
415
  packet_info->l4_payload = ptr;
435
416
  packet_info->l4_payload_length = payload_length;
436
- packet_info->etherip_offset = ( uint16_t ) ( ( char * ) ptr - ( char *) buf->data );
417
+ packet_info->etherip_offset = ( uint16_t ) ( ( char * ) ptr - ( char * ) buf->data );
437
418
  }
438
419
 
439
420
  packet_info->format |= TP_ETHERIP;
440
-
441
- return;
442
421
  }
443
422
 
444
423
 
@@ -204,7 +204,7 @@ handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
204
204
  case MESSENGER_ADD_PACKETIN_FILTER_REPLY:
205
205
  {
206
206
  if ( length != sizeof( add_packetin_filter_reply ) ) {
207
- error( "Invalid add packetin filter reply ( length = %u ).", length );
207
+ error( "Invalid add packetin filter reply ( length = %zu ).", length );
208
208
  return;
209
209
  }
210
210
  add_packetin_filter_reply *reply = data;
@@ -214,7 +214,7 @@ handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
214
214
  case MESSENGER_DELETE_PACKETIN_FILTER_REPLY:
215
215
  {
216
216
  if ( length != sizeof( delete_packetin_filter_reply ) ) {
217
- error( "Invalid delete packetin filter reply ( length = %u ).", length );
217
+ error( "Invalid delete packetin filter reply ( length = %zu ).", length );
218
218
  return;
219
219
  }
220
220
  delete_packetin_filter_reply *reply = data;
@@ -224,13 +224,13 @@ handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
224
224
  case MESSENGER_DUMP_PACKETIN_FILTER_REPLY:
225
225
  {
226
226
  if ( length < offsetof( dump_packetin_filter_reply, entries ) ) {
227
- error( "Invalid dump packetin filter reply ( length = %u ).", length );
227
+ error( "Invalid dump packetin filter reply ( length = %zu ).", length );
228
228
  return;
229
229
  }
230
230
  dump_packetin_filter_reply *reply = data;
231
231
  size_t expected_length = offsetof( dump_packetin_filter_reply, entries ) + sizeof( packetin_filter_entry ) * ntohl( reply->n_entries );
232
232
  if ( length != expected_length ) {
233
- error( "Invalid dump packetin filter reply ( length = %u ).", length );
233
+ error( "Invalid dump packetin filter reply ( length = %zu ).", length );
234
234
  return;
235
235
  }
236
236
  packetin_filter_entry *entries = NULL;
@@ -249,7 +249,7 @@ handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
249
249
  break;
250
250
  default:
251
251
  {
252
- warn( "Undefined reply tag ( tag = %#x, length = %u ).", tag, length );
252
+ warn( "Undefined reply tag ( tag = %#x, length = %zu ).", tag, length );
253
253
  }
254
254
  return;
255
255
  }
@@ -131,14 +131,14 @@ save_value( void *value, int n_columns, char **columns, char **column_names ) {
131
131
  }
132
132
 
133
133
 
134
- static char*
134
+ static char *
135
135
  get_value_from_backend( const char *key ) {
136
136
  assert( db_handle != NULL );
137
137
  assert( key != NULL );
138
138
 
139
139
  char *value = NULL;
140
140
  char *err = NULL;
141
- char *statement= sqlite3_mprintf( "SELECT value FROM trema WHERE key = '%q'", key );
141
+ char *statement = sqlite3_mprintf( "SELECT value FROM trema WHERE key = '%q'", key );
142
142
  int ret = trema_sqlite3_exec( db_handle, statement, save_value, &value, &err );
143
143
  if ( ret != SQLITE_OK ) {
144
144
  error( "Failed to execute a SQL statement ( statement = %s, error = %s ).", statement, err );
@@ -336,7 +336,7 @@ valid_key( const char *key ) {
336
336
 
337
337
  size_t length = strlen( key );
338
338
  if ( length > MAX_KEY_LENGTH ) {
339
- error( "Too long key ( length = %u ) specified. Maximum length is %u.", length, MAX_KEY_LENGTH );
339
+ error( "Too long key ( length = %zu ) specified. Maximum length is %zu.", length, MAX_KEY_LENGTH );
340
340
  return false;
341
341
  }
342
342
 
@@ -358,7 +358,7 @@ valid_value( const char *value ) {
358
358
 
359
359
  size_t length = strlen( value );
360
360
  if ( length > MAX_KEY_LENGTH ) {
361
- error( "Too long value ( length = %u ) specified. Maximum length is %u.", length, MAX_VALUE_LENGTH );
361
+ error( "Too long value ( length = %zu ) specified. Maximum length is %zu.", length, MAX_VALUE_LENGTH );
362
362
  return false;
363
363
  }
364
364
 
@@ -412,7 +412,7 @@ get_value( const char *key, char *value, const size_t length ) {
412
412
 
413
413
  size_t required_length = strlen( retrieved ) + 1;
414
414
  if ( required_length > length ) {
415
- error( "Insufficient buffer space ( %u [bytes] > %u [bytes] ).",
415
+ error( "Insufficient buffer space ( %zu [bytes] > %zu [bytes] ).",
416
416
  required_length, length );
417
417
  return false;
418
418
  }
@@ -442,13 +442,13 @@ delete_key_value( const char *key ) {
442
442
  }
443
443
 
444
444
 
445
- const char*
445
+ const char *
446
446
  _get_db_file( void ) {
447
447
  return db_file;
448
448
  }
449
449
 
450
450
 
451
- const sqlite3*
451
+ const sqlite3 *
452
452
  _get_db_handle( void ) {
453
453
  return db_handle;
454
454
  }
@@ -239,7 +239,7 @@ flush_send_queue( int fd, void *user_data ) {
239
239
  assert( send_queue != NULL );
240
240
  assert( connection.fd >= 0 );
241
241
 
242
- debug( "Flushing send queue ( length = %d ).", send_queue->length );
242
+ debug( "Flushing send queue ( length = %u ).", send_queue->length );
243
243
 
244
244
  set_writable( connection.fd, false );
245
245
 
@@ -309,7 +309,7 @@ static void
309
309
  check_connected( void *user_data ) {
310
310
  UNUSED( user_data );
311
311
 
312
- debug( "Checking a connection ( fd = %d ip = %#x, port = %u ).", connection.fd, connection.ip, connection.port );
312
+ debug( "Checking a connection ( fd = %d, ip = %#x, port = %u ).", connection.fd, connection.ip, connection.port );
313
313
 
314
314
  assert( secure_channel_initialized );
315
315
  assert( connection.fd >= 0 );
@@ -326,7 +326,7 @@ check_connected( void *user_data ) {
326
326
  return;
327
327
  }
328
328
 
329
- switch( err ) {
329
+ switch ( err ) {
330
330
  case 0:
331
331
  connected();
332
332
  break;
@@ -341,7 +341,7 @@ check_connected( void *user_data ) {
341
341
  return;
342
342
 
343
343
  case EINPROGRESS:
344
- set_fd_handler( connection.fd, NULL ,NULL, ( event_fd_callback ) check_connected, NULL );
344
+ set_fd_handler( connection.fd, NULL, NULL, ( event_fd_callback ) check_connected, NULL );
345
345
  set_writable( connection.fd, true );
346
346
  break;
347
347
 
@@ -393,7 +393,7 @@ try_connect() {
393
393
 
394
394
  ret = connect( connection.fd, ( struct sockaddr * ) &addr, sizeof( struct sockaddr_in ) );
395
395
  if ( ret < 0 ) {
396
- switch( errno ) {
396
+ switch ( errno ) {
397
397
  case EINTR:
398
398
  case EAGAIN:
399
399
  case ECONNREFUSED:
@@ -476,7 +476,7 @@ send_message_to_secure_channel( buffer *message ) {
476
476
  assert( connection.state == CONNECTED );
477
477
  assert( connection.fd >= 0 );
478
478
 
479
- debug( "Enqueuing a message to send queue ( queue length = %d, message length = %d ).",
479
+ debug( "Enqueuing a message to send queue ( queue length = %u, message length = %zu ).",
480
480
  send_queue->length, message->length );
481
481
 
482
482
  if ( send_queue->length == 0 ) {
@@ -25,7 +25,7 @@
25
25
 
26
26
 
27
27
  typedef void ( *connected_handler )( void );
28
- typedef void ( *disconnected_handler ) ( void );
28
+ typedef void ( *disconnected_handler )( void );
29
29
 
30
30
 
31
31
  bool init_secure_channel( uint32_t ip, uint16_t port,
data/src/lib/stat.c CHANGED
@@ -64,12 +64,6 @@ static hash_table *stats = NULL;
64
64
  static pthread_mutex_t stats_table_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
65
65
 
66
66
 
67
- typedef struct {
68
- char key[ STAT_KEY_LENGTH ];
69
- uint64_t value;
70
- } stat_entry;
71
-
72
-
73
67
  static void
74
68
  create_stats_table() {
75
69
  assert( stats == NULL );
@@ -88,7 +82,9 @@ delete_stats_table() {
88
82
  init_hash_iterator( stats, &iter );
89
83
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
90
84
  void *value = delete_hash_entry( stats, e->key );
91
- xfree( value );
85
+ if ( value != NULL ) {
86
+ xfree( value );
87
+ }
92
88
  }
93
89
  delete_hash( stats );
94
90
  stats = NULL;
@@ -178,29 +174,71 @@ increment_stat( const char *key ) {
178
174
 
179
175
 
180
176
  void
181
- dump_stats() {
177
+ reset_stats() {
182
178
  assert( stats != NULL );
183
179
 
184
- int n_stats = 0;
180
+ pthread_mutex_lock( &stats_table_mutex );
181
+
182
+ hash_entry *e = NULL;
185
183
  hash_iterator iter;
186
- hash_entry *e;
184
+ init_hash_iterator( stats, &iter );
185
+ while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
186
+ stat_entry *st = e->value;
187
+ if ( st != NULL ) {
188
+ void *deleted = delete_hash_entry( stats, st->key );
189
+ if ( deleted != NULL ) {
190
+ xfree( deleted );
191
+ }
192
+ }
193
+ }
187
194
 
188
- pthread_mutex_lock( &stats_table_mutex );
195
+ pthread_mutex_unlock( &stats_table_mutex );
196
+ }
189
197
 
190
- info( "Statistics:" );
191
198
 
199
+ void
200
+ foreach_stat( void function( const char *key, const uint64_t value, void *user_data ), void *user_data ) {
201
+ assert( stats != NULL );
202
+ assert( function != NULL );
203
+
204
+ pthread_mutex_lock( &stats_table_mutex );
205
+
206
+ hash_entry *e = NULL;
207
+ hash_iterator iter;
192
208
  init_hash_iterator( stats, &iter );
193
209
  while ( ( e = iterate_hash_next( &iter ) ) != NULL ) {
194
210
  stat_entry *st = e->value;
195
- info( "%s: %" PRIu64, st->key, st->value );
196
- n_stats++;
211
+ if ( st != NULL ) {
212
+ function( st->key, st->value, user_data );
213
+ }
197
214
  }
198
215
 
216
+ pthread_mutex_unlock( &stats_table_mutex );
217
+ }
218
+
219
+
220
+ static void
221
+ print_stat( const char *key, const uint64_t value, void *user_data ) {
222
+ assert( key != NULL );
223
+ assert( user_data != NULL );
224
+
225
+ info( "%s: %" PRIu64, key, value );
226
+ ( *( int * ) user_data )++;
227
+ }
228
+
229
+
230
+ void
231
+ dump_stats() {
232
+ assert( stats != NULL );
233
+
234
+ info( "Statistics:" );
235
+
236
+ int n_stats = 0;
237
+ foreach_stat( print_stat, &n_stats );
238
+
199
239
  if ( n_stats == 0 ) {
200
240
  info( "No statistics found." );
201
241
  }
202
-
203
- pthread_mutex_unlock( &stats_table_mutex );
204
242
  }
205
243
 
206
244
 
@@ -210,4 +248,3 @@ dump_stats() {
210
248
  * indent-tabs-mode: nil
211
249
  * End:
212
250
  */
213
-