trema 0.2.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. data/.gitmodules +3 -0
  2. data/.travis.yml +13 -0
  3. data/.yardopts +4 -0
  4. data/Gemfile +2 -3
  5. data/README.md +43 -97
  6. data/Rakefile +60 -4
  7. data/Rantfile +11 -10
  8. data/cruise.rb +4 -6
  9. data/features/example.packetin_filter_config.feature +10 -10
  10. data/features/example.switch_monitor.feature +14 -2
  11. data/features/step_definitions/kill_steps.rb +2 -2
  12. data/features/step_definitions/{off_steps.rb → killall_steps.rb} +2 -2
  13. data/features/step_definitions/misc_steps.rb +1 -1
  14. data/features/step_definitions/up_steps.rb +30 -0
  15. data/features/trema.feature +1 -0
  16. data/features/trema.run.feature +1 -0
  17. data/locale/README.ja.md +19 -0
  18. data/locale/ja/yard.po +3762 -0
  19. data/locale/yard.pot +3740 -0
  20. data/ruby/extconf.rb +4 -1
  21. data/ruby/trema/action-common.c +3 -17
  22. data/ruby/trema/action-common.h +3 -7
  23. data/ruby/trema/action.rb +33 -0
  24. data/ruby/trema/app.rb +1 -1
  25. data/ruby/trema/barrier-request.c +1 -0
  26. data/ruby/trema/command/run.rb +13 -9
  27. data/ruby/trema/command/usage.rb +1 -0
  28. data/ruby/trema/command/version.rb +1 -1
  29. data/ruby/trema/controller.c +133 -50
  30. data/ruby/trema/controller.rb +2 -2
  31. data/ruby/trema/desc-stats-reply.rb +77 -0
  32. data/ruby/trema/dsl/configuration.rb +3 -14
  33. data/ruby/trema/dsl/rswitch.rb +47 -0
  34. data/ruby/trema/dsl/runner.rb +4 -1
  35. data/ruby/trema/dsl/syntax.rb +11 -8
  36. data/ruby/trema/echo-reply.c +59 -45
  37. data/ruby/trema/echo-reply.h +1 -3
  38. data/ruby/trema/echo-request.c +49 -71
  39. data/ruby/trema/echo-request.h +0 -2
  40. data/ruby/trema/echo.c +99 -0
  41. data/ruby/trema/{action-enqueue.h → echo.h} +6 -7
  42. data/ruby/trema/enqueue.rb +87 -0
  43. data/ruby/trema/error.c +109 -104
  44. data/ruby/trema/error.h +0 -2
  45. data/ruby/trema/features-reply.c +89 -35
  46. data/ruby/trema/features-reply.h +0 -6
  47. data/ruby/trema/features-request.c +63 -37
  48. data/ruby/trema/features-request.h +0 -2
  49. data/ruby/trema/flow-mod.c +149 -0
  50. data/ruby/trema/{action-output.h → flow-mod.h} +6 -6
  51. data/ruby/trema/get-config-request.c +1 -0
  52. data/ruby/trema/hardware-switch.rb +88 -0
  53. data/ruby/trema/hello.c +55 -31
  54. data/ruby/trema/hello.h +0 -2
  55. data/ruby/trema/ip.rb +12 -2
  56. data/ruby/trema/logger.rb +29 -0
  57. data/ruby/trema/mac.rb +57 -36
  58. data/ruby/trema/match.c +7 -9
  59. data/ruby/trema/monkey-patch/integer/ranges.rb +0 -2
  60. data/ruby/trema/network-component.rb +1 -1
  61. data/ruby/trema/open-vswitch.rb +2 -2
  62. data/ruby/trema/openflow-switch.rb +3 -54
  63. data/ruby/trema/{packet_in.c → packet-in.c} +262 -175
  64. data/ruby/trema/{packet_in.h → packet-in.h} +0 -2
  65. data/ruby/trema/packet-queue.rb +4 -3
  66. data/ruby/trema/port-mod.c +8 -9
  67. data/ruby/trema/port-status-add.rb +60 -0
  68. data/ruby/trema/port-status-delete.rb +60 -0
  69. data/ruby/trema/port-status-modify.rb +60 -0
  70. data/ruby/trema/port-status.c +48 -15
  71. data/ruby/trema/port-status.h +6 -8
  72. data/ruby/trema/port.c +63 -8
  73. data/ruby/trema/queue-get-config-request.c +1 -0
  74. data/ruby/trema/ruby-switch.rb +62 -0
  75. data/ruby/trema/send-out-port.rb +97 -0
  76. data/ruby/trema/set-config.c +1 -0
  77. data/ruby/trema/set-eth-addr.rb +45 -0
  78. data/ruby/trema/set-eth-dst-addr.rb +54 -0
  79. data/ruby/trema/set-eth-src-addr.rb +54 -0
  80. data/ruby/trema/set-ip-addr.rb +47 -0
  81. data/ruby/trema/set-ip-dst-addr.rb +53 -0
  82. data/ruby/trema/set-ip-src-addr.rb +52 -0
  83. data/ruby/trema/set-ip-tos.rb +63 -0
  84. data/ruby/trema/set-transport-dst-port.rb +53 -0
  85. data/ruby/trema/set-transport-port.rb +52 -0
  86. data/ruby/trema/set-transport-src-port.rb +54 -0
  87. data/ruby/trema/set-vlan-priority.rb +65 -0
  88. data/ruby/trema/set-vlan-vid.rb +64 -0
  89. data/ruby/trema/shell/down.rb +1 -1
  90. data/ruby/trema/shell/link.rb +4 -4
  91. data/ruby/trema/shell/run.rb +8 -6
  92. data/ruby/trema/shell/up.rb +3 -3
  93. data/ruby/trema/stats-reply.c +27 -2
  94. data/ruby/trema/stats-request.c +64 -23
  95. data/ruby/trema/strip-vlan-header.rb +41 -0
  96. data/ruby/trema/switch.c +196 -0
  97. data/ruby/trema/{action-vendor.h → switch.h} +5 -7
  98. data/ruby/trema/switch.rb +28 -9
  99. data/ruby/trema/trema-ruby-utils.c +66 -0
  100. data/ruby/trema/{action-set-dl-src.h → trema-ruby-utils.h} +9 -11
  101. data/ruby/trema/trema.c +61 -61
  102. data/ruby/trema/vendor-action.rb +73 -0
  103. data/ruby/trema/vendor.c +121 -52
  104. data/ruby/trema/vendor.h +6 -10
  105. data/ruby/trema/version.rb +1 -1
  106. data/spec/spec_helper.rb +1 -1
  107. data/spec/support/action.rb +52 -0
  108. data/spec/support/mandatory-option.rb +56 -0
  109. data/spec/support/openflow-message.rb +91 -7
  110. data/spec/support/port-status.rb +38 -0
  111. data/spec/trema/controller_spec.rb +0 -26
  112. data/spec/trema/dsl/configuration_spec.rb +3 -3
  113. data/spec/trema/dsl/runner_spec.rb +12 -32
  114. data/spec/trema/dsl/syntax_spec.rb +2 -11
  115. data/spec/trema/echo-reply_spec.rb +49 -14
  116. data/spec/trema/echo-request_spec.rb +86 -34
  117. data/spec/trema/enqueue_spec.rb +76 -0
  118. data/spec/trema/error_spec.rb +43 -58
  119. data/spec/trema/features-reply_spec.rb +58 -24
  120. data/spec/trema/features-request_spec.rb +54 -28
  121. data/spec/trema/flow-mod_spec.rb +99 -0
  122. data/spec/trema/{openflow-switch_spec.rb → hardware-switch_spec.rb} +3 -3
  123. data/spec/trema/hello_spec.rb +28 -14
  124. data/spec/trema/ip_spec.rb +54 -0
  125. data/spec/trema/mac_spec.rb +49 -64
  126. data/spec/trema/match_spec.rb +1 -1
  127. data/spec/trema/open-vswitch_spec.rb +7 -7
  128. data/spec/trema/packet-in_spec.rb +73 -16
  129. data/spec/trema/port-status-add_spec.rb +32 -0
  130. data/spec/trema/port-status-delete_spec.rb +32 -0
  131. data/spec/trema/port-status-modify_spec.rb +71 -0
  132. data/spec/trema/port-status_spec.rb +5 -76
  133. data/spec/trema/{action-output_spec.rb → send-out-port_spec.rb} +20 -47
  134. data/spec/trema/set-eth-dst-addr_spec.rb +75 -0
  135. data/spec/trema/set-eth-src-addr_spec.rb +72 -0
  136. data/spec/trema/set-ip-dst-addr_spec.rb +58 -0
  137. data/spec/trema/set-ip-src-addr_spec.rb +58 -0
  138. data/spec/trema/set-ip-tos_spec.rb +65 -0
  139. data/spec/trema/set-transport-dst-port_spec.rb +65 -0
  140. data/spec/trema/set-transport-src-port_spec.rb +65 -0
  141. data/spec/trema/set-vlan-priority_spec.rb +65 -0
  142. data/spec/trema/set-vlan-vid_spec.rb +65 -0
  143. data/spec/trema/shell/vhost_spec.rb +4 -1
  144. data/spec/trema/shell/vswitch_spec.rb +11 -11
  145. data/spec/trema/stats-reply_spec.rb +59 -13
  146. data/spec/trema/stats-request_spec.rb +6 -0
  147. data/spec/trema/{action-strip-vlan_spec.rb → strip-vlan-header_spec.rb} +3 -17
  148. data/spec/trema/switch-daemon_spec.rb +39 -0
  149. data/spec/trema/vendor-action_spec.rb +81 -0
  150. data/spec/trema/vendor_spec.rb +76 -0
  151. data/spec/trema_spec.rb +56 -0
  152. data/src/examples/dumper/dumper.c +0 -8
  153. data/src/examples/dumper/dumper.rb +52 -52
  154. data/src/examples/hello_trema/hello_trema.c +0 -2
  155. data/src/examples/learning_switch/learning-switch.rb +3 -3
  156. data/src/examples/multi_learning_switch/multi-learning-switch.rb +3 -3
  157. data/src/examples/openflow_message/features-request.rb +3 -3
  158. data/src/examples/packetin_filter_config/utils.c +4 -4
  159. data/src/examples/repeater_hub/repeater-hub.rb +3 -3
  160. data/src/examples/switch_info/switch_info.rb +2 -2
  161. data/src/examples/switch_monitor/switch_monitor.c +1 -1
  162. data/src/examples/traffic_monitor/traffic-monitor.rb +3 -3
  163. data/src/lib/arp.h +4 -1
  164. data/src/lib/chibach.c +391 -0
  165. data/src/lib/chibach.h +71 -0
  166. data/src/lib/chibach_private.c +170 -0
  167. data/src/lib/chibach_private.h +52 -0
  168. data/src/lib/ether.c +2 -1
  169. data/src/lib/ether.h +0 -1
  170. data/src/lib/ipv4.h +13 -14
  171. data/{ruby/trema/action-set-nw-src.h → src/lib/ipv6.h} +13 -9
  172. data/src/lib/log.c +161 -58
  173. data/src/lib/log.h +11 -16
  174. data/src/lib/messenger.c +36 -1
  175. data/src/lib/messenger.h +1 -0
  176. data/src/lib/openflow_application_interface.c +128 -28
  177. data/src/lib/openflow_application_interface.h +31 -6
  178. data/src/lib/openflow_message.c +2 -1
  179. data/src/lib/openflow_service_interface.h +1 -0
  180. data/src/lib/openflow_switch_interface.c +1380 -0
  181. data/src/lib/openflow_switch_interface.h +264 -0
  182. data/src/lib/packet_info.c +94 -11
  183. data/src/lib/packet_info.h +22 -3
  184. data/src/lib/packet_parser.c +38 -2
  185. data/src/lib/secure_channel.c +498 -0
  186. data/{ruby/trema/vendor-request.h → src/lib/secure_channel.h} +11 -10
  187. data/src/lib/tcp.h +0 -3
  188. data/src/lib/trema.c +38 -5
  189. data/{ruby/trema/action-set-nw-dst.h → src/lib/trema.hpp} +17 -8
  190. data/src/lib/trema_wrapper.c +5 -0
  191. data/src/lib/trema_wrapper.h +4 -0
  192. data/src/lib/utility.c +93 -4
  193. data/src/lib/utility.h +1 -0
  194. data/src/lib/wrapper.c +30 -7
  195. data/src/lib/wrapper.h +2 -0
  196. data/src/switch_manager/ofpmsg_recv.c +44 -30
  197. data/src/switch_manager/ofpmsg_send.c +40 -1
  198. data/src/switch_manager/ofpmsg_send.h +2 -0
  199. data/src/switch_manager/switch.c +153 -8
  200. data/src/switch_manager/switch.h +1 -0
  201. data/src/switch_manager/switchinfo.h +5 -0
  202. data/src/tremashark/README +2 -2
  203. data/src/tremashark/plugin/packet-trema/packet-trema.c +1 -0
  204. data/trema +1 -1
  205. data/unittests/lib/log_test.c +158 -34
  206. data/unittests/lib/openflow_application_interface_test.c +252 -69
  207. data/unittests/lib/openflow_message_test.c +3 -1
  208. data/unittests/lib/packet_parser_test.c +60 -15
  209. data/unittests/lib/test_packets/icmp6_echo_rep.cap +0 -0
  210. data/unittests/lib/test_packets/icmp6_echo_req.cap +0 -0
  211. data/unittests/lib/trema_test.c +2 -0
  212. data/unittests/lib/utility_test.c +65 -2
  213. data/unittests/lib/wrapper_test.c +29 -0
  214. data/vendor/{README → README.md} +2 -12
  215. data/vendor/packet-openflow.diff +13 -0
  216. metadata +86 -53
  217. data/GPL2 +0 -339
  218. data/ruby/trema/action-enqueue.c +0 -161
  219. data/ruby/trema/action-output.c +0 -169
  220. data/ruby/trema/action-set-dl-dst.c +0 -131
  221. data/ruby/trema/action-set-dl-dst.h +0 -44
  222. data/ruby/trema/action-set-dl-src.c +0 -131
  223. data/ruby/trema/action-set-nw-dst.c +0 -135
  224. data/ruby/trema/action-set-nw-src.c +0 -140
  225. data/ruby/trema/action-set-nw-tos.c +0 -124
  226. data/ruby/trema/action-set-nw-tos.h +0 -42
  227. data/ruby/trema/action-set-tp-dst.c +0 -122
  228. data/ruby/trema/action-set-tp-dst.h +0 -42
  229. data/ruby/trema/action-set-tp-src.c +0 -124
  230. data/ruby/trema/action-set-tp-src.h +0 -42
  231. data/ruby/trema/action-set-vlan-pcp.c +0 -128
  232. data/ruby/trema/action-set-vlan-pcp.h +0 -42
  233. data/ruby/trema/action-set-vlan-vid.c +0 -125
  234. data/ruby/trema/action-set-vlan-vid.h +0 -42
  235. data/ruby/trema/action-strip-vlan.c +0 -81
  236. data/ruby/trema/action-strip-vlan.h +0 -42
  237. data/ruby/trema/action-vendor.c +0 -121
  238. data/ruby/trema/vendor-request.c +0 -193
  239. data/spec/trema/action-enqueue_spec.rb +0 -100
  240. data/spec/trema/action-set-dl-dst_spec.rb +0 -95
  241. data/spec/trema/action-set-dl-src_spec.rb +0 -92
  242. data/spec/trema/action-set-nw-dst_spec.rb +0 -96
  243. data/spec/trema/action-set-nw-src_spec.rb +0 -97
  244. data/spec/trema/action-set-nw-tos_spec.rb +0 -88
  245. data/spec/trema/action-set-tp-dst_spec.rb +0 -88
  246. data/spec/trema/action-set-tp-src_spec.rb +0 -88
  247. data/spec/trema/action-set-vlan-pcp_spec.rb +0 -91
  248. data/spec/trema/action-set-vlan-vid_spec.rb +0 -91
  249. data/spec/trema/action-vendor_spec.rb +0 -90
  250. data/spec/trema/vendor-request_spec.rb +0 -79
