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
@@ -265,7 +265,7 @@ test_peek_message_if_queue_is_not_created() {
265
265
 
266
266
  static int count = 0;
267
267
 
268
- static void
268
+ static bool
269
269
  test_foreach_message_queue_helper( buffer *message, void *user_data ) {
270
270
  const char *str = message->data;
271
271
  assert_string_equal( ( char * ) user_data, "user_data" );
@@ -280,6 +280,8 @@ test_foreach_message_queue_helper( buffer *message, void *user_data ) {
280
280
  assert_true( false );
281
281
  break;
282
282
  }
283
+
284
+ return true;
283
285
  }
284
286
 
285
287
 
@@ -323,11 +325,13 @@ test_foreach_message_queue() {
323
325
  }
324
326
 
325
327
 
326
- static void
328
+ static bool
327
329
  test_foreach_message_queue_if_queue_is_empty_helper( buffer *message, void *user_data ) {
328
330
  UNUSED( message );
329
331
  UNUSED( user_data );
330
332
  assert_true( false );
333
+
334
+ return true;
331
335
  }
332
336
 
333
337
 
@@ -124,8 +124,8 @@ static size_t message_buffer_remain_bytes( message_buffer *buf );
124
124
 
125
125
  static void delete_timer_callbacks( void );
126
126
 
127
- static messenger_context* insert_context( void *user_data );
128
- static messenger_context* get_context( uint32_t transaction_id );
127
+ static messenger_context *insert_context( void *user_data );
128
+ static messenger_context *get_context( uint32_t transaction_id );
129
129
  static void delete_context( messenger_context *context );
130
130
  static void delete_context_db( void );
131
131
  static void age_context_db( void * );
@@ -282,9 +282,25 @@ mock_debug( char *format, ... ) {
282
282
  }
283
283
 
284
284
 
285
+ static bool check_warn = false;
286
+ static void
287
+ mock_warn_check( char *format, va_list args ) {
288
+ char message[ 1000 ];
289
+ vsnprintf( message, 1000, format, args );
290
+
291
+ check_expected( message );
292
+ }
293
+
294
+
285
295
  void
286
296
  mock_warn( char *format, ... ) {
287
297
  UNUSED( format );
298
+ if ( check_warn ) {
299
+ va_list arg;
300
+ va_start( arg, format );
301
+ mock_warn_check( format, arg );
302
+ va_end( arg );
303
+ }
288
304
  }
289
305
 
290
306
 
@@ -325,6 +341,8 @@ reset_messenger() {
325
341
  finalized = false;
326
342
 
327
343
  execute_timer_events = mock_execute_timer_events;
344
+
345
+ check_warn = false;
328
346
  }
329
347
 
330
348
 
@@ -400,6 +418,138 @@ test_send_then_message_received_callback_is_called() {
400
418
  }
401
419
 
402
420
 
421
+ static void callback_req_hello( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) {
422
+ UNUSED( handle );
423
+ check_expected( tag );
424
+ check_expected( data );
425
+ check_expected( len );
426
+
427
+ send_reply_message( handle, 65534, "OLLEH", strlen("OLLEH")+1 );
428
+ }
429
+
430
+
431
+ static void callback_req_hello2( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) {
432
+ UNUSED( handle );
433
+ UNUSED( tag );
434
+ UNUSED( data );
435
+ UNUSED( len );
436
+ }
437
+
438
+
439
+ static void callback_rep_hello_end( uint16_t tag, void *data, size_t len, void *user_data ) {
440
+ check_expected( tag );
441
+ check_expected( data );
442
+ check_expected( len );
443
+ check_expected( user_data );
444
+
445
+ stop_event_handler();
446
+ stop_messenger();
447
+ }
448
+
449
+
450
+ static void callback_rep_hello2( uint16_t tag, void *data, size_t len, void *user_data ) {
451
+ UNUSED( tag );
452
+ UNUSED( data );
453
+ UNUSED( len );
454
+ UNUSED( user_data );
455
+ }
456
+
457
+
458
+ static void
459
+ test_send_then_message_requested_and_replied_callback_is_called() {
460
+ init_messenger( "/tmp" );
461
+
462
+ const char service_name[] = "Say HELLO";
463
+
464
+ expect_value( callback_req_hello, tag, 43556 );
465
+ expect_string( callback_req_hello, data, "HELLO" );
466
+ expect_value( callback_req_hello, len, 6 );
467
+ add_message_requested_callback( service_name, callback_req_hello );
468
+
469
+ expect_value( callback_rep_hello_end, tag, 65534 );
470
+ expect_string( callback_rep_hello_end, data, "OLLEH" );
471
+ expect_value( callback_rep_hello_end, len, 6 );
472
+ expect_value( callback_rep_hello_end, user_data, NULL );
473
+ add_message_replied_callback( service_name, callback_rep_hello_end );
474
+
475
+ send_request_message( service_name, service_name, 43556, "HELLO", strlen( "HELLO" ) + 1, NULL );
476
+
477
+ start_messenger();
478
+ start_event_handler();
479
+
480
+ delete_message_replied_callback( service_name, callback_rep_hello_end );
481
+ delete_message_requested_callback( service_name, callback_req_hello );
482
+ delete_send_queue( lookup_hash_entry( send_queues, service_name ) );
483
+
484
+ finalize_messenger();
485
+ }
486
+
487
+
488
+ static void
489
+ test_double_add_message_requested_callback_prints_error_message() {
490
+ init_messenger( "/tmp" );
491
+
492
+
493
+ const char service_name[] = "Some Service";
494
+ char expected_mes[ 1024+1 ] = {};
495
+ snprintf( expected_mes, 1024, "Multiple message_requested/replied handler is not supported. ( service_name = %s, message_type = %#x, callback = %p )",
496
+ service_name, MESSAGE_TYPE_REQUEST, callback_req_hello2 );
497
+
498
+
499
+ check_warn = true;
500
+
501
+ assert_true( add_message_requested_callback( service_name, callback_req_hello ) );
502
+
503
+ expect_string( mock_warn_check, message, expected_mes );
504
+ assert_true( add_message_requested_callback( service_name, callback_req_hello2 ) );
505
+
506
+ check_warn = false;
507
+
508
+ finalize_messenger();
509
+ }
510
+
511
+ static void
512
+ test_double_add_message_replied_callback_prints_error_message() {
513
+ init_messenger( "/tmp" );
514
+
515
+
516
+ const char service_name[] = "Some Service";
517
+ char expected_mes[ 1024+1 ] = {};
518
+ snprintf( expected_mes, 1024, "Multiple message_requested/replied handler is not supported. ( service_name = %s, message_type = %#x, callback = %p )",
519
+ service_name, MESSAGE_TYPE_REPLY, callback_rep_hello2 );
520
+
521
+
522
+ check_warn = true;
523
+
524
+ assert_true( add_message_replied_callback( service_name, callback_rep_hello_end ) );
525
+
526
+ expect_string( mock_warn_check, message, expected_mes );
527
+ assert_true( add_message_replied_callback( service_name, callback_rep_hello2 ) );
528
+
529
+ check_warn = false;
530
+
531
+ finalize_messenger();
532
+ }
533
+
534
+
535
+ static void
536
+ test_add_1_message_requested_and_replied_callback_each_prints_no_error_message() {
537
+ init_messenger( "/tmp" );
538
+
539
+ const char service_name[] = "Some Service";
540
+
541
+ check_warn = true;
542
+
543
+ assert_true( add_message_requested_callback( service_name, callback_req_hello ) );
544
+
545
+ assert_true( add_message_replied_callback( service_name, callback_rep_hello_end ) );
546
+
547
+ check_warn = false;
548
+
549
+ finalize_messenger();
550
+ }
551
+
552
+
403
553
  /********************************************************************************
404
554
  * Run tests.
405
555
  ********************************************************************************/
@@ -425,6 +575,21 @@ main() {
425
575
  unit_test_setup_teardown( test_send_then_message_received_callback_is_called,
426
576
  reset_messenger,
427
577
  reset_messenger ),
578
+ // Message request callback tests.
579
+ unit_test_setup_teardown( test_send_then_message_requested_and_replied_callback_is_called,
580
+ reset_messenger,
581
+ reset_messenger ),
582
+ // Message request duplicate registrationcallback tests.
583
+ unit_test_setup_teardown( test_double_add_message_requested_callback_prints_error_message,
584
+ reset_messenger,
585
+ reset_messenger ),
586
+ unit_test_setup_teardown( test_double_add_message_replied_callback_prints_error_message,
587
+ reset_messenger,
588
+ reset_messenger ),
589
+ unit_test_setup_teardown( test_add_1_message_requested_and_replied_callback_each_prints_no_error_message,
590
+ reset_messenger,
591
+ reset_messenger ),
592
+
428
593
  };
429
594
  return run_tests( tests );
430
595
  }
