trema 0.2.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright (C) 2008-2012 NEC Corporation
3
+ *
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License, version 2, as
6
+ * published by the Free Software Foundation.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License along
14
+ * with this program; if not, write to the Free Software Foundation, Inc.,
15
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+ */
17
+
18
+
19
+ #include "ruby.h"
20
+ #include "trema.h"
21
+
22
+
23
+ void
24
+ set_xid( const buffer *openflow_message, uint32_t xid ) {
25
+ ( ( struct ofp_header * ) ( openflow_message->data ) )->xid = htonl( xid );
26
+ }
27
+
28
+
29
+ VALUE
30
+ get_xid( VALUE self ) {
31
+ buffer *openflow_message;
32
+ Data_Get_Struct( self, buffer, openflow_message );
33
+ uint32_t xid = ntohl( ( ( struct ofp_header * ) ( openflow_message->data ) )->xid );
34
+ return UINT2NUM( xid );
35
+ }
36
+
37
+
38
+ void
39
+ set_length( const buffer *openflow_message, uint16_t length ) {
40
+ ( ( struct ofp_header * ) ( openflow_message->data ) )->length = htons( ( uint16_t ) ( sizeof( struct ofp_header ) + length ) );
41
+ }
42
+
43
+
44
+ uint16_t
45
+ get_length( const buffer *openflow_message ) {
46
+ return ( uint16_t ) ( openflow_message->length - sizeof( struct ofp_vendor_header ) );
47
+ }
48
+
49
+
50
+ void
51
+ validate_xid( VALUE xid ) {
52
+ if ( rb_obj_is_kind_of( xid, rb_cInteger ) != Qtrue ) {
53
+ rb_raise( rb_eTypeError, "Transaction ID must be an integer" );
54
+ }
55
+ if ( rb_funcall( xid, rb_intern( "unsigned_32bit?" ), 0 ) == Qfalse ) {
56
+ rb_raise( rb_eArgError, "Transaction ID must be an unsigned 32-bit integer" );
57
+ }
58
+ }
59
+
60
+
61
+ /*
62
+ * Local variables:
63
+ * c-basic-offset: 2
64
+ * indent-tabs-mode: nil
65
+ * End:
66
+ */
@@ -1,8 +1,4 @@
1
1
  /*
2
- * Prototype for setting the source data link address flow action.
3
- *
4
- * Author: Nick Karanatsios <nickkaranatsios@gmail.com>
5
- *
6
2
  * Copyright (C) 2008-2012 NEC Corporation
7
3
  *
8
4
  * This program is free software; you can redistribute it and/or modify
@@ -20,20 +16,22 @@
20
16
  */
21
17
 
22
18
 
23
- #ifndef ACTION_SET_DL_SRC_H
24
- #define ACTION_SET_DL_SRC_H
19
+ #ifndef TREMA_RUBY_UTILS_H
20
+ #define TREMA_RUBY_UTILS_H
25
21
 
26
22
 
27
23
  #include "ruby.h"
24
+ #include "trema.h"
28
25
 
29
26
 
30
- extern VALUE cActionSetDlSrc;
31
-
32
-
33
- void Init_action_set_dl_src( void );
27
+ void set_xid( const buffer *openflow_message, uint32_t xid );
28
+ VALUE get_xid( VALUE self );
29
+ void set_length( const buffer *openflow_message, uint16_t length );
30
+ uint16_t get_length( const buffer *openflow_message );
31
+ void validate_xid( VALUE xid );
34
32
 
35
33
 
36
- #endif // ACTION_SET_DL_SRC_H
34
+ #endif // TREMA_RUBY_UTILS_H
37
35
 
38
36
 
39
37
  /*
data/ruby/trema/trema.c CHANGED
@@ -1,8 +1,6 @@
1
1
  /*
2
2
  * Ruby wrapper around libtrema.
3
3
  *
4
- * Author: Yasuhito Takamiya <yasuhito@gmail.com>
5
- *
6
4
  * Copyright (C) 2008-2012 NEC Corporation
7
5
  *
8
6
  * This program is free software; you can redistribute it and/or modify
@@ -20,45 +18,34 @@
20
18
  */
21
19
 