data/src/lib/log.h CHANGED
@@ -36,28 +36,23 @@
36
36
 
37
37
 
38
38
  #include "bool.h"
39
+ #include <syslog.h>
39
40
 
40
41
 
41
- /**
42
- * Constants specifying the level of log messages.
43
- */
44
42
  typedef enum {
45
- LOG_CRITICAL,
46
- LOG_ERROR,
47
- LOG_WARN,
48
- LOG_NOTICE,
49
- LOG_INFO,
50
- LOG_DEBUG,
51
- } logging_level;
52
-
53
-
54
- bool init_log( const char *ident, const char *log_directory, bool run_as_daemon );
55
- void restart_log( const char *ident, const char *log_directory );
56
- void rename_log( const char *old_ident, const char *new_ident, const char *directory );
43
+ LOGGING_TYPE_FILE = 0x1,
44
+ LOGGING_TYPE_SYSLOG = 0x2,
45
+ LOGGING_TYPE_STDOUT = 0x4,
46
+ } logging_type;
47
+
48
+
49
+ bool init_log( const char *ident, const char *log_directory, logging_type type );
50
+ void restart_log( const char *new_ident );
51
+ void rename_log( const char *new_ident );
57
52
  bool finalize_log( void );
58
53
 
59
54
  bool set_logging_level( const char *level );
