pio 0.30.0 → 0.30.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (535) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +6 -53
  4. data/Rakefile +8 -6
  5. data/features/{arp.feature → arp/arp.feature} +14 -30
  6. data/features/arp/arp_reply.feature +69 -0
  7. data/features/arp/arp_request.feature +67 -0
  8. data/features/dhcp.feature +157 -162
  9. data/features/ethernet_header.feature +149 -0
  10. data/features/icmp/icmp.feature +47 -0
  11. data/features/icmp/icmp_reply.feature +93 -0
  12. data/features/icmp/icmp_request.feature +89 -0
  13. data/features/ipv4_header.feature +89 -0
  14. data/features/lldp.feature +5 -8
  15. data/features/open_flow/header.feature +13 -0
  16. data/features/open_flow/nicira_resubmit.feature +4 -22
  17. data/features/open_flow/nicira_resubmit_table.feature +6 -16
  18. data/features/open_flow10/aggregate_stats_reply.feature +5 -7
  19. data/features/open_flow10/aggregate_stats_request.feature +12 -14
  20. data/features/open_flow10/bad_request.feature +7 -24
  21. data/features/open_flow10/barrier_reply.feature +14 -25
  22. data/features/open_flow10/barrier_request.feature +12 -25
  23. data/features/open_flow10/description_stats_reply.feature +9 -7
  24. data/features/open_flow10/description_stats_request.feature +12 -25
  25. data/features/open_flow10/echo_reply.feature +14 -35
  26. data/features/open_flow10/echo_request.feature +16 -39
  27. data/features/open_flow10/enqueue.feature +3 -4
  28. data/features/open_flow10/exact_match.feature +5 -5
  29. data/features/open_flow10/features_reply.feature +28 -73
  30. data/features/open_flow10/features_request.feature +10 -28
  31. data/features/open_flow10/flow_mod.feature +4 -188
  32. data/features/open_flow10/flow_removed.feature +28 -30
  33. data/features/open_flow10/flow_stats_reply.feature +5 -89
  34. data/features/open_flow10/flow_stats_request.feature +12 -42
  35. data/features/open_flow10/hello.feature +10 -32
  36. data/features/open_flow10/hello_failed.feature +7 -57
  37. data/features/open_flow10/packet_in.feature +130 -49
  38. data/features/open_flow10/packet_out.feature +29 -18
  39. data/features/open_flow10/port_stats_request.feature +8 -29
  40. data/features/open_flow10/port_status.feature +22 -21
  41. data/features/open_flow10/queue_stats_request.feature +12 -30
  42. data/features/open_flow10/send_out_port.feature +17 -25
  43. data/features/open_flow10/set_destination_mac_address.feature +3 -4
  44. data/features/open_flow10/set_ip_destination_address.feature +3 -4
  45. data/features/open_flow10/set_source_ip_address.feature +3 -4
  46. data/features/open_flow10/set_source_mac_address.feature +3 -4
  47. data/features/open_flow10/set_tos.feature +3 -4
  48. data/features/open_flow10/set_transport_destination_port.feature +3 -4
  49. data/features/open_flow10/set_transport_source_port.feature +3 -4
  50. data/features/open_flow10/set_vlan_priority.feature +3 -4
  51. data/features/open_flow10/set_vlan_vid.feature +3 -4
  52. data/features/open_flow10/strip_vlan_header.feature +3 -4
  53. data/features/open_flow10/table_stats_request.feature +11 -13
  54. data/features/open_flow10/vendor_action.feature +4 -5
  55. data/features/open_flow13/apply_actions.feature +15 -18
  56. data/features/open_flow13/bad_request.feature +7 -13
  57. data/features/open_flow13/copy_ttl_inwards.feature +13 -0
  58. data/features/open_flow13/copy_ttl_outwards.feature +13 -0
  59. data/features/open_flow13/decrement_ip_ttl.feature +11 -0
  60. data/features/open_flow13/echo_reply.feature +16 -42
  61. data/features/open_flow13/echo_request.feature +16 -42
  62. data/features/open_flow13/features_reply.feature +4 -25
  63. data/features/open_flow13/features_request.feature +7 -36
  64. data/features/open_flow13/flow_mod.feature +16 -76
  65. data/features/open_flow13/goto_table.feature +18 -20
  66. data/features/open_flow13/hello.feature +7 -37
  67. data/features/open_flow13/hello_failed.feature +7 -30
  68. data/features/open_flow13/match.feature +239 -248
  69. data/features/open_flow13/meter.feature +18 -20
  70. data/features/open_flow13/nicira_conjunction.feature +15 -0
  71. data/features/open_flow13/nicira_reg_load.feature +27 -42
  72. data/features/open_flow13/nicira_reg_move.feature +41 -35
  73. data/features/open_flow13/nicira_send_out_port.feature +21 -13
  74. data/features/open_flow13/nicira_stack_pop.feature +26 -0
  75. data/features/open_flow13/nicira_stack_push.feature +26 -0
  76. data/features/open_flow13/packet_in.feature +7 -34
  77. data/features/open_flow13/packet_out.feature +7 -45
  78. data/features/open_flow13/send_out_port.feature +19 -28
  79. data/features/open_flow13/set_arp_operation.feature +4 -5
  80. data/features/open_flow13/set_arp_sender_hardware_address.feature +3 -4
  81. data/features/open_flow13/set_arp_sender_protocol_address.feature +3 -4
  82. data/features/open_flow13/set_destination_mac_address.feature +3 -4
  83. data/features/open_flow13/set_ip_ttl.feature +12 -0
  84. data/features/open_flow13/set_metadata.feature +3 -4
  85. data/features/open_flow13/set_source_mac_address.feature +3 -4
  86. data/features/open_flow13/stats_request.feature +4 -7
  87. data/features/open_flow13/write_metadata.feature +20 -22
  88. data/features/open_flow_read.feature +24 -5
  89. data/features/open_flow_version.feature +1 -1
  90. data/features/parser.feature +8 -9
  91. data/features/step_definitions/Gemfile +2 -0
  92. data/features/step_definitions/Guardfile +2 -0
  93. data/features/step_definitions/Rakefile +2 -0
  94. data/features/step_definitions/dump_flows_steps.rb +2 -0
  95. data/features/step_definitions/open_flow_steps.rb +13 -16
  96. data/features/step_definitions/packet_data_steps.rb +19 -33
  97. data/features/step_definitions/rest_api_steps.rb +2 -0
  98. data/features/step_definitions/ruby_steps.rb +9 -0
  99. data/features/step_definitions/show_stats_steps.rb +5 -3
  100. data/features/step_definitions/trema_steps.rb +2 -0
  101. data/features/step_definitions/virtual_link_steps.rb +2 -0
  102. data/features/support/env.rb +2 -2
  103. data/features/support/hooks.rb +4 -2
  104. data/features/udp.feature +26 -27
  105. data/lib/pio/arp/format.rb +5 -7
  106. data/lib/pio/arp/message.rb +10 -4
  107. data/lib/pio/arp/reply.rb +11 -32
  108. data/lib/pio/arp/request.rb +11 -33
  109. data/lib/pio/arp.rb +11 -6
  110. data/lib/pio/class_inspector.rb +20 -0
  111. data/lib/pio/dhcp/ack.rb +2 -0
  112. data/lib/pio/dhcp/boot_reply.rb +2 -0
  113. data/lib/pio/dhcp/boot_reply_options.rb +2 -0
  114. data/lib/pio/dhcp/boot_request.rb +2 -0
  115. data/lib/pio/dhcp/boot_request_options.rb +2 -0
  116. data/lib/pio/dhcp/client_id.rb +2 -0
  117. data/lib/pio/dhcp/common_options.rb +2 -0
  118. data/lib/pio/dhcp/dhcp_field.rb +2 -0
  119. data/lib/pio/dhcp/dhcp_tlv_options.rb +30 -20
  120. data/lib/pio/dhcp/discover.rb +2 -0
  121. data/lib/pio/dhcp/field_util.rb +3 -1
  122. data/lib/pio/dhcp/frame.rb +6 -4
  123. data/lib/pio/dhcp/message.rb +2 -0
  124. data/lib/pio/dhcp/offer.rb +2 -0
  125. data/lib/pio/dhcp/optional_tlv.rb +4 -2
  126. data/lib/pio/dhcp/parameter_list.rb +2 -0
  127. data/lib/pio/dhcp/request.rb +2 -0
  128. data/lib/pio/dhcp.rb +4 -2
  129. data/lib/pio/ethernet_frame.rb +22 -0
  130. data/lib/pio/ethernet_header.rb +37 -13
  131. data/lib/pio/icmp/format.rb +21 -22
  132. data/lib/pio/icmp/message.rb +20 -4
  133. data/lib/pio/icmp/reply.rb +10 -34
  134. data/lib/pio/icmp/request.rb +10 -43
  135. data/lib/pio/icmp.rb +10 -5
  136. data/lib/pio/instance_inspector.rb +16 -0
  137. data/lib/pio/ipv4_address.rb +13 -11
  138. data/lib/pio/ipv4_header.rb +26 -2
  139. data/lib/pio/lldp/chassis_id_tlv.rb +2 -0
  140. data/lib/pio/lldp/end_of_lldpdu_value.rb +2 -0
  141. data/lib/pio/lldp/frame.rb +4 -2
  142. data/lib/pio/lldp/management_address_value.rb +2 -0
  143. data/lib/pio/lldp/optional_tlv.rb +4 -2
  144. data/lib/pio/lldp/options.rb +4 -2
  145. data/lib/pio/lldp/organizationally_specific_value.rb +2 -0
  146. data/lib/pio/lldp/port_description_value.rb +2 -0
  147. data/lib/pio/lldp/port_id_tlv.rb +2 -0
  148. data/lib/pio/lldp/system_capabilities_value.rb +2 -0
  149. data/lib/pio/lldp/system_description_value.rb +2 -0
  150. data/lib/pio/lldp/system_name_value.rb +2 -0
  151. data/lib/pio/lldp/ttl_tlv.rb +2 -0
  152. data/lib/pio/lldp.rb +2 -0
  153. data/lib/pio/mac.rb +9 -3
  154. data/lib/pio/message.rb +52 -0
  155. data/lib/pio/message_type_selector.rb +2 -0
  156. data/lib/pio/monkey_patch/bindata_record.rb +8 -0
  157. data/lib/pio/monkey_patch/bindata_string.rb +12 -0
  158. data/lib/pio/monkey_patch/integer/base_conversions.rb +3 -1
  159. data/lib/pio/monkey_patch/integer/ranges.rb +2 -0
  160. data/lib/pio/monkey_patch/integer.rb +2 -0
  161. data/lib/pio/monkey_patch/uint/base_conversions.rb +16 -0
  162. data/lib/pio/monkey_patch/uint.rb +11 -0
  163. data/lib/pio/open_flow/action.rb +10 -4
  164. data/lib/pio/open_flow/buffer_id.rb +21 -0
  165. data/lib/pio/open_flow/datapath_id.rb +5 -3
  166. data/lib/pio/open_flow/error_message.rb +34 -0
  167. data/lib/pio/open_flow/flags.rb +17 -6
  168. data/lib/pio/open_flow/flow_match.rb +12 -0
  169. data/lib/pio/open_flow/header.rb +28 -0
  170. data/lib/pio/open_flow/hello_failed_code.rb +3 -1
  171. data/lib/pio/open_flow/instruction.rb +12 -0
  172. data/lib/pio/open_flow/message.rb +51 -14
  173. data/lib/pio/open_flow/nicira_action.rb +2 -0
  174. data/lib/pio/open_flow/nicira_resubmit.rb +15 -11
  175. data/lib/pio/open_flow/nicira_resubmit_table.rb +19 -10
  176. data/lib/pio/open_flow/parser.rb +21 -0
  177. data/lib/pio/open_flow/port.rb +4 -2
  178. data/lib/pio/open_flow/transaction_id.rb +4 -2
  179. data/lib/pio/open_flow/version.rb +24 -0
  180. data/lib/pio/open_flow.rb +40 -52
  181. data/lib/pio/open_flow10/actions.rb +18 -16
  182. data/lib/pio/open_flow10/aggregate_stats/reply.rb +4 -1
  183. data/lib/pio/open_flow10/aggregate_stats/request.rb +3 -3
  184. data/lib/pio/open_flow10/barrier/reply.rb +3 -1
  185. data/lib/pio/open_flow10/barrier/request.rb +3 -1
  186. data/lib/pio/open_flow10/description_stats/reply.rb +3 -1
  187. data/lib/pio/open_flow10/description_stats/request.rb +3 -3
  188. data/lib/pio/open_flow10/echo/reply.rb +5 -3
  189. data/lib/pio/open_flow10/echo/request.rb +5 -3
  190. data/lib/pio/open_flow10/enqueue.rb +5 -3
  191. data/lib/pio/open_flow10/error/bad_request/bad_request_code.rb +37 -0
  192. data/lib/pio/open_flow10/error/bad_request.rb +7 -29
  193. data/lib/pio/open_flow10/error/error_type10.rb +3 -1
  194. data/lib/pio/open_flow10/error/hello_failed.rb +8 -4
  195. data/lib/pio/open_flow10/error.rb +5 -13
  196. data/lib/pio/open_flow10/exact_match.rb +14 -10
  197. data/lib/pio/open_flow10/features/reply.rb +35 -48
  198. data/lib/pio/open_flow10/features/request.rb +3 -4
  199. data/lib/pio/open_flow10/features.rb +2 -0
  200. data/lib/pio/open_flow10/flow_mod/command.rb +30 -0
  201. data/lib/pio/open_flow10/flow_mod.rb +10 -33
  202. data/lib/pio/open_flow10/flow_removed/reason.rb +24 -0
  203. data/lib/pio/open_flow10/flow_removed.rb +4 -17
  204. data/lib/pio/open_flow10/flow_stats/reply.rb +5 -4
  205. data/lib/pio/open_flow10/flow_stats/request.rb +3 -3
  206. data/lib/pio/open_flow10/hello.rb +3 -4
  207. data/lib/pio/open_flow10/match.rb +16 -13
  208. data/lib/pio/open_flow10/match10.rb +2 -0
  209. data/lib/pio/open_flow10/packet_in/reason.rb +27 -0
  210. data/lib/pio/open_flow10/packet_in.rb +34 -28
  211. data/lib/pio/open_flow10/packet_out.rb +7 -6
  212. data/lib/pio/open_flow10/phy_port16.rb +41 -61
  213. data/lib/pio/open_flow10/port16.rb +2 -0
  214. data/lib/pio/open_flow10/port_stats/request.rb +3 -3
  215. data/lib/pio/open_flow10/port_status/reason.rb +23 -0
  216. data/lib/pio/open_flow10/port_status.rb +25 -30
  217. data/lib/pio/open_flow10/queue_stats/request.rb +3 -3
  218. data/lib/pio/open_flow10/send_out_port.rb +4 -2
  219. data/lib/pio/open_flow10/set_destination_ip_address.rb +2 -0
  220. data/lib/pio/open_flow10/set_destination_mac_address.rb +2 -0
  221. data/lib/pio/open_flow10/set_source_ip_address.rb +2 -0
  222. data/lib/pio/open_flow10/set_source_mac_address.rb +2 -0
  223. data/lib/pio/open_flow10/set_tos.rb +4 -2
  224. data/lib/pio/open_flow10/set_transport_port.rb +6 -2
  225. data/lib/pio/open_flow10/set_vlan_priority.rb +3 -1
  226. data/lib/pio/open_flow10/set_vlan_vid.rb +3 -1
  227. data/lib/pio/open_flow10/stats_reply.rb +9 -10
  228. data/lib/pio/open_flow10/stats_request.rb +18 -15
  229. data/lib/pio/open_flow10/stats_type.rb +3 -1
  230. data/lib/pio/open_flow10/strip_vlan_header.rb +2 -0
  231. data/lib/pio/open_flow10/table_stats/request.rb +3 -3
  232. data/lib/pio/open_flow10/vendor_action.rb +24 -20
  233. data/lib/pio/open_flow10.rb +2 -0
  234. data/lib/pio/open_flow13/actions.rb +36 -32
  235. data/lib/pio/open_flow13/apply.rb +27 -22
  236. data/lib/pio/open_flow13/copy_ttl_inwards.rb +17 -0
  237. data/lib/pio/open_flow13/copy_ttl_outwards.rb +17 -0
  238. data/lib/pio/open_flow13/decrement_ip_ttl.rb +17 -0
  239. data/lib/pio/open_flow13/echo/reply.rb +5 -3
  240. data/lib/pio/open_flow13/echo/request.rb +5 -3
  241. data/lib/pio/open_flow13/error/bad_request.rb +6 -3
  242. data/lib/pio/open_flow13/error/error_type13.rb +3 -1
  243. data/lib/pio/open_flow13/error/hello_failed.rb +5 -2
  244. data/lib/pio/open_flow13/error.rb +9 -18
  245. data/lib/pio/open_flow13/features/reply.rb +15 -20
  246. data/lib/pio/open_flow13/features/request.rb +3 -1
  247. data/lib/pio/open_flow13/flow_mod.rb +16 -19
  248. data/lib/pio/open_flow13/goto_table.rb +28 -24
  249. data/lib/pio/open_flow13/hello.rb +5 -4
  250. data/lib/pio/open_flow13/match.rb +187 -21
  251. data/lib/pio/open_flow13/meter.rb +25 -20
  252. data/lib/pio/open_flow13/nicira_conjunction.rb +28 -0
  253. data/lib/pio/open_flow13/nicira_reg_load.rb +46 -24
  254. data/lib/pio/open_flow13/nicira_reg_move.rb +79 -35
  255. data/lib/pio/open_flow13/nicira_send_out_port.rb +39 -21
  256. data/lib/pio/open_flow13/nicira_stack_pop.rb +51 -0
  257. data/lib/pio/open_flow13/nicira_stack_push.rb +51 -0
  258. data/lib/pio/open_flow13/packet_in.rb +13 -8
  259. data/lib/pio/open_flow13/packet_out.rb +11 -8
  260. data/lib/pio/open_flow13/port32.rb +2 -0
  261. data/lib/pio/open_flow13/send_out_port.rb +2 -0
  262. data/lib/pio/open_flow13/set_arp_operation.rb +2 -0
  263. data/lib/pio/open_flow13/set_arp_sender_hardware_address.rb +2 -0
  264. data/lib/pio/open_flow13/set_arp_sender_protocol_address.rb +2 -0
  265. data/lib/pio/open_flow13/set_destination_mac_address.rb +2 -0
  266. data/lib/pio/open_flow13/set_ip_ttl.rb +18 -0
  267. data/lib/pio/open_flow13/set_metadata.rb +2 -0
  268. data/lib/pio/open_flow13/set_source_mac_address.rb +2 -0
  269. data/lib/pio/open_flow13/stats_request.rb +10 -10
  270. data/lib/pio/open_flow13/write_metadata.rb +42 -38
  271. data/lib/pio/open_flow13.rb +9 -0
  272. data/lib/pio/options.rb +10 -3
  273. data/lib/pio/parse_error.rb +2 -0
  274. data/lib/pio/parser.rb +9 -16
  275. data/lib/pio/payload.rb +2 -0
  276. data/lib/pio/pcap.rb +2 -0
  277. data/lib/pio/ruby_dumper.rb +71 -0
  278. data/lib/pio/type/ether_type.rb +33 -0
  279. data/lib/pio/type/ip_address.rb +10 -0
  280. data/lib/pio/type/ipv6_address.rb +2 -0
  281. data/lib/pio/type/mac_address.rb +12 -0
  282. data/lib/pio/udp.rb +5 -3
  283. data/lib/pio/udp_header.rb +3 -1
  284. data/lib/pio/version.rb +3 -1
  285. data/lib/pio.rb +3 -1
  286. data/pio.gemspec +7 -38
  287. data/spec/pio/arp/reply_spec.rb +2 -4
  288. data/spec/pio/arp/request_spec.rb +2 -4
  289. data/spec/pio/arp_spec.rb +2 -4
  290. data/spec/pio/dhcp/ack_spec.rb +2 -0
  291. data/spec/pio/dhcp/discover_spec.rb +2 -0
  292. data/spec/pio/dhcp/offer_spec.rb +2 -0
  293. data/spec/pio/dhcp/request_spec.rb +2 -0
  294. data/spec/pio/dhcp_spec.rb +2 -0
  295. data/spec/pio/icmp/reply_spec.rb +6 -8
  296. data/spec/pio/icmp/request_spec.rb +8 -10
  297. data/spec/pio/icmp_spec.rb +10 -12
  298. data/spec/pio/ipv4_address_spec.rb +2 -0
  299. data/spec/pio/lldp/options_spec.rb +2 -0
  300. data/spec/pio/mac_spec.rb +2 -0
  301. data/spec/pio/monkey_patch/integer_spec.rb +25 -0
  302. data/spec/pio/open_flow/nicira_resubmit_spec.rb +21 -0
  303. data/spec/pio/open_flow/nicira_resubmit_table_spec.rb +22 -0
  304. data/spec/pio/open_flow10/echo/reply_spec.rb +2 -0
  305. data/spec/pio/open_flow10/echo/request_spec.rb +2 -0
  306. data/spec/pio/open_flow10/enqueue_spec.rb +2 -0
  307. data/spec/pio/open_flow10/error/hello_failed_spec.rb +4 -2
  308. data/spec/pio/open_flow10/features/reply_spec.rb +2 -0
  309. data/spec/pio/open_flow10/features/request_spec.rb +2 -0
  310. data/spec/pio/open_flow10/flow_mod_spec.rb +53 -51
  311. data/spec/pio/open_flow10/flow_stats_reply_spec.rb +2 -0
  312. data/spec/pio/open_flow10/flow_stats_request_spec.rb +10 -8
  313. data/spec/pio/open_flow10/hello_spec.rb +2 -2
  314. data/spec/pio/open_flow10/match_spec.rb +106 -104
  315. data/spec/pio/open_flow10/packet_in_spec.rb +2 -0
  316. data/spec/pio/open_flow10/packet_out_spec.rb +2 -349
  317. data/spec/pio/open_flow10/phy_port16_spec.rb +9 -7
  318. data/spec/pio/open_flow10/send_out_port_spec.rb +2 -0
  319. data/spec/pio/open_flow10/set_destination_ip_address_spec.rb +2 -0
  320. data/spec/pio/open_flow10/set_destination_mac_address_spec.rb +2 -0
  321. data/spec/pio/open_flow10/set_source_ip_address_spec.rb +2 -0
  322. data/spec/pio/open_flow10/set_source_mac_address_spec.rb +2 -0
  323. data/spec/pio/open_flow10/set_tos_spec.rb +2 -0
  324. data/spec/pio/open_flow10/set_transport_destination_port_spec.rb +2 -0
  325. data/spec/pio/open_flow10/set_transport_source_port_spec.rb +2 -0
  326. data/spec/pio/open_flow10/set_vlan_priority_spec.rb +2 -0
  327. data/spec/pio/open_flow10/set_vlan_vid_spec.rb +2 -0
  328. data/spec/pio/open_flow10/strip_vlan_header_spec.rb +2 -0
  329. data/spec/pio/open_flow10/wildcards_spec.rb +2 -0
  330. data/spec/pio/open_flow13/echo_reply_spec.rb +2 -0
  331. data/spec/pio/open_flow13/echo_request_spec.rb +2 -0
  332. data/spec/pio/open_flow13/error/bad_request_spec.rb +2 -0
  333. data/spec/pio/open_flow13/error/hello_failed_spec.rb +4 -2
  334. data/spec/pio/open_flow13/features/reply_spec.rb +2 -0
  335. data/spec/pio/open_flow13/features/request_spec.rb +2 -0
  336. data/spec/pio/open_flow13/goto_table_spec.rb +4 -2
  337. data/spec/pio/open_flow13/hello_spec.rb +18 -16
  338. data/spec/pio/open_flow13/match_spec.rb +31 -29
  339. data/spec/pio/open_flow13/meter_spec.rb +4 -2
  340. data/spec/pio/open_flow13/nicira_reg_load_spec.rb +73 -0
  341. data/spec/pio/open_flow13/nicira_reg_move_spec.rb +42 -0
  342. data/spec/pio/open_flow13/nicira_send_out_port_spec.rb +31 -0
  343. data/spec/pio/open_flow13/packet_in_spec.rb +2 -0
  344. data/spec/pio/open_flow13/packet_out_spec.rb +2 -0
  345. data/spec/pio/open_flow13/write_metadata_spec.rb +5 -3
  346. data/spec/pio/open_flow_spec.rb +8 -6
  347. data/spec/spec_helper.rb +1 -12
  348. data/spec/support/shared_examples_for_openflow_messages.rb +7 -13
  349. metadata +83 -683
  350. data/LICENSE +0 -674
  351. data/bin/_guard-core +0 -16
  352. data/bin/byebug +0 -16
  353. data/bin/cc-tddium-post-worker +0 -16
  354. data/bin/cdiff +0 -16
  355. data/bin/coderay +0 -16
  356. data/bin/colortab +0 -16
  357. data/bin/coveralls +0 -16
  358. data/bin/cucumber +0 -16
  359. data/bin/decolor +0 -16
  360. data/bin/flay +0 -16
  361. data/bin/flog +0 -16
  362. data/bin/guard +0 -16
  363. data/bin/htmldiff +0 -16
  364. data/bin/inch +0 -16
  365. data/bin/ldiff +0 -16
  366. data/bin/listen +0 -16
  367. data/bin/minitar +0 -16
  368. data/bin/pry +0 -16
  369. data/bin/rake +0 -16
  370. data/bin/reek +0 -16
  371. data/bin/relish +0 -16
  372. data/bin/restclient +0 -16
  373. data/bin/rspec +0 -16
  374. data/bin/rubocop +0 -16
  375. data/bin/ruby-parse +0 -16
  376. data/bin/ruby-rewrite +0 -16
  377. data/bin/ruby_parse +0 -16
  378. data/bin/ruby_parse_extract_error +0 -16
  379. data/bin/sparkr +0 -16
  380. data/bin/term_display +0 -16
  381. data/bin/term_mandel +0 -16
  382. data/bin/terminal-notifier +0 -16
  383. data/bin/thor +0 -16
  384. data/bin/unparser +0 -16
  385. data/bin/yard +0 -16
  386. data/bin/yardoc +0 -16
  387. data/bin/yri +0 -16
  388. data/features/arp-storm.pcap +0 -0
  389. data/features/arp.pcap +0 -0
  390. data/features/dhcp.pcap +0 -0
  391. data/features/icmp.feature +0 -130
  392. data/features/icmp.pcap +0 -0
  393. data/features/icmpv6.pcap +0 -0
  394. data/features/lldp.detailed.pcap +0 -0
  395. data/features/lldp.minimal.pcap +0 -0
  396. data/features/open_flow10/aggregate_stats_reply.raw +0 -0
  397. data/features/open_flow10/aggregate_stats_request.raw +0 -0
  398. data/features/open_flow10/bad_request.raw +0 -0
  399. data/features/open_flow10/barrier_reply.raw +0 -0
  400. data/features/open_flow10/barrier_request.raw +0 -0
  401. data/features/open_flow10/description_stats_reply.raw +0 -0
  402. data/features/open_flow10/description_stats_request.raw +0 -0
  403. data/features/open_flow10/echo_reply.raw +0 -0
  404. data/features/open_flow10/echo_request.raw +0 -0
  405. data/features/open_flow10/error.raw +0 -0
  406. data/features/open_flow10/features_reply.raw +0 -0
  407. data/features/open_flow10/features_request.raw +0 -0
  408. data/features/open_flow10/flow_mod_add.raw +0 -0
  409. data/features/open_flow10/flow_mod_delete.raw +0 -0
  410. data/features/open_flow10/flow_mod_delete_strict.raw +0 -0
  411. data/features/open_flow10/flow_mod_modify.raw +0 -0
  412. data/features/open_flow10/flow_mod_modify_strict.raw +0 -0
  413. data/features/open_flow10/flow_removed.raw +0 -0
  414. data/features/open_flow10/flow_stats_reply.raw +0 -0
  415. data/features/open_flow10/flow_stats_request.raw +0 -0
  416. data/features/open_flow10/get_config_reply.raw +0 -0
  417. data/features/open_flow10/get_config_request.raw +0 -0
  418. data/features/open_flow10/hello.raw +0 -0
  419. data/features/open_flow10/hello_failed.raw +0 -0
  420. data/features/open_flow10/nx_flow_mod_add.raw +0 -0
  421. data/features/open_flow10/nx_flow_mod_delete.raw +0 -0
  422. data/features/open_flow10/nx_flow_mod_delete_strict.raw +0 -0
  423. data/features/open_flow10/nx_flow_mod_modify.raw +0 -0
  424. data/features/open_flow10/nx_flow_mod_modify_strict.raw +0 -0
  425. data/features/open_flow10/nxast_learn.raw +0 -0
  426. data/features/open_flow10/packet_in.raw +0 -0
  427. data/features/open_flow10/packet_in_arp_reply.raw +0 -0
  428. data/features/open_flow10/packet_in_arp_request.raw +0 -0
  429. data/features/open_flow10/packet_in_cbench.raw +0 -0
  430. data/features/open_flow10/packet_out.raw +0 -0
  431. data/features/open_flow10/port_mod.raw +0 -0
  432. data/features/open_flow10/port_stats_reply.raw +0 -0
  433. data/features/open_flow10/port_stats_request.raw +0 -0
  434. data/features/open_flow10/port_status.raw +0 -0
  435. data/features/open_flow10/queue_get_config_reply.raw +0 -0
  436. data/features/open_flow10/queue_get_config_request.raw +0 -0
  437. data/features/open_flow10/queue_stats_request.raw +0 -0
  438. data/features/open_flow10/set_config.raw +0 -0
  439. data/features/open_flow10/table_stats_reply.raw +0 -0
  440. data/features/open_flow10/table_stats_request.raw +0 -0
  441. data/features/open_flow10/vendor.raw +0 -0
  442. data/features/open_flow10/vendor_stats_request.raw +0 -0
  443. data/features/open_flow13/action_copy_ttl_in.raw +0 -0
  444. data/features/open_flow13/action_copy_ttl_out.raw +0 -0
  445. data/features/open_flow13/action_dec_mpls_ttl.raw +0 -0
  446. data/features/open_flow13/action_dec_nw_ttl.raw +0 -0
  447. data/features/open_flow13/action_group.raw +0 -0
  448. data/features/open_flow13/action_pop_mpls.raw +0 -0
  449. data/features/open_flow13/action_pop_pbb.raw +0 -0
  450. data/features/open_flow13/action_pop_vlan.raw +0 -0
  451. data/features/open_flow13/action_push_mpls.raw +0 -0
  452. data/features/open_flow13/action_push_pbb.raw +0 -0
  453. data/features/open_flow13/action_push_vlan.raw +0 -0
  454. data/features/open_flow13/action_set_field.raw +0 -0
  455. data/features/open_flow13/action_set_mpls_ttl.raw +0 -0
  456. data/features/open_flow13/action_set_nw_ttl.raw +0 -0
  457. data/features/open_flow13/action_set_queue.raw +0 -0
  458. data/features/open_flow13/apply_actions.raw +0 -0
  459. data/features/open_flow13/bad_request.raw +0 -0
  460. data/features/open_flow13/echo_reply_body.raw +0 -0
  461. data/features/open_flow13/echo_reply_no_body.raw +0 -0
  462. data/features/open_flow13/echo_request_body.raw +0 -0
  463. data/features/open_flow13/echo_request_no_body.raw +0 -0
  464. data/features/open_flow13/features_reply.raw +0 -0
  465. data/features/open_flow13/features_request.raw +0 -0
  466. data/features/open_flow13/flow_add_apply_no_match.raw +0 -0
  467. data/features/open_flow13/flow_mod_add_apply_no_match.raw +0 -0
  468. data/features/open_flow13/flow_mod_no_match_or_instructions.raw +0 -0
  469. data/features/open_flow13/hello_failed.raw +0 -0
  470. data/features/open_flow13/hello_no_version_bitmap.raw +0 -0
  471. data/features/open_flow13/hello_version_bitmap.raw +0 -0
  472. data/features/open_flow13/instruction_clear_actions.raw +0 -0
  473. data/features/open_flow13/instruction_goto_table.raw +0 -0
  474. data/features/open_flow13/instruction_meter.raw +0 -0
  475. data/features/open_flow13/instruction_write_actions.raw +0 -0
  476. data/features/open_flow13/instruction_write_metadata.raw +0 -0
  477. data/features/open_flow13/oxm_arp_op_field.raw +0 -0
  478. data/features/open_flow13/oxm_arp_sha_field.raw +0 -0
  479. data/features/open_flow13/oxm_arp_spa_field.raw +0 -0
  480. data/features/open_flow13/oxm_arp_tha_field.raw +0 -0
  481. data/features/open_flow13/oxm_arp_tpa_field.raw +0 -0
  482. data/features/open_flow13/oxm_ether_destination_field.raw +0 -0
  483. data/features/open_flow13/oxm_ether_source_field.raw +0 -0
  484. data/features/open_flow13/oxm_ether_type_field.raw +0 -0
  485. data/features/open_flow13/oxm_experimenter_stratos_basic_dot11.raw +0 -0
  486. data/features/open_flow13/oxm_icmpv4_code_field.raw +0 -0
  487. data/features/open_flow13/oxm_icmpv4_type_field.raw +0 -0
  488. data/features/open_flow13/oxm_in_phy_port_field.raw +0 -0
  489. data/features/open_flow13/oxm_in_port_field.raw +0 -0
  490. data/features/open_flow13/oxm_invalid_field.raw +0 -0
  491. data/features/open_flow13/oxm_ip_dscp_field.raw +0 -0
  492. data/features/open_flow13/oxm_ip_ecn_field.raw +0 -0
  493. data/features/open_flow13/oxm_ipv4_destination_field.raw +0 -0
  494. data/features/open_flow13/oxm_ipv4_source_field.raw +0 -0
  495. data/features/open_flow13/oxm_ipv6_destination_field.raw +0 -0
  496. data/features/open_flow13/oxm_ipv6_source_field.raw +0 -0
  497. data/features/open_flow13/oxm_masked_arp_sha_field.raw +0 -0
  498. data/features/open_flow13/oxm_masked_arp_spa_field.raw +0 -0
  499. data/features/open_flow13/oxm_masked_arp_tha_field.raw +0 -0
  500. data/features/open_flow13/oxm_masked_arp_tpa_field.raw +0 -0
  501. data/features/open_flow13/oxm_masked_ether_destination_field.raw +0 -0
  502. data/features/open_flow13/oxm_masked_ether_source_field.raw +0 -0
  503. data/features/open_flow13/oxm_masked_ipv4_destination_field.raw +0 -0
  504. data/features/open_flow13/oxm_masked_ipv4_source_field.raw +0 -0
  505. data/features/open_flow13/oxm_masked_ipv6_destination_field.raw +0 -0
  506. data/features/open_flow13/oxm_masked_ipv6_source_field.raw +0 -0
  507. data/features/open_flow13/oxm_masked_tunnel_id_field.raw +0 -0
  508. data/features/open_flow13/oxm_metadata_field.raw +0 -0
  509. data/features/open_flow13/oxm_metadata_masked_field.raw +0 -0
  510. data/features/open_flow13/oxm_no_fields.raw +0 -0
  511. data/features/open_flow13/oxm_sctp_destination_field.raw +0 -0
  512. data/features/open_flow13/oxm_sctp_source_field.raw +0 -0
  513. data/features/open_flow13/oxm_tcp_destination_field.raw +0 -0
  514. data/features/open_flow13/oxm_tcp_field.raw +0 -0
  515. data/features/open_flow13/oxm_tcp_source_field.raw +0 -0
  516. data/features/open_flow13/oxm_tunnel_id_field.raw +0 -0
  517. data/features/open_flow13/oxm_udp_destination_field.raw +0 -0
  518. data/features/open_flow13/oxm_udp_field.raw +0 -0
  519. data/features/open_flow13/oxm_udp_source_field.raw +0 -0
  520. data/features/open_flow13/oxm_vlan_pcp_field.raw +0 -0
  521. data/features/open_flow13/oxm_vlan_vid_field.raw +0 -0
  522. data/features/open_flow13/packet_in.raw +0 -0
  523. data/features/open_flow13/packet_out.raw +0 -0
  524. data/features/open_flow13/send_out_port.raw +0 -0
  525. data/features/open_flow13/table_stats_reply.raw +0 -0
  526. data/features/open_flow13/table_stats_request.raw +0 -0
  527. data/features/step_definitions/LICENSE +0 -675
  528. data/features/udp_no_payload.raw +0 -0
  529. data/features/udp_with_payload.raw +0 -0
  530. data/lib/pio/icmp/options.rb +0 -21
  531. data/lib/pio/open_flow/error.rb +0 -19
  532. data/lib/pio/open_flow/open_flow_header.rb +0 -31
  533. data/lib/pio/open_flow13/buffer_id.rb +0 -17
  534. data/spec/pio/arp/reply/options_spec.rb +0 -143
  535. data/spec/pio/arp/request/options_spec.rb +0 -113