22
20
 
23
- #include "action-output.h"
21
+ #include "barrier-reply.h"
22
+ #include "barrier-request.h"
24
23
  #include "controller.h"
25
- #include "features-reply.h"
26
- #include "features-request.h"
27
- #include "set-config.h"
28
- #include "hello.h"
29
- #include "logger.h"
30
- #include "packet_in.h"
31
- #include "port.h"
32
- #include "action-set-dl-dst.h"
33
- #include "action-set-dl-src.h"
34
- #include "action-enqueue.h"
35
- #include "action-set-nw-src.h"
36
- #include "action-set-nw-dst.h"
37
- #include "action-set-tp-src.h"
38
- #include "action-set-tp-dst.h"
39
- #include "action-set-nw-tos.h"
40
- #include "action-set-vlan-vid.h"
41
- #include "action-set-vlan-pcp.h"
42
- #include "action-strip-vlan.h"
43
- #include "action-vendor.h"
44
- #include "echo-request.h"
45
24
  #include "echo-reply.h"
25
+ #include "echo-request.h"
46
26
  #include "error.h"
47
- #include "stats-request.h"
27
+ #include "features-reply.h"
28
+ #include "features-request.h"
29
+ #include "flow-mod.h"
48
30
  #include "flow-removed.h"
49
- #include "port-status.h"
50
- #include "stats-reply.h"
51
- #include "openflow-error.h"
52
31
  #include "get-config-reply.h"
53
32
  #include "get-config-request.h"
54
- #include "barrier-reply.h"
55
- #include "barrier-request.h"
56
- #include "vendor-request.h"
57
- #include "queue-get-config-request.h"
58
- #include "queue-get-config-reply.h"
59
- #include "port-mod.h"
33
+ #include "hello.h"
34
+ #include "logger.h"
60
35
  #include "match.h"
36
+ #include "openflow-error.h"
37
+ #include "packet-in.h"
38
+ #include "port-mod.h"
39
+ #include "port-status.h"
40
+ #include "port.h"
41
+ #include "queue-get-config-reply.h"
42
+ #include "queue-get-config-request.h"
61
43
  #include "ruby.h"
44
+ #include "set-config.h"
45
+ #include "stats-reply.h"
46
+ #include "stats-request.h"
47
+ #include "switch.h"
48
+ #include "vendor.h"
62
49
 
63
50
 
64
51
  VALUE mTrema;
