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
data/src/lib/messenger.h CHANGED
@@ -75,7 +75,7 @@ enum {
75
75
  MESSENGER_DUMP_SEND_REFUSED,
76
76
  MESSENGER_DUMP_SEND_OVERFLOW,
77
77
  MESSENGER_DUMP_SEND_CLOSED,
78
- MESSENGER_DUMP_LOGGER,
78
+ MESSENGER_DUMP_LOGGER,
79
79
  MESSENGER_DUMP_PCAP,
80
80
  MESSENGER_DUMP_SYSLOG,
81
81
  MESSENGER_DUMP_TEXT,
@@ -115,13 +115,14 @@ extern bool ( *add_message_received_callback )( const char *service_name, const
115
115
  extern bool ( *rename_message_received_callback )( const char *old_service_name, const char *new_service_name );
116
116
  extern bool ( *delete_message_received_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len ) );
117
117
  extern bool ( *add_message_requested_callback )( const char *service_name, void ( *callback )( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) );
118
+ extern bool ( *rename_message_requested_callback )( const char *old_service_name, const char *new_service_name );
118
119
  extern bool ( *delete_message_requested_callback )( const char *service_name, void ( *callback )( const messenger_context_handle *handle, uint16_t tag, void *data, size_t len ) );
119
120
  extern bool ( *add_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
120
121
  extern bool ( *delete_message_replied_callback )( const char *service_name, void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
121
122
  extern bool ( *send_message )( const char *service_name, const uint16_t tag, const void *data, size_t len );
122
123
  extern bool ( *send_request_message )( const char *to_service_name, const char *from_service_name, const uint16_t tag, const void *data, size_t len, void *user_data );
123
124
  extern bool ( *send_reply_message )( const messenger_context_handle *handle, const uint16_t tag, const void *data, size_t len );
124
- extern bool ( *clear_send_queue ) ( const char *service_name );
125
+ extern bool ( *clear_send_queue )( const char *service_name );
125
126
 
126
127
  bool init_messenger( const char *working_directory );
127
128
  bool finalize_messenger( void );
@@ -538,8 +538,8 @@ handle_error( const uint64_t datapath_id, buffer *data ) {
538
538
  body = duplicate_buffer( data );
539
539
  remove_front_buffer( body, offsetof( struct ofp_error_msg, data ) );
540
540
 
541
- debug( "An error message is received from %#lx "
542
- "( transaction_id = %#x, type = %u, code = %u, data length = %u ).",
541
+ debug( "An error message is received from %#" PRIx64 " "
542
+ "( transaction_id = %#x, type = %#x, code = %#x, data length = %zu ).",
543
543
  datapath_id, transaction_id, type, code, body->length );
544
544
 
545
545
  if ( event_handlers.error_callback == NULL ) {
@@ -718,7 +718,7 @@ handle_features_reply( const uint64_t datapath_id, buffer *data ) {
718
718
 
719
719
  if ( event_handlers.features_reply_callback == NULL ) {
720
720
  debug( "Callback function for features reply events is not set." );
721
- if( phy_ports_head != NULL ) {
721
+ if ( phy_ports_head != NULL ) {
722
722
  element = phy_ports_head;
723
723
  while ( element != NULL ) {
724
724
  xfree( element->data );
@@ -811,7 +811,7 @@ handle_packet_in( const uint64_t datapath_id, buffer *data ) {
811
811
 
812
812
  debug(
813
813
  "A packet_in message is received from %#" PRIx64
814
- " (transaction_id = %#x, buffer_id = %#x, total_len = %u, in_port = %u, reason = %#x, body length = %u).",
814
+ " ( transaction_id = %#x, buffer_id = %#x, total_len = %u, in_port = %u, reason = %#x, body length = %u ).",
815
815
  datapath_id,
816
816
  transaction_id,
817
817
  buffer_id,
@@ -843,7 +843,7 @@ handle_packet_in( const uint64_t datapath_id, buffer *data ) {
843
843
  }
844
844
 
845
845
  assert( event_handlers.packet_in_callback != NULL );
846
- debug( "Calling packet_in handler (callback = %p, user_data = %p).",
846
+ debug( "Calling packet_in handler ( callback = %p, user_data = %p ).",
847
847
  event_handlers.packet_in_callback,
848
848
  event_handlers.packet_in_user_data
849
849
  );
@@ -926,7 +926,7 @@ handle_flow_removed( const uint64_t datapath_id, buffer *data ) {
926
926
  }
927
927
 
928
928
  debug(
929
- "Calling flow removed handler (callback = %p, user_data = %p).",
929
+ "Calling flow removed handler ( callback = %p, user_data = %p ).",
930
930
  event_handlers.flow_removed_callback,
931
931
  event_handlers.flow_removed_user_data
932
932
  );
@@ -1162,7 +1162,7 @@ handle_stats_reply( const uint64_t datapath_id, buffer *data ) {
1162
1162
  if ( body != NULL ) {
1163
1163
  free_buffer( body );
1164
1164
  }
1165
- critical( "Unhandled stats type ( type = %u ).", type );
1165
+ critical( "Unhandled stats type ( type = %#x ).", type );
1166
1166
  assert( 0 );
1167
1167
  break;
1168
1168
  }
@@ -1368,7 +1368,7 @@ handle_switch_ready( uint64_t datapath_id ) {
1368
1368
  static void
1369
1369
  handle_messenger_openflow_disconnected( uint64_t datapath_id ) {
1370
1370
  if ( event_handlers.switch_disconnected_callback != NULL ) {
1371
- debug( "Calling switch disconnected handler (callback = %p, user_data = %p).",
1371
+ debug( "Calling switch disconnected handler ( callback = %p, user_data = %p ).",
1372
1372
  event_handlers.switch_disconnected_callback, event_handlers.switch_disconnected_user_data );
1373
1373
  event_handlers.switch_disconnected_callback( datapath_id, event_handlers.switch_disconnected_user_data );
1374
1374
  }
@@ -1384,7 +1384,7 @@ handle_switch_events( uint16_t type, void *data, size_t length ) {
1384
1384
  assert( data != NULL );
1385
1385
  assert( length == sizeof( openflow_service_header_t ) );
1386
1386
 
1387
- debug( "Received a switch event (type = %u) from remote.", type );
1387
+ debug( "Received a switch event ( type = %#x ) from remote.", type );
1388
1388
 
1389
1389
  openflow_service_header_t *message = data;
1390
1390
  uint64_t datapath_id = ntohll( message->datapath_id );
@@ -1401,7 +1401,7 @@ handle_switch_events( uint16_t type, void *data, size_t length ) {
1401
1401
  handle_messenger_openflow_disconnected( datapath_id );
1402
1402
  break;
1403
1403
  default:
1404
- error( "Unhandled switch event (type = %u).", type );
1404
+ error( "Unhandled switch event ( type = %#x ).", type );
1405
1405
  break;
1406
1406
  }
1407
1407
 
@@ -1543,7 +1543,7 @@ handle_openflow_message( void *data, size_t length ) {
1543
1543
  ret = validate_openflow_message( buffer );
1544
1544
 
1545
1545
  if ( ret < 0 ) {
1546
- error( "Failed to validate an OpenFlow message ( code = %d, length = %u ).", ret, length );
1546
+ error( "Failed to validate an OpenFlow message ( code = %d, length = %zu ).", ret, length );
1547
1547
  free_buffer( buffer );
1548
1548
 
1549
1549
  return;
@@ -1586,7 +1586,7 @@ handle_openflow_message( void *data, size_t length ) {
1586
1586
  handle_queue_get_config_reply( datapath_id, buffer );
1587
1587
  break;
1588
1588
  default:
1589
- error( "Unhandled OpenFlow message ( type = %u ).", header->type );
1589
+ error( "Unhandled OpenFlow message ( type = %#x ).", header->type );
1590
1590
  break;
1591
1591
  }
1592
1592
 
@@ -1601,7 +1601,7 @@ handle_message( uint16_t type, void *data, size_t length ) {
1601
1601
  assert( data != NULL );
1602
1602
  assert( length >= sizeof( openflow_service_header_t ) );
1603
1603
 
1604
- debug( "A message is received from remote ( type = %u ).", type );
1604
+ debug( "A message is received from remote ( type = %#x ).", type );
1605
1605
 
1606
1606
  switch ( type ) {
1607
1607
  case MESSENGER_OPENFLOW_MESSAGE:
@@ -1612,7 +1612,7 @@ handle_message( uint16_t type, void *data, size_t length ) {
1612
1612
  case MESSENGER_OPENFLOW_DISCONNECTED:
1613
1613
  return handle_switch_events( type, data, length );
1614
1614
  default:
1615
- error( "Unhandled message ( type = %u ).", type );
1615
+ error( "Unhandled message ( type = %#x ).", type );
1616
1616
  update_switch_event_stats( type, OPENFLOW_MESSAGE_RECEIVE, true );
1617
1617
  break;
1618
1618
  }
@@ -1647,10 +1647,10 @@ handle_list_switches_reply( uint16_t message_type, void *data, size_t length, vo
1647
1647
  UNUSED( message_type );
1648
1648
  assert( data != NULL );
1649
1649
 
1650
- uint64_t *dpid = ( uint64_t *) data;
1650
+ uint64_t *dpid = ( uint64_t * ) data;
1651
1651
  size_t num_switch = length / sizeof( uint64_t );
1652
1652
 
1653
- debug( "A list switches reply message is received ( number of switches = %u ).",
1653
+ debug( "A list switches reply message is received ( number of switches = %zu ).",
1654
1654
  num_switch );
1655
1655
 
1656
1656
  if ( event_handlers.list_switches_reply_callback == NULL ) {
@@ -1663,7 +1663,7 @@ handle_list_switches_reply( uint16_t message_type, void *data, size_t length, vo
1663
1663
 
1664
1664
  unsigned int i;
1665
1665
  for ( i = 0; i < num_switch; ++i ) {
1666
- uint64_t *datapath_id = ( uint64_t *) xmalloc( sizeof( uint64_t ) );
1666
+ uint64_t *datapath_id = ( uint64_t * ) xmalloc( sizeof( uint64_t ) );
1667
1667
  *datapath_id = ntohll( dpid[ i ] );
1668
1668
  insert_dpid( &switches, datapath_id );
1669
1669
  }
@@ -57,10 +57,12 @@ extern void mock_debug( const char *format, ... );
57
57
  #endif // UNIT_TESTING
58
58
 
59
59
 
60
- #define VLAN_VID_MASK 0x0fff // 12 bits
61
- #define VLAN_PCP_MASK 0x07 // 3 bits
62
- #define NW_TOS_MASK 0xfc // upper 6 bits
63
- #define ARP_OP_MASK 0x00ff // 8 bits
60
+ #define VLAN_VID_MASK 0x0fff // 12 bits
61
+ #define VLAN_PCP_MASK 0x07 // 3 bits
62
+ #define NW_TOS_MASK 0xfc // upper 6 bits
63
+ #define ARP_OP_MASK 0x00ff // 8 bits
64
+ #define ICMP_TYPE_MASK 0x00ff // 8 bits
65
+ #define ICMP_CODE_MASK 0x00ff // 8 bits
64
66
 
65
67
  #define PORT_CONFIG ( OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV \
66
68
  | OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD \
@@ -104,7 +106,7 @@ init_openflow_message( void ) {
104
106
 
105
107
  static buffer *
106
108
  create_header( const uint32_t transaction_id, const uint8_t type, const uint16_t length ) {
107
- debug( "Creating an OpenFlow header (version = %#x, type = %#x, length = %u, xid = %#x).",
109
+ debug( "Creating an OpenFlow header ( version = %#x, type = %#x, length = %u, xid = %#x ).",
108
110
  OFP_VERSION, type, length, transaction_id );
109
111
 
110
112
  assert( length >= sizeof( struct ofp_header ) );
@@ -291,7 +293,7 @@ create_features_reply( const uint32_t transaction_id, const uint64_t datapath_id
291
293
 
292
294
  if ( n_ports ) {
293
295
  phy_port = ( struct ofp_phy_port * ) ( ( char * ) buffer->data
294
- + offsetof( struct ofp_switch_features, ports) );
296
+ + offsetof( struct ofp_switch_features, ports ) );
295
297
  port = p;
296
298
  while ( port != NULL ) {
297
299
  phy_port_to_string( port->data, port_str, sizeof( port_str ) );
@@ -433,7 +435,7 @@ create_flow_removed( const uint32_t transaction_id, const struct ofp_match match
433
435
 
434
436
  buffer *
435
437
  create_port_status( const uint32_t transaction_id, const uint8_t reason,
436
- const struct ofp_phy_port desc) {
438
+ const struct ofp_phy_port desc ) {
437
439
  char desc_str[ 1024 ];
438
440
  buffer *buffer;
439
441
  struct ofp_phy_port d = desc;
@@ -480,10 +482,10 @@ get_actions_length( const openflow_actions *actions ) {
480
482
  action = action->next;
481
483
  }
482
484
 
483
- debug( "Total length of actions = %u.", actions_length );
485
+ debug( "Total length of actions = %d.", actions_length );
484
486
 
485
487
  if ( actions_length > UINT16_MAX ) {
486
- critical( "Too many actions ( # of actions = %d, actions length = %u ).",
488
+ critical( "Too many actions ( # of actions = %d, actions length = %d ).",
487
489
  actions->n_actions, actions_length );
488
490
  assert( 0 );
489
491
  }
@@ -585,7 +587,7 @@ create_flow_mod( const uint32_t transaction_id, const struct ofp_match match,
585
587
  "buffer_id = %#x, out_port = %u, flags = %#x ).",
586
588
  transaction_id, match_str, cookie, command,
587
589
  idle_timeout, hard_timeout, priority,
588
- buffer_id, out_port, flags );
590
+ buffer_id, out_port, flags );
589
591
  }
590
592
 
591
593
  if ( actions != NULL ) {
@@ -922,7 +924,7 @@ create_flow_stats_reply( const uint32_t transaction_id, const uint16_t flags,
922
924
  flow = flow->next;
923
925
  }
924
926
 
925
- debug( "# of flows = %u.", n_flows );
927
+ debug( "# of flows = %d.", n_flows );
926
928
 
927
929
  length = ( uint16_t ) ( offsetof( struct ofp_stats_reply, body ) + length );
928
930
 
@@ -1635,7 +1637,7 @@ append_action_vendor( openflow_actions *actions, const uint32_t vendor, const bu
1635
1637
  body_length = ( uint16_t ) body->length;
1636
1638
  }
1637
1639
 
1638
- debug( "Appending a vendor action ( vendor = %#" PRIx64 ", body length = %u ).", vendor, body_length );
1640
+ debug( "Appending a vendor action ( vendor = %#" PRIx32 ", body length = %u ).", vendor, body_length );
1639
1641
 
1640
1642
  assert( actions != NULL );
1641
1643
 
@@ -1645,6 +1647,10 @@ append_action_vendor( openflow_actions *actions, const uint32_t vendor, const bu
1645
1647
  action_vendor->len = ( uint16_t ) ( sizeof( struct ofp_action_vendor_header ) + body_length );
1646
1648
  action_vendor->vendor = vendor;
1647
1649
 
1650
+ if ( body_length > 0 ) {
1651
+ memcpy( ( char * ) action_vendor + sizeof( struct ofp_action_vendor_header ), body->data, body_length );
1652
+ }
1653
+
1648
1654
  ret = append_to_tail( &actions->list, ( void * ) action_vendor );
1649
1655
  if ( ret ) {
1650
1656
  actions->n_actions++;
@@ -3447,18 +3453,14 @@ validate_action_enqueue( const struct ofp_action_enqueue *action ) {
3447
3453
 
3448
3454
  int
3449
3455
  validate_action_vendor( const struct ofp_action_vendor_header *action ) {
3450
- struct ofp_action_vendor_header vendor;
3451
-
3452
- ntoh_action_vendor( &vendor, action );
3453
-
3454
- if ( vendor.type != OFPAT_VENDOR ) {
3456
+ if ( ntohs( action->type ) != OFPAT_VENDOR ) {
3455
3457
  return ERROR_INVALID_ACTION_TYPE;
3456
3458
  }
3457
- if ( vendor.len < sizeof( struct ofp_action_vendor_header ) ) {
3459
+ if ( ntohs( action->len ) < sizeof( struct ofp_action_vendor_header ) ) {
3458
3460
  return ERROR_TOO_SHORT_ACTION_VENDOR;
3459
3461
  }
3460
3462
 
3461
- // vendor.vendor
3463
+ // action->vendor
3462
3464
 
3463
3465
  return 0;
3464
3466
  }
@@ -3929,6 +3931,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
3929
3931
  const uint32_t wildcards, const buffer *packet ) {
3930
3932
  // Note that wildcards must be filled before calling this function.
3931
3933
 
3934
+ assert( match != NULL );
3932
3935
  assert( packet != NULL );
3933
3936
  assert( packet->user_data != NULL );
3934
3937
 
@@ -3948,8 +3951,8 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
3948
3951
  if ( packet_type_eth_vtag( packet ) ) {
3949
3952
  match->dl_vlan = ( ( packet_info * ) packet->user_data )->vlan_vid;
3950
3953
  if ( ( match->dl_vlan & ~VLAN_VID_MASK ) != 0 ) {
3951
- warn( "Invalid vlan id ( change %u to %u )", match->dl_vlan, match->dl_vlan & VLAN_VID_MASK );
3952
- match->dl_vlan = ( uint16_t ) ( match->dl_vlan & VLAN_VID_MASK );
3954
+ warn( "Invalid vlan id ( change %#x to %#x )", match->dl_vlan, match->dl_vlan & VLAN_VID_MASK );
3955
+ match->dl_vlan = ( uint16_t ) ( match->dl_vlan & VLAN_VID_MASK );
3953
3956
  }
3954
3957
  }
3955
3958
  else {
@@ -3961,7 +3964,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
3961
3964
  match->dl_vlan_pcp = ( ( packet_info * ) packet->user_data )->vlan_prio;
3962
3965
  if ( ( match->dl_vlan_pcp & ~VLAN_PCP_MASK ) != 0 ) {
3963
3966
  warn( "Invalid vlan pcp ( change %u to %u )", match->dl_vlan_pcp, match->dl_vlan_pcp & VLAN_PCP_MASK );
3964
- match->dl_vlan_pcp = ( uint8_t ) ( match->dl_vlan_pcp & VLAN_PCP_MASK );
3967
+ match->dl_vlan_pcp = ( uint8_t ) ( match->dl_vlan_pcp & VLAN_PCP_MASK );
3965
3968
  }
3966
3969
  }
3967
3970
  }
@@ -3972,7 +3975,7 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
3972
3975
  if ( !( wildcards & OFPFW_NW_TOS ) ) {
3973
3976
  match->nw_tos = ( ( packet_info * ) packet->user_data )->ipv4_tos;
3974
3977
  if ( ( match->nw_tos & ~NW_TOS_MASK ) != 0 ) {
3975
- warn( "Invalid ipv4 tos ( change %u to %u )", match->nw_tos, match->nw_tos & NW_TOS_MASK );
3978
+ warn( "Invalid ipv4 tos ( change %#x to %#x )", match->nw_tos, match->nw_tos & NW_TOS_MASK );
3976
3979
  match->nw_tos = ( uint8_t ) ( match->nw_tos & NW_TOS_MASK );
3977
3980
  }
3978
3981
  }
@@ -4034,6 +4037,155 @@ set_match_from_packet( struct ofp_match *match, const uint16_t in_port,
4034
4037
  }
4035
4038
 
4036
4039
 
4040
+ void
4041
+ normalize_match( struct ofp_match *match ) {
4042
+
4043
+ assert( match != NULL );
4044
+
4045
+ char match_string[ 1024 ];
4046
+ match_to_string( match, match_string, sizeof( match_string ) );
4047
+ debug( "Normalizing match structure ( original match = [%s] ).", match_string );
4048
+
4049
+ memset( match->pad1, 0, sizeof( match->pad1 ) );
4050
+ memset( match->pad2, 0, sizeof( match->pad2 ) );
4051
+
4052
+ match->wildcards &= OFPFW_ALL;
4053
+
4054
+ if ( match->wildcards & OFPFW_IN_PORT ) {
4055
+ match->in_port = 0;
4056
+ }
4057
+ if ( match->wildcards & OFPFW_DL_VLAN ) {
4058
+ match->dl_vlan = 0;
4059
+ }
4060
+ else {
4061
+ if ( match->dl_vlan == UINT16_MAX ) {
4062
+ match->wildcards |= ( uint32_t ) OFPFW_DL_VLAN_PCP;
4063
+ match->dl_vlan_pcp = 0;
4064
+ }
4065
+ else {
4066
+ match->dl_vlan &= VLAN_VID_MASK;
4067
+ }
4068
+ }
4069
+ if ( match->wildcards & OFPFW_DL_SRC ) {
4070
+ memset( match->dl_src, 0, sizeof( match->dl_src ) );
4071
+ }
4072
+ if ( match->wildcards & OFPFW_DL_DST ) {
4073
+ memset( match->dl_dst, 0, sizeof( match->dl_dst ) );
4074
+ }
4075
+ if ( match->wildcards & OFPFW_DL_TYPE ) {
4076
+ match->dl_type = 0;
4077
+ match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
4078
+ match->wildcards |= ( uint32_t ) OFPFW_NW_PROTO;
4079
+ match->wildcards |= ( uint32_t ) OFPFW_NW_SRC_MASK;
4080
+ match->wildcards |= ( uint32_t ) OFPFW_NW_DST_MASK;
4081
+ match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
4082
+ match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
4083
+ match->nw_tos = 0;
4084
+ match->nw_proto = 0;
4085
+ match->nw_src = 0;
4086
+ match->nw_dst = 0;
4087
+ match->tp_src = 0;
4088
+ match->tp_dst = 0;
4089
+ }
4090
+ else {
4091
+ if ( match->dl_type == ETH_ETHTYPE_ARP ) {
4092
+ match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
4093
+ match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
4094
+ match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
4095
+ match->nw_tos = 0;
4096
+ match->tp_src = 0;
4097
+ match->tp_dst = 0;
4098
+ }
4099
+ else if ( match->dl_type != ETH_ETHTYPE_IPV4 ) {
4100
+ match->wildcards |= ( uint32_t ) OFPFW_NW_TOS;
4101
+ match->wildcards |= ( uint32_t ) OFPFW_NW_PROTO;
4102
+ match->wildcards |= ( uint32_t ) OFPFW_NW_SRC_MASK;
4103
+ match->wildcards |= ( uint32_t ) OFPFW_NW_DST_MASK;
4104
+ match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
4105
+ match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
4106
+ match->nw_tos = 0;
4107
+ match->nw_proto = 0;
4108
+ match->nw_src = 0;
4109
+ match->nw_dst = 0;
4110
+ match->tp_src = 0;
4111
+ match->tp_dst = 0;
4112
+ }
4113
+ }
4114
+ if ( match->wildcards & OFPFW_NW_PROTO ) {
4115
+ match->nw_proto = 0;
4116
+ if ( match->dl_type != ETH_ETHTYPE_IPV4 ) {
4117
+ match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
4118
+ match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
4119
+ match->tp_src = 0;
4120
+ match->tp_dst = 0;
4121
+ }
4122
+ }
4123
+ else {
4124
+ if ( match->dl_type == ETH_ETHTYPE_ARP ) {
4125
+ match->nw_proto &= ARP_OP_MASK;
4126
+ }
4127
+ if ( match->dl_type == ETH_ETHTYPE_IPV4 &&
4128
+ match->nw_proto != IPPROTO_TCP && match->nw_proto != IPPROTO_UDP && match->nw_proto != IPPROTO_ICMP ) {
4129
+ match->wildcards |= ( uint32_t ) OFPFW_TP_SRC;
4130
+ match->wildcards |= ( uint32_t ) OFPFW_TP_DST;
4131
+ match->tp_src = 0;
4132
+ match->tp_dst = 0;
4133
+ }
4134
+ }
4135
+
4136
+ unsigned int nw_src_mask_len = ( match->wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
4137
+ if ( nw_src_mask_len >= 32 ) {
4138
+ match->wildcards &= ( uint32_t ) ~OFPFW_NW_SRC_MASK;
4139
+ match->wildcards |= OFPFW_NW_SRC_ALL;
4140
+ match->nw_src = 0;
4141
+ }
4142
+ else {
4143
+ match->nw_src &= ( 0xffffffff << nw_src_mask_len );
4144
+ }
4145
+ unsigned int nw_dst_mask_len = ( match->wildcards & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT;
4146
+ if ( nw_dst_mask_len >= 32 ) {
4147
+ match->wildcards &= ( uint32_t ) ~OFPFW_NW_DST_MASK;
4148
+ match->wildcards |= OFPFW_NW_DST_ALL;
4149
+ match->nw_dst = 0;
4150
+ }
4151
+ else {
4152
+ match->nw_dst &= ( 0xffffffff << nw_dst_mask_len );
4153
+ }
4154
+ if ( match->wildcards & OFPFW_TP_SRC ) {
4155
+ match->tp_src = 0;
4156
+ }
4157
+ else {
4158
+ if ( match->nw_proto == IPPROTO_ICMP ) {
4159
+ match->tp_src &= ICMP_TYPE_MASK;
4160
+ }
4161
+ }
4162
+ if ( match->wildcards & OFPFW_TP_DST ) {
4163
+ match->tp_dst = 0;
4164
+ }
4165
+ else {
4166
+ if ( match->nw_proto == IPPROTO_ICMP ) {
4167
+ match->tp_dst &= ICMP_CODE_MASK;
4168
+ }
4169
+ }
4170
+
4171
+ if ( match->wildcards & OFPFW_DL_VLAN_PCP ) {
4172
+ match->dl_vlan_pcp = 0;
4173
+ }
4174
+ else {
4175
+ match->dl_vlan_pcp &= VLAN_PCP_MASK;
4176
+ }
4177
+ if ( match->wildcards & OFPFW_NW_TOS ) {
4178
+ match->nw_tos = 0;
4179
+ }
4180
+ else {
4181
+ match->nw_tos &= NW_TOS_MASK;
4182
+ }
4183
+
4184
+ match_to_string( match, match_string, sizeof( match_string ) );
4185
+ debug( "Normalization completed ( updated match = [%s] ).", match_string );
4186
+ }
4187
+
4188
+
4037
4189
  /*
4038
4190
  * Local variables:
4039
4191
  * c-basic-offset: 2