@@ -1,44 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/arp/message'
4
+ require 'pio/instance_inspector'
2
5
  require 'pio/mac'
3
- require 'pio/options'
4
6
 
5
7
  module Pio
6
8
  class Arp
7
9
  # ARP Request packet generator
8
10
  class Request < Message
9
- OPERATION = 1
10
- public_class_method :new
11
-
12
- # User options for creating an Arp Request.
13
- class Options < Pio::Options
14
- mandatory_option :source_mac
15
- mandatory_option :sender_protocol_address
16
- mandatory_option :target_protocol_address
17
-
18
- BROADCAST_MAC = Mac.new(0xffffffffffff).freeze
19
- ALL_ZERO_MAC = Mac.new(0).freeze
20
-
21
- def initialize(options)
22
- validate options
23
- @source_mac = Mac.new(options[:source_mac]).freeze
24
- @sender_protocol_address =
25
- IPv4Address.new(options[:sender_protocol_address]).freeze
26
- @target_protocol_address =
27
- IPv4Address.new(options[:target_protocol_address]).freeze
28
- end
11
+ include InstanceInspector
29
12
 
30
- def to_hash
31
- {
32
- operation: OPERATION,
33
- source_mac: @source_mac,
34
- destination_mac: BROADCAST_MAC,
35
- sender_hardware_address: @source_mac,
36
- target_hardware_address: ALL_ZERO_MAC,
37
- sender_protocol_address: @sender_protocol_address,
38
- target_protocol_address: @target_protocol_address
39
- }.freeze
40
- end
41
- end
13
+ option :operation, value: 1
14
+ option :source_mac
15
+ option :destination_mac, default: 'ff:ff:ff:ff:ff:ff'
16
+ option :sender_hardware_address, value: :source_mac
17
+ option :target_hardware_address, default: '00:00:00:00:00:00'
18
+ option :sender_protocol_address
19
+ option :target_protocol_address
42
20
  end
