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.
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
data/src/lib/stat.h CHANGED
@@ -21,15 +21,24 @@
21
21
 
22
22
 
23
23
  #ifndef STAT_H
24
+ #define STAT_H
24
25
 
25
26
 
26
27
  #define STAT_KEY_LENGTH 256
27
28
 
28
29
 
30
+ typedef struct {
31
+ char key[ STAT_KEY_LENGTH ];
32
+ uint64_t value;
33
+ } stat_entry;
34
+
35
+
29
36
  bool init_stat( void );
30
37
  bool finalize_stat( void );
31
38
  bool add_stat_entry( const char *key );
32
39
  void increment_stat( const char *key );
40
+ void reset_stats( void );
41
+ void foreach_stat( void function( const char *key, const uint64_t value, void *user_data ), void *user_data );
33
42
  void dump_stats();
34
43
 
35
44
 
data/src/lib/timer.c CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  #include <assert.h>
22
22
  #include <errno.h>
23
+ #include <inttypes.h>
23
24
  #include <limits.h>
24
25
  #include "doubly_linked_list.h"
25
26
  #include "log.h"
@@ -143,9 +144,9 @@ on_timer( timer_callback_info *callback, struct timespec *now ) {
143
144
  assert( callback != NULL );
144
145
  assert( callback->function != NULL );
145
146
 
146
- debug( "Executing a timer event ( function = %p, expires_at = %u.%09u, interval = %u.%09u, user_data = %p ).",
147
- callback->function, callback->expires_at.tv_sec, callback->expires_at.tv_nsec,
148
- callback->interval.tv_sec, callback->interval.tv_nsec, callback->user_data );
147
+ debug( "Executing a timer event ( function = %p, expires_at = %" PRIu64 ".%09lu, interval = %" PRIu64 ".%09lu, user_data = %p ).",
148
+ callback->function, ( int64_t ) callback->expires_at.tv_sec, callback->expires_at.tv_nsec,
149
+ ( int64_t ) callback->interval.tv_sec, callback->interval.tv_nsec, callback->user_data );
149
150
 
150
151
  if ( VALID_TIMESPEC( &callback->expires_at ) ) {
151
152
  callback->function( callback->user_data );
@@ -161,7 +162,7 @@ on_timer( timer_callback_info *callback, struct timespec *now ) {
161
162
  callback->expires_at.tv_nsec = 0;
162
163
  callback->function = NULL;
163
164
  }
164
- debug( "Set expires_at value to %u.%09u.", callback->expires_at.tv_sec, callback->expires_at.tv_nsec );
165
+ debug( "Set expires_at value to %" PRIu64 ".%09lu.", ( int64_t ) callback->expires_at.tv_sec, callback->expires_at.tv_nsec );
165
166
  }
166
167
  else {
167
168
  error( "Invalid expires_at value." );
@@ -245,9 +246,9 @@ _add_timer_event_callback( struct itimerspec *interval, timer_callback callback,
245
246
  assert( interval != NULL );
246
247
  assert( callback != NULL );
247
248
 
248
- debug( "Adding a timer event callback ( interval = %u.%09u, initial expiration = %u.%09u, callback = %p, user_data = %p ).",
249
- interval->it_interval.tv_sec, interval->it_interval.tv_nsec,
250
- interval->it_value.tv_sec, interval->it_value.tv_nsec, callback, user_data );
249
+ debug( "Adding a timer event callback ( interval = %" PRIu64 ".%09lu, initial expiration = %" PRIu64 ".%09lu, callback = %p, user_data = %p ).",
250
+ ( int64_t ) interval->it_interval.tv_sec, interval->it_interval.tv_nsec,
251
+ ( int64_t ) interval->it_value.tv_sec, interval->it_value.tv_nsec, callback, user_data );
251
252
 
252
253
  timer_callback_info *cb;
253
254
  struct timespec now;
@@ -277,7 +278,7 @@ _add_timer_event_callback( struct itimerspec *interval, timer_callback callback,
277
278
  return false;
278
279
  }
279
280
 
280
- debug( "Set an initial expiration time to %u.%09u.", now.tv_sec, now.tv_nsec );
281
+ debug( "Set an initial expiration time to %" PRIu64 ".%09lu.", ( int64_t ) now.tv_sec, now.tv_nsec );
281
282
 
282
283
  assert( timer_callbacks != NULL );
283
284
  insert_timer_callback( cb );
@@ -291,8 +292,8 @@ bool
291
292
  _add_periodic_event_callback( const time_t seconds, timer_callback callback, void *user_data ) {
292
293
  assert( callback != NULL );
293
294
 
294
- debug( "Adding a periodic event callback ( interval = %u, callback = %p, user_data = %p ).",
295
- seconds, callback, user_data );
295
+ debug( "Adding a periodic event callback ( interval = %" PRIu64 ", callback = %p, user_data = %p ).",
296
+ ( const int64_t ) seconds, callback, user_data );
296
297
 
297
298
  struct itimerspec interval;
298
299
 
data/src/lib/trema.c CHANGED
@@ -35,6 +35,7 @@
35
35
  #include "daemon.h"
36
36
  #include "doubly_linked_list.h"
37
37
  #include "log.h"
38
+ #include "management_interface.h"
38
39
  #include "messenger.h"
39
40
  #include "openflow_application_interface.h"
40
41
  #include "packetin_filter_interface.h"
@@ -200,7 +201,7 @@ bool mock_finalize_openflow_application_interface( void );
200
201
  #undef printf
201
202
  #endif
202
203
  #define printf mock_printf
203
- int mock_printf(const char *format, ...);
204
+ int mock_printf( const char *format, ...);
204
205
 
205
206
  typedef struct stat _stat;
206
207
  #ifdef stat
@@ -243,7 +244,7 @@ bool mock_finalize_timer();
243
244
  #undef set_external_callback
244
245
  #endif
245
246
  #define set_external_callback mock_set_external_callback
246
- bool mock_set_external_callback( void ( *callback ) ( void ) );
247
+ bool mock_set_external_callback( void ( *callback )( void ) );
247
248
 
248
249
  #ifdef dump_stats
249
250
  #undef dump_stats
@@ -257,6 +258,18 @@ void mock_dump_stats();
257
258
  #define finalize_packetin_filter_interface mock_finalize_packetin_filter_interface
258
259
  bool mock_finalize_packetin_filter_interface();
259
260
 
261
+ #ifdef init_management_interface
262
+ #undef init_management_interface
263
+ #endif
264
+ #define init_management_interface mock_init_management_interface
265
+ bool mock_init_management_interface();
266
+
267
+ #ifdef finalize_management_interface
268
+ #undef finalize_management_interface
269
+ #endif
270
+ #define finalize_management_interface mock_finalize_management_interface
271
+ bool mock_finalize_management_interface();
272
+
260
273
  #define static
261
274
 
262
275
  #endif // UNIT_TESTING
@@ -284,10 +297,11 @@ static struct option long_options[] = {
284
297
  { "daemonize", 0, NULL, 'd' },
285
298
  { "logging_level", 1, NULL, 'l' },
286
299
  { "syslog", 0, NULL, 'g' },
300
+ { "logging_facility", 1, NULL, 'f' },
287
301
  { "help", 0, NULL, 'h' },
288
302
  { NULL, 0, NULL, 0 },
289
303
  };
290
- static char short_options[] = "n:dl:gh";
304
+ static char short_options[] = "n:dl:gf:h";
291
305
 
292
306
 
293
307
  /**
@@ -301,11 +315,12 @@ usage() {
301
315
  printf(
302
316
  "Usage: %s [OPTION]...\n"
303
317
  "\n"
304
- " -n, --name=SERVICE_NAME service name\n"
305
- " -d, --daemonize run in the background\n"
306
- " -l, --logging_level=LEVEL set logging level\n"
307
- " -g, --syslog output log messages to syslog\n"
308
- " -h, --help display this help and exit\n",
318
+ " -n, --name=SERVICE_NAME service name\n"
319
+ " -d, --daemonize run in the background\n"
320
+ " -l, --logging_level=LEVEL set logging level\n"
321
+ " -g, --syslog output log messages to syslog\n"
322
+ " -f, --logging_facility=FACILITY set syslog facility\n"
323
+ " -h, --help display this help and exit\n",
309
324
  executable_name
310
325
  );
311
326
  }
@@ -367,6 +382,7 @@ finalize_trema() {
367
382
  debug( "Terminating %s...", get_trema_name() );
368
383
 
369
384
  maybe_finalize_openflow_application_interface();
385
+ finalize_management_interface();
370
386
  finalize_packetin_filter_interface();
371
387
  finalize_messenger();
372
388
  finalize_stat();
@@ -443,6 +459,9 @@ parse_argv( int *argc, char ***argv ) {
443
459
  case 'g':
444
460
  log_output_type = LOGGING_TYPE_SYSLOG;
445
461
  break;
462
+ case 'f':
463
+ set_syslog_facility( optarg );
464
+ break;
446
465
  case 'h':
447
466
  usage();
448
467
  xfree( trema_name );
@@ -607,6 +626,7 @@ init_trema( int *argc, char ***argv ) {
607
626
  init_messenger( get_trema_sock() );
608
627
  init_stat();
609
628
  init_timer();
629
+ init_management_interface();
610
630
 
611
631
  initialized = true;
612
632
 
@@ -631,7 +651,7 @@ start_trema_up() {
631
651
 
632
652
  die_unless_initialized();
633
653
 
634
- debug( "Starting %s ... (TREMA_HOME = %s)", get_trema_name(), get_trema_home() );
654
+ debug( "Starting %s ... ( TREMA_HOME = %s )", get_trema_name(), get_trema_home() );
635
655
 
636
656
  maybe_daemonize();
637
657
  write_pid( get_trema_pid(), get_trema_name() );
@@ -735,6 +755,15 @@ terminate_trema_process( pid_t pid ) {
735
755
  }
736
756
 
737
757
 
758
+ void
759
+ _free_trema_name() {
760
+ if ( trema_name != NULL ) {
761
+ xfree( trema_name );
762
+ trema_name = NULL;
763
+ }
764
+ }
765
+
766
+
738
767
  /*
739
768
  * Local variables:
740
769
  * c-basic-offset: 2
data/src/lib/trema.h CHANGED
@@ -34,6 +34,7 @@
34
34
  #include "hash_table.h"
35
35
  #include "linked_list.h"
36
36
  #include "log.h"
37
+ #include "management_service_interface.h"
37
38
  #include "match.h"
38
39
  #include "match_table.h"
39
40
  #include "message_queue.h"
@@ -26,6 +26,7 @@
26
26
 
27
27
  #include <sqlite3.h>
28
28
  #include "bool.h"
29
+ #include "management_service_interface.h"
29
30
 
30
31
 
31
32
  void set_trema_home( void );
@@ -39,6 +40,7 @@ void unset_trema_tmp( void );
39
40
 
40
41
  const char *_get_trema_home( void );
41
42
  const char *_get_trema_tmp( void );
43
+ void _free_trema_name( void );
42
44
 
43
45
  const char *_get_db_file( void );
44
46
  const sqlite3 *_get_db_handle( void );
@@ -48,6 +50,10 @@ bool _get_backend_initialized( void );
48
50
  size_t _get_max_key_length( void );
49
51
  size_t _get_max_value_length( void );
50
52
 
53
+ bool *_get_management_interface_initialized( void );
54
+
55
+ void _set_management_application_request_handler( management_application_request_handler callback, void *user_data );
56
+
51
57
 
52
58
  #endif // TREMA_PRIVATE_H
53
59
 
@@ -41,13 +41,13 @@ int ( *trema_unlink )( const char *pathname ) = unlink;
41
41
 
42
42
  pid_t ( *trema_getpid )( void ) = getpid;
43
43
 
44
- void ( *trema_openlog ) ( const char *ident, int option, int facility ) = openlog;
45
- void ( *trema_closelog ) ( void ) = closelog;
46
- void ( *trema_vsyslog ) ( int priority, const char *format, va_list ap ) = vsyslog;
44
+ void ( *trema_openlog )( const char *ident, int option, int facility ) = openlog;
45
+ void ( *trema_closelog )( void ) = closelog;
46
+ void ( *trema_vsyslog )( int priority, const char *format, va_list ap ) = vsyslog;
47
47
 
48
48
  int ( *trema_sqlite3_open )( const char *filename, sqlite3 **ppDb ) = sqlite3_open;
49
49
  int ( *trema_sqlite3_close )( sqlite3 * ) = sqlite3_close;
50
- int ( *trema_sqlite3_exec )( sqlite3 *, const char *sql, int ( *callback ) ( void *, int, char **, char ** ), void *, char **errmsg ) = sqlite3_exec;
50
+ int ( *trema_sqlite3_exec )( sqlite3 *, const char *sql, int ( *callback )( void *, int, char **, char ** ), void *, char **errmsg ) = sqlite3_exec;
51
51
  int ( *trema_sqlite3_changes )( sqlite3 * ) = sqlite3_changes;
52
52
  void ( *trema_sqlite3_free )( void * ) = sqlite3_free;
53
53
  const char * ( *trema_sqlite3_errmsg )( sqlite3 * ) = sqlite3_errmsg;
@@ -41,20 +41,20 @@ extern void ( *trema_free )( void *ptr );
41
41
 
42
42
  extern void ( *trema_abort )( void );
43
43
 
44
- extern int ( *trema_unlink ) ( const char *pathname );
44
+ extern int ( *trema_unlink )( const char *pathname );
45
45
 
46
46
  extern pid_t ( *trema_getpid )( void );
47
47
 
48
- extern void ( *trema_openlog ) ( const char *ident, int option, int facility );
49
- extern void ( *trema_closelog ) ( void );
50
- extern void ( *trema_vsyslog ) ( int priority, const char *format, va_list ap );
48
+ extern void ( *trema_openlog )( const char *ident, int option, int facility );
49
+ extern void ( *trema_closelog )( void );
50
+ extern void ( *trema_vsyslog )( int priority, const char *format, va_list ap );
51
51
 
52
- extern int ( *trema_sqlite3_open) ( const char *filename, sqlite3 **ppDb );
53
- extern int ( *trema_sqlite3_close ) ( sqlite3 * );
54
- extern int ( *trema_sqlite3_exec ) ( sqlite3 *, const char *sql, int ( *callback ) ( void *, int, char **, char ** ), void *, char **errmsg );
55
- extern int ( *trema_sqlite3_changes ) ( sqlite3 * );
56
- extern void ( *trema_sqlite3_free ) ( void * );
57
- extern const char * ( *trema_sqlite3_errmsg ) ( sqlite3 * );
52
+ extern int ( *trema_sqlite3_open )( const char *filename, sqlite3 **ppDb );
53
+ extern int ( *trema_sqlite3_close )( sqlite3 * );
54
+ extern int ( *trema_sqlite3_exec )( sqlite3 *, const char *sql, int ( *callback )( void *, int, char **, char ** ), void *, char **errmsg );
55
+ extern int ( *trema_sqlite3_changes )( sqlite3 * );
56
+ extern void ( *trema_sqlite3_free )( void * );
57
+ extern const char * ( *trema_sqlite3_errmsg )( sqlite3 * );
58
58
 
59
59
 
60
60
  #endif // TREMA_WRAPPER_H
data/src/lib/utility.c CHANGED
@@ -45,7 +45,7 @@ _die( const char *format, ... ) {
45
45
  vsnprintf( err, sizeof( err ), format, args );
46
46
  va_end( args );
47
47
 
48
- critical( err );
48
+ critical( "%s", err );
49
49
  trema_abort();
50
50
  }
51
51
  void ( *die )( const char *format, ... ) = _die;
@@ -176,7 +176,7 @@ wildcards_to_string( uint32_t wildcards, char *str, size_t size ) {
176
176
  uint32_t nw_src_mask = ( wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
177
177
  uint32_t nw_dst_mask = ( wildcards & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT;
178
178
  uint32_t mask = OFPFW_ALL & ~OFPFW_NW_SRC_MASK & ~OFPFW_NW_DST_MASK;
179
- if ( ( wildcards & mask ) == mask && nw_src_mask >=32 && nw_dst_mask >= 32 ) {
179
+ if ( ( wildcards & mask ) == mask && nw_src_mask >= 32 && nw_dst_mask >= 32 ) {
180
180
  ret &= append_string( str, size, "all" );
181
181
  return ret;
182
182
  }
@@ -195,7 +195,7 @@ wildcards_to_string( uint32_t wildcards, char *str, size_t size ) {
195
195
  }
196
196
  if ( wildcards & OFPFW_DL_VLAN ) {
197
197
  ret &= append_string( str, size, "dl_vlan|" );
198
- }
198
+ }
199
199
  if ( wildcards & OFPFW_DL_VLAN_PCP ) {
200
200
  ret &= append_string( str, size, "dl_vlan_pcp|" );
201
201
  }
@@ -263,7 +263,7 @@ match_to_string( const struct ofp_match *match, char *str, size_t size ) {
263
263
  "wildcards = %#x(%s), in_port = %u, "
264
264
  "dl_src = %02x:%02x:%02x:%02x:%02x:%02x, "
265
265
  "dl_dst = %02x:%02x:%02x:%02x:%02x:%02x, "
266
- "dl_vlan = %u, dl_vlan_pcp = %u, dl_type = %#x, "
266
+ "dl_vlan = %#x, dl_vlan_pcp = %#x, dl_type = %#x, "
267
267
  "nw_tos = %u, nw_proto = %u, nw_src = %s/%u, nw_dst = %s/%u, "
268
268
  "tp_src = %u, tp_dst = %u",
269
269
  match->wildcards, wildcards_str, match->in_port,
@@ -520,7 +520,7 @@ actions_to_string( const struct ofp_action_header *actions, uint16_t actions_len
520
520
  }
521
521
  char *p = str + current_str_length;
522
522
  const struct ofp_action_header *header = ( const struct ofp_action_header * ) ( ( const char * ) actions + offset );
523
- switch( header->type ) {
523
+ switch ( header->type ) {
524
524
  case OFPAT_OUTPUT:
525
525
  ret = action_output_to_string( ( const struct ofp_action_output * ) header, p, remaining_str_length );
526
526
  break;
@@ -567,7 +567,7 @@ actions_to_string( const struct ofp_action_header *actions, uint16_t actions_len
567
567
 
568
568
  if ( ret == false ) {
569
569
  break;
570
- }
570
+ }
571
571
  offset += header->len;
572
572
  }
573
573
 
@@ -0,0 +1,224 @@
1
+ /*
2
+ * Management command for any application specific managements.
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 <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ #include "trema.h"
28
+
29
+
30
+ static char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
31
+ static uint32_t application_id = 0;
32
+ static uint8_t *data = NULL;
33
+ static size_t data_length = 0;
34
+
35
+
36
+ void
37
+ usage( void ) {
38
+ printf( "Usage: application SERVICE_NAME APPLICATION_ID [DATA_IN_HEX]\n" );
39
+ }
40
+
41
+
42
+ static void
43
+ print_usage_and_exit( void ) {
44
+ usage();
45
+ exit( EXIT_FAILURE );
46
+ }
47
+
48
+
49
+ static bool
50
+ hex_string_to_data( char *string ) {
51
+ assert( string != NULL );
52
+
53
+ size_t string_length = strlen( string );
54
+ if ( string_length % 2 ) {
55
+ return false;
56
+ }
57
+
58
+ data_length = string_length / 2;
59
+ data = xmalloc( data_length );
60
+ memset( data, 0, data_length );
61
+
62
+ int byte = 0;
63
+ for ( size_t i = 0; i < string_length; i++ ) {
64
+ char c = string[ i ];
65
+ byte <<= 4;
66
+
67
+ if ( ( c >= '0' ) && ( c <= '9' ) ) {
68
+ byte += c - '0';
69
+ }
70
+ else if ( ( c >= 'a' ) && ( c <= 'f' ) ) {
71
+ byte += c - 'a' + 10;
72
+ }
73
+ else if ( ( c >= 'A' ) && ( c <= 'F' ) ) {
74
+ byte += c - 'A' + 10;
75
+ }
76
+ else {
77
+ xfree( data );
78
+ data = NULL;
79
+ data_length = 0;
80
+ return false;
81
+ }
82
+
83
+ if ( i % 2 ) {
84
+ data[ i / 2 ] = ( uint8_t ) byte;
85
+ byte = 0;
86
+ }
87
+ }
88
+
89
+ return true;
90
+ }
91
+
92
+
93
+ static void
94
+ parse_arguments( int argc, char **argv ) {
95
+ assert( argv != NULL );
96
+
97
+ if ( argc < 3 || argc > 4 ) {
98
+ print_usage_and_exit();
99
+ }
100
+
101
+ if ( argv[ 1 ] == NULL || ( argv[ 1 ] != NULL && strlen( argv[ 1 ] ) == 0 ) ) {
102
+ print_usage_and_exit();
103
+ }
104
+
105
+ if ( argv[ 2 ] == NULL ) {
106
+ print_usage_and_exit();
107
+ }
108
+
109
+ memset( service_name, '\0', MESSENGER_SERVICE_NAME_LENGTH );
110
+ snprintf( service_name, MESSENGER_SERVICE_NAME_LENGTH, "%s", get_management_service_name( argv[ 1 ] ) );
111
+
112
+ char *endp = NULL;
113
+ application_id = ( uint32_t ) strtoul( argv[ 2 ], &endp, 0 );
114
+ if ( *endp != '\0' ) {
115
+ print_usage_and_exit();
116
+ }
117
+
118
+ if ( argc >= 4 && argv[ 3 ] != NULL ) {
119
+ hex_string_to_data( argv[ 3 ] );
120
+ if ( data == NULL ) {
121
+ print_usage_and_exit();
122
+ }
123
+ }
124
+ }
125
+
126
+
127
+ static void
128
+ timeout( void *user_data ) {
129
+ UNUSED( user_data );
130
+
131
+ printf( "Timeout.\n" );
132
+
133
+ delete_timer_event( timeout, NULL );
134
+
135
+ stop_trema();
136
+ }
137
+
138
+
139
+ static void
140
+ handle_reply( uint16_t tag, void *data, size_t length, void *user_data ) {
141
+ UNUSED( user_data );
142
+
143
+ assert( tag == MESSENGER_MANAGEMENT_REPLY );
144
+ assert( data != NULL );
145
+ assert( length >= offsetof( management_application_reply, data ) );
146
+
147
+ management_application_reply *reply = data;
148
+ assert( ntohs( reply->header.type ) == MANAGEMENT_APPLICATION_REPLY );
149
+ assert( ntohl( reply->header.length ) == length );
150
+ uint32_t id = ntohl( reply->application_id );
151
+
152
+ if ( reply->header.status == MANAGEMENT_REQUEST_SUCCEEDED ) {
153
+ printf( "An application specific management command is executed successfully ( application_id = %#x ).\n", id );
154
+ }
155
+ else {
156
+ printf( "Failed to execute an application specific management command ( application_id = %#x ).\n", id );
157
+ }
158
+
159
+ size_t data_length = length - offsetof( management_application_reply, data );
160
+ if ( data_length > 0 ) {
161
+ printf( "Data: " );
162
+ for ( size_t i = 0; i < data_length; i++ ) {
163
+ printf( "%02x", reply->data[ i ] );
164
+ }
165
+ printf( "\n" );
166
+ }
167
+
168
+ stop_trema();
169
+ }
170
+
171
+
172
+ static void
173
+ send_application_request() {
174
+ size_t length = offsetof( management_application_request, data ) + data_length;
175
+ management_application_request *request = xmalloc( length );
176
+ memset( request, 0, sizeof( management_application_request ) );
177
+ request->header.type = htons( MANAGEMENT_APPLICATION_REQUEST );
178
+ request->header.length = htonl( ( uint32_t ) length );
179
+ request->application_id = htonl( application_id );
180
+ if ( data_length > 0 && data != NULL ) {
181
+ memcpy( request->data, data, data_length );
182
+ xfree( data );
183
+ }
184
+
185
+ bool ret = send_request_message( service_name, get_trema_name(), MESSENGER_MANAGEMENT_REQUEST,
186
+ request, length, NULL );
187
+ xfree( request );
188
+ if ( !ret ) {
189
+ printf( "Failed to send an application specific management request to %s.\n", service_name );
190
+ exit( EXIT_FAILURE );
191
+ }
192
+ }
193
+
194
+
195
+ int
196
+ main( int argc, char *argv[] ) {
197
+ // Initialize the Trema world
198
+ init_trema( &argc, &argv );
199
+
200
+ // Parse arguments
201
+ parse_arguments( argc, argv );
202
+
203
+ // Set a handler to handle application specific management reply
204
+ add_message_replied_callback( get_trema_name(), handle_reply );
205
+
206
+ // Send an application specific management request
207
+ send_application_request();
208
+
209
+ // Set timeout
210
+ add_periodic_event_callback( 5, timeout, NULL );
211
+
212
+ // Main loop
213
+ start_trema();
214
+
215
+ return EXIT_SUCCESS;
216
+ }
217
+
218
+
219
+ /*
220
+ * Local variables:
221
+ * c-basic-offset: 2
222
+ * indent-tabs-mode: nil
223
+ * End:
224
+ */