@@ -41,12 +41,6 @@
41
41
  * Helpers.
42
42
  ********************************************************************************/
43
43
 
44
- typedef struct {
45
- char key[ STAT_KEY_LENGTH ];
46
- uint64_t value;
47
- } stat_entry;
48
-
49
-
50
44
  extern bool openflow_application_interface_initialized;
51
45
  extern openflow_event_handlers_t event_handlers;
52
46
  extern char service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
@@ -159,7 +153,7 @@ static bool packet_in_handler_called = false;
159
153
  * Mocks.
160
154
  ********************************************************************************/
161
155
 
162
- const char*
156
+ const char *
163
157
  mock_get_trema_name() {
164
158
  return "TEST_SERVICE_NAME";
165
159
  }
@@ -286,12 +280,12 @@ mock_error_handler( uint64_t datapath_id, uint32_t transaction_id, uint16_t type
286
280
 
287
281
  static void
288
282
  mock_echo_reply_handler( uint64_t datapath_id, uint32_t transaction_id, const buffer *data,
289
- void *user_data ){
283
+ void *user_data ) {
290
284
  void *data_uc;
291
285
 
292
286
  check_expected( &datapath_id );
293
287
  check_expected( transaction_id );
294
- if( data != NULL ) {
288
+ if ( data != NULL ) {
295
289
  check_expected( data->length );
296
290
  check_expected( data->data );
297
291
  }
@@ -305,13 +299,13 @@ mock_echo_reply_handler( uint64_t datapath_id, uint32_t transaction_id, const bu
305
299
 
306
300
  static void
307
301
  mock_vendor_handler( uint64_t datapath_id, uint32_t transaction_id, uint32_t vendor,
308
- const buffer *data, void *user_data ){
302
+ const buffer *data, void *user_data ) {
309
303
  void *data_uc;
310
304
 
311
305
  check_expected( &datapath_id );
312
306
  check_expected( transaction_id );
313
307
  check_expected( vendor );
314
- if( data != NULL ) {
308
+ if ( data != NULL ) {
315
309
  check_expected( data->length );
316
310
  check_expected( data->data );
317
311
  }
@@ -1319,7 +1313,7 @@ test_send_openflow_message() {
1319
1313
  will_return( mock_send_message, true );
1320
1314
 
1321
1315
  ret = send_openflow_message( DATAPATH_ID, buffer );
1322
-
1316
+
1323
1317
  assert_true( ret );
1324
1318
  stat_entry *stat = lookup_hash_entry( stats, "openflow_application_interface.hello_send_succeeded" );
1325
1319
  assert_int_equal( ( int ) stat->value, 1 );
@@ -1649,8 +1643,8 @@ test_handle_features_reply() {
1649
1643
  set_features_reply_handler( mock_features_reply_handler, USER_DATA );
1650
1644
  handle_features_reply( DATAPATH_ID, buffer );
1651
1645
 
1652
- xfree( phy_port[0] );
1653
- xfree( phy_port[1] );
1646
+ xfree( phy_port[ 0 ] );
1647
+ xfree( phy_port[ 1 ] );
1654
1648
  delete_list( ports );
1655
1649
  free_buffer( buffer );
1656
1650
  }
@@ -1733,8 +1727,8 @@ test_handle_features_reply_if_handler_is_not_registered() {
1733
1727
 
1734
1728
  handle_features_reply( DATAPATH_ID, buffer );
1735
1729
 
1736
- xfree( phy_port[0] );
1737
- xfree( phy_port[1] );
1730
+ xfree( phy_port[ 0 ] );
1731
+ xfree( phy_port[ 1 ] );
1738
1732
  delete_list( ports );
1739
1733
  free_buffer( buffer );
1740
1734
  }
@@ -2884,7 +2878,7 @@ test_handle_openflow_message() {
2884
2878
  data = alloc_buffer_with_length( 16 );
2885
2879
  append_back_buffer( data, 16 );
2886
2880
  memset( data->data, 'a', 16 );
2887
-
2881
+
2888
2882
  buffer = create_error( TRANSACTION_ID, OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE, data );
2889
2883
  append_front_buffer( buffer, sizeof( openflow_service_header_t ) );
2890
2884
  memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
@@ -2895,7 +2889,7 @@ test_handle_openflow_message() {
2895
2889
  expect_value( mock_error_handler, data->length, data->length );
2896
2890
  expect_memory( mock_error_handler, data->data, data->data, data->length );
2897
2891
  expect_memory( mock_error_handler, user_data, USER_DATA, USER_DATA_LEN );
2898
-
2892
+
2899
2893
  set_error_handler( mock_error_handler, USER_DATA );
2900
2894
  handle_openflow_message( buffer->data, buffer->length );
2901
2895
 
@@ -2925,7 +2919,7 @@ test_handle_openflow_message() {
2925
2919
  expect_value( mock_vendor_handler, data->length, data->length );
2926
2920
  expect_memory( mock_vendor_handler, data->data, data->data, data->length );
2927
2921
  expect_memory( mock_vendor_handler, user_data, USER_DATA, USER_DATA_LEN );
2928
-
2922
+
2929
2923
  set_vendor_handler( mock_vendor_handler, USER_DATA );
2930
2924
  handle_openflow_message( buffer->data, buffer->length );
2931
2925
 
@@ -2996,8 +2990,8 @@ test_handle_openflow_message() {
2996
2990
  stat = lookup_hash_entry( stats, "openflow_application_interface.features_reply_receive_succeeded" );
2997
2991
  assert_int_equal( ( int ) stat->value, 1 );
2998
2992
 
2999
- xfree( phy_port[0] );
3000
- xfree( phy_port[1] );
2993
+ xfree( phy_port[ 0 ] );
2994
+ xfree( phy_port[ 1 ] );
3001
2995
  delete_list( ports );
3002
2996
  free_buffer( buffer );
3003
2997
  xfree( delete_hash_entry( stats, "openflow_application_interface.features_reply_receive_succeeded" ) );
@@ -3312,7 +3306,7 @@ test_handle_openflow_message_with_malformed_message() {
3312
3306
  memcpy( buffer->data, &messenger_header, sizeof( openflow_service_header_t ) );
3313
3307
 
3314
3308
  handle_openflow_message( buffer->data, buffer->length );
3315
-
3309
+
3316
3310
  free_buffer( buffer );
3317
3311
  }
3318
3312
 
@@ -21,14 +21,14 @@
21
21
 
22
22
 
23
23
  #include <arpa/inet.h>
24
+ #include <net/if_arp.h>
25
+ #include <netinet/ip.h>
24
26
  #include <openflow.h>
25
27
  #include <stdio.h>
26
28
  #include <stdlib.h>
27
29
  #include <string.h>
28
30
  #include <sys/types.h>
29
31
  #include <unistd.h>
30
- #include <netinet/ip.h>
31
- #include <net/if_arp.h>
32
32
  #include "byteorder.h"
33
33
  #include "checks.h"
34
34
  #include "cmockery_trema.h"
@@ -1213,7 +1213,7 @@ static void
1213
1213
  test_append_action_vendor() {
1214
1214
  openflow_actions *actions = NULL;
1215
1215
  uint32_t vendor = 1;
1216
- buffer *body;
1216
+ buffer *body = NULL;
1217
1217
  struct ofp_action_vendor_header *action_vendor;
1218
1218
  uint16_t length;
1219
1219
  bool ret;
@@ -1234,6 +1234,7 @@ test_append_action_vendor() {
1234
1234
  assert_int_equal( action_vendor->type, OFPAT_VENDOR );
1235
1235
  assert_int_equal( action_vendor->len, length );
1236
1236
  assert_int_equal( ( int ) action_vendor->vendor, ( int ) vendor );
1237
+ assert_memory_equal( ( char * ) action_vendor + sizeof( struct ofp_action_vendor_header ), body->data, body->length );
1237
1238
 
1238
1239
  assert_int_equal( actions->n_actions, 1 );
1239
1240
 
@@ -2327,7 +2328,7 @@ test_create_vendor_stats_request() {
2327
2328
  assert_int_equal( ( int ) ntohs( stats->flags ), ( int ) VENDOR_STATS_FLAG );
2328
2329
  uint32_t vendor_id = *( ( uint32_t * ) ( ( char * ) stats + offsetof( struct ofp_stats_request, body ) ) );
2329
2330
  assert_int_equal( ( int ) ntohl( vendor_id ), ( int ) VENDOR_ID );
2330
- assert_memory_equal( ( char * ) stats + offsetof( struct ofp_stats_request, body ) + sizeof ( uint32_t ),
2331
+ assert_memory_equal( ( char * ) stats + offsetof( struct ofp_stats_request, body ) + sizeof( uint32_t ),
2331
2332
  body->data, body_length );
2332
2333
 
2333
2334
  free_buffer( body );
@@ -4454,13 +4455,14 @@ test_validate_action_enqueue_fails_with_invalid_action_type() {
4454
4455
  buffer *body = create_dummy_data( SHORT_DATA_LENGTH );
4455
4456
  openflow_actions *actions = create_actions();
4456
4457
  append_action_vendor( actions, VENDOR_ID, body );
4457
- struct ofp_action_vendor_header action_vendor;
4458
- hton_action_vendor( &action_vendor, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4458
+ struct ofp_action_vendor_header *action_vendor = xmalloc( sizeof( struct ofp_action_vendor_header ) + body->length );
4459
+ hton_action_vendor( action_vendor, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4459
4460
 
4460
- assert_int_equal( validate_action_enqueue( ( struct ofp_action_enqueue * ) &action_vendor ), ERROR_INVALID_ACTION_TYPE );
4461
+ assert_int_equal( validate_action_enqueue( ( struct ofp_action_enqueue * ) action_vendor ), ERROR_INVALID_ACTION_TYPE );
4461
4462
 
4462
4463
  free_buffer( body );
4463
4464
  delete_actions( actions );
4465
+ xfree( action_vendor );
4464
4466
  }
4465
4467
 
4466
4468
 
@@ -4509,13 +4511,14 @@ test_validate_action_vendor() {
4509
4511
  buffer *body = create_dummy_data( SHORT_DATA_LENGTH );
4510
4512
  openflow_actions *actions = create_actions();
4511
4513
  append_action_vendor( actions, VENDOR_ID, body );
4512
- struct ofp_action_vendor_header action_vendor_header;
4513
- hton_action_vendor( &action_vendor_header, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4514
+ struct ofp_action_vendor_header *action_vendor_header = xmalloc( sizeof( struct ofp_action_vendor_header ) + body->length );
4515
+ hton_action_vendor( action_vendor_header, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4514
4516
 
4515
- assert_int_equal( validate_action_vendor( &action_vendor_header ), 0 );
4517
+ assert_int_equal( validate_action_vendor( action_vendor_header ), 0 );
4516
4518
 
4517
4519
  free_buffer( body );
4518
4520
  delete_actions( actions );
4521
+ xfree( action_vendor_header );
4519
4522
  }
4520
4523
 
4521
4524
 
@@ -4540,15 +4543,16 @@ test_validate_action_vendor_fails_with_too_short_ofp_action_vendor_header() {
4540
4543
  buffer *body = create_dummy_data( SHORT_DATA_LENGTH );
4541
4544
  openflow_actions *actions = create_actions();
4542
4545
  append_action_vendor( actions, VENDOR_ID, body );
4546
+ struct ofp_action_vendor_header *too_short_action_vendor_header = xmalloc( sizeof( struct ofp_action_vendor_header ) + body->length );
4547
+ hton_action_vendor( too_short_action_vendor_header, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4543
4548
  uint16_t too_short_action_length = sizeof( struct ofp_action_vendor_header ) - 1;
4544
- ( ( struct ofp_action_vendor_header * )( actions->list->data ) )->len = too_short_action_length;
4545
- struct ofp_action_vendor_header too_short_action_vendor_header;
4546
- hton_action_vendor( &too_short_action_vendor_header, ( struct ofp_action_vendor_header * ) ( actions->list->data ) );
4549
+ too_short_action_vendor_header->len = htons( too_short_action_length );
4547
4550
 
4548
- assert_int_equal( validate_action_vendor( &too_short_action_vendor_header ), ERROR_TOO_SHORT_ACTION_VENDOR );
4551
+ assert_int_equal( validate_action_vendor( too_short_action_vendor_header ), ERROR_TOO_SHORT_ACTION_VENDOR );
4549
4552
 
4550
4553
  free_buffer( body );
4551
- delete_actions( ( openflow_actions * ) actions );
4554
+ delete_actions( actions );
4555
+ xfree( too_short_action_vendor_header );
4552
4556
  }
4553
4557
 
4554
4558
 
@@ -5047,8 +5051,8 @@ setup_ether_packet( size_t length, uint16_t type ) {
5047
5051
  if ( type == ETH_ETHTYPE_TPID ) {
5048
5052
  packet_info0->l3_header = ( void * ) ( vtag + 1 );
5049
5053
  packet_info0->format |= ETH_8021Q;
5050
- }
5051
- else {
5054
+ }
5055
+ else {
5052
5056
  packet_info0->l3_header = ( void * ) ( ether + 1 );
5053
5057
  }
5054
5058
 
@@ -5082,7 +5086,7 @@ setup_ipv4_packet( size_t length, uint16_t type ) {
5082
5086
 
5083
5087
  switch ( type ) {
5084
5088
  case IPPROTO_ICMP:
5085
- ipv4->protocol = ( uint8_t ) IPPROTO_ICMP;
5089
+ ipv4->protocol = ( uint8_t ) IPPROTO_ICMP;
5086
5090
  icmp_header_t *icmpv4 = packet_info0->l4_header;
5087
5091
  icmpv4->type = ICMP_TYPE_UNREACH;
5088
5092
  icmpv4->code = ICMP_CODE_PORTUNREACH;
@@ -5094,7 +5098,7 @@ setup_ipv4_packet( size_t length, uint16_t type ) {
5094
5098
  udp->src_port = ntohs( src_port );
5095
5099
  udp->dst_port = ntohs( dst_port );
5096
5100
  break;
5097
-
5101
+
5098
5102
  case IPPROTO_TCP:
5099
5103
  ipv4->protocol = ( uint8_t ) IPPROTO_TCP;
5100
5104
  tcp_header_t *tcp = packet_info0->l4_header;
@@ -5142,7 +5146,7 @@ setup_ipv4_packet( size_t length, uint16_t type ) {
5142
5146
  default:
5143
5147
  break;
5144
5148
  }
5145
-
5149
+
5146
5150
  return buf;
5147
5151
  }
5148
5152
 
@@ -5151,7 +5155,7 @@ static buffer *
5151
5155
  setup_arp_packet( uint16_t type ) {
5152
5156
  buffer *buf = setup_ether_packet( sizeof( ether_header_t ) + sizeof( arp_header_t ), type );
5153
5157
  packet_info *packet_info0 = buf->user_data;
5154
-
5158
+
5155
5159
  /* Fill arp values into the test packet. */
5156
5160
  if ( type == ETH_ETHTYPE_TPID ) {
5157
5161
  ether_header_t *ether = packet_info0->l2_header;
@@ -5217,7 +5221,7 @@ setup_snap_packet( uint16_t type ) {
5217
5221
  length += sizeof( vlantag_header_t );
5218
5222
  vlantag_header_t *vtag = ( void * ) ( ether + 1 );
5219
5223
  vtag->type = htons( ( uint16_t ) length );
5220
- }
5224
+ }
5221
5225
  else {
5222
5226
  ether->type = htons( ( uint16_t ) length );
5223
5227
  }
@@ -6015,7 +6019,7 @@ test_set_match_from_packet_succeeds_if_datatype_is_ipv4_tcp_tag_and_wildcards_is
6015
6019
  packet_info0->tcp_src_port = src_port;
6016
6020
  packet_info0->tcp_dst_port = dst_port;
6017
6021
  packet_info0->format |= TP_TCP;
6018
-
6022
+
6019
6023
  uint16_t expected_in_port = 1;
6020
6024
  struct ofp_match match;
6021
6025
  set_match_from_packet( &match, expected_in_port, 0, buf );
@@ -6424,7 +6428,7 @@ test_set_match_from_packet_succeeds_if_datatype_is_ipv4_icmp_tag_and_wildcards_i
6424
6428
  /* Add a icmp data into the test packet. */
6425
6429
  ipv4_header_t *ipv4 = packet_info0->l3_header;
6426
6430
  ipv4->protocol = IPPROTO_ICMP;
6427
- icmp_header_t *icmpv4 = packet_info0->l4_header;
6431
+ icmp_header_t *icmpv4 = packet_info0->l4_header;
6428
6432
  icmpv4->type = ICMP_TYPE_UNREACH;
6429
6433
  icmpv4->code = ICMP_CODE_PORTUNREACH;
6430
6434
  /* Add the icmp data into the packet_info data for verification. */
@@ -6980,6 +6984,16 @@ test_set_match_from_packet_succeeds_if_datatype_is_ieee8023_not_llc_and_wildcard
6980
6984
  }
6981
6985
 
6982
6986
 
6987
+ static void
6988
+ test_set_match_from_packet_fails_if_match_is_NULL() {
6989
+ buffer *buf = setup_arp_packet( ETH_ETHTYPE_TPID );
6990
+
6991
+ expect_assert_failure( set_match_from_packet( NULL, 1, 0, buf ) );
6992
+
6993
+ free_buffer( buf );
6994
+ }
6995
+
6996
+
6983
6997
  static void
6984
6998
  test_set_match_from_packet_fails_if_packet_data_is_NULL() {
6985
6999
  struct ofp_match match;
@@ -6998,6 +7012,666 @@ test_set_match_from_packet_fails_if_packet_is_not_parsed_yet() {
6998
7012
  }
6999
7013
 
7000
7014
 
7015
+ /********************************************************************************
7016
+ * normalize_match() tests.
7017
+ ********************************************************************************/
7018
+
7019
+ #define NORMALIZED_OFPFW_ALL \
7020
+ ( OFPFW_IN_PORT | OFPFW_DL_VLAN | OFPFW_DL_SRC | OFPFW_DL_DST | OFPFW_DL_TYPE | \
7021
+ OFPFW_NW_PROTO | OFPFW_TP_SRC | OFPFW_TP_DST | OFPFW_NW_SRC_ALL | OFPFW_NW_DST_ALL | \
7022
+ OFPFW_DL_VLAN_PCP | OFPFW_NW_TOS )
7023
+
7024
+
7025
+ const char all_zero_mac_addr[] = { 0, 0, 0, 0, 0, 0 };
7026
+ const char all_one_mac_addr[] = { ( char ) 0xff, ( char ) 0xff, ( char ) 0xff,
7027
+ ( char ) 0xff, ( char ) 0xff, ( char ) 0xff };
7028
+ const char all_zero_pad1[] = { 0 };
7029
+ const char all_zero_pad2[] = { 0, 0 };
7030
+
7031
+
7032
+ static void
7033
+ setup_arp_match( struct ofp_match *match ) {
7034
+ memset( match, 0xa8, sizeof( match ) );
7035
+ match->wildcards = 0;
7036
+ match->in_port = 1;
7037
+ memcpy( match->dl_src, macsa, ETH_ADDRLEN );
7038
+ memcpy( match->dl_dst, macda, ETH_ADDRLEN );
7039
+ match->dl_vlan = UINT16_MAX;
7040
+ match->dl_type = ETH_ETHTYPE_ARP;
7041
+ match->nw_proto = ARP_OP_REQUEST;
7042
+ match->nw_src = 0x01020304;
7043
+ match->nw_dst = 0x05060708;
7044
+ }
7045
+
7046
+
7047
+ static void
7048
+ setup_icmp_match( struct ofp_match *match ) {
7049
+ memset( match, 0xa8, sizeof( match ) );
7050
+ match->wildcards = 0;
7051
+ match->in_port = 1;
7052
+ memcpy( match->dl_src, macsa, ETH_ADDRLEN );
7053
+ memcpy( match->dl_dst, macda, ETH_ADDRLEN );
7054
+ match->dl_vlan = UINT16_MAX;
7055
+ match->dl_type = ETH_ETHTYPE_IPV4;
7056
+ match->nw_tos = 0;
7057
+ match->nw_proto = IPPROTO_ICMP;
7058
+ match->nw_src = 0x01020304;
7059
+ match->nw_dst = 0x05060708;
7060
+ match->tp_src = ICMP_TYPE_UNREACH;
7061
+ match->tp_dst = ICMP_CODE_PORTUNREACH;
7062
+ }
7063
+
7064
+
7065
+ static void
7066
+ setup_tcp_match( struct ofp_match *match ) {
7067
+ memset( match, 0xa8, sizeof( match ) );
7068
+ match->wildcards = 0;
7069
+ match->in_port = 1;
7070
+ memcpy( match->dl_src, macsa, ETH_ADDRLEN );
7071
+ memcpy( match->dl_dst, macda, ETH_ADDRLEN );
7072
+ match->dl_vlan = 1;
7073
+ match->dl_vlan_pcp = 0xff;
7074
+ match->dl_type = ETH_ETHTYPE_IPV4;
7075
+ match->nw_tos = 0xff;
7076
+ match->nw_proto = IPPROTO_TCP;
7077
+ match->nw_src = 0x01020304;
7078
+ match->nw_dst = 0x05060708;
7079
+ match->tp_src = 0xa;
7080
+ match->tp_dst = 0xb;
7081
+ }
7082
+
7083
+
7084
+ static void
7085
+ setup_udp_match( struct ofp_match *match ) {
7086
+ memset( match, 0xa8, sizeof( match ) );
7087
+ match->wildcards = 0;
7088
+ match->in_port = 1;
7089
+ memcpy( match->dl_src, macsa, ETH_ADDRLEN );
7090
+ memcpy( match->dl_dst, macda, ETH_ADDRLEN );
7091
+ match->dl_vlan = UINT16_MAX;
7092
+ match->dl_vlan_pcp = 0xff;
7093
+ match->dl_type = ETH_ETHTYPE_IPV4;
7094
+ match->nw_tos = 0xff;
7095
+ match->nw_proto = IPPROTO_UDP;
7096
+ match->nw_src = 0x01020304;
7097
+ match->nw_dst = 0x05060708;
7098
+ match->tp_src = 0xa;
7099
+ match->tp_dst = 0xb;
7100
+ }
7101
+
7102
+
7103
+ static void
7104
+ setup_invalid_match( struct ofp_match *match ) {
7105
+ memset( match, 0xa8, sizeof( match ) );
7106
+ match->wildcards = 0;
7107
+ match->in_port = 1;
7108
+ memcpy( match->dl_src, macsa, ETH_ADDRLEN );
7109
+ memcpy( match->dl_dst, macda, ETH_ADDRLEN );
7110
+ match->dl_vlan = UINT16_MAX;
7111
+ match->dl_vlan_pcp = 0xff;
7112
+ match->dl_type = UINT16_MAX;
7113
+ }
7114
+
7115
+
7116
+ static void
7117
+ test_normalize_match_succeeds_if_datatype_is_arp_and_wildcards_is_zero() {
7118
+ struct ofp_match match;
7119
+ setup_arp_match( &match );
7120
+
7121
+ normalize_match( &match );
7122
+
7123
+ uint32_t wildcards = OFPFW_DL_VLAN_PCP | OFPFW_NW_TOS | OFPFW_TP_SRC | OFPFW_TP_DST;
7124
+
7125
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7126
+ assert_int_equal( match.in_port, 1 );
7127
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7128
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7129
+ assert_int_equal( match.dl_vlan, UINT16_MAX );
7130
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7131
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7132
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_ARP );
7133
+ assert_int_equal( match.nw_tos, 0 );
7134
+ assert_int_equal( match.nw_proto, ARP_OP_REQUEST );
7135
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7136
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7137
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7138
+ assert_int_equal( ( int ) match.tp_src, 0 );
7139
+ assert_int_equal( ( int ) match.tp_dst, 0 );
7140
+ }
7141
+
7142
+
7143
+ static void
7144
+ test_normalize_match_succeeds_if_protocol_is_icmp_and_wildcards_is_zero() {
7145
+ struct ofp_match match;
7146
+ setup_icmp_match( &match );
7147
+
7148
+ normalize_match( &match );
7149
+
7150
+ uint32_t wildcards = OFPFW_DL_VLAN_PCP;
7151
+
7152
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7153
+ assert_int_equal( match.in_port, 1 );
7154
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7155
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7156
+ assert_int_equal( match.dl_vlan, UINT16_MAX );
7157
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7158
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7159
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7160
+ assert_int_equal( match.nw_tos, 0 );
7161
+ assert_int_equal( match.nw_proto, IPPROTO_ICMP );
7162
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7163
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7164
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7165
+ assert_int_equal( ( int ) match.tp_src, ICMP_TYPE_UNREACH );
7166
+ assert_int_equal( ( int ) match.tp_dst, ICMP_CODE_PORTUNREACH );
7167
+ }
7168
+
7169
+
7170
+ static void
7171
+ test_normalize_match_succeeds_if_protocol_is_tcp_and_wildcards_is_zero() {
7172
+ struct ofp_match match;
7173
+ setup_tcp_match( &match );
7174
+
7175
+ normalize_match( &match );
7176
+
7177
+ uint32_t wildcards = 0;
7178
+
7179
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7180
+ assert_int_equal( match.in_port, 1 );
7181
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7182
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7183
+ assert_int_equal( match.dl_vlan, 1 );
7184
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7185
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7186
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7187
+ assert_int_equal( match.nw_tos, 0xfc );
7188
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7189
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7190
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7191
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7192
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7193
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7194
+ }
7195
+
7196
+
7197
+ static void
7198
+ test_normalize_match_succeeds_if_protocol_is_udp_and_wildcards_is_zero() {
7199
+ struct ofp_match match;
7200
+ setup_udp_match( &match );
7201
+
7202
+ normalize_match( &match );
7203
+
7204
+ uint32_t wildcards = OFPFW_DL_VLAN_PCP;
7205
+
7206
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7207
+ assert_int_equal( match.in_port, 1 );
7208
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7209
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7210
+ assert_int_equal( match.dl_vlan, UINT16_MAX );
7211
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7212
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7213
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7214
+ assert_int_equal( match.nw_tos, 0xfc );
7215
+ assert_int_equal( match.nw_proto, IPPROTO_UDP );
7216
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7217
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7218
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7219
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7220
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7221
+ }
7222
+
7223
+
7224
+ static void
7225
+ test_normalize_match_succeeds_if_packet_is_invalid_and_wildcards_is_zero() {
7226
+ struct ofp_match match;
7227
+ setup_invalid_match( &match );
7228
+
7229
+ normalize_match( &match );
7230
+
7231
+ uint32_t wildcards = OFPFW_DL_VLAN_PCP | OFPFW_NW_PROTO | OFPFW_NW_TOS | OFPFW_NW_SRC_ALL | OFPFW_NW_DST_ALL | OFPFW_TP_SRC | OFPFW_TP_DST;
7232
+
7233
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7234
+ assert_int_equal( match.in_port, 1 );
7235
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7236
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7237
+ assert_int_equal( match.dl_vlan, UINT16_MAX );
7238
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7239
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7240
+ assert_int_equal( match.dl_type, UINT16_MAX );
7241
+ assert_int_equal( match.nw_tos, 0 );
7242
+ assert_int_equal( match.nw_proto, 0 );
7243
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7244
+ assert_int_equal( ( int ) match.nw_src, 0 );
7245
+ assert_int_equal( ( int ) match.nw_dst, 0 );
7246
+ assert_int_equal( ( int ) match.tp_src, 0 );
7247
+ assert_int_equal( ( int ) match.tp_dst, 0 );
7248
+ }
7249
+
7250
+
7251
+ static void
7252
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_ALL() {
7253
+ struct ofp_match match;
7254
+ setup_tcp_match( &match );
7255
+ match.wildcards = OFPFW_ALL;
7256
+
7257
+ normalize_match( &match );
7258
+
7259
+ assert_int_equal( ( int ) match.wildcards, NORMALIZED_OFPFW_ALL );
7260
+ assert_int_equal( match.in_port, 0 );
7261
+ assert_memory_equal( match.dl_src, all_zero_mac_addr, ETH_ADDRLEN );
7262
+ assert_memory_equal( match.dl_dst, all_zero_mac_addr, ETH_ADDRLEN );
7263
+ assert_int_equal( match.dl_vlan, 0 );
7264
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7265
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7266
+ assert_int_equal( match.dl_type, 0 );
7267
+ assert_int_equal( match.nw_tos, 0 );
7268
+ assert_int_equal( match.nw_proto, 0 );
7269
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7270
+ assert_int_equal( ( int ) match.nw_src, 0 );
7271
+ assert_int_equal( ( int ) match.nw_dst, 0 );
7272
+ assert_int_equal( ( int ) match.tp_src, 0 );
7273
+ assert_int_equal( ( int ) match.tp_dst, 0 );
7274
+ }
7275
+
7276
+
7277
+ static void
7278
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_IN_PORT() {
7279
+ struct ofp_match match;
7280
+ setup_tcp_match( &match );
7281
+ match.wildcards = OFPFW_IN_PORT;
7282
+
7283
+ normalize_match( &match );
7284
+
7285
+ uint32_t wildcards = OFPFW_IN_PORT;
7286
+
7287
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7288
+ assert_int_equal( match.in_port, 0 );
7289
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7290
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7291
+ assert_int_equal( match.dl_vlan, 1 );
7292
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7293
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7294
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7295
+ assert_int_equal( match.nw_tos, 0xfc );
7296
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7297
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7298
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7299
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7300
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7301
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7302
+ }
7303
+
7304
+
7305
+ static void
7306
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_VLAN() {
7307
+ struct ofp_match match;
7308
+ setup_tcp_match( &match );
7309
+ match.wildcards = OFPFW_DL_VLAN;
7310
+
7311
+ normalize_match( &match );
7312
+
7313
+ uint32_t wildcards = OFPFW_DL_VLAN;
7314
+
7315
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7316
+ assert_int_equal( match.in_port, 1 );
7317
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7318
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7319
+ assert_int_equal( match.dl_vlan, 0 );
7320
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7321
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7322
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7323
+ assert_int_equal( match.nw_tos, 0xfc );
7324
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7325
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7326
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7327
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7328
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7329
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7330
+ }
7331
+
7332
+
7333
+ static void
7334
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_SRC() {
7335
+ struct ofp_match match;
7336
+ setup_tcp_match( &match );
7337
+ match.wildcards = OFPFW_DL_SRC;
7338
+
7339
+ normalize_match( &match );
7340
+
7341
+ uint32_t wildcards = OFPFW_DL_SRC;
7342
+
7343
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7344
+ assert_int_equal( match.in_port, 1 );
7345
+ assert_memory_equal( match.dl_src, all_zero_mac_addr, ETH_ADDRLEN );
7346
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7347
+ assert_int_equal( match.dl_vlan, 1 );
7348
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7349
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7350
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7351
+ assert_int_equal( match.nw_tos, 0xfc );
7352
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7353
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7354
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7355
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7356
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7357
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7358
+ }
7359
+
7360
+
7361
+ static void
7362
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_DST() {
7363
+ struct ofp_match match;
7364
+ setup_tcp_match( &match );
7365
+ match.wildcards = OFPFW_DL_DST;
7366
+
7367
+ normalize_match( &match );
7368
+
7369
+ uint32_t wildcards = OFPFW_DL_DST;
7370
+
7371
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7372
+ assert_int_equal( match.in_port, 1 );
7373
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7374
+ assert_memory_equal( match.dl_dst, all_zero_mac_addr, ETH_ADDRLEN );
7375
+ assert_int_equal( match.dl_vlan, 1 );
7376
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7377
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7378
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7379
+ assert_int_equal( match.nw_tos, 0xfc );
7380
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7381
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7382
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7383
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7384
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7385
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7386
+ }
7387
+
7388
+
7389
+ static void
7390
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_TYPE() {
7391
+ struct ofp_match match;
7392
+ setup_tcp_match( &match );
7393
+ match.wildcards = OFPFW_DL_TYPE;
7394
+
7395
+ normalize_match( &match );
7396
+
7397
+ uint32_t wildcards = OFPFW_DL_TYPE | OFPFW_NW_PROTO | OFPFW_NW_TOS | OFPFW_NW_SRC_ALL | OFPFW_NW_DST_ALL | OFPFW_TP_SRC | OFPFW_TP_DST;
7398
+
7399
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7400
+ assert_int_equal( match.in_port, 1 );
7401
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7402
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7403
+ assert_int_equal( match.dl_vlan, 1 );
7404
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7405
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7406
+ assert_int_equal( match.dl_type, 0 );
7407
+ assert_int_equal( match.nw_tos, 0 );
7408
+ assert_int_equal( match.nw_proto, 0 );
7409
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7410
+ assert_int_equal( ( int ) match.nw_src, 0 );
7411
+ assert_int_equal( ( int ) match.nw_dst, 0 );
7412
+ assert_int_equal( ( int ) match.tp_src, 0 );
7413
+ assert_int_equal( ( int ) match.tp_dst, 0 );
7414
+ }
7415
+
7416
+
7417
+ static void
7418
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_PROTO() {
7419
+ struct ofp_match match;
7420
+ setup_tcp_match( &match );
7421
+ match.wildcards = OFPFW_NW_PROTO;
7422
+
7423
+ normalize_match( &match );
7424
+
7425
+ uint32_t wildcards = OFPFW_NW_PROTO;
7426
+
7427
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7428
+ assert_int_equal( match.in_port, 1 );
7429
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7430
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7431
+ assert_int_equal( match.dl_vlan, 1 );
7432
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7433
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7434
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7435
+ assert_int_equal( match.nw_tos, 0xfc );
7436
+ assert_int_equal( match.nw_proto, 0 );
7437
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7438
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7439
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7440
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7441
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7442
+ }
7443
+
7444
+
7445
+ static void
7446
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_TP_SRC() {
7447
+ struct ofp_match match;
7448
+ setup_tcp_match( &match );
7449
+ match.wildcards = OFPFW_TP_SRC;
7450
+
7451
+ normalize_match( &match );
7452
+
7453
+ uint32_t wildcards = OFPFW_TP_SRC;
7454
+
7455
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7456
+ assert_int_equal( match.in_port, 1 );
7457
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7458
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7459
+ assert_int_equal( match.dl_vlan, 1 );
7460
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7461
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7462
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7463
+ assert_int_equal( match.nw_tos, 0xfc );
7464
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7465
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7466
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7467
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7468
+ assert_int_equal( ( int ) match.tp_src, 0 );
7469
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7470
+ }
7471
+
7472
+
7473
+ static void
7474
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_TP_DST() {
7475
+ struct ofp_match match;
7476
+ setup_tcp_match( &match );
7477
+ match.wildcards = OFPFW_TP_DST;
7478
+
7479
+ normalize_match( &match );
7480
+
7481
+ uint32_t wildcards = OFPFW_TP_DST;
7482
+
7483
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7484
+ assert_int_equal( match.in_port, 1 );
7485
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7486
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7487
+ assert_int_equal( match.dl_vlan, 1 );
7488
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7489
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7490
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7491
+ assert_int_equal( match.nw_tos, 0xfc );
7492
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7493
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7494
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7495
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7496
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7497
+ assert_int_equal( ( int ) match.tp_dst, 0 );
7498
+ }
7499
+
7500
+
7501
+ static void
7502
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_SRC_ALL() {
7503
+ struct ofp_match match;
7504
+ setup_tcp_match( &match );
7505
+ match.wildcards = OFPFW_NW_SRC_ALL;
7506
+
7507
+ normalize_match( &match );
7508
+
7509
+ uint32_t wildcards = OFPFW_NW_SRC_ALL;
7510
+
7511
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7512
+ assert_int_equal( match.in_port, 1 );
7513
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7514
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7515
+ assert_int_equal( match.dl_vlan, 1 );
7516
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7517
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7518
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7519
+ assert_int_equal( match.nw_tos, 0xfc );
7520
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7521
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7522
+ assert_int_equal( ( int ) match.nw_src, 0 );
7523
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7524
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7525
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7526
+ }
7527
+
7528
+
7529
+ static void
7530
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_DST_ALL() {
7531
+ struct ofp_match match;
7532
+ setup_tcp_match( &match );
7533
+ match.wildcards = OFPFW_NW_DST_ALL;
7534
+
7535
+ normalize_match( &match );
7536
+
7537
+ uint32_t wildcards = OFPFW_NW_DST_ALL;
7538
+
7539
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7540
+ assert_int_equal( match.in_port, 1 );
7541
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7542
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7543
+ assert_int_equal( match.dl_vlan, 1 );
7544
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7545
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7546
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7547
+ assert_int_equal( match.nw_tos, 0xfc );
7548
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7549
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7550
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7551
+ assert_int_equal( ( int ) match.nw_dst, 0 );
7552
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7553
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7554
+ }
7555
+
7556
+
7557
+ static void
7558
+ test_normalize_match_succeeds_if_src_mask_len_is_24() {
7559
+ struct ofp_match match;
7560
+ setup_tcp_match( &match );
7561
+ match.wildcards = 24 << OFPFW_NW_SRC_SHIFT;
7562
+
7563
+ normalize_match( &match );
7564
+
7565
+ uint32_t wildcards = 24 << OFPFW_NW_SRC_SHIFT;
7566
+
7567
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7568
+ assert_int_equal( match.in_port, 1 );
7569
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7570
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7571
+ assert_int_equal( match.dl_vlan, 1 );
7572
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7573
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7574
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7575
+ assert_int_equal( match.nw_tos, 0xfc );
7576
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7577
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7578
+ assert_int_equal( ( int ) match.nw_src, 0x01000000 );
7579
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7580
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7581
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7582
+ }
7583
+
7584
+
7585
+ static void
7586
+ test_normalize_match_succeeds_if_dst_mask_len_is_24() {
7587
+ struct ofp_match match;
7588
+ setup_tcp_match( &match );
7589
+ match.wildcards = 24 << OFPFW_NW_DST_SHIFT;
7590
+
7591
+ normalize_match( &match );
7592
+
7593
+ uint32_t wildcards = 24 << OFPFW_NW_DST_SHIFT;
7594
+
7595
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7596
+ assert_int_equal( match.in_port, 1 );
7597
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7598
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7599
+ assert_int_equal( match.dl_vlan, 1 );
7600
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7601
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7602
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7603
+ assert_int_equal( match.nw_tos, 0xfc );
7604
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7605
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7606
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7607
+ assert_int_equal( ( int ) match.nw_dst, 0x05000000 );
7608
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7609
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7610
+ }
7611
+
7612
+
7613
+ static void
7614
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_VLAN_PCP() {
7615
+ struct ofp_match match;
7616
+ setup_tcp_match( &match );
7617
+ match.wildcards = OFPFW_DL_VLAN_PCP;
7618
+
7619
+ normalize_match( &match );
7620
+
7621
+ uint32_t wildcards = OFPFW_DL_VLAN_PCP;
7622
+
7623
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7624
+ assert_int_equal( match.in_port, 1 );
7625
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7626
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7627
+ assert_int_equal( match.dl_vlan, 1 );
7628
+ assert_int_equal( match.dl_vlan_pcp, 0 );
7629
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7630
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7631
+ assert_int_equal( match.nw_tos, 0xfc );
7632
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7633
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7634
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7635
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7636
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7637
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7638
+ }
7639
+
7640
+
7641
+ static void
7642
+ test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_TOS() {
7643
+ struct ofp_match match;
7644
+ setup_tcp_match( &match );
7645
+ match.wildcards = OFPFW_NW_TOS;
7646
+
7647
+ normalize_match( &match );
7648
+
7649
+ uint32_t wildcards = OFPFW_NW_TOS;
7650
+
7651
+ assert_int_equal( ( int ) match.wildcards, wildcards );
7652
+ assert_int_equal( match.in_port, 1 );
7653
+ assert_memory_equal( match.dl_src, macsa, ETH_ADDRLEN );
7654
+ assert_memory_equal( match.dl_dst, macda, ETH_ADDRLEN );
7655
+ assert_int_equal( match.dl_vlan, 1 );
7656
+ assert_int_equal( match.dl_vlan_pcp, 0x7 );
7657
+ assert_memory_equal( match.pad1, all_zero_pad1, sizeof( match.pad1 ) );
7658
+ assert_int_equal( match.dl_type, ETH_ETHTYPE_IPV4 );
7659
+ assert_int_equal( match.nw_tos, 0 );
7660
+ assert_int_equal( match.nw_proto, IPPROTO_TCP );
7661
+ assert_memory_equal( match.pad2, all_zero_pad2, sizeof( match.pad2 ) );
7662
+ assert_int_equal( ( int ) match.nw_src, 0x01020304 );
7663
+ assert_int_equal( ( int ) match.nw_dst, 0x05060708 );
7664
+ assert_int_equal( ( int ) match.tp_src, 0xa );
7665
+ assert_int_equal( ( int ) match.tp_dst, 0xb );
7666
+ }
7667
+
7668
+
7669
+ static void
7670
+ test_normalize_match_fails_if_match_is_NULL() {
7671
+ expect_assert_failure( normalize_match( NULL ) );
7672
+ }
7673
+
7674
+
7001
7675
  /********************************************************************************
7002
7676
  * Run tests.
7003
7677
  ********************************************************************************/
@@ -7318,8 +7992,31 @@ main() {
7318
7992
  unit_test_setup_teardown( test_set_match_from_packet_succeeds_if_datatype_is_ieee8023_netbios_and_wildcards_is_zero, init, teardown ),
7319
7993
  unit_test_setup_teardown( test_set_match_from_packet_succeeds_if_datatype_is_ieee8023_not_llc_tag_and_wildcards_is_zero, init, teardown ),
7320
7994
  unit_test_setup_teardown( test_set_match_from_packet_succeeds_if_datatype_is_ieee8023_not_llc_and_wildcards_is_zero, init, teardown ),
7995
+ unit_test_setup_teardown( test_set_match_from_packet_fails_if_match_is_NULL, init, teardown ),
7321
7996
  unit_test_setup_teardown( test_set_match_from_packet_fails_if_packet_data_is_NULL, init, teardown ),
7322
7997
  unit_test_setup_teardown( test_set_match_from_packet_fails_if_packet_is_not_parsed_yet, init, teardown ),
7998
+
7999
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_datatype_is_arp_and_wildcards_is_zero, init, teardown ),
8000
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_protocol_is_icmp_and_wildcards_is_zero, init, teardown ),
8001
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_protocol_is_tcp_and_wildcards_is_zero, init, teardown ),
8002
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_protocol_is_udp_and_wildcards_is_zero, init, teardown ),
8003
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_packet_is_invalid_and_wildcards_is_zero, init, teardown ),
8004
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_ALL, init, teardown ),
8005
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_IN_PORT, init, teardown ),
8006
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_VLAN, init, teardown ),
8007
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_SRC, init, teardown ),
8008
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_DST, init, teardown ),
8009
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_TYPE, init, teardown ),
8010
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_PROTO, init, teardown ),
8011
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_TP_SRC, init, teardown ),
8012
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_TP_DST, init, teardown ),
8013
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_SRC_ALL, init, teardown ),
8014
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_DST_ALL, init, teardown ),
8015
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_src_mask_len_is_24, init, teardown ),
8016
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_dst_mask_len_is_24, init, teardown ),
8017
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_DL_VLAN_PCP, init, teardown ),
8018
+ unit_test_setup_teardown( test_normalize_match_succeeds_if_wildcards_is_OFPFW_NW_TOS, init, teardown ),
8019
+ unit_test_setup_teardown( test_normalize_match_fails_if_match_is_NULL, init, teardown ),
7323
8020
  };
7324
8021
  return run_tests( tests );
7325
8022
  }