43
21
  end
44
22
  end
data/lib/pio/arp.rb CHANGED
@@ -1,14 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/arp/format'
2
- require 'pio/arp/request'
3
4
  require 'pio/arp/reply'
4
- require 'pio/message_type_selector'
5
+ require 'pio/arp/request'
6
+ require 'pio/parse_error'
5
7
 
6
- # Packet parser and generator library.
7
8
  module Pio
8
9
  # ARP parser and generator.
9
10
  class Arp
10
- extend MessageTypeSelector
11
- message_type Request::OPERATION => Request, Reply::OPERATION => Reply
11
+ def self.read(raw_data)
12
+ format = Format.read(raw_data)
13
+ { Request.operation => Request,
14
+ Reply.operation => Reply }.fetch(format.operation).create(format)
15
+ rescue
16
+ raise Pio::ParseError, $ERROR_INFO.message
17
+ end
12
18
  end
13
- ARP = Arp
14
19
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+
5
+ module Pio
6
+ # Introduces Class.inspect method
7
+ module ClassInspector
8
+ # rubocop:disable LineLength
9
+ def inspect
10
+ field_and_type = fields.each_with_object([]) do |each, result|
11
+ next if each.name == :padding
12
+ result << [each.name,
13
+ each.prototype.instance_variable_get(:@obj_class).name.demodulize.sub(/be$/, '').underscore]
14
+ end
15
+ signature = field_and_type.map { |field, type| "#{field}: #{type}" }.join(', ')
16
+ "#{self}(#{signature})"
17
+ end
18
+ # rubocop:enable LineLength
19
+ end
20
+ end
data/lib/pio/dhcp/ack.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/boot_reply'
2
4
 