60
- extern logging_level ( *get_logging_level )( void );
55
+ extern int ( *get_logging_level )( void );
61
56
 
62
57
  extern void ( *critical )( const char *format, ... );
63
58
  extern void ( *error )( const char *format, ... );
data/src/lib/messenger.c CHANGED
@@ -1052,7 +1052,7 @@ push_message_to_send_queue( const char *service_name, const uint8_t message_type
1052
1052
  }
1053
1053
 
1054
1054
  set_writable( sq->server_socket, true );
1055
- if ( sq->buffer->data_length > messenger_send_length_for_flush ) {
1055
+ if ( sq->buffer->data_length > messenger_send_length_for_flush ) {
1056
1056
  on_send_write( sq->server_socket, sq );
1057
1057
  }
1058
1058
  return true;
@@ -1152,6 +1152,41 @@ _send_reply_message( const messenger_context_handle *handle, const uint16_t tag,
1152
1152
  bool ( *send_reply_message )( const messenger_context_handle *handle, const uint16_t tag, const void *data, size_t len ) = _send_reply_message;
1153
1153
 
1154
1154
 
1155
+ static bool
1156
+ _clear_send_queue( const char *service_name ) {
1157
+ assert( service_name != NULL );
1158
+
1159
+ debug( "Deleting all messages from send queue ( service_name = %s ).", service_name );
1160
+
1161
+ if ( send_queues == NULL ) {
1162
+ error( "All send queues are already deleted or not created yet." );
1163
+ return false;
1164
+ }
1165
+
1166
+ send_queue *sq = lookup_hash_entry( send_queues, service_name );
1167
+
1168
+ if ( NULL == sq ) {
1169
+ error( "Send queue is already deleted or not created yet ( service_name = %s ).", service_name );
1170
+ return false;
1171
+ }
1172
+ if ( NULL == sq->buffer ) {
1173
+ error( "Message buffer is already deleted or not created yet ( send_queue = %p, service_name = %s ).",
1174
+ sq, service_name );
1175
+ return false;
1176
+ }
1177
+
1178
+ if ( sq->buffer->data_length > 0 ) {
1179
+ set_writable( sq->server_socket, false );
1180
+ }
1181
+
1182
+ sq->buffer->head_offset = 0;
1183
+ sq->buffer->data_length = 0;
1184
+
1185
+ return true;
1186
+ }
1187
+ bool ( *clear_send_queue )( const char *service_name ) = _clear_send_queue;
1188
+
1189
+
1155
1190
  static void
1156
1191
  number_of_send_queue( int *connected_count, int *sending_count, int *reconnecting_count, int *closed_count ) {
1157
1192
  assert( connected_count != NULL );
data/src/lib/messenger.h CHANGED
@@ -121,6 +121,7 @@ extern bool ( *delete_message_replied_callback )( const char *service_name, void
121
121
  extern bool ( *send_message )( const char *service_name, const uint16_t tag, const void *data, size_t len );
122
122
  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
123
  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 );
124
125
 
125
126
  bool init_messenger( const char *working_directory );
126
127
  bool finalize_messenger( void );
@@ -89,6 +89,12 @@ bool mock_delete_message_received_callback( char *service_name,
89
89
  bool mock_delete_message_replied_callback( char *service_name,
90
90
  void ( *callback )( uint16_t tag, void *data, size_t len, void *user_data ) );
91
91
 
92
+ #ifdef clear_send_queue
93
+ #undef clear_send_queue
94
+ #endif
95
+ #define clear_send_queue mock_clear_send_queue
96
+ bool mock_clear_send_queue( const char *service_name );
97
+
92
98
  #ifdef getpid
93
99
  #undef getpid
94
100
  #endif
@@ -293,6 +299,26 @@ set_error_handler( error_handler callback, void *user_data ) {
293
299
  }
294
300
 
295
301
 
302
+ bool
303
+ set_echo_reply_handler( echo_reply_handler callback, void *user_data ) {
304
+ if ( callback == NULL ) {
305
+ die( "Callback function ( echo_reply_handler ) must not be NULL." );
306
+ }
307
+ assert( callback != NULL );
308
+
309
+ maybe_init_openflow_application_interface();
310
+ assert( openflow_application_interface_initialized );
311
+
312
+ debug( "Setting a echo reply handler ( callback = %p, user_data = %p ).",
313
+ callback, user_data );
314
+
315
+ event_handlers.echo_reply_callback = callback;
316
+ event_handlers.echo_reply_user_data = user_data;
317
+
318
+ return true;
319
+ }
320
+
321
+
296
322
  bool
297
323
  set_vendor_handler( vendor_handler callback, void *user_data ) {
298
324
  if ( callback == NULL ) {
@@ -536,6 +562,57 @@ handle_error( const uint64_t datapath_id, buffer *data ) {
536
562
  }
537
563
 
538
564
 
565
+ static void
566
+ handle_echo_reply( const uint64_t datapath_id, buffer *data ) {
567
+ uint16_t body_length;
568
+ uint32_t transaction_id;
569
+ buffer *body;
570
+ struct ofp_header *header;
571
+
572
+ if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
573
+ critical( "An OpenFlow message must be filled before calling handle_echo_reply()." );
574
+ assert( 0 );
575
+ }
576
+
577
+ header = ( struct ofp_header * ) data->data;
578
+
579
+ transaction_id = ntohl( header->xid );
580
+
581
+ body_length = ( uint16_t ) ( ntohs( header->length )
582
+ - sizeof( struct ofp_header ) );
583
+
584
+ debug( "A echo reply message is received from %#" PRIx64
585
+ " ( transaction_id = %#x, body length = %u ).",
586
+ datapath_id, transaction_id, body_length );
587
+
588
+ if ( event_handlers.echo_reply_callback == NULL ) {
589
+ debug( "Callback function for echo reply events is not set." );
590
+ return;
591
+ }
592
+
593
+ if ( body_length > 0 ) {
594
+ body = duplicate_buffer( data );
595
+ remove_front_buffer( body, sizeof( struct ofp_header ) );
596
+ }
597
+ else {
598
+ body = NULL;
599
+ }
600
+
601
+ debug( "Calling echo reply handler ( callback = %p, user_data = %p ).",
602
+ event_handlers.echo_reply_callback, event_handlers.echo_reply_user_data );
603
+
604
+ event_handlers.echo_reply_callback( datapath_id,
605
+ transaction_id,
606
+ body,
607
+ event_handlers.echo_reply_user_data );
608
+
609
+ if ( body != NULL ) {
610
+ free_buffer( body );
611
+ }
612
+ }
613
+
614
+
615
+
539
616
  static void
540
617
  handle_vendor( const uint64_t datapath_id, buffer *data ) {
541
618
  uint16_t body_length;
@@ -631,7 +708,7 @@ handle_features_reply( const uint64_t datapath_id, buffer *data ) {
631
708
  ntoh_phy_port( p, phy_port );
632
709
  append_to_tail( &phy_ports_head, ( void * ) p );
633
710
  phy_port_to_string( p, description, sizeof( description ) );
634
- debug( "[%u] %s", phy_port, description );
711
+ debug( "[%p] %s", phy_port, description );
635
712
  phy_port++;
636
713
  }
637
714
  }
@@ -1114,7 +1191,7 @@ static void
1114
1191
  handle_barrier_reply( const uint64_t datapath_id, buffer *data ) {
1115
1192
  uint32_t transaction_id;
1116
1193
  struct ofp_header *header;
1117
-
1194
+
1118
1195
  if ( ( data == NULL ) || ( ( data != NULL ) && ( data->length == 0 ) ) ) {
1119
1196
  critical( "An OpenFlow message must be filled before calling handle_barrier_reply()." );
1120
1197
  assert( 0 );
@@ -1252,6 +1329,9 @@ update_switch_event_stats( uint16_t type, int send_receive, bool result ) {
1252
1329
  case MESSENGER_OPENFLOW_DISCONNECTED:
1253
1330
  snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_disconnected", direction, suffix );
1254
1331
  break;
1332
+ case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
1333
+ snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "switch_failed_to_connect", direction, suffix );
1334
+ break;
1255
1335
  default:
1256
1336
  snprintf( key, STAT_KEY_LENGTH, "%s%s%s%s", prefix, "undefined_switch_event", direction, suffix );
1257
1337
  break;
@@ -1286,39 +1366,43 @@ handle_switch_ready( uint64_t datapath_id ) {
1286
1366
 
1287
1367
 
1288
1368
  static void
1289
- handle_switch_events( uint16_t type, void *data, size_t length ) {
1290
- uint64_t datapath_id;
1291
- openflow_service_header_t *message;
1369
+ handle_messenger_openflow_disconnected( uint64_t datapath_id ) {
1370
+ if ( event_handlers.switch_disconnected_callback != NULL ) {
1371
+ debug( "Calling switch disconnected handler (callback = %p, user_data = %p).",
1372
+ event_handlers.switch_disconnected_callback, event_handlers.switch_disconnected_user_data );
1373
+ event_handlers.switch_disconnected_callback( datapath_id, event_handlers.switch_disconnected_user_data );
1374
+ }
1375
+ else {
1376
+ debug( "Callback function for switch disconnected events is not set." );
1377
+ }
1378
+ delete_openflow_messages( datapath_id );
1379
+ }
1380
+
1292
1381
 
1382
+ static void
1383
+ handle_switch_events( uint16_t type, void *data, size_t length ) {
1293
1384
  assert( data != NULL );
1294
1385
  assert( length == sizeof( openflow_service_header_t ) );
1295
1386
 
1296
- debug( "A switch event is received from remote ( type = %u ).", type );
1387
+ debug( "Received a switch event (type = %u) from remote.", type );
1297
1388
 
1298
- message = ( openflow_service_header_t * ) data;
1299
-
1300
- datapath_id = ntohll( message->datapath_id );
1389
+ openflow_service_header_t *message = data;
1390
+ uint64_t datapath_id = ntohll( message->datapath_id );
1301
1391
 
1302
1392
  switch ( type ) {
1303
- case MESSENGER_OPENFLOW_CONNECTED:
1304
- break;
1305
- case MESSENGER_OPENFLOW_READY:
1306
- handle_switch_ready( datapath_id );
1307
- break;
1308
- case MESSENGER_OPENFLOW_DISCONNECTED:
1309
- if ( event_handlers.switch_disconnected_callback != NULL ) {
1310
- debug( "Calling switch disconnected handler ( callback = %p, user_data = %p ).",
1311
- event_handlers.switch_disconnected_callback, event_handlers.switch_disconnected_user_data );
1312
- event_handlers.switch_disconnected_callback( datapath_id,
1313
- event_handlers.switch_disconnected_user_data );
1314
- }
1315
- else {
1316
- debug( "Callback function for switch disconnected events is not set." );
1317
- }
1318
- break;
1319
- default:
1320
- error( "Unhandled switch event ( type = %u ).", type );
1321
- break;
1393
+ case MESSENGER_OPENFLOW_CONNECTED:
1394
+ case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
1395
+ // Do nothing.
1396
+ break;
1397
+ case MESSENGER_OPENFLOW_READY:
1398
+ handle_switch_ready( datapath_id );
1399
+ break;
1400
+ case MESSENGER_OPENFLOW_DISCONNECTED:
1401
+ handle_messenger_openflow_disconnected( datapath_id );
1402
+ break;
1403
+ default:
1404
+ error( "Unhandled switch event (type = %u).", type );
1405
+ break;
1322
1406
  }
1323
1407
 
1324
1408
  update_switch_event_stats( type, OPENFLOW_MESSAGE_RECEIVE, true );
@@ -1471,6 +1555,9 @@ handle_openflow_message( void *data, size_t length ) {
1471
1555
  case OFPT_ERROR:
1472
1556
  handle_error( datapath_id, buffer );
1473
1557
  break;
1558
+ case OFPT_ECHO_REPLY:
1559
+ handle_echo_reply( datapath_id, buffer );
1560
+ break;
1474
1561
  case OFPT_VENDOR:
1475
1562
  handle_vendor( datapath_id, buffer );
1476
1563
  break;
@@ -1520,6 +1607,7 @@ handle_message( uint16_t type, void *data, size_t length ) {
1520
1607
  case MESSENGER_OPENFLOW_MESSAGE:
1521
1608
  return handle_openflow_message( data, length );
1522
1609
  case MESSENGER_OPENFLOW_CONNECTED:
1610
+ case MESSENGER_OPENFLOW_FAILD_TO_CONNECT:
1523
1611
  case MESSENGER_OPENFLOW_READY:
1524
1612
  case MESSENGER_OPENFLOW_DISCONNECTED:
1525
1613
  return handle_switch_events( type, data, length );
@@ -1665,6 +1753,18 @@ send_list_switches_request( void *user_data ) {
1665
1753
  }
1666
1754
 
1667
1755
 
1756
+ bool
1757
+ delete_openflow_messages( uint64_t datapath_id ) {
1758
+ debug( "Deleting OpenFlow messages in a send queue ( datapath_id = %#" PRIx64 " ).", datapath_id );
1759
+
1760
+ char remote_service_name[ MESSENGER_SERVICE_NAME_LENGTH ];
1761
+ memset( remote_service_name, '\0', sizeof( remote_service_name ) );
1762
+ snprintf( remote_service_name, sizeof( remote_service_name ),
1763
+ "switch.%#" PRIx64, datapath_id );
1764
+ return clear_send_queue( remote_service_name );
1765
+ }
1766
+
1767
+
1668
1768
  /*
1669
1769
  * Local variables:
1670
1770
  * c-basic-offset: 2
@@ -24,6 +24,7 @@
24
24
  #define OPENFLOW_APPLICATION_INTERFACE_H
25
25
 
26
26
 
27
+ #include <arpa/inet.h>
27
28
  #include "buffer.h"
28
29
  #include "linked_list.h"
29
30
  #include "openflow.h"
@@ -72,6 +73,14 @@ typedef void ( *error_handler )(
72
73
  );
73
74
 
74
75
 
76
+ typedef void ( *echo_reply_handler )(
77
+ uint64_t datapath_id,
78
+ uint32_t transaction_id,
79
+ const buffer *data,
80
+ void *user_data
81
+ );
82
+
83
+
75
84
  typedef void ( *vendor_handler )(
76
85
  uint64_t datapath_id,
77
86
  uint32_t transaction_id,
@@ -210,6 +219,9 @@ typedef struct openflow_event_handlers {
210
219
  error_handler error_callback;
211
220
  void *error_user_data;
212
221
 
222
+ echo_reply_handler echo_reply_callback;
223
+ void *echo_reply_user_data;
224
+
213
225
  vendor_handler vendor_callback;
214
226
  void *vendor_user_data;
215
227
 
@@ -252,10 +264,10 @@ bool set_openflow_event_handlers( const openflow_event_handlers_t handlers );
252
264
  #define set_switch_ready_handler( callback, user_data ) \
253
265
  { \
254
266
  if ( __builtin_types_compatible_p( typeof( callback ), simple_switch_ready_handler ) ) { \
255
- _set_switch_ready_handler( true, callback, user_data ); \
267
+ _set_switch_ready_handler( true, ( void * ) callback, user_data ); \
256
268
  } \
257
269
  else if ( __builtin_types_compatible_p( typeof( callback ), switch_ready_handler ) ) { \
258
- _set_switch_ready_handler( false, callback, user_data ); \
270
+ _set_switch_ready_handler( false, ( void * ) callback, user_data ); \
259
271
  } \
260
272
  else { \
261
273
  _set_switch_ready_handler( false, NULL, NULL ); \
@@ -266,6 +278,7 @@ bool _set_switch_ready_handler( bool simple_callback, void *callback, void *user
266
278
 
267
279
  bool set_switch_disconnected_handler( switch_disconnected_handler callback, void *user_data );
268
280
  bool set_error_handler( error_handler callback, void *user_data );
281
+ bool set_echo_reply_handler( echo_reply_handler callback, void *user_data );
269
282
  bool set_vendor_handler( vendor_handler callback, void *user_data );
270
283
  bool set_features_reply_handler( features_reply_handler callback, void *user_data );
271
284
  bool set_get_config_reply_handler( get_config_reply_handler callback, void *user_data );
@@ -274,10 +287,10 @@ bool set_get_config_reply_handler( get_config_reply_handler callback, void *user
274
287
  #define set_packet_in_handler( callback, user_data ) \
275
288
  { \
276
289
  if ( __builtin_types_compatible_p( typeof( callback ), simple_packet_in_handler ) ) { \
277
- _set_packet_in_handler( true, callback, user_data ); \
290
+ _set_packet_in_handler( true, ( void * ) callback, user_data ); \
278
291
  } \
279
292
  else if ( __builtin_types_compatible_p( typeof( callback ), packet_in_handler ) ) { \
280
- _set_packet_in_handler( false, callback, user_data ); \
293
+ _set_packet_in_handler( false, ( void * ) callback, user_data ); \
281
294
  } \
282
295
  else { \
283
296
  _set_packet_in_handler( false, NULL, NULL ); \
@@ -289,10 +302,10 @@ bool _set_packet_in_handler( bool simple_callback, void *callback, void *user_da
289
302
  #define set_flow_removed_handler( callback, user_data ) \
290
303
  { \
291
304
  if ( __builtin_types_compatible_p( typeof( callback ), simple_flow_removed_handler ) ) { \
292
- _set_flow_removed_handler( true, callback, user_data ); \
305
+ _set_flow_removed_handler( true, ( void * ) callback, user_data ); \
293
306
  } \
294
307
  else if ( __builtin_types_compatible_p( typeof( callback ), flow_removed_handler ) ) { \
295
- _set_flow_removed_handler( false, callback, user_data ); \
308
+ _set_flow_removed_handler( false, ( void * ) callback, user_data ); \
296
309
  } \
297
310
  else { \
298
311
  _set_flow_removed_handler( false, NULL, NULL ); \
@@ -315,9 +328,21 @@ bool set_list_switches_reply_handler( list_switches_reply_handler callback );
315
328
 
316
329
  bool send_openflow_message( const uint64_t datapath_id, buffer *message );
317
330
 
331
+
332
+ /********************************************************************************
333
+ * Function for retrieving the list of switches from Switch Manager.
334
+ ********************************************************************************/
335
+
318
336
  bool send_list_switches_request( void *user_data );
319
337
 
320
338
 
339
+ /********************************************************************************
340
+ * Function for deleting OpenFlow messages in a send queue
341
+ ********************************************************************************/
342
+
343
+ bool delete_openflow_messages( uint64_t datapath_id );
344
+
345
+
321
346
  #endif // OPENFLOW_APPLICATION_INTERFACE_H
322
347
 
323
348
 
@@ -25,6 +25,7 @@
25
25
  #include <string.h>
26
26
  #include <sys/socket.h>
27
27
  #include <sys/types.h>
28
+ #include <syslog.h>
28
29
  #include <unistd.h>
29
30
  #include "openflow_message.h"
30
31
  #include "packet_info.h"
@@ -139,7 +140,7 @@ create_error( const uint32_t transaction_id, const uint16_t type,
139
140
  debug( "Creating an error ( xid = %#x, type = %#x, code = %#x, data length = %u ).",
140
141
  transaction_id, type, code, data_len );
141
142
 
142
- length = ( uint16_t ) ( sizeof( struct ofp_error_msg ) + data_len );
143
+ length = ( uint16_t ) ( sizeof( struct ofp_error_msg ) + data_len );
143
144
  buffer = create_header( transaction_id, OFPT_ERROR, length );
144
145
  assert( buffer != NULL );
145
146
 
@@ -33,6 +33,7 @@
33
33
  #define MESSENGER_OPENFLOW_READY 3
34
34
  #define MESSENGER_OPENFLOW_DISCONNECTED 4
35
35
  #define MESSENGER_OPENFLOW_DISCONNECT_REQUEST 5
36
+ #define MESSENGER_OPENFLOW_FAILD_TO_CONNECT 6
36
37
 
37
38
 
38
39
  /**