@@ -68,48 +55,61 @@ void
68
55
  Init_trema() {
69
56
  mTrema = rb_define_module( "Trema" );
70
57
 
58
+ rb_define_const( mTrema, "OFPC_FLOW_STATS", INT2NUM( OFPC_FLOW_STATS ) );
59
+ rb_define_const( mTrema, "OFPC_TABLE_STATS", INT2NUM( OFPC_TABLE_STATS ) );
60
+ rb_define_const( mTrema, "OFPC_PORT_STATS", INT2NUM( OFPC_PORT_STATS ) );
61
+ rb_define_const( mTrema, "OFPC_STP", INT2NUM( OFPC_STP) );
62
+ rb_define_const( mTrema, "OFPC_RESERVED", INT2NUM( OFPC_RESERVED ) );
63
+ rb_define_const( mTrema, "OFPC_IP_REASM", INT2NUM( OFPC_IP_REASM ) );
64
+ rb_define_const( mTrema, "OFPC_QUEUE_STATS", INT2NUM( OFPC_QUEUE_STATS ) );
65
+ rb_define_const( mTrema, "OFPC_ARP_MATCH_IP", INT2NUM( OFPC_ARP_MATCH_IP ) );
66
+
67
+ rb_define_const( mTrema, "OFPAT_OUTPUT", INT2NUM( OFPAT_OUTPUT ) );
68
+ rb_define_const( mTrema, "OFPAT_SET_VLAN_VID", INT2NUM( OFPAT_SET_VLAN_VID ) );
69
+ rb_define_const( mTrema, "OFPAT_SET_VLAN_PCP", INT2NUM( OFPAT_SET_VLAN_PCP ) );
70
+ rb_define_const( mTrema, "OFPAT_STRIP_VLAN", INT2NUM( OFPAT_STRIP_VLAN ) );
71
+ rb_define_const( mTrema, "OFPAT_SET_DL_SRC", INT2NUM( OFPAT_SET_DL_SRC) );
72
+ rb_define_const( mTrema, "OFPAT_SET_DL_DST", INT2NUM( OFPAT_SET_DL_DST) );
73
+ rb_define_const( mTrema, "OFPAT_SET_NW_SRC", INT2NUM( OFPAT_SET_NW_SRC ) );
74
+ rb_define_const( mTrema, "OFPAT_SET_NW_DST", INT2NUM( OFPAT_SET_NW_DST ) );
75
+ rb_define_const( mTrema, "OFPAT_SET_NW_TOS", INT2NUM( OFPAT_SET_NW_TOS ) );
76
+ rb_define_const( mTrema, "OFPAT_SET_TP_SRC", INT2NUM( OFPAT_SET_TP_SRC ) );
77
+ rb_define_const( mTrema, "OFPAT_SET_TP_DST", INT2NUM( OFPAT_SET_TP_DST ) );
78
+ rb_define_const( mTrema, "OFPAT_ENQUEUE", INT2NUM( OFPAT_ENQUEUE ) );
79
+ rb_define_const( mTrema, "OFPAT_VENDOR", INT2NUM( OFPAT_VENDOR ) );
80
+
71
81
  rb_require( "trema/host" );
82
+ rb_require( "trema/openflow-switch" );
72
83
  rb_require( "trema/path" );
73
- rb_require( "trema/switch" );
74
84
 
75
- Init_action_output();
76
- Init_action_set_dl_dst();
77
- Init_action_set_dl_src();
78
- Init_action_enqueue();
79
- Init_action_set_nw_src();
80
- Init_action_set_nw_dst();
81
- Init_action_set_tp_src();
82
- Init_action_set_tp_dst();
83
- Init_action_set_nw_tos();
84
- Init_action_set_vlan_vid();
85
- Init_action_set_vlan_pcp();
86
- Init_action_strip_vlan();
87
- Init_action_vendor();
85
+ Init_barrier_reply();
86
+ Init_barrier_request();
87
+ Init_controller();
88
88
  Init_echo_reply();
89
89
  Init_echo_request();
90
90
  Init_error();
91
- Init_logger();
92
- Init_controller();
93
91
  Init_features_reply();
94
92
  Init_features_request();
95
- Init_set_config();
96
- Init_stats_request();
93
+ Init_flow_mod();
94
+ Init_flow_removed();
95
+ Init_get_config_reply();
96
+ Init_get_config_request();
97
97
  Init_hello();
98
+ Init_logger();
98
99
  Init_match();
100
+ Init_openflow_error();
99
101
  Init_packet_in();
100
102
  Init_port();
101
- Init_flow_removed();
103
+ Init_port_mod();
102
104
  Init_port_status();
103
- Init_stats_reply();
104
- Init_openflow_error();
105
- Init_get_config_request();
106
- Init_get_config_reply();
107
- Init_barrier_request();
108
- Init_barrier_reply();
109
- Init_queue_get_config_request();
110
105
  Init_queue_get_config_reply();
111
- Init_vendor_request();
112
- Init_port_mod();
106
+ Init_queue_get_config_request();
107
+ Init_set_config();
108
+ Init_stats_reply();
109
+ Init_stats_request();
110
+ Init_switch();
111
+ Init_vendor();
112
+
113
113
  rb_require( "trema/exact-match" );
114
114
  }
115
115
 