3
5
  module Pio
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/message'
2
4
  require 'pio/dhcp/boot_reply_options'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/options'
2
4
  require 'pio/dhcp/common_options'
3
5
  require 'pio/dhcp/dhcp_tlv_options'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/message'
2
4
  require 'pio/dhcp/boot_request_options'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/options'
2
4
  require 'pio/dhcp/common_options'
3
5
  require 'pio/dhcp/dhcp_tlv_options'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/type/mac_address'
2
4
 
3
5
  module Pio
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pio
2
4
  class Dhcp
3
5
  # DHCP Common Options.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/optional_tlv'
2
4
  require 'pio/type/ip_address'
3
5
  require 'pio/type/mac_address'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/common_options'
2
4
 
3
5
  module Pio
@@ -31,11 +33,13 @@ module Pio
31
33
  end
32
34
 
33
35
  def dhcp_server_identifier_hash
34
- {
35
- tlv_type: Dhcp::SERVER_IDENTIFIER_TLV,
36
- tlv_info_length: 4,
37
- tlv_value: server_identifier
38
- } if server_identifier
36
+ if server_identifier
37
+ {
38
+ tlv_type: Dhcp::SERVER_IDENTIFIER_TLV,
39
+ tlv_info_length: 4,
40
+ tlv_value: server_identifier
41
+ }
42
+ end
39
43
  end
