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
@@ -36,7 +36,7 @@ typedef struct queue {
36
36
  queue_element *head;
37
37
  queue_element *divider;
38
38
  queue_element *tail;
39
- int length;
39
+ volatile int length;
40
40
  } queue;
41
41
 
42
42
 
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * stdin_relay: An application that relays text string from stdin to tremashark
3
- *
3
+ *
4
4
  * Author: Yasunobu Chiba
5
5
  *
6
6
  * Copyright (C) 2008-2012 NEC Corporation
@@ -155,10 +155,12 @@ usage( void ) {
155
155
  printf(
156
156
  "Usage: stdin_relay [OPTION]...\n"
157
157
  "\n"
158
- " -s DUMP_SERVICE_NAME dump service name\n"
159
- " -n, --name=SERVICE_NAME service name\n"
160
- " -l, --logging_level=LEVEL set logging level\n"
161
- " -h, --help display this help and exit\n"
158
+ " -s DUMP_SERVICE_NAME dump service name\n"
159
+ " -n, --name=SERVICE_NAME service name\n"
160
+ " -l, --logging_level=LEVEL set logging level\n"
161
+ " -g, --syslog output log messages to syslog\n"
162
+ " -f, --logging_facility=FACILITY set syslog facility\n"
163
+ " -h, --help display this help and exit\n"
162
164
  );
163
165
  }
164
166
 
