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
@@ -24,7 +24,7 @@
24
24
 
25
25
  void
26
26
  handle_list_switches_reply( const list_element *switches, void *controller ) {
27
- if ( rb_respond_to( ( VALUE ) controller, rb_intern( "list_switches_reply" ) ) == Qfalse ) {
27
+ if ( rb_respond_to( ( VALUE ) controller, rb_intern( "list_switches_reply" ) ) == Qfalse ) {
28
28
  return;
29
29
  }
30
30
  VALUE dpids = rb_ary_new();
data/ruby/trema/mac.rb CHANGED
@@ -152,7 +152,7 @@ module Trema
152
152
 
153
153
 
154
154
  def validate_value_range
155
- if not ( @value >= 0 and @value <= 0xffffffffffff )
155
+ unless ( @value >= 0 and @value <= 0xffffffffffff )
156
156
  raise ArgumentError, "Invalid MAC address: #{ @value }"
157
157
  end
158
158
  end
data/ruby/trema/match.c CHANGED
@@ -43,8 +43,7 @@ ofp_match *get_match( VALUE self ) {
43
43
 
44
44
  /*
45
45
  * Creates a {Match} instance from packet_in's data, the method accepts an
46
- * additional single argument whose type is an array of symbols to wildcard set
47
- * to don't care and ignore while matching flow entries.
46
+ * additional list of symbols to wildcard set and ignore while matching flow entries.
48
47
  *
49
48
  * @overload match_from(message, *options)
50
49
  *
@@ -52,7 +51,7 @@ ofp_match *get_match( VALUE self ) {
52
51
  * def packet_in datapath_id, message
53
52
  * send_flow_mod(
54
53
  * datapath_id,
55
- * :match => Match.from( message, [ :dl_type, :nw_proto ] ),
54
+ * :match => Match.from( message, :dl_type, :nw_proto ),
56
55
  * :actions => Trema::ActionOutput.new( 2 )
57
56
  * )
58
57
  * end
@@ -60,10 +59,10 @@ ofp_match *get_match( VALUE self ) {
60
59
  * @param [PacketIn] message
61
60
  * the {PacketIn}'s message content.
62
61
  *
63
- * @param [optional, Array] options
64
- * If supplied an array of symbol ids indicating fields to be wildcarded.
62
+ * @param [optional, list] options
63
+ * If supplied a comma-separated list of symbol ids indicating fields to be wildcarded.
65
64
  *
66
- * [:inport]
65
+ * [:in_port]
67
66
  * the physical port number to wildcard.
68
67
  *
69
68
  * [:dl_src]
@@ -117,7 +116,7 @@ match_from( int argc, VALUE *argv, VALUE self ) {
117
116
  int i;
118
117
  for ( i = 0; i < RARRAY_LEN( options ); i++ ) {
119
118
  wildcard_id = SYM2ID( RARRAY_PTR( options )[ i ] );
120
- if ( rb_intern( "inport" ) == wildcard_id ) {
119
+ if ( rb_intern( "in_port" ) == wildcard_id ) {
121
120
  wildcards |= OFPFW_IN_PORT;
122
121
  }
123
122
  if ( rb_intern( "dl_src" ) == wildcard_id ) {
@@ -166,7 +165,7 @@ match_from( int argc, VALUE *argv, VALUE self ) {
166
165
  * @example
167
166
  * def packet_in datapath_id, message
168
167
  * match = Match.new( :dl_type => 0x0800, :nw_src => "192.168.0.1" )
169
- * if match.compare( ExactMatch.form( message ) )
168
+ * if match.compare( ExactMatch.from( message ) )
170
169
  * info "Received packet from 192.168.0.1"
171
170
  * end
172
171
  * end
@@ -187,7 +186,7 @@ match_compare( VALUE self, VALUE other ) {
187
186
  */
188
187
  static VALUE
189
188
  match_replace( VALUE self, VALUE other ) {
190
- memcpy( get_match( self ), get_match( other ), sizeof ( struct ofp_match ) );
189
+ memcpy( get_match( self ), get_match( other ), sizeof( struct ofp_match ) );
191
190
  return self;
192
191
  }
193
192
 
@@ -199,7 +198,7 @@ static VALUE
199
198
  match_to_s( VALUE self ) {
200
199
  char match_str[ 1024 ];
201
200
 
202
- match_to_string( get_match( self ), match_str, sizeof ( match_str ) );
201
+ match_to_string( get_match( self ), match_str, sizeof( match_str ) );
203
202
  return rb_str_new2( match_str );
204
203
  }
205
204
 
@@ -232,7 +231,8 @@ match_dl( VALUE self, uint8_t which ) {
232
231
  match = get_match( self );
233
232
  if ( which ) {
234
233
  dl_addr = match->dl_src;
235
- } else {
234
+ }
235
+ else {
236
236
  dl_addr = match->dl_dst;
237
237
  }
238
238
  return rb_funcall( rb_eval_string( "Trema::Mac" ), rb_intern( "new" ), 1, ULL2NUM( mac_to_uint64( dl_addr ) ) );
@@ -312,7 +312,8 @@ match_nw( VALUE self, uint8_t which ) {
312
312
  if ( which ) {
313
313
  nw_addr = match->nw_src;
314
314
  masklen = ( match->wildcards & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT;
315
- } else {
315
+ }
316
+ else {
316
317
  nw_addr = match->nw_dst;
317
318
  masklen = ( match->wildcards & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT;
318
319
  }
@@ -387,7 +388,7 @@ match_tp_dst( VALUE self ) {
387
388
  *
388
389
  * @param [Hash] options the options hash.
389
390
  *
390
- * @option options [Number] :inport
391
+ * @option options [Number] :in_port
391
392
  * the physical port number to match.
392
393
  *
393
394
  * @option options [String,Number,Trema::Mac] :dl_src
@@ -450,7 +451,7 @@ match_init( int argc, VALUE *argv, VALUE self ) {
450
451
  // Always clear the memory as the unused memory locations are
451
452
  // exposed to both the user and the OpenFlow controller.
452
453
  Data_Get_Struct( self, struct ofp_match, match );
453
- memset( match, 0, sizeof ( *match ) );
454
+ memset( match, 0, sizeof( *match ) );
454
455
 
455
456
  // Default matches all packets.
456
457
  match->wildcards = ( OFPFW_ALL & ~( OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK ) )
@@ -1,6 +1,4 @@
1
1
  #
2
- # Author: Yasuhito Takamiya <yasuhito@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
@@ -0,0 +1,127 @@
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/network-component"
20
+
21
+
22
+ module Trema
23
+ #
24
+ # The controller class of network namespace
25
+ #
26
+ class Netns < NetworkComponent
27
+ #
28
+ # Set a network interface
29
+ #
30
+ # @example
31
+ # netns.interface #=> "trema0-1"
32
+ #
33
+ # @return [String]
34
+ #
35
+ # @api public
36
+ #
37
+ attr_accessor :interface
38
+
39
+
40
+ #
41
+ # Creates a new Trema netns from {DSL::Netns}
42
+ #
43
+ # @example
44
+ # netns = Trema::Netns.new( stanza )
45
+ #
46
+ # @return [Netns]
47
+ #
48
+ # @api public
49
+ #
50
+ def initialize stanza
51
+ @stanza = stanza
52
+ Netns.add self
53
+ end
54
+
55
+
56
+ #
57
+ # Define netns attribute accessors
58
+ #
59
+ # @example
60
+ # netns.name # delegated to @stanza[ :name ]
61
+ #
62
+ # @return an attribute value
63
+ #
64
+ # @api public
65
+ #
66
+ def method_missing message, *args
67
+ @stanza.__send__ :[], message
68
+ end
69
+
70
+
71
+ #
72
+ # Returns netmask
73
+ #
74
+ # @example
75
+ # host.netmask #=> "255.255.0.0"
76
+ #
77
+ # @return [String]
78
+ #
79
+ # @api public
80
+ #
81
+ def netmask
82
+ @stanza[ :netmask ] || "255.255.255.255"
83
+ end
84
+
85
+
86
+ #
87
+ # Runs a netns process
88
+ #
89
+ # @example
90
+ # netns.run! => self
91
+ #
92
+ # @return [Netns]
93
+ #
94
+ # @api public
95
+ #
96
+ def run!
97
+ sh "sudo ip netns add #{ name }"
98
+ sh "sudo ip link set dev #{ interface } netns #{ name }"
99
+ sh "sudo ip netns exec #{ name } ifconfig lo 127.0.0.1"
100
+ sh "sudo ip netns exec #{ name } ifconfig #{ interface } #{ @stanza[ :ip ] } netmask #{ netmask }" if @stanza[ :ip ]
101
+ sh "sudo ip netns exec #{ name } route add -net #{ @stanza[ :net ] } gw #{ @stanza[ :gw ] }" if @stanza[ :net ] and @stanza[ :gw ]
102
+ self
103
+ end
104
+
105
+
106
+ #
107
+ # Kills running netns
108
+ #
109
+ # @example
110
+ # netns.shutdown!
111
+ #
112
+ # @return [undefined]
113
+ #
114
+ # @api public
115
+ #
116
+ def shutdown!
117
+ sh "sudo ip netns delete #{ name }"
118
+ end
119
+ end
120
+ end
121
+
122
+
123
+ ### Local variables:
124
+ ### mode: Ruby
125
+ ### coding: utf-8-unix
126
+ ### indent-tabs-mode: nil
127
+ ### End:
@@ -1,6 +1,4 @@
1
1
  #
2
- # Author: Yasuhito Takamiya <yasuhito@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
@@ -20,6 +18,9 @@
20
18
 
21
19
  module Trema
22
20
  class OrderedHash
21
+ attr_reader :keys
22
+
23
+
23
24
  def initialize
24
25
  @keys = Array.new
25
26
  @content = Hash.new
@@ -38,11 +39,11 @@ module Trema
38
39
 
39
40
  def []= key, value
40
41
  @content[ key ] = value
41
- if not @keys.include?( key )
42
+ unless @keys.include?( key )
42
43
  @keys << key
43
44
  end
44
45
  end
45
-
46
+
46
47
 
47
48
  def values
48
49
  @keys.map do | each |
@@ -42,7 +42,8 @@ VALUE cPacketIn;
42
42
  { \
43
43
  if ( get_packet_in_info( self )->format & flag ) { \
44
44
  return func( get_packet_in_info( self )->packet_member ); \
45
- } else { \
45
+ } \
46
+ else { \
46
47
  return Qnil; \
47
48
  } \
48
49
  }
@@ -109,8 +110,7 @@ packet_in_buffer_id( VALUE self ) {
109
110
  /*
110
111
  * A buffer_id value either than +UINT32_MAX+ marks the packet_in as buffered.
111
112
  *
112
- * @return [true] if packet_in is buffered.
113
- * @return [false] if packet_in is not buffered.
113
+ * @return [Boolean] whether the packet_in is buffered or not.
114
114
  */
115
115
  static VALUE
116
116
  packet_in_is_buffered( VALUE self ) {
@@ -170,9 +170,9 @@ packet_in_reason( VALUE self ) {
170
170
 
171
171
 
172
172
  /*
173
- * The MAC source address.
173
+ * The source MAC address.
174
174
  *
175
- * @return [Trema::Mac] macsa MAC source address.
175
+ * @return [Trema::Mac] the value of source MAC address as a Trema::MAC object.
176
176
  */
177
177
  static VALUE
178
178
  packet_in_macsa( VALUE self ) {
@@ -181,9 +181,10 @@ packet_in_macsa( VALUE self ) {
181
181
 
182
182
 
183
183
  /*
184
- * The MAC destination address.
184
+ * The destination MAC address.
185
185
  *
186
- * @return [Trema::Mac] macda MAC destination address.
186
+ * @return [Trema::Mac] the value of destination MAC address as a
187
+ * Trema::MAC object.
187
188
  */
188
189
  static VALUE
189
190
  packet_in_macda( VALUE self ) {
@@ -194,7 +195,7 @@ packet_in_macda( VALUE self ) {
194
195
  /*
195
196
  * The ethernet type.
196
197
  *
197
- * @return [integer] eth_type The ehternet type.
198
+ * @return [Integer] the value of ethernet type.
198
199
  */
199
200
  static VALUE
200
201
  packet_in_eth_type( VALUE self ) {
@@ -203,9 +204,9 @@ packet_in_eth_type( VALUE self ) {
203
204
 
204
205
 
205
206
  /*
206
- * Is a packet with VLAN tag?
207
+ * Is it an IEEE 802.1q packet?
207
208
  *
208
- * @return [bool] vtag? Is a packet with VLAN tag?
209
+ * @return [Boolean] whether the packet is an IEEE 802.1q or not.
209
210
  */
210
211
  static VALUE
211
212
  packet_in_is_vtag( VALUE self ) {
@@ -219,9 +220,9 @@ packet_in_is_vtag( VALUE self ) {
219
220
 
220
221
 
221
222
  /*
222
- * The vlan tpid.
223
+ * The vlan tag protocol identifier (tpid).
223
224
  *
224
- * @return [integer] vlan_tpid The vlan tpid
225
+ * @return [Integer] the value of the vlan tag protocol identifier.
225
226
  */
226
227
  static VALUE
227
228
  packet_in_vlan_tpid( VALUE self ) {
@@ -230,9 +231,9 @@ packet_in_vlan_tpid( VALUE self ) {
230
231
 
231
232
 
232
233
  /*
233
- * The vlan tci.
234
+ * The vlan tag control identifier (tci).
234
235
  *
235
- * @return [integer] vlan_tci The vlan tci
236
+ * @return [Integer] the value of the vlan tag control identifier.
236
237
  */
237
238
  static VALUE
238
239
  packet_in_vlan_tci( VALUE self ) {
@@ -241,9 +242,9 @@ packet_in_vlan_tci( VALUE self ) {
241
242
 
242
243
 
243
244
  /*
244
- * The vlan prio.
245
+ * The vlan priority.
245
246
  *
246
- * @return [integer] vlan_prio The vlan prio
247
+ * @return [Integer] the value of the vlan priority.
247
248
  */
248
249
  static VALUE
249
250
  packet_in_vlan_prio( VALUE self ) {
@@ -252,9 +253,9 @@ packet_in_vlan_prio( VALUE self ) {
252
253
 
253
254
 
254
255
  /*
255
- * The vlan cfi.
256
+ * The vlan canonical format indicator (cfi).
256
257
  *
257
- * @return [integer] vlan_cfi The vlan cfi
258
+ * @return [Integer] the value of the vlan canonical format indicator.
258
259
  */
259
260
  static VALUE
260
261
  packet_in_vlan_cfi( VALUE self ) {
@@ -263,9 +264,9 @@ packet_in_vlan_cfi( VALUE self ) {
263
264
 
264
265
 
265
266
  /*
266
- * The vlan vid.
267
+ * The vlan identifier.
267
268
  *
268
- * @return [integer] vlan_vid The vlan vid
269
+ * @return [Integer] the value of the vlan identifier.
269
270
  */
270
271
  static VALUE
271
272
  packet_in_vlan_vid( VALUE self ) {
@@ -274,9 +275,9 @@ packet_in_vlan_vid( VALUE self ) {
274
275
 
275
276
 
276
277
  /*
277
- * Is an ARP packet?
278
+ * Is it an ARP packet?
278
279
  *
279
- * @return [bool] arp? Is an ARP packet?
280
+ * @return [Boolean] whether the packet is an ARP packet or not.
280
281
  */
281
282
  static VALUE
282
283
  packet_in_is_arp( VALUE self ) {
@@ -290,9 +291,9 @@ packet_in_is_arp( VALUE self ) {
290
291
 
291
292
 
292
293
  /*
293
- * Is an ARP request packet?
294
+ * Is it an ARP request packet?
294
295
  *
295
- * @return [bool] arp_request? Is an ARP request packet?
296
+ * @return [Boolean] whether the packet is an ARP request packet or not.
296
297
  */
297
298
  static VALUE
298
299
  packet_in_is_arp_request( VALUE self ) {
@@ -306,9 +307,9 @@ packet_in_is_arp_request( VALUE self ) {
306
307
 
307
308
 
308
309
  /*
309
- * Is an ARP reply packet?
310
+ * Is it an ARP reply packet?
310
311
  *
311
- * @return [bool] arp_reply? Is an ARP reply packet?
312
+ * @return [Boolean] whether the packet is an ARP reply packet or not.
312
313
  */
313
314
  static VALUE
314
315
  packet_in_is_arp_reply( VALUE self ) {
@@ -324,7 +325,7 @@ packet_in_is_arp_reply( VALUE self ) {
324
325
  /*
325
326
  * The ARP operation code.
326
327
  *
327
- * @return [integer] arp_oper Operation code.
328
+ * @return [Integer] the value of the ARP opcode field.
328
329
  */
329
330
  static VALUE
330
331
  packet_in_arp_oper( VALUE self ) {
@@ -333,9 +334,11 @@ packet_in_arp_oper( VALUE self ) {
333
334
 
334
335
 
335
336
  /*
336
- * The ARP source hardware address.
337
+ * The ARP source hardware address of a packet.
337
338
  *
338
- * @return [Trema::Mac] arp_sha MAC hardware address.
339
+ * @return [Trema::Mac, nil]
340
+ * the value of the ARP source hardware address as a Trema::Mac object or nil
341
+ * if packet not an ARP.
339
342
  */
340
343
  static VALUE
341
344
  packet_in_arp_sha( VALUE self ) {
@@ -349,9 +352,11 @@ packet_in_arp_sha( VALUE self ) {
349
352
 
350
353
 
351
354
  /*
352
- * The ARP source protocol address.
355
+ * The ARP source protocol address of a packet.
353
356
  *
354
- * @return [Trema::IP] arp_spa IP protocol address.
357
+ * @return [Trema::IP, nil]
358
+ * the value of ARP source protocol address as a Trema::IP object or nil if
359
+ * packet is not an ARP.
355
360
  */
356
361
  static VALUE
357
362
  packet_in_arp_spa( VALUE self ) {
@@ -365,9 +370,11 @@ packet_in_arp_spa( VALUE self ) {
365
370
 
366
371
 
367
372
  /*
368
- * The ARP target hardware address.
373
+ * The ARP target hardware address of a packet.
369
374
  *
370
- * @return [Trema::Mac] arp_tha MAC hardware address.
375
+ * @return [Trema::Mac]
376
+ * the value of ARP target hardware address as a Trema::Mac object or nil if
377
+ * packet is not an ARP.
371
378
  */
372
379
  static VALUE
373
380
  packet_in_arp_tha( VALUE self ) {
@@ -381,9 +388,11 @@ packet_in_arp_tha( VALUE self ) {
381
388
 
382
389
 
383
390
  /*
384
- * The ARP target protocol address.
391
+ * The ARP target protocol address of a packet.
385
392
  *
386
- * @return [Trema::IP] arp_tpa IP protocol address.
393
+ * @return [Trema::IP]
394
+ * the value of ARP target protocol address as a Trema::IP object or nil if
395
+ * packet is not an ARP.
387
396
  */
388
397
  static VALUE
389
398
  packet_in_arp_tpa( VALUE self ) {
@@ -397,9 +406,9 @@ packet_in_arp_tpa( VALUE self ) {
397
406
 
398
407
 
399
408
  /*
400
- * Is an IPV4 packet?
409
+ * Is it an IPv4 packet?
401
410
  *
402
- * @return [bool] ipv4? Is an IPV4 packet?
411
+ * @return [Boolean] whether the packet is an IPv4 packet or not.
403
412
  */
404
413
  static VALUE
405
414
  packet_in_is_ipv4( VALUE self ) {
@@ -413,9 +422,9 @@ packet_in_is_ipv4( VALUE self ) {
413
422
 
414
423
 
415
424
  /*
416
- * The IPv4 version number.
425
+ * The IPv4 version number (version).
417
426
  *
418
- * @return [Integer] ipv4_version The IPv4 version number.
427
+ * @return [Integer] the value of IPv4 version number.
419
428
  */
420
429
  static VALUE
421
430
  packet_in_ipv4_version( VALUE self ) {
@@ -424,9 +433,9 @@ packet_in_ipv4_version( VALUE self ) {
424
433
 
425
434
 
426
435
  /*
427
- * The IPv4 internet header length.
436
+ * The IPv4 internet header length (ihl).
428
437
  *
429
- * @return [Integer] ipv4_ihl The IPv4 internet header length.
438
+ * @return [Integer] the value of IPv4 internet header length.
430
439
  */
431
440
  static VALUE
432
441
  packet_in_ipv4_ihl( VALUE self ) {
@@ -435,9 +444,9 @@ packet_in_ipv4_ihl( VALUE self ) {
435
444
 
436
445
 
437
446
  /*
438
- * The IPv4 tos value.
447
+ * The IPv4 type of service (tos).
439
448
  *
440
- * @return [Integer] ipv4_tos The IPv4 tos value.
449
+ * @return [Integer] the value of IPv4 type of service.
441
450
  */
442
451
  static VALUE
443
452
  packet_in_ipv4_tos( VALUE self ) {
@@ -446,9 +455,9 @@ packet_in_ipv4_tos( VALUE self ) {
446
455
 
447
456
 
448
457
  /*
449
- * The IPv4 total length.
458
+ * The IPv4 total length, the length of the datagram.
450
459
  *
451
- * @return [Integer] ipv4_tot_len The IPv4 total length.
460
+ * @return [Integer] the value of IPv4 total length.
452
461
  */
453
462
  static VALUE
454
463
  packet_in_ipv4_tot_len( VALUE self ) {
@@ -457,9 +466,9 @@ packet_in_ipv4_tot_len( VALUE self ) {
457
466
 
458
467
 
459
468
  /*
460
- * The IPv4 identifier.
469
+ * The IPv4 identification.
461
470
  *
462
- * @return [Integer] ipv4_id The IPv4 identifier.
471
+ * @return [Integer] the value of IPv4 identification.
463
472
  */
464
473
  static VALUE
465
474
  packet_in_ipv4_id( VALUE self ) {
@@ -470,7 +479,7 @@ packet_in_ipv4_id( VALUE self ) {
470
479
  /*
471
480
  * The IPv4 fragment offset.
472
481
  *
473
- * @return [Integer] ipv4_frag_off The IPv4 fragment offset.
482
+ * @return [Integer] the value of IPv4 fragment offset.
474
483
  */
475
484
  static VALUE
476
485
  packet_in_ipv4_frag_off( VALUE self ) {
@@ -479,9 +488,9 @@ packet_in_ipv4_frag_off( VALUE self ) {
479
488
 
480
489
 
481
490
  /*
482
- * The IPv4 ttl value.
491
+ * The IPv4 time to live (ttl).
483
492
  *
484
- * @return [Integer] ipv4_ttl The IPv4 ttl value.
493
+ * @return [Integer] the value of IPv4 time to live.
485
494
  */
486
495
  static VALUE
487
496
  packet_in_ipv4_ttl( VALUE self ) {
@@ -492,7 +501,7 @@ packet_in_ipv4_ttl( VALUE self ) {
492
501
  /*
493
502
  * The IPv4 protocol number.
494
503
  *
495
- * @return [Integer] ipv4_protocol The IPv4 protocol number.
504
+ * @return [Integer] the value of IPv4 protocol number.
496
505
  */
497
506
  static VALUE
498
507
  packet_in_ipv4_protocol( VALUE self ) {
@@ -503,7 +512,7 @@ packet_in_ipv4_protocol( VALUE self ) {
503
512
  /*
504
513
  * The IPv4 checksum.
505
514
  *
506
- * @return [Integer] ipv4_checksum The IPv4 checksum.
515
+ * @return [Integer] the value of IPv4 checksum.
507
516
  */
508
517
  static VALUE
509
518
  packet_in_ipv4_checksum( VALUE self ) {
@@ -512,9 +521,11 @@ packet_in_ipv4_checksum( VALUE self ) {
512
521
 
513
522
 
514
523
  /*
515
- * The IPV4 source protocol address.
524
+ * The IPv4 source IP address of a packet.
516
525
  *
517
- * @return [Trema::IP] ipv4_saddr IP protocol address.
526
+ * @return [Trema::IP,nil]
527
+ * the value of IPv4 source IP address as a Trema::IP object or nil if
528
+ * packet is not an IPv4.
518
529
  */
519
530
  static VALUE
520
531
  packet_in_ipv4_saddr( VALUE self ) {
@@ -528,9 +539,11 @@ packet_in_ipv4_saddr( VALUE self ) {
528
539
 
529
540
 
530
541
  /*
531
- * The IPV4 destination protocol address.
542
+ * The IPV4 destination IP address of a packet.
532
543
  *
533
- * @return [Trema::IP] ipv4_daddr IP protocol address.
544
+ * @return [Trema::IP, nil]
545
+ * the value of IPv4 destination IP address as a Trema::IP object or nil if
546
+ * packet is not an IPv4.
534
547
  */
535
548
  static VALUE
536
549
  packet_in_ipv4_daddr( VALUE self ) {
@@ -544,9 +557,9 @@ packet_in_ipv4_daddr( VALUE self ) {
544
557
 
545
558
 
546
559
  /*
547
- * Is an ICMPv4 packet?
560
+ * Is it an ICMPv4 packet?
548
561
  *
549
- * @return [bool] icmpv4? Is an ICMPv4 packet?
562
+ * @return [Boolean] whether the packet is an ICMPv4 packet or not.
550
563
  */
551
564
  static VALUE
552
565
  packet_in_is_icmpv4( VALUE self ) {
@@ -560,9 +573,9 @@ packet_in_is_icmpv4( VALUE self ) {
560
573
 
561
574
 
562
575
  /*
563
- * The ICMPv4 message type.
576
+ * The ICMPv4 message type, ie echo_reply, echo_request.
564
577
  *
565
- * @return [Integer] icmpv4_type The ICMPv4 message type.
578
+ * @return [Integer] the value of ICMPv4 message type.
566
579
  */
567
580
  static VALUE
568
581
  packet_in_icmpv4_type( VALUE self ) {
@@ -571,9 +584,9 @@ packet_in_icmpv4_type( VALUE self ) {
571
584
 
572
585
 
573
586
  /*
574
- * The ICMPv4 message code.
587
+ * The ICMPv4 message code the further qualifies the message type.
575
588
  *
576
- * @return [Integer] icmpv4_code The ICMPv4 message code.
589
+ * @return [Integer] the value of ICMPv4 message code.
577
590
  */
578
591
  static VALUE
579
592
  packet_in_icmpv4_code( VALUE self ) {
@@ -584,7 +597,7 @@ packet_in_icmpv4_code( VALUE self ) {
584
597
  /*
585
598
  * The ICMPv4 message checksum.
586
599
  *
587
- * @return [Integer] icmpv4_checksum The ICMPv4 message checksum.
600
+ * @return [Integer] the value of ICMPv4 message checksum.
588
601
  */
589
602
  static VALUE
590
603
  packet_in_icmpv4_checksum( VALUE self ) {
@@ -593,9 +606,9 @@ packet_in_icmpv4_checksum( VALUE self ) {
593
606
 
594
607
 
595
608
  /*
596
- * The identifier of ICMPv4 echo.
609
+ * The ICMPv4 echo identifier to be used to match echo requests to echo replies.
597
610
  *
598
- * @return [Integer] icmpv4_id The identifier of ICMPv4 echo.
611
+ * @return [Integer] the value of ICMPv4 echo identifier.
599
612
  */
600
613
  static VALUE
601
614
  packet_in_icmpv4_id( VALUE self ) {
@@ -604,9 +617,9 @@ packet_in_icmpv4_id( VALUE self ) {
604
617
 
605
618
 
606
619
  /*
607
- * The sequence number of ICMPv4 echo.
620
+ * The ICMPv4 echo sequence number.
608
621
  *
609
- * @return [Integer] icmpv4_id The sequence number of ICMPv4 echo.
622
+ * @return [Integer] the value of ICMPv4 echo sequence number.
610
623
  */
611
624
  static VALUE
612
625
  packet_in_icmpv4_seq( VALUE self ) {
@@ -615,9 +628,11 @@ packet_in_icmpv4_seq( VALUE self ) {
615
628
 
616
629
 
617
630
  /*
618
- * The gateway address of ICMPv4 redicect.
631
+ * The ICMPv4 redirect message gateway IP address.
619
632
  *
620
- * @return [Trema::IP] icmp_gateway The gateway address of ICMPv4 redicect.
633
+ * @return [Trema::IP, nil]
634
+ * the value of ICMPv4 redirect message IP gateway address as a Trema::IP
635
+ * object or nil if packet is not ICMPv4.
621
636
  */
622
637
  static VALUE
623
638
  packet_in_icmpv4_gateway( VALUE self ) {
@@ -631,9 +646,9 @@ packet_in_icmpv4_gateway( VALUE self ) {
631
646
 
632
647
 
633
648
  /*
634
- * Is an ICMPv4 echo reply packet?
649
+ * Is it an ICMPv4 echo reply packet?
635
650
  *
636
- * @return [bool] icmpv4_echo_reply? Is an ICMP echo reply packet?
651
+ * @return [Boolean] whether the packet is an ICMPv4 echo reply packet or not.
637
652
  */
638
653
  static VALUE
639
654
  packet_in_is_icmpv4_echo_reply( VALUE self ) {
@@ -647,9 +662,10 @@ packet_in_is_icmpv4_echo_reply( VALUE self ) {
647
662
 
648
663
 
649
664
  /*
650
- * Is an ICMPv4 destination unreachable packet?
665
+ * Is it an ICMPv4 destination unreachable packet?
651
666
  *
652
- * @return [bool] icmpv4_dst_unreach? Is an ICMP destination unreachable packet?
667
+ * @return [Boolean] whether the packet is an ICMPv4 destination
668
+ * unreachable packet or not.
653
669
  */
654
670
  static VALUE
655
671
  packet_in_is_icmpv4_dst_unreach( VALUE self ) {
@@ -663,9 +679,9 @@ packet_in_is_icmpv4_dst_unreach( VALUE self ) {
663
679
 
664
680
 
665
681
  /*
666
- * Is an ICMPv4 redirect packet?
682
+ * Is it an ICMPv4 redirect packet?
667
683
  *
668
- * @return [bool] icmpv4_redirect? Is an ICMP redirect packet?
684
+ * @return [Boolean] whether the packet is an ICMPv4 redirect packet or not.
669
685
  */
670
686
  static VALUE
671
687
  packet_in_is_icmpv4_redirect( VALUE self ) {
@@ -679,9 +695,9 @@ packet_in_is_icmpv4_redirect( VALUE self ) {
679
695
 
680
696
 
681
697
  /*
682
- * Is an ICMPv4 echo request packet?
698
+ * Is it an ICMPv4 echo request packet?
683
699
  *
684
- * @return [bool] icmpv4_echo_request? Is an ICMP echo request packet?
700
+ * @return [Boolean] whether the packet is an ICMPv4 echo request packet or not.
685
701
  */
686
702
  static VALUE
687
703
  packet_in_is_icmpv4_echo_request( VALUE self ) {
@@ -695,9 +711,9 @@ packet_in_is_icmpv4_echo_request( VALUE self ) {
695
711
 
696
712
 
697
713
  /*
698
- * Is an IGMP packet?
714
+ * Is it an IGMP packet?
699
715
  *
700
- * @return [bool] igmp? Is an IGMP packet?
716
+ * @return [Boolean] whether the packet is an IGMP packet or not.
701
717
  */
702
718
  static VALUE
703
719
  packet_in_is_igmp( VALUE self ) {
@@ -711,9 +727,10 @@ packet_in_is_igmp( VALUE self ) {
711
727
 
712
728
 
713
729
  /*
714
- * Is an IGMP membership query packet?
730
+ * Is it an IGMP membership query packet?
715
731
  *
716
- * @return [bool] igmp_membership_query? Is an IGMP membership query packet?
732
+ * @return [Boolean] whether the packet is an IGMP membership query
733
+ * packet or not.
717
734
  */
718
735
  static VALUE
719
736
  packet_in_is_igmp_membership_query( VALUE self ) {
@@ -727,9 +744,10 @@ packet_in_is_igmp_membership_query( VALUE self ) {
727
744
 
728
745
 
729
746
  /*
730
- * Is an IGMP v1 membership report packet?
747
+ * Is it an IGMP v1 membership report packet?
731
748
  *
732
- * @return [bool] igmp_v1_membership_report? Is an IGMP v1 membership report packet?
749
+ * @return [Boolean] whether the packet is an IGMP v1 membership report packet
750
+ * or not.
733
751
  */
734
752
  static VALUE
735
753
  packet_in_is_igmp_v1_membership_report( VALUE self ) {
@@ -743,9 +761,10 @@ packet_in_is_igmp_v1_membership_report( VALUE self ) {
743
761
 
744
762
 
745
763
  /*
746
- * Is an IGMP v2 membership report packet?
764
+ * Is it an IGMP v2 membership report packet?
747
765
  *
748
- * @return [bool] igmp_v2_membership_report? Is an IGMP v2 membership report packet?
766
+ * @return [Boolean] whether the packet is an IGMP v2 membership report packet
767
+ * or not.
749
768
  */
750
769
  static VALUE
751
770
  packet_in_is_igmp_v2_membership_report( VALUE self ) {
@@ -759,9 +778,10 @@ packet_in_is_igmp_v2_membership_report( VALUE self ) {
759
778
 
760
779
 
761
780
  /*
762
- * Is an IGMP v2 leave group packet?
781
+ * Is it an IGMP v2 leave group packet?
763
782
  *
764
- * @return [bool] igmp_v2_leave_group? Is an IGMP v2 leave group packet?
783
+ * @return [Boolean] whether the packet is an IGMP v2 leave group packet
784
+ * or not.
765
785
  */
766
786
  static VALUE
767
787
  packet_in_is_igmp_v2_leave_group( VALUE self ) {
@@ -775,9 +795,10 @@ packet_in_is_igmp_v2_leave_group( VALUE self ) {
775
795
 
776
796
 
777
797
  /*
778
- * Is an IGMP v3 membership report packet?
798
+ * Is it an IGMP v3 membership report packet?
779
799
  *
780
- * @return [bool] igmp_v3_membership_report? Is an IGMP v3 membership report packet?
800
+ * @return [Boolean] whether the packet is an IGMP v3 membership report packet
801
+ * or not.
781
802
  */
782
803
  static VALUE
783
804
  packet_in_is_igmp_v3_membership_report( VALUE self ) {
@@ -793,7 +814,7 @@ packet_in_is_igmp_v3_membership_report( VALUE self ) {
793
814
  /*
794
815
  * The IGMP message type.
795
816
  *
796
- * @return [Integer] igmp_type IGMP type.
817
+ * @return [Integer] the value of IGMP message type.
797
818
  */
798
819
  static VALUE
799
820
  packet_in_igmp_type( VALUE self ) {
@@ -804,7 +825,9 @@ packet_in_igmp_type( VALUE self ) {
804
825
  /*
805
826
  * The IGMP group address.
806
827
  *
807
- * @return [Trema::IP] igmp_group an IGMP group address.
828
+ * @return [Trema::IP, nil]
829
+ * the value of IGMP IP group address as a Trema::IP object
830
+ * or nil if packet is not IGMP.
808
831
  */
809
832
  static VALUE
810
833
  packet_in_igmp_group( VALUE self ) {
@@ -820,7 +843,7 @@ packet_in_igmp_group( VALUE self ) {
820
843
  /*
821
844
  * The IGMP checksum.
822
845
  *
823
- * @return [Integer] igmp_checksum a IGMP checksum.
846
+ * @return [Integer] the value of IGMP checksum.
824
847
  */
825
848
  static VALUE
826
849
  packet_in_igmp_checksum( VALUE self ) {
@@ -829,9 +852,9 @@ packet_in_igmp_checksum( VALUE self ) {
829
852
 
830
853
 
831
854
  /*
832
- * Is a TCP packet?
855
+ * Is it a TCP packet?
833
856
  *
834
- * @return [bool] tcp? Is a TCP packet?
857
+ * @return [Boolean] whether the packet is a TCP packet or not.
835
858
  */
836
859
  static VALUE
837
860
  packet_in_is_tcp( VALUE self ) {
@@ -847,7 +870,7 @@ packet_in_is_tcp( VALUE self ) {
847
870
  /*
848
871
  * The TCP source port.
849
872
  *
850
- * @return [Integer] tcp_src_port TCP port.
873
+ * @return [Integer] the value of TCP source port.
851
874
  */
852
875
  static VALUE
853
876
  packet_in_tcp_src_port( VALUE self ) {
@@ -858,7 +881,7 @@ packet_in_tcp_src_port( VALUE self ) {
858
881
  /*
859
882
  * The TCP destination port.
860
883
  *
861
- * @return [Integer] tcp_dst_port TCP port.
884
+ * @return [Integer] the value of TCP destination port.
862
885
  */
863
886
  static VALUE
864
887
  packet_in_tcp_dst_port( VALUE self ) {
@@ -869,7 +892,7 @@ packet_in_tcp_dst_port( VALUE self ) {
869
892
  /*
870
893
  * The TCP sequence number.
871
894
  *
872
- * @return [Integer] tcp_seq_no a TCP sequence number.
895
+ * @return [Integer] the value of TCP sequence number.
873
896
  */
874
897
  static VALUE
875
898
  packet_in_tcp_seq_no( VALUE self ) {
@@ -878,9 +901,9 @@ packet_in_tcp_seq_no( VALUE self ) {
878
901
 
879
902
 
880
903
  /*
881
- * The TCP acknowledge number.
904
+ * The TCP acknowledgment number.
882
905
  *
883
- * @return [Integer] tcp_ack_no a TCP acknowkedge number.
906
+ * @return [Integer] the value of TCP acknowledgment number.
884
907
  */
885
908
  static VALUE
886
909
  packet_in_tcp_ack_no( VALUE self ) {
@@ -889,9 +912,9 @@ packet_in_tcp_ack_no( VALUE self ) {
889
912
 
890
913
 
891
914
  /*
892
- * The TCP offset.
915
+ * The TCP data offset.
893
916
  *
894
- * @return [Integer] tcp_offset a TCP offset.
917
+ * @return [Integer] the value of TCP data offset.
895
918
  */
896
919
  static VALUE
897
920
  packet_in_tcp_offset( VALUE self ) {
@@ -902,7 +925,7 @@ packet_in_tcp_offset( VALUE self ) {
902
925
  /*
903
926
  * The TCP flags.
904
927
  *
905
- * @return [Integer] tcp_flags TCP flags.
928
+ * @return [Integer] the value of TCP flags.
906
929
  */
907
930
  static VALUE
908
931
  packet_in_tcp_flags( VALUE self ) {
@@ -913,7 +936,7 @@ packet_in_tcp_flags( VALUE self ) {
913
936
  /*
914
937
  * The TCP window.
915
938
  *
916
- * @return [Integer] tcp_window a TCP window.
939
+ * @return [Integer] the value of TCP window.
917
940
  */
918
941
  static VALUE
919
942
  packet_in_tcp_window( VALUE self ) {
@@ -924,7 +947,7 @@ packet_in_tcp_window( VALUE self ) {
924
947
  /*
925
948
  * The TCP checksum.
926
949
  *
927
- * @return [Integer] tcp_checksum a TCP checksum.
950
+ * @return [Integer] the value of TCP checksum.
928
951
  */
929
952
  static VALUE
930
953
  packet_in_tcp_checksum( VALUE self ) {
@@ -933,9 +956,9 @@ packet_in_tcp_checksum( VALUE self ) {
933
956
 
934
957
 
935
958
  /*
936
- * The TCP urgent.
959
+ * The TCP urgent pointer.
937
960
  *
938
- * @return [Integer] tcp_urgent a TCP urgent.
961
+ * @return [Integer] the value of TCP urgent pointer.
939
962
  */
940
963
  static VALUE
941
964
  packet_in_tcp_urgent( VALUE self ) {
@@ -944,9 +967,9 @@ packet_in_tcp_urgent( VALUE self ) {
944
967
 
945
968
 
946
969
  /*
947
- * Is an UDP packet?
970
+ * Is it a UDP packet?
948
971
  *
949
- * @return [bool] udp? Is an UDP packet?
972
+ * @return [Boolean] whether the packet is a UDP packet or not.
950
973
  */
951
974
  static VALUE
952
975
  packet_in_is_udp( VALUE self ) {
@@ -975,7 +998,7 @@ packet_in_udp_payload( VALUE self ) {
975
998
  /*
976
999
  * The UDP source port.
977
1000
  *
978
- * @return [Integer] udp_src_port UDP port.
1001
+ * @return [Integer] the value of UDP source port.
979
1002
  */
980
1003
  static VALUE
981
1004
  packet_in_udp_src_port( VALUE self ) {
@@ -986,7 +1009,7 @@ packet_in_udp_src_port( VALUE self ) {
986
1009
  /*
987
1010
  * The UDP destination port.
988
1011
  *
989
- * @return [Integer] udp_dst_port UDP port.
1012
+ * @return [Integer] the value of UDP destination port.
990
1013
  */
991
1014
  static VALUE
992
1015
  packet_in_udp_dst_port( VALUE self ) {
@@ -995,9 +1018,9 @@ packet_in_udp_dst_port( VALUE self ) {
995
1018
 
996
1019
 
997
1020
  /*
998
- * The UDP length.
1021
+ * The UDP length
999
1022
  *
1000
- * @return [Integer] udp_len a UDP length.
1023
+ * @return [Integer] the value in bytes of UDP header and data.
1001
1024
  */
1002
1025
  static VALUE
1003
1026
  packet_in_udp_len( VALUE self ) {
@@ -1008,7 +1031,7 @@ packet_in_udp_len( VALUE self ) {
1008
1031
  /*
1009
1032
  * The UDP checksum.
1010
1033
  *
1011
- * @return [Integer] udp_checksum a UDP checksum.
1034
+ * @return [Integer] the value of UDP checksum.
1012
1035
  */
1013
1036
  static VALUE
1014
1037
  packet_in_udp_checksum( VALUE self ) {