40
44
 
41
45
  def parameters_list_hash
@@ -47,19 +51,23 @@ module Pio
47
51
  end
48
52
 
49
53
  def renewal_time_value_hash
50
- {
51
- tlv_type: Dhcp::RENEWAL_TIME_VALUE_TLV,
52
- tlv_info_length: 4,
53
- tlv_value: renewal_time_value
54
- } if renewal_time_value
54
+ if renewal_time_value
55
+ {
56
+ tlv_type: Dhcp::RENEWAL_TIME_VALUE_TLV,
57
+ tlv_info_length: 4,
58
+ tlv_value: renewal_time_value
59
+ }
60
+ end
55
61
  end
56
62
 
57
63
  def rebinding_time_value_hash
58
- {
59
- tlv_type: Dhcp::REBINDING_TIME_VALUE_TLV,
60
- tlv_info_length: 4,
61
- tlv_value: rebinding_time_value
62
- } if rebinding_time_value
64
+ if rebinding_time_value
65
+ {
66
+ tlv_type: Dhcp::REBINDING_TIME_VALUE_TLV,
67
+ tlv_info_length: 4,
68
+ tlv_value: rebinding_time_value
69
+ }
70
+ end
63
71
  end
64
72
 
65
73
  def ip_address_lease_time_hash