@@ -174,14 +176,14 @@ static void
174
176
  parse_options( int *argc, char **argv[] ) {
175
177
  int opt;
176
178
 
177
- while( 1 ) {
179
+ while ( 1 ) {
178
180
  opt = getopt( *argc, *argv, "s:" );
179
181
 
180
- if( opt < 0 ){
182
+ if ( opt < 0 ) {
181
183
  break;
182
184
  }
183
185
 
184
- switch ( opt ){
186
+ switch ( opt ) {
185
187
  case 's':
186
188
  if ( optarg && dump_service_name == NULL ) {
187
189
  dump_service_name = xstrdup( optarg );
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * syslog_relay: An application that relays syslog messages to tremashark
3
- *
3
+ *
4
4
  * Author: Yasunobu Chiba
5
5
  *
6
6
  * Copyright (C) 2008-2012 NEC Corporation
@@ -24,8 +24,8 @@
24
24
  #include <getopt.h>
25
25
  #include <inttypes.h>
26
26
  #include <string.h>
27
- #include <sys/types.h>
28
27
  #include <sys/socket.h>
28
+ #include <sys/types.h>
29
29
  #include <unistd.h>
30
30
  #include "trema.h"
31
31
 
@@ -112,12 +112,14 @@ usage( void ) {
112
112
  printf(
113
113
  "Usage: syslog_relay [OPTION]...\n"
114
114
  "\n"
115
- " -p LISTEN_PORT listen port for receiving syslog messages\n"
116
- " -s DUMP_SERVICE_NAME dump service name\n"
117
- " -n, --name=SERVICE_NAME service name\n"
118
- " -d, --daemonize run in the background\n"
119
- " -l, --logging_level=LEVEL set logging level\n"
120
- " -h, --help display this help and exit\n"
115
+ " -p LISTEN_PORT listen port for receiving syslog messages\n"
116
+ " -s DUMP_SERVICE_NAME dump service name\n"
117
+ " -n, --name=SERVICE_NAME service name\n"
118
+ " -d, --daemonize run in the background\n"
119
+ " -l, --logging_level=LEVEL set logging level\n"
120
+ " -g, --syslog output log messages to syslog\n"
121
+ " -f, --logging_facility=FACILITY set syslog facility\n"
122
+ " -h, --help display this help and exit\n"
121
123
  );
122
124
  }
123
125
 
@@ -133,14 +135,14 @@ static void
133
135
  parse_options( int *argc, char **argv[] ) {
134
136
  int opt;
135
137
 
136
- while( 1 ) {
138
+ while ( 1 ) {
137
139
  opt = getopt( *argc, *argv, "p:s:" );
138
140
 
139
- if( opt < 0 ){
141
+ if ( opt < 0 ) {
140
142
  break;
141
143
  }
142
144
 
143
- switch ( opt ){
145
+ switch ( opt ) {
144
146
  case 'p':
145
147
  if ( ( optarg != NULL ) && ( atoi( optarg ) <= UINT16_MAX ) && ( atoi ( optarg ) >= 0 ) ) {
146
148
  listen_port = ( uint16_t ) atoi( optarg );
@@ -178,7 +180,7 @@ init_syslog_relay( int *argc, char **argv[] ) {
178
180
  close( syslog_fd );
179
181
  syslog_fd = -1;
180
182
  }
181
-
183
+
182
184
  syslog_fd = socket( PF_INET, SOCK_DGRAM, 0 );
183
185
  if ( syslog_fd < 0 ) {
184
186
  error( "Failed to create socket ( errno = %s [%d] ).", strerror( errno ), errno );
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * tremashark: A bridge for printing various events on Wireshark
3
- *
3
+ *
4
4
  * Author: Yasunobu Chiba, Yasunori Nakazawa
5
5
  *
6
6
  * Copyright (C) 2008-2012 NEC Corporation
@@ -97,7 +97,7 @@ write_to_file( buffer *packet ) {
97
97
  if ( err == EAGAIN || err == EWOULDBLOCK ) {
98
98
  return WRITE_BUSY;
99
99
  }
100
- error( "write error ( errno = %s [%d] ).", strerror( err), err );
100
+ error( "write error ( errno = %s [%d] ).", strerror( err ), err );
101
101
  return WRITE_ERROR;
102
102
  }
103
103
 
@@ -219,7 +219,7 @@ write_pcap_packet( void *user_data ) {
219
219
 
220
220
  timersub( &now, &buffer_length, &threshold );
221
221
 
222
- for ( ; ; ) {
222
+ for ( ;; ) {
223
223
  buffer *packet;
224
224
  queue_status status = peek_pcap_packet( &packet );
225
225
  if ( status == QUEUE_EMPTY ) {
@@ -251,8 +251,6 @@ write_pcap_packet( void *user_data ) {
251
251
  }
252
252
 
253
253
  fsync( outfile_fd );
254
-
255
- return;
256
254
  }
257
255
 
258
256
 
@@ -274,7 +272,6 @@ set_timer_event() {
274
272
  critical( "failed in set timer event" );
275
273
  abort();
276
274
  }
277
- return;
278
275
  }
279
276
 
280
277
 
@@ -350,8 +347,6 @@ write_circular_buffer( void ) {
350
347
  foreach_pcap_queue( ( void * ) write_to_file );
351
348
 
352
349
  finalize_pcap();
353
-
354
- return;
355
350
  }
356
351
 
357
352
 
@@ -403,16 +398,18 @@ usage( void ) {
403
398
  printf(
404
399
  "Usage: tremashark [OPTION]...\n"
405
400
  "\n"
406
- " -t launch tshark instead of wireshark\n"
407
- " -w FILE_TO_SAVE save messages to pcap file\n"
408
- " -p do not launch wireshark nor tshark\n"
409
- " -r do not trust remote clock\n"
410
- " -c NUMBER_OF_MESSAGES save messages to circular buffer\n"
411
- " -s DUMP_SERVICE_NAME dump service name\n"
412
- " -n, --name=SERVICE_NAME service name\n"
413
- " -d, --daemonize run in the background\n"
414
- " -l, --logging_level=LEVEL set logging level\n"
415
- " -h, --help display this help and exit\n"
401
+ " -t launch tshark instead of wireshark\n"
402
+ " -w FILE_TO_SAVE save messages to pcap file\n"
403
+ " -p do not launch wireshark nor tshark\n"
404
+ " -r do not trust remote clock\n"
405
+ " -c NUMBER_OF_MESSAGES save messages to circular buffer\n"
406
+ " -s DUMP_SERVICE_NAME dump service name\n"
407
+ " -n, --name=SERVICE_NAME service name\n"
408
+ " -d, --daemonize run in the background\n"
409
+ " -l, --logging_level=LEVEL set logging level\n"
410
+ " -g, --syslog output log messages to syslog\n"
411
+ " -f, --logging_facility=FACILITY set syslog facility\n"
412
+ " -h, --help display this help and exit\n"
416
413
  );
417
414
  }
418
415
 
data/trema CHANGED
@@ -1,101 +1,7 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # Trema command-line tool.
4
- #
5
- # Author: Yasuhito Takamiya <yasuhito@gmail.com>
6
- #
7
- # Copyright (C) 2008-2012 NEC Corporation
8
- #
9
- # This program is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License, version 2, as
11
- # published by the Free Software Foundation.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License along
19
- # with this program; if not, write to the Free Software Foundation, Inc.,
20
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
- #
1
+ #!/usr/bin/env ruby
22
2
 
23
3
 
24
- $LOAD_PATH.unshift File.expand_path( File.join File.dirname( __FILE__ ), "ruby" )
25
-
26
-
27
- require "English"
28
- require "fileutils"
29
- require "trema/command"
30
- require "trema/path"
31
-
32
-
33
- def setup_tmp
34
- if FileTest.exist?( Trema.tmp ) and not FileTest.writable?( Trema.tmp )
35
- # Trema is system widely installed with gem command
36
- sh "sudo chmod o+w -R #{ Trema.tmp }"
37
- end
38
-
39
- FileUtils.mkdir_p Trema.log
40
- FileUtils.mkdir_p Trema.pid
41
- FileUtils.mkdir_p Trema.sock
42
- end
43
-
44
-
45
- def method_for command
46
- case command
47
- when "version", "-V", "--version"
48
- return :show_version
49
- when "ruby"
50
- return :ruby
51
- when "help", "-h", "--help", "/?", "-?"
52
- return :usage
53
- end
54
-
55
- setup_tmp
56
-
57
- case command
58
- when "run", "start"
59
- return :run
60
- when "up"
61
- return :up
62
- when "kill", "stop", "off", "down"
63
- return :kill
64
- when "killall"
65
- return :killall
66
- when "send_packets", "send_packet"
67
- return :send_packets
68
- when "show_stats"
69
- return :show_stats
70
- when "reset_stats"
71
- return :reset_stats
72
- when "dump_flows", "dump_flow"
73
- return :dump_flows
74
- when "shell", NilClass
75
- return :shell
76
- else
77
- return nil
78
- end
79
- end
80
-
81
-
82
- command = ARGV.shift
83
- if method_for( command )
84
- begin
85
- include Trema::Command
86
- __send__ method_for( command )
87
- rescue
88
- $stderr.puts $ERROR_INFO.message
89
- $ERROR_INFO.backtrace.each do | each |
90
- $stderr.puts each if $verbose
91
- end
92
- exit false
93
- end
94
- else
95
- $stderr.puts "Unknown command: '#{ command }'"
96
- $stderr.puts "Type '#{ $0 } --help' for usage."
97
- exit false
98
- end
4
+ exec File.join( File.dirname( __FILE__ ), "./bin/trema" ), *ARGV
99
5
 
100
6
 
101
7
  ### Local variables:
data/trema-config CHANGED
@@ -1,57 +1,7 @@
1
- #! /usr/bin/env ruby
2
- #
3
- # Trema compile helper.
4
- #
5
- # Author: Yasuhito Takamiya <yasuhito@gmail.com>
6
- #
7
- # Copyright (C) 2008-2012 NEC Corporation
8
- #
9
- # This program is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License, version 2, as
11
- # published by the Free Software Foundation.
12
- #
13
- # This program is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License along
19
- # with this program; if not, write to the Free Software Foundation, Inc.,
20
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
- #
1
+ #!/usr/bin/env ruby
22
2
 
23
3
 
24
- $LOAD_PATH.unshift( File.expand_path( File.dirname( __FILE__ ) + "/ruby" ) )
25
-
26
-
27
- require "fileutils"
28
- require "optparse"
29
- require "trema/path"
30
-
31
-
32
- $opts = OptionParser.new
33
-
34
- FileUtils.cd Trema.home do
35
- $opts.banner = "Usage: #{ $0 } [OPTIONS ...]"
36
-
37
- $opts.on( "-c", "--cflags" ) do
38
- $cflags = true
39
- end
40
- $opts.on( "-l", "--libs" ) do
41
- $libs = true
42
- end
43
-
44
- $opts.parse! ARGV
45
-
46
- output = []
47
- if $cflags
48
- output << "-I#{ Trema.home }/src/lib -I#{ Trema.openflow }"
49
- end
50
- if $libs
51
- output << "-L#{ Trema.objects }/lib -ltrema -lrt -lpthread -lsqlite3 -ldl"
52
- end
53
- print output.join( " " )
54
- end
4
+ exec File.join( File.dirname( __FILE__ ), "./bin/trema-config" ), *ARGV
55
5
 
56
6
 
57
7
  ### Local variables:
data/trema.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  $:.push File.expand_path( "../ruby", __FILE__ )
3
2
  require "trema/version"
4
3
 
@@ -23,4 +22,16 @@ Gem::Specification.new do | s |
23
22
  # specify any dependencies here; for example:
24
23
  # s.add_development_dependency "rspec"
25
24
  s.add_runtime_dependency "rake"
25
+ s.add_runtime_dependency "gli", "~> 2.5.2"
26
+
27
+ s.add_development_dependency "rake"
28
+ s.add_development_dependency "rdoc"
29
+ s.add_development_dependency "aruba"
26
30
  end
31
+
32
+
33
+ ### Local variables:
34
+ ### mode: Ruby
35
+ ### coding: utf-8-unix
36
+ ### indent-tabs-mode: nil
37
+ ### End:
@@ -55,26 +55,27 @@ void unstub_logger( void );
55
55
  #ifdef expect_string_count
56
56
  #undef expect_string_count
57
57
  #endif
58
- #define expect_string_count( function, parameter, string, count ) \
58
+ #define expect_string_count( function, parameter, string, count ) \
59
59
  _expect_string( #function, #parameter, __FILE__, __LINE__, string, count )
60
60
 
61
61
 
62
62
  #ifdef expect_assert_failure
63
63
  #undef expect_assert_failure
64
64
  #endif
65
- #define expect_assert_failure( function_call ) \
66
- { \
65
+ #define expect_assert_failure( function_call ) \
66
+ { \
67
67
  const char *expression = ( const char * ) ( uintptr_t ) setjmp( global_expect_assert_env ); \
68
- global_expecting_assert = 1; \
69
- if ( expression ) { \
70
- print_message( "Expected assertion %s occurred\n", expression ); \
71
- global_expecting_assert = 0; \
72
- } else { \
73
- function_call ; \
74
- global_expecting_assert = 0; \
75
- print_error( "Expected assert in %s\n", #function_call ) ; \
76
- _fail( __FILE__, __LINE__ ); \
77
- } \
68
+ global_expecting_assert = 1; \
69
+ if ( expression ) { \
70
+ print_message( "Expected assertion %s occurred\n", expression ); \
71
+ global_expecting_assert = 0; \
72
+ } \
73
+ else { \
74
+ function_call; \
75
+ global_expecting_assert = 0; \
76
+ print_error( "Expected assert in %s\n", #function_call ); \
77
+ _fail( __FILE__, __LINE__ ); \
78
+ } \
78
79
  }
79
80
 
80
81
 
@@ -267,7 +267,7 @@ test_duplicate_buffer_succeeds() {
267
267
  unsigned char *data = append_back_buffer( buf, 1024 );
268
268
  int i;
269
269
  for ( i = 0; i < 1024; i++ ) {
270
- data[ i ] = ( unsigned char ) ( i % 0xff ) ;
270
+ data[ i ] = ( unsigned char ) ( i % 0xff );
271
271
  }
272
272
 
273
273
  buffer *duplicate = duplicate_buffer( buf );
@@ -184,14 +184,22 @@ create_action_enqueue() {
184
184
 
185
185
 
186
186
  static struct ofp_action_vendor_header *
187
- create_action_vendor() {
188
- struct ofp_action_vendor_header *action = xmalloc( sizeof( struct ofp_action_vendor_header ) );
189
- memset( action, 0, sizeof( struct ofp_action_vendor_header ) );
187
+ create_action_vendor( size_t body_length ) {
188
+ size_t length = sizeof( struct ofp_action_vendor_header ) + body_length;
189
+ struct ofp_action_vendor_header *action = xmalloc( length );
190
+ memset( action, 0, length );
190
191
 
191
192
  action->type = htons( OFPAT_VENDOR );
192
- action->len = htons( 8 );
193
+ action->len = htons( ( uint16_t ) length );
193
194
  action->vendor = htonl( 2048 );
194
195
 
196
+ if ( body_length > 0 ) {
197
+ uint8_t *body = ( uint8_t * ) action + sizeof( struct ofp_action_vendor_header );
198
+ for ( size_t i = 0; i < body_length; i++ ) {
199
+ body[ i ] = ( uint8_t ) rand();
200
+ }
201
+ }
202
+
195
203
  return action;
196
204
  }
197
205
 
@@ -469,7 +477,7 @@ test_ntoh_action_enqueue() {
469
477
 
470
478
  assert_int_equal( htons( dst.type ), src->type );
471
479
  assert_int_equal( htons( dst.len ), src->len );
472
- assert_int_equal( htons( dst.port) , src->port );
480
+ assert_int_equal( htons( dst.port ), src->port );
473
481
  assert_int_equal( ( int ) htonl( dst.queue_id ), ( int ) src->queue_id );
474
482
 
475
483
  xfree( src );
@@ -482,19 +490,91 @@ test_ntoh_action_enqueue() {
482
490
 
483
491
  void
484
492
  test_ntoh_action_vendor() {
485
- struct ofp_action_vendor_header dst;
493
+ struct ofp_action_vendor_header *src = create_action_vendor( 0 );
486
494
 
487
- memset( &dst, 0, sizeof( struct ofp_action_vendor_header ) );
495
+ size_t length = sizeof( struct ofp_action_vendor_header );
496
+ struct ofp_action_vendor_header *dst = xmalloc( length );
497
+ memset( dst, 0, length );
488
498
 
489
- struct ofp_action_vendor_header *src = create_action_vendor();
499
+ ntoh_action_vendor( dst, src );
490
500
 
491
- ntoh_action_vendor( &dst, src );
501
+ assert_int_equal( htons( dst->type ), src->type );
502
+ assert_int_equal( htons( dst->len ), src->len );
503
+ assert_int_equal( ( int ) htonl( dst->vendor ), ( int ) src->vendor );
492
504
 
493
- assert_int_equal( htons( dst.type ), src->type );
494
- assert_int_equal( htons( dst.len ), src->len );
495
- assert_int_equal( ( int ) htonl( dst.vendor ), ( int ) src->vendor );
505
+ xfree( src );
506
+ xfree( dst );
507
+ }
508
+
509
+
510
+ void
511
+ test_ntoh_action_vendor_with_body() {
512
+ const size_t body_length = 128;
513
+ struct ofp_action_vendor_header *src = create_action_vendor( body_length );
514
+
515
+ size_t length = sizeof( struct ofp_action_vendor_header ) + body_length;
516
+ struct ofp_action_vendor_header *dst = xmalloc( length );
517
+ memset( dst, 0, length );
518
+
519
+ ntoh_action_vendor( dst, src );
520
+
521
+ assert_int_equal( htons( dst->type ), src->type );
522
+ assert_int_equal( htons( dst->len ), src->len );
523
+ assert_int_equal( ( int ) htonl( dst->vendor ), ( int ) src->vendor );
524
+ void *src_body = ( char * ) src + sizeof( struct ofp_action_header );
525
+ void *dst_body = ( char * ) dst + sizeof( struct ofp_action_header );
526
+ assert_memory_equal( dst_body, src_body, body_length );
496
527
 
497
528
  xfree( src );
529
+ xfree( dst );
530
+ }
531
+
532
+
533
+ /********************************************************************************
534
+ * hton_action_vendor() test.
535
+ ********************************************************************************/
536
+
537
+ void
538
+ test_hton_action_vendor() {
539
+ struct ofp_action_vendor_header *src = create_action_vendor( 0 );
540
+ hton_action_vendor( src, src );
541
+
542
+ size_t length = sizeof( struct ofp_action_vendor_header );
543
+ struct ofp_action_vendor_header *dst = xmalloc( length );
544
+ memset( dst, 0, length );
545
+
546
+ hton_action_vendor( dst, src );
547
+
548
+ assert_int_equal( ntohs( dst->type ), src->type );
549
+ assert_int_equal( ntohs( dst->len ), src->len );
550
+ assert_int_equal( ( int ) ntohl( dst->vendor ), ( int ) src->vendor );
551
+
552
+ xfree( src );
553
+ xfree( dst );
554
+ }
555
+
556
+
557
+ void
558
+ test_hton_action_vendor_with_body() {
559
+ const size_t body_length = 128;
560
+ struct ofp_action_vendor_header *src = create_action_vendor( body_length );
561
+ hton_action_vendor( src, src );
562
+
563
+ size_t length = sizeof( struct ofp_action_vendor_header ) + body_length;
564
+ struct ofp_action_vendor_header *dst = xmalloc( length );
565
+ memset( dst, 0, length );
566
+
567
+ hton_action_vendor( dst, src );
568
+
569
+ assert_int_equal( ntohs( dst->type ), src->type );
570
+ assert_int_equal( ntohs( dst->len ), src->len );
571
+ assert_int_equal( ( int ) ntohl( dst->vendor ), ( int ) src->vendor );
572
+ void *src_body = ( char * ) src + sizeof( struct ofp_action_header );
573
+ void *dst_body = ( char * ) dst + sizeof( struct ofp_action_header );
574
+ assert_memory_equal( dst_body, src_body, body_length );
575
+
576
+ xfree( src );
577
+ xfree( dst );
498
578
  }
499
579
 
500
580
 
@@ -643,7 +723,7 @@ test_ntoh_action() {
643
723
 
644
724
  assert_int_equal( htons( dst.type ), src->type );
645
725
  assert_int_equal( htons( dst.len ), src->len );
646
- assert_int_equal( htons( dst.port) , src->port );
726
+ assert_int_equal( htons( dst.port ), src->port );
647
727
  assert_int_equal( ( int ) htonl( dst.queue_id ), ( int ) src->queue_id );
648
728
 
649
729
  xfree( src );
@@ -654,7 +734,7 @@ test_ntoh_action() {
654
734
 
655
735
  memset( &dst, 0, sizeof( struct ofp_action_vendor_header ) );
656
736
 
657
- struct ofp_action_vendor_header *src = create_action_vendor();
737
+ struct ofp_action_vendor_header *src = create_action_vendor( 0 );
658
738
 
659
739
  ntoh_action( ( struct ofp_action_header * ) &dst, ( struct ofp_action_header * ) src );
660
740
 
@@ -676,7 +756,7 @@ test_ntoh_action_with_undefined_action_type() {
676
756
  struct ofp_action_output *src = create_action_output();
677
757
 
678
758
  src->type = htons( OFPAT_ENQUEUE + 1 );
679
-
759
+
680
760
  expect_assert_failure( ntoh_action( ( struct ofp_action_header * ) &dst, ( struct ofp_action_header * ) src ) );
681
761
 
682
762
  xfree( src );
@@ -837,7 +917,7 @@ test_hton_action() {
837
917
 
838
918
  assert_int_equal( htons( dst.type ), src->type );
839
919
  assert_int_equal( htons( dst.len ), src->len );
840
- assert_int_equal( htons( dst.port) , src->port );
920
+ assert_int_equal( htons( dst.port ), src->port );
841
921
  assert_int_equal( ( int ) htonl( dst.queue_id ), ( int ) src->queue_id );
842
922
 
843
923
  xfree( src );
@@ -848,7 +928,7 @@ test_hton_action() {
848
928
 
849
929
  memset( &dst, 0, sizeof( struct ofp_action_vendor_header ) );
850
930
 
851
- struct ofp_action_vendor_header *src = create_action_vendor();
931
+ struct ofp_action_vendor_header *src = create_action_vendor( 0 );
852
932
  ntoh_action_vendor( src, src );
853
933
 
854
934
  hton_action( ( struct ofp_action_header * ) &dst, ( struct ofp_action_header * ) src );
@@ -872,7 +952,7 @@ test_hton_action_with_undefined_action_type() {
872
952
  ntoh_action_output( src, src );
873
953
 
874
954
  src->type = OFPAT_ENQUEUE + 1;
875
-
955
+
876
956
  expect_assert_failure( hton_action( ( struct ofp_action_header * ) &dst, ( struct ofp_action_header * ) src ) );
877
957
 
878
958
  xfree( src );
@@ -903,7 +983,7 @@ test_ntoh_flow_stats_without_action() {
903
983
  src->hard_timeout = htons( 300 );
904
984
  src->cookie = htonll( COOKIE );
905
985
  src->packet_count = htonll( PACKET_COUNT );
906
- src->byte_count= htonll( BYTE_COUNT );
986
+ src->byte_count = htonll( BYTE_COUNT );
907
987
 
908
988
  ntoh_flow_stats( dst, src );
909
989
 
@@ -944,7 +1024,7 @@ test_ntoh_flow_stats_with_single_output_action() {
944
1024
  src->hard_timeout = htons( 300 );
945
1025
  src->cookie = htonll( COOKIE );
946
1026
  src->packet_count = htonll( PACKET_COUNT );
947
- src->byte_count= htonll( BYTE_COUNT );
1027
+ src->byte_count = htonll( BYTE_COUNT );
948
1028
  struct ofp_action_output *act_src = ( struct ofp_action_output * ) src->actions;
949
1029
  act_src->type = htons( OFPAT_OUTPUT );
950
1030
  act_src->len = htons( 8 );
@@ -996,7 +1076,7 @@ test_ntoh_flow_stats_with_two_output_actions() {
996
1076
  src->hard_timeout = htons( 300 );
997
1077
  src->cookie = htonll( COOKIE );
998
1078
  src->packet_count = htonll( PACKET_COUNT );
999
- src->byte_count= htonll( BYTE_COUNT );
1079
+ src->byte_count = htonll( BYTE_COUNT );
1000
1080
  struct ofp_action_output *act_src[ 2 ];
1001
1081
  act_src[ 0 ] = ( struct ofp_action_output * ) src->actions;
1002
1082
  act_src[ 0 ]->type = htons( OFPAT_OUTPUT );
@@ -1064,7 +1144,7 @@ test_hton_flow_stats_without_action() {
1064
1144
  src->hard_timeout = 300;
1065
1145
  src->cookie = COOKIE;
1066
1146
  src->packet_count = PACKET_COUNT;
1067
- src->byte_count= BYTE_COUNT;
1147
+ src->byte_count = BYTE_COUNT;
1068
1148
 
1069
1149
  hton_flow_stats( dst, src );
1070
1150
 
@@ -1103,13 +1183,13 @@ test_hton_flow_stats_with_single_output_action() {
1103
1183
  src->table_id = 1;
1104
1184
  src->match = MATCH;
1105
1185
  src->duration_sec = 60;
1106
- src->duration_nsec = 5000 ;
1186
+ src->duration_nsec = 5000;
1107
1187
  src->priority = UINT16_MAX;
1108
1188
  src->idle_timeout = 60;
1109
1189
  src->hard_timeout = 300;
1110
1190
  src->cookie = COOKIE;
1111
1191
  src->packet_count = PACKET_COUNT;
1112
- src->byte_count= BYTE_COUNT;
1192
+ src->byte_count = BYTE_COUNT;
1113
1193
  struct ofp_action_output *act_src = ( struct ofp_action_output * ) src->actions;
1114
1194
  act_src->type = OFPAT_OUTPUT;
1115
1195
  act_src->len = 8;
@@ -1165,7 +1245,7 @@ test_hton_flow_stats_with_two_output_actions() {
1165
1245
  src->hard_timeout = 300;
1166
1246
  src->cookie = COOKIE;
1167
1247
  src->packet_count = PACKET_COUNT;
1168
- src->byte_count= BYTE_COUNT;
1248
+ src->byte_count = BYTE_COUNT;
1169
1249
  struct ofp_action_output *act_src[ 2 ];
1170
1250
  act_src[ 0 ] = ( struct ofp_action_output * ) src->actions;
1171
1251
  act_src[ 0 ]->type = OFPAT_OUTPUT;
@@ -1680,6 +1760,9 @@ main() {
1680
1760
  unit_test( test_ntoh_action_tp_port ),
1681
1761
  unit_test( test_ntoh_action_enqueue ),
1682
1762
  unit_test( test_ntoh_action_vendor ),
1763
+ unit_test( test_ntoh_action_vendor_with_body ),
1764
+ unit_test( test_hton_action_vendor ),
1765
+ unit_test( test_hton_action_vendor_with_body ),
1683
1766
  unit_test( test_ntoh_action ),
1684
1767
  unit_test( test_ntoh_action_with_undefined_action_type ),
1685
1768
  unit_test( test_hton_action ),