@@ -0,0 +1,73 @@
1
+ #
2
+ # Copyright (C) 2008-2012 NEC Corporation
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License, version 2, as
6
+ # published by the Free Software Foundation.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+ #
17
+
18
+
19
+ require "trema/action"
20
+ require "trema/monkey-patch/integer"
21
+
22
+
23
+ module Trema
24
+ #
25
+ # An action to set vendor specific extensions.
26
+ #
27
+ class VendorAction < Action
28
+ attr_reader :body
29
+ attr_reader :vendor_id
30
+
31
+
32
+ #
33
+ # Creates an action to set vendor specific extensions.
34
+ #
35
+ # @example
36
+ # VendorAction.new( 0x00004cff, "deadbeef".unpack( "C*" ) )
37
+ #
38
+ # @param [Integer] vendor_id
39
+ # the vendor identifier. If MSB is zero low order bytes are IEEE
40
+ # OUI. Otherwise defined by openflow.
41
+ # @param [Array] body
42
+ # vendor-defined arbitrary additional data.
43
+ #
44
+ # @raise [TypeError] if vendor ID is not an Integer.
45
+ # @raise [ArgumentError] if vendor ID is not an unsigned 32-bit Integer.
46
+ # @raise [TypeError] if body is not an Array.
47
+ #
48
+ def initialize vendor_id, body = nil
49
+ if not vendor_id.is_a?( Integer )
50
+ raise TypeError, "Vendor ID must be an unsigned 32-bit integer"
51
+ end
52
+ if not vendor_id.unsigned_32bit?
53
+ raise ArgumentError, "Vendor ID must be an unsigned 32-bit integer"
54
+ end
55
+ if ( not body.nil? ) and ( not body.is_a?( Array ) )
56
+ raise TypeError, "Body must be an Array"
57
+ end
58
+
59
+ @vendor_id = vendor_id
60
+ @body = body
61
+ end
62
+ end
63
+
64
+
65
+ ActionVendor = VendorAction
66
+ end
67
+
68
+
69
+ ### Local variables:
70
+ ### mode: Ruby
71
+ ### coding: utf-8-unix
72
+ ### indent-tabs-mode: nil
73
+ ### End:
data/ruby/trema/vendor.c CHANGED
@@ -1,6 +1,4 @@
1
1
  /*
2
- * Author: Nick Karanatsios <nickkaranatsios@gmail.com>
3
- *
4
2
  * Copyright (C) 2008-2012 NEC Corporation
5
3
  *
6
4
  * This program is free software; you can redistribute it and/or modify
@@ -18,103 +16,174 @@
18
16
  */
19
17
 
20
18
 
21
- #include "trema.h"
22
19
  #include "ruby.h"
20
+ #include "trema-ruby-utils.h"
21
+ #include "trema.h"
23
22
 
24
23
 
25
24
  extern VALUE mTrema;
26
25
  VALUE cVendor;
27
26
 
28
27
 
28
+ static VALUE
29
+ vendor_alloc( VALUE klass ) {
30
+ buffer *vendor = create_vendor( 0, 0, NULL );
31
+ return Data_Wrap_Struct( klass, NULL, free_buffer, vendor );
32
+ }
33
+
34
+
29
35
  /*
30
- * Creates a {Vendor} instance that encapsulates the handling of vendor's messages.
36
+ * Creates a Vendor Reqeust message. This message can be used
37
+ * to facilitate sending of vendor-defined arbitrary data.
31
38
  *
32
- * @overload initialize(options={})
39
+ * @overload initialize
40
+ * @example
41
+ * Vendor.new
33
42
  *
34
- * @example
43
+ * @overload initialize(options)
44
+ * @example
35
45
  * Vendor.new(
36
- * :datapath_id => 0xabc,
37
- * :transaction_id => 123,
38
- * :vendor => vendor_id,
39
- * :buffer => data
46
+ * :vendor => 0x3000,
47
+ * :data => "deadbeef".unpack( "C*" ),
48
+ * :transaction_id => 123
40
49
  * )
41
50
  *
42
51
  * @param [Hash] options
43
52
  * the options to create a message with.
44
- *
45
- * @option options [Number] :datapath_id
46
- * message originator identifier.
47
- *
53
+ * @option options [Number] :xid
48
54
  * @option options [Number] :transaction_id
49
- * zero for unsolicited message otherwise a positive number.
55
+ * an unsigned 32bit integer number associated with this message.
56
+ * if not specified, an auto-generated value is set.
57
+ * @option options [Number] :vendor
58
+ * the vendor identifier. If MSB is zero low order bytes are IEEE OUI. Otherwise defined by openflow.
59
+ * @option options [Array] :data
60
+ * a String that holds vendor's defined arbitrary length data.
50
61
  *
51
- * @option options [Number] :vendor_id
52
- * the vendor identifier. if MSB is zero low order bytes are IEEE OUI.
53
- * If MSB not equal to zero defined by openflow.
54
- *
55
- * @option options [String] :buffer
56
- * a String that holds vendor's defined arbitrary length data.
57
- *
58
- * @return [Vendor]
59
- * an object that encapsulates the +OFPT_VENDOR+ OpenFlow symmetric message.
62
+ * @raise [ArgumentError] if transaction ID is not an unsigned 32-bit integer.
63
+ * @raise [ArgumentError] if user data is not an array of bytes.
64
+ * @raise [TypeError] if options is not a hash.
65
+ * @return [Vendor]
60
66
  */