@@ -71,11 +79,13 @@ module Pio
71
79
  end
72
80
 
73
81
  def subnet_mask_hash
74
- {
75
- tlv_type: Dhcp::SUBNET_MASK_TLV,
76
- tlv_info_length: 4,
77
- tlv_value: subnet_mask
78
- } if subnet_mask
82
+ if subnet_mask
83
+ {
84
+ tlv_type: Dhcp::SUBNET_MASK_TLV,
85
+ tlv_info_length: 4,
86
+ tlv_value: subnet_mask
87
+ }
88
+ end
79
89
  end
80
90
  end
81
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/boot_request'
2
4
 
3
5
  module Pio
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pio
2
4
  class Dhcp
3
5
  # Dhcp Field Read Methods.
@@ -93,7 +95,7 @@ module Pio
93
95
 
94
96
  def get_tlv_field(tlv_type)
95
97
  tlv = get_tlv(tlv_type)
96
- tlv.snapshot if tlv
98
+ tlv&.snapshot
97
99
  end
98
100
  end
99
101
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/dhcp_field'
2
4
  require 'pio/dhcp/field_util'
3
5
  require 'pio/ipv4_header'
@@ -12,12 +14,12 @@ module Pio
12
14
 
13
15
  OPTION_FIELD_LENGTH = 60
14
16
 
15
- include EthernetHeader
16
- include IPv4Header
17
+ include Ethernet
18
+ include IPv4
17
19
  include UdpHeader
18
20
 
19
21
  endian :big
20
- ethernet_header ether_type: EtherType::IPV4
22
+ ethernet_header ether_type: Ethernet::Type::IPV4
21
23
  ipv4_header ip_protocol: ProtocolNumber::UDP
22
24
  udp_header
23
25
  dhcp_field :dhcp
@@ -31,7 +33,7 @@ module Pio
31
33
 
32
34
  def ff_and_padding
33
35
  padding_length = OPTION_FIELD_LENGTH - dhcp.optional_tlvs.num_bytes - 1
34
- "\xFF" + (padding_length > 0 ? "\x00" * padding_length : '')
36
+ [0xFF].pack('C') + (padding_length > 0 ? "\x00" * padding_length : '')
35
37
  end
36
38
  end
37
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/frame'
2
4
  require 'forwardable'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/boot_reply'
2
4
 
3
5
  module Pio
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/parameter_list'
2
4
  require 'pio/dhcp/client_id'
3
5
  require 'pio/type/ip_address'
@@ -13,9 +15,9 @@ module Pio
13
15
 
14
16
  bit8 :tlv_type
15
17
  bit8 :tlv_info_length,
16
- onlyif: -> { !(end_of_dhcpdu?) }
18
+ onlyif: -> { !end_of_dhcpdu? }
17
19
  choice :tlv_value,
18
- onlyif: -> { !(end_of_dhcpdu?) },
20
+ onlyif: -> { !end_of_dhcpdu? },
19
21
  selection: :chooser do
20
22
  uint8 Dhcp::MESSAGE_TYPE_TLV
21
23
  ip_address Dhcp::SERVER_IDENTIFIER_TLV
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bindata'
2
4
 
3
5
  module Pio
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/dhcp/boot_request'
2
4
 
3
5
  module Pio
data/lib/pio/dhcp.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Packet parser and generator library.
2
4
  module Pio
3
5
  # Dhcp parser and generator.
@@ -22,7 +24,7 @@ module Pio
22
24
  ROUTER_TLV,
23
25
  DNS_TLV,
24
26
  NTP_SERVERS_TLV
25
- ]
27
+ ].freeze
26
28
  end
27
29
  DHCP = Dhcp
28
30
  end
@@ -41,7 +43,7 @@ module Pio
41
43
  Offer::TYPE => Offer,
42
44
  Request::TYPE => Request,
43
45
  Ack::TYPE => Ack
44
- }
46
+ }.freeze
45
47
 
46
48
  def self.read(raw_data)
47
49
  begin
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bindata'
4
+ require 'pio/ethernet_header'
5
+ require 'pio/class_inspector'
6
+ require 'pio/instance_inspector'
7
+ require 'pio/ruby_dumper'
8
+
9
+ module Pio
10
+ # Ethernet frame parser
11
+ class EthernetFrame < BinData::Record
12
+ extend ClassInspector
13
+ include Ethernet
14
+ include InstanceInspector
15
+ include RubyDumper
16
+
17
+ endian :big
18
+
19
+ ethernet_header
20
+ rest :rest
21
+ end
22
+ end
@@ -1,10 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pio/class_inspector'
4
+ require 'pio/instance_inspector'
5
+ require 'pio/ruby_dumper'
6
+ require 'pio/type/ether_type'
1
7
  require 'pio/type/mac_address'
2
8
 
3
9
  module Pio
4
10
  # Adds ethernet_header macro.
5
- module EthernetHeader
6
- # EtherType constants for ethernet_header.ether_type.
7
- module EtherType
11
+ module Ethernet
12
+ MINIMUM_FRAME_SIZE = 64
13
+
14
+ # EtherType constants
15
+ module Type
8
16
  ARP = 0x0806
9
17
  IPV4 = 0x0800
10
18
  VLAN = 0x8100
@@ -12,28 +20,44 @@ module Pio
12
20
  end
13
21
 
14
22
  # This method smells of :reek:TooManyStatements
23
+ # rubocop:disable MethodLength
15
24
  def self.included(klass)
16
- def klass.ethernet_header(options)
25
+ def klass.ethernet_header(options = nil)
17
26
  mac_address :destination_mac
18
27
  mac_address :source_mac