61
67
  static VALUE
62
- vendor_init( VALUE self, VALUE options ) {
63
- rb_iv_set( self, "@attribute", options );
64
- return self;
65
- }
68
+ vendor_init( int argc, VALUE *argv, VALUE self ) {
69
+ buffer *vendor = NULL;
70
+ Data_Get_Struct( self, buffer, vendor );
71
+ VALUE options = Qnil;
66
72
 
67
- /*
68
- * Message originator identifier.
69
- *
70
- * @return [Number] the value of datapath_id.
71
- */
72
- static VALUE
73
- vendor_datapath_id( VALUE self ) {
74
- return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "datapath_id" ) ) );
73
+ if ( rb_scan_args( argc, argv, "01", &options ) == 0 ) {
74
+ set_xid( vendor, get_transaction_id() );
75
+ }
76
+ else {
77
+ if ( options == Qnil ) {
78
+ set_xid( vendor, get_transaction_id() );
79
+ }
80
+ else {
81
+ if ( rb_scan_args( argc, argv, "01", &options ) == 1 ) {
82
+ Check_Type( options, T_HASH );
83
+ VALUE tmp = Qnil;
84
+ VALUE xid = Qnil;
85
+
86
+ tmp = rb_hash_aref( options, ID2SYM( rb_intern( "transaction_id" ) ) );
87
+ if ( tmp != Qnil ) {
88
+ xid = tmp;
89
+ }
90
+ tmp = rb_hash_aref( options, ID2SYM( rb_intern( "xid" ) ) );
91
+ if ( tmp != Qnil ) {
92
+ xid = tmp;
93
+ }
94
+
95
+ if ( xid != Qnil ) {
96
+ validate_xid( xid );
97
+ set_xid( vendor, ( uint32_t ) NUM2UINT( xid ) );
98
+ }
99
+ else {
100
+ set_xid( vendor, get_transaction_id() );
101
+ }
102
+
103
+ tmp = rb_hash_aref( options, ID2SYM( rb_intern( "vendor" ) ) );
104
+ if ( tmp != Qnil ) {
105
+ ( ( struct ofp_vendor_header * ) ( vendor->data ) )->vendor = htonl( ( uint32_t ) NUM2UINT( tmp ) );
106
+ }
107
+
108
+ tmp = rb_hash_aref( options, ID2SYM( rb_intern( "data" ) ) );
109
+ if ( tmp != Qnil ) {
110
+ Check_Type( tmp, T_ARRAY );
111
+ uint16_t length = ( uint16_t ) RARRAY_LEN( tmp );
112
+ append_back_buffer( vendor, length );
113
+ set_length( vendor, length );
114
+ uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
115
+ int i;
116
+ for ( i = 0; i < length; i++ ) {
117
+ data[ i ] = ( uint8_t ) FIX2INT( RARRAY_PTR( tmp )[ i ] );
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ return self;
75
125
  }
76
126
 
77
127
 
78
128
  /*
79
- * Zero for unsolicited message otherwise a positive number copied from request
80
- * message.
129
+ * Transaction ids, message sequence numbers matching requests to replies.
81
130
  *
82
- * @return [Number] the value of transaction_id.
131
+ * @return [Number] the value of transaction id.
83
132
  */
84
133
  static VALUE
85
134
  vendor_transaction_id( VALUE self ) {
86
- return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "transaction_id" ) ) );
135
+ return get_xid( self );
87
136
  }
88
137
 
89
138
 
90
139
  /*
91
- * (see VendorRequest#vendor)
140
+ * A 32-bit value that uniquely identifies the vendor.
141
+ *
142
+ * @return [Number] the value of vendor id.
92
143
  */
93
144
  static VALUE
94
145
  vendor_vendor( VALUE self ) {
95
- return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "vendor" ) ) );
146
+ buffer *vendor_message;
147
+ Data_Get_Struct( self, buffer, vendor_message );
148
+ uint32_t vendor = ntohl( ( ( struct ofp_vendor_header * ) ( vendor_message->data ) )->vendor );
149
+ return UINT2NUM( vendor );
96
150
  }