19
- uint16 :ether_type, value: options.fetch(:ether_type)
20
- bit3 :vlan_pcp_internal, onlyif: :vlan?
28
+ if options
29
+ ether_type :ether_type, value: options.fetch(:ether_type)
30
+ else
31
+ ether_type :ether_type
32
+ end
33
+ bit3 :vlan_pcp, onlyif: :vlan?
21
34
  bit1 :vlan_cfi, onlyif: :vlan?
22
- bit12 :vlan_vid_internal, onlyif: :vlan?
35
+ bit12 :vlan_vid, onlyif: :vlan?
23
36
  uint16 :ether_type_vlan, value: :ether_type, onlyif: :vlan?
24
37
  end
25
38
  end
39
+ # rubocop:enable MethodLength
26
40
 
27
- def vlan_vid
28
- vlan? ? vlan_vid_internal : 0xffff
41
+ def ethernet_header_length
42
+ vlan? ? 18 : 14
29
43
  end
30
44
 
31
- def vlan_pcp
32
- vlan? ? vlan_pcp_internal : 0
33
- end
45
+ private
34
46
 
35
47
  def vlan?
36
- ether_type == EtherType::VLAN
48
+ ether_type == Type::VLAN
37
49
  end
38
50
  end
51
+
52
+ # Ethernet header generator/parser
53
+ class EthernetHeader < BinData::Record
54
+ extend ClassInspector
55
+ include Ethernet
56
+ include InstanceInspector
57
+ include RubyDumper
58
+
59
+ endian :big
60
+
61
+ ethernet_header
62
+ end
39
63
  end
@@ -1,37 +1,35 @@
1
- require 'bindata'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'pio/ethernet_header'
3
4
  require 'pio/ipv4_header'
5
+ require 'pio/monkey_patch/bindata_record'
4
6
 
5
7
  module Pio
6
- # Icmp parser and generator.
8
+ # ICMP parser and generator
7
9
  class Icmp
8
- # Icmp parser.
10
+ # ICMP format
9
11
  class Format < BinData::Record
10
- MINIMUM_IP_PACKET_LENGTH = 50
11
-
12
- include EthernetHeader
13
- include IPv4Header
12
+ include Ethernet
13
+ include IPv4
14
14
 
15
15
  endian :big
16
16
 
17
- ethernet_header ether_type: EtherType::IPV4
17
+ ethernet_header ether_type: Ethernet::Type::IPV4
18
18
  ipv4_header ip_protocol: ProtocolNumber::ICMP
19
19
  uint8 :icmp_type
20
20
  uint8 :icmp_code, initial_value: 0
21
21
  uint16 :icmp_checksum, value: :calculate_icmp_checksum
22
22
  uint16 :icmp_identifier
23
23
  uint16 :icmp_sequence_number
24
- string :echo_data, read_length: :echo_data_read_length
25
- string :padding, read_length: 0, initial_value: :icmp_padding_length
26
-
27
- def message_type
28
- icmp_type
29
- end
30
-
31
- alias_method :to_binary, :to_binary_s
24
+ string :echo_data, read_length: :echo_data_length
25
+ string :padding, length: :padding_length
32
26
 
33
27
  private
34
28
 
29
+ def icmp_header_length
30
+ 8
31
+ end
32
+
35
33
  def calculate_icmp_checksum
36
34
  sum = [icmp_type * 0x100 + icmp_code,
37
35
  icmp_identifier,
@@ -40,14 +38,15 @@ module Pio
40
38
  ~((sum & 0xffff) + (sum >> 16)) & 0xffff
41
39
  end
42
40
 
43
- def echo_data_read_length
44
- ip_total_length - (ip_header_length * 4) - 8
41
+ def echo_data_length
42
+ ip_total_length - ip_header_length_in_bytes - icmp_header_length
45
43
  end
46
44
 
47
- def icmp_padding_length
48
- length = MINIMUM_IP_PACKET_LENGTH -
49
- (ip_header_length * 4) - 8 - echo_data.length
50
- length > 0 ? "\x00" * length : ''
45
+ def padding_length
46
+ tmp = Ethernet::MINIMUM_FRAME_SIZE -
47
+ ethernet_header_length - ip_header_length_in_bytes -
48
+ icmp_header_length - echo_data.length
49
+ tmp > 0 ? tmp : 0
51
50
  end
52
51
  end
53
52
  end
@@ -1,14 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pio/class_inspector'
1
4
  require 'pio/icmp/format'
5
+ require 'pio/instance_inspector'
6
+ require 'pio/message'
7
+ require 'pio/ruby_dumper'
2
8
 
3
9
  module Pio
4
10
  class Icmp
5
11
  # Base class of Icmp::Request and Icmp::Reply.
6
- class Message
7
- private_class_method :new
12
+ class Message < Pio::Message
13
+ extend ClassInspector
14
+ include InstanceInspector
15
+
16
+ def self.fields
17
+ Icmp::Format.fields
18
+ end
19
+
20
+ def self.create(format)
21
+ allocate.tap do |message|
22
+ message.instance_variable_set :@format, format
23
+ end
24
+ end
8
25
 
9
26
  def initialize(user_options)
10
- options = self.class.const_get(:Options).new(user_options)
11
- @format = Icmp::Format.new(options.to_hash)
27
+ @format = Icmp::Format.new(parse_options(user_options))
12
28
  end
13
29
 
14
30
  def method_missing(method, *args)
@@ -1,43 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pio/icmp/message'
2
- require 'pio/icmp/options'
3
- require 'pio/mac'
4
4
 
5
5
  module Pio
6
6
  class Icmp
7
7
  # ICMP Reply packet generator
8
8
  class Reply < Message
9
- TYPE = 0
10
- public_class_method :new
11
-
12
- # User options for creating an ICMP Reply.
13
- class Options < Pio::Icmp::Options
14
- mandatory_option :source_mac
15
- mandatory_option :destination_mac
16
- mandatory_option :source_ip_address
17
- mandatory_option :destination_ip_address
18
- mandatory_option :identifier
19
- mandatory_option :sequence_number
20
- option :echo_data
21
-
22
- # rubocop:disable MethodLength
23
- # rubocop:disable AbcSize
24
- def initialize(options)
25
- validate options
26
- @type = TYPE
27
-
28
- @source_mac = Mac.new(options[:source_mac]).freeze
29
- @destination_mac = Mac.new(options[:destination_mac]).freeze
30
- @source_ip_address =
31
- IPv4Address.new(options[:source_ip_address]).freeze
32
- @destination_ip_address =
33
- IPv4Address.new(options[:destination_ip_address]).freeze
34
- @identifier = options[:identifier]
35
- @sequence_number = options[:sequence_number]
36
- @echo_data = options[:echo_data] || ''
37
- end
38
- # rubocop:enable AbcSize
39
- # rubocop:enable MethodLength
40
- end
9
+ option :icmp_type, value: 0
10
+ option :source_mac
11
+ option :destination_mac
12
+ option :source_ip_address
13
+ option :destination_ip_address
14
+ option :icmp_identifier
15
+ option :icmp_sequence_number
16
+ option :echo_data, default: ''
41
17
  end
42
18
  end
43
19
  end