97
151
 
98
152
 
99
153
  /*
100
- * Vendor's arbitrary length data.
154
+ * Vendor specific data payload.
101
155
  *
102
- * @return [Buffer] the value of buffer.
156
+ * @return [Array] an array of data payload bytes.
157
+ * @return [nil] vendor specific data not found.
103
158
  */
104
159
  static VALUE
105
- vendor_buffer( VALUE self ) {
106
- return rb_hash_aref( rb_iv_get( self, "@attribute" ), ID2SYM( rb_intern( "buffer" ) ) );
160
+ vendor_data( VALUE self ) {
161
+ buffer *vendor;
162
+ Data_Get_Struct( self, buffer, vendor );
163
+ uint16_t length = get_length( vendor );
164
+
165
+ if ( length > 0 ) {
166
+ VALUE data_array = rb_ary_new2( length );
167
+ uint8_t *data = ( uint8_t * ) ( ( char * ) vendor->data + sizeof( struct ofp_vendor_header ) );
168
+ int i;
169
+ for ( i = 0; i < length; i++ ) {
170
+ rb_ary_push( data_array, INT2FIX( data[ i ] ) );
171
+ }
172
+ return data_array;
173
+ }
174
+ return Qnil;
107
175
  }
108
176
 
109
177
 
110
178
  void
111
179
  Init_vendor() {
112
180
  cVendor = rb_define_class_under( mTrema, "Vendor", rb_cObject );
113
- rb_define_method( cVendor, "initialize", vendor_init, 1 );
114
- rb_define_method( cVendor, "datapath_id", vendor_datapath_id, 0 );
181
+ rb_define_alloc_func( cVendor, vendor_alloc );
182
+ rb_define_method( cVendor, "initialize", vendor_init, -1 );
115
183
  rb_define_method( cVendor, "transaction_id", vendor_transaction_id, 0 );
184
+ rb_alias( cVendor, rb_intern( "xid" ), rb_intern( "transaction_id" ) );
116
185
  rb_define_method( cVendor, "vendor", vendor_vendor, 0 );
117
- rb_define_method( cVendor, "buffer", vendor_buffer, 0 );
186
+ rb_define_method( cVendor, "data", vendor_data, 0 );
118
187
  }
119
188
 
120
189
 
@@ -123,7 +192,7 @@ handle_vendor(
123
192
  uint64_t datapath_id,
124
193
  uint32_t transaction_id,
125
194
  uint32_t vendor,
126
- buffer *body,
195
+ buffer *data,
127
196
  void *user_data
128
197
  ) {
129
198
  VALUE controller = ( VALUE ) user_data;
@@ -136,8 +205,8 @@ handle_vendor(
136
205
  rb_hash_aset( attributes, ID2SYM( rb_intern( "transaction_id" ) ), UINT2NUM( transaction_id ) );
137
206
  rb_hash_aset( attributes, ID2SYM( rb_intern( "vendor" ) ), UINT2NUM( vendor ) );
138
207
 
139
- if ( body->length ) {
140
- rb_hash_aset( attributes, ID2SYM( rb_intern( "buffer" ) ), rb_str_new( body->data, ( long ) body->length ) );
208
+ if ( data->length ) {
209
+ rb_hash_aset( attributes, ID2SYM( rb_intern( "data" ) ), rb_str_new( data->data, ( long ) data->length ) );
141
210
  }
142
211
  VALUE vendor_r = rb_funcall( cVendor, rb_intern( "new" ), 1, attributes );
143
212
  rb_funcall( controller, rb_intern( "vendor" ), 1, vendor_r );