trema 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (560) hide show
  1. data/.mono.rant +4107 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +4 -0
  4. data/Doxyfile +1679 -0
  5. data/GPL2 +339 -0
  6. data/Gemfile +22 -0
  7. data/Gemfile.lock +71 -0
  8. data/README.md +135 -0
  9. data/Rakefile +140 -0
  10. data/Rantfile +834 -0
  11. data/VERSION +1 -0
  12. data/build.rb +32 -0
  13. data/cruise.rb +389 -0
  14. data/features/example.dumper.feature +87 -0
  15. data/features/example.learning_switch.feature +39 -0
  16. data/features/example.list_switches.feature +38 -0
  17. data/features/example.message.echo_reply.feature +26 -0
  18. data/features/example.message.echo_request.feature +25 -0
  19. data/features/example.message.features_request.feature +84 -0
  20. data/features/example.message.hello.feature +25 -0
  21. data/features/example.message.set_config.feature +27 -0
  22. data/features/example.multi_learning_switch.feature +135 -0
  23. data/features/example.packetin_filter_config.feature +91 -0
  24. data/features/example.repeater_hub.feature +49 -0
  25. data/features/example.switch_monitor.feature +39 -0
  26. data/features/packetin_filter.feature +49 -0
  27. data/features/step_definitions/kill_steps.rb +30 -0
  28. data/features/step_definitions/log_steps.rb +90 -0
  29. data/features/step_definitions/misc_steps.rb +64 -0
  30. data/features/step_definitions/off_steps.rb +30 -0
  31. data/features/step_definitions/run_steps.rb +91 -0
  32. data/features/step_definitions/send_packets_steps.rb +42 -0
  33. data/features/step_definitions/show_stats_steps.rb +43 -0
  34. data/features/step_definitions/stats_steps.rb +39 -0
  35. data/features/support/env.rb +75 -0
  36. data/features/support/hooks.rb +8 -0
  37. data/features/switch_manager.feature +35 -0
  38. data/features/trema-config.feature +68 -0
  39. data/features/trema.dump_flows.feature +25 -0
  40. data/features/trema.feature +25 -0
  41. data/features/trema.kill.feature +53 -0
  42. data/features/trema.killall.feature +30 -0
  43. data/features/trema.reset_stats.feature +14 -0
  44. data/features/trema.run.feature +46 -0
  45. data/features/trema.send_packets.feature +56 -0
  46. data/features/trema.show_stats.feature +67 -0
  47. data/features/tutorial.hello_trema.feature +27 -0
  48. data/features/tutorial.packet_in.feature +47 -0
  49. data/features/tutorial.switch_info.feature +55 -0
  50. data/ruby/.gitignore +4 -0
  51. data/ruby/blocker.rb +78 -0
  52. data/ruby/extconf.rb +71 -0
  53. data/ruby/sub-process.rb +291 -0
  54. data/ruby/trema/action-common.c +60 -0
  55. data/ruby/trema/action-common.h +42 -0
  56. data/ruby/trema/action-enqueue.c +161 -0
  57. data/ruby/trema/action-enqueue.h +40 -0
  58. data/ruby/trema/action-output.c +169 -0
  59. data/ruby/trema/action-output.h +42 -0
  60. data/ruby/trema/action-set-dl-dst.c +131 -0
  61. data/ruby/trema/action-set-dl-dst.h +44 -0
  62. data/ruby/trema/action-set-dl-src.c +131 -0
  63. data/ruby/trema/action-set-dl-src.h +44 -0
  64. data/ruby/trema/action-set-nw-dst.c +135 -0
  65. data/ruby/trema/action-set-nw-dst.h +42 -0
  66. data/ruby/trema/action-set-nw-src.c +140 -0
  67. data/ruby/trema/action-set-nw-src.h +42 -0
  68. data/ruby/trema/action-set-nw-tos.c +124 -0
  69. data/ruby/trema/action-set-nw-tos.h +42 -0
  70. data/ruby/trema/action-set-tp-dst.c +122 -0
  71. data/ruby/trema/action-set-tp-dst.h +42 -0
  72. data/ruby/trema/action-set-tp-src.c +124 -0
  73. data/ruby/trema/action-set-tp-src.h +42 -0
  74. data/ruby/trema/action-set-vlan-pcp.c +128 -0
  75. data/ruby/trema/action-set-vlan-pcp.h +42 -0
  76. data/ruby/trema/action-set-vlan-vid.c +125 -0
  77. data/ruby/trema/action-set-vlan-vid.h +42 -0
  78. data/ruby/trema/action-strip-vlan.c +81 -0
  79. data/ruby/trema/action-strip-vlan.h +42 -0
  80. data/ruby/trema/action-vendor.c +121 -0
  81. data/ruby/trema/action-vendor.h +42 -0
  82. data/ruby/trema/aggregate-stats-reply.rb +70 -0
  83. data/ruby/trema/app.rb +112 -0
  84. data/ruby/trema/barrier-reply.c +99 -0
  85. data/ruby/trema/barrier-reply.h +46 -0
  86. data/ruby/trema/barrier-request.c +108 -0
  87. data/ruby/trema/barrier-request.h +44 -0
  88. data/ruby/trema/cli.rb +269 -0
  89. data/ruby/trema/command.rb +40 -0
  90. data/ruby/trema/command/dump_flows.rb +62 -0
  91. data/ruby/trema/command/kill.rb +71 -0
  92. data/ruby/trema/command/killall.rb +56 -0
  93. data/ruby/trema/command/reset_stats.rb +61 -0
  94. data/ruby/trema/command/ruby.rb +55 -0
  95. data/ruby/trema/command/run.rb +120 -0
  96. data/ruby/trema/command/send_packets.rb +130 -0
  97. data/ruby/trema/command/shell.rb +61 -0
  98. data/ruby/trema/command/show_stats.rb +84 -0
  99. data/ruby/trema/command/usage.rb +61 -0
  100. data/ruby/trema/command/version.rb +39 -0
  101. data/ruby/trema/controller.c +595 -0
  102. data/ruby/trema/controller.h +44 -0
  103. data/ruby/trema/controller.rb +81 -0
  104. data/ruby/trema/daemon.rb +167 -0
  105. data/ruby/trema/dsl.rb +34 -0
  106. data/ruby/trema/dsl/configuration.rb +153 -0
  107. data/ruby/trema/dsl/context.rb +71 -0
  108. data/ruby/trema/dsl/link.rb +41 -0
  109. data/ruby/trema/dsl/parser.rb +70 -0
  110. data/ruby/trema/dsl/run.rb +49 -0
  111. data/ruby/trema/dsl/runner.rb +165 -0
  112. data/ruby/trema/dsl/stanza.rb +53 -0
  113. data/ruby/trema/dsl/switch.rb +78 -0
  114. data/ruby/trema/dsl/syntax-error.rb +33 -0
  115. data/ruby/trema/dsl/syntax.rb +109 -0
  116. data/ruby/trema/dsl/vhost.rb +108 -0
  117. data/ruby/trema/dsl/vswitch.rb +47 -0
  118. data/ruby/trema/echo-reply.c +107 -0
  119. data/ruby/trema/echo-reply.h +42 -0
  120. data/ruby/trema/echo-request.c +140 -0
  121. data/ruby/trema/echo-request.h +42 -0
  122. data/ruby/trema/error.c +253 -0
  123. data/ruby/trema/error.h +44 -0
  124. data/ruby/trema/exact-match.rb +36 -0
  125. data/ruby/trema/executables.rb +95 -0
  126. data/ruby/trema/features-reply.c +238 -0
  127. data/ruby/trema/features-reply.h +60 -0
  128. data/ruby/trema/features-request.c +109 -0
  129. data/ruby/trema/features-request.h +44 -0
  130. data/ruby/trema/flow-removed.c +275 -0
  131. data/ruby/trema/flow-removed.h +46 -0
  132. data/ruby/trema/flow-stats-reply.rb +109 -0
  133. data/ruby/trema/flow.rb +56 -0
  134. data/ruby/trema/get-config-reply.c +159 -0
  135. data/ruby/trema/get-config-reply.h +52 -0
  136. data/ruby/trema/get-config-request.c +107 -0
  137. data/ruby/trema/get-config-request.h +44 -0
  138. data/ruby/trema/hello.c +110 -0
  139. data/ruby/trema/hello.h +44 -0
  140. data/ruby/trema/host.rb +257 -0
  141. data/ruby/trema/ip.rb +101 -0
  142. data/ruby/trema/link.rb +176 -0
  143. data/ruby/trema/list-switches-reply.c +46 -0
  144. data/ruby/trema/list-switches-reply.h +40 -0
  145. data/ruby/trema/logger.c +162 -0
  146. data/ruby/trema/logger.h +44 -0
  147. data/ruby/trema/mac.rb +151 -0
  148. data/ruby/trema/match.c +594 -0
  149. data/ruby/trema/match.h +36 -0
  150. data/ruby/trema/monkey-patch/integer.rb +35 -0
  151. data/ruby/trema/monkey-patch/integer/base-conversions.rb +36 -0
  152. data/ruby/trema/monkey-patch/integer/ranges.rb +51 -0
  153. data/ruby/trema/monkey-patch/module.rb +33 -0
  154. data/ruby/trema/monkey-patch/module/deprecation.rb +41 -0
  155. data/ruby/trema/monkey-patch/string.rb +33 -0
  156. data/ruby/trema/monkey-patch/string/inflectors.rb +54 -0
  157. data/ruby/trema/network-component.rb +153 -0
  158. data/ruby/trema/ofctl.rb +62 -0
  159. data/ruby/trema/open-vswitch.rb +154 -0
  160. data/ruby/trema/openflow-error.c +191 -0
  161. data/ruby/trema/openflow-error.h +53 -0
  162. data/ruby/trema/openflow-switch.rb +88 -0
  163. data/ruby/trema/ordered-hash.rb +74 -0
  164. data/ruby/trema/packet-queue.rb +178 -0
  165. data/ruby/trema/packet_in.c +736 -0
  166. data/ruby/trema/packet_in.h +46 -0
  167. data/ruby/trema/packetin-filter.rb +126 -0
  168. data/ruby/trema/path.rb +135 -0
  169. data/ruby/trema/phost.rb +69 -0
  170. data/ruby/trema/port-mod.c +226 -0
  171. data/ruby/trema/port-mod.h +36 -0
  172. data/ruby/trema/port-stats-reply.rb +111 -0
  173. data/ruby/trema/port-status.c +156 -0
  174. data/ruby/trema/port-status.h +45 -0
  175. data/ruby/trema/port.c +295 -0
  176. data/ruby/trema/port.h +47 -0
  177. data/ruby/trema/process.rb +76 -0
  178. data/ruby/trema/queue-get-config-reply.c +200 -0
  179. data/ruby/trema/queue-get-config-reply.h +47 -0
  180. data/ruby/trema/queue-get-config-request.c +141 -0
  181. data/ruby/trema/queue-get-config-request.h +44 -0
  182. data/ruby/trema/queue-stats-reply.rb +78 -0
  183. data/ruby/trema/set-config.c +171 -0
  184. data/ruby/trema/set-config.h +44 -0
  185. data/ruby/trema/shell.rb +39 -0
  186. data/ruby/trema/shell/down.rb +39 -0
  187. data/ruby/trema/shell/killall.rb +40 -0
  188. data/ruby/trema/shell/link.rb +61 -0
  189. data/ruby/trema/shell/reset_stats.rb +50 -0
  190. data/ruby/trema/shell/run.rb +67 -0
  191. data/ruby/trema/shell/send_packets.rb +42 -0
  192. data/ruby/trema/shell/show_stats.rb +49 -0
  193. data/ruby/trema/shell/up.rb +43 -0
  194. data/ruby/trema/shell/vhost.rb +44 -0
  195. data/ruby/trema/shell/vswitch.rb +49 -0
  196. data/ruby/trema/stats-helper.rb +65 -0
  197. data/ruby/trema/stats-reply.c +483 -0
  198. data/ruby/trema/stats-reply.h +53 -0
  199. data/ruby/trema/stats-request.c +634 -0
  200. data/ruby/trema/stats-request.h +42 -0
  201. data/ruby/trema/switch-daemon.rb +74 -0
  202. data/ruby/trema/switch-disconnected.c +40 -0
  203. data/ruby/trema/switch-disconnected.h +38 -0
  204. data/ruby/trema/switch-manager.rb +121 -0
  205. data/ruby/trema/switch.rb +37 -0
  206. data/ruby/trema/table-stats-reply.rb +87 -0
  207. data/ruby/trema/timers.rb +97 -0
  208. data/ruby/trema/trema.c +122 -0
  209. data/ruby/trema/tremashark.rb +39 -0
  210. data/ruby/trema/util.rb +84 -0
  211. data/ruby/trema/vendor-request.c +193 -0
  212. data/ruby/trema/vendor-request.h +44 -0
  213. data/ruby/trema/vendor-stats-reply.rb +62 -0
  214. data/ruby/trema/vendor.c +152 -0
  215. data/ruby/trema/vendor.h +52 -0
  216. data/ruby/trema/version.rb +30 -0
  217. data/spec/spec_helper.rb +153 -0
  218. data/spec/support/openflow-message.rb +94 -0
  219. data/spec/trema/action-enqueue_spec.rb +100 -0
  220. data/spec/trema/action-output_spec.rb +116 -0
  221. data/spec/trema/action-set-dl-dst_spec.rb +95 -0
  222. data/spec/trema/action-set-dl-src_spec.rb +92 -0
  223. data/spec/trema/action-set-nw-dst_spec.rb +96 -0
  224. data/spec/trema/action-set-nw-src_spec.rb +97 -0
  225. data/spec/trema/action-set-nw-tos_spec.rb +88 -0
  226. data/spec/trema/action-set-tp-dst_spec.rb +88 -0
  227. data/spec/trema/action-set-tp-src_spec.rb +88 -0
  228. data/spec/trema/action-set-vlan-pcp_spec.rb +91 -0
  229. data/spec/trema/action-set-vlan-vid_spec.rb +91 -0
  230. data/spec/trema/action-strip-vlan_spec.rb +57 -0
  231. data/spec/trema/action-vendor_spec.rb +90 -0
  232. data/spec/trema/app_spec.rb +90 -0
  233. data/spec/trema/barrier-reply_spec.rb +45 -0
  234. data/spec/trema/barrier-request_spec.rb +83 -0
  235. data/spec/trema/cli_spec.rb +160 -0
  236. data/spec/trema/controller_spec.rb +100 -0
  237. data/spec/trema/dsl/configuration_spec.rb +122 -0
  238. data/spec/trema/dsl/link_spec.rb +54 -0
  239. data/spec/trema/dsl/run_spec.rb +78 -0
  240. data/spec/trema/dsl/runner_spec.rb +239 -0
  241. data/spec/trema/dsl/switch_spec.rb +77 -0
  242. data/spec/trema/dsl/syntax_spec.rb +121 -0
  243. data/spec/trema/dsl/vhost_spec.rb +148 -0
  244. data/spec/trema/dsl/vswitch_spec.rb +90 -0
  245. data/spec/trema/echo-reply_spec.rb +49 -0
  246. data/spec/trema/echo-request_spec.rb +75 -0
  247. data/spec/trema/error_spec.rb +142 -0
  248. data/spec/trema/executables_spec.rb +75 -0
  249. data/spec/trema/features-reply_spec.rb +57 -0
  250. data/spec/trema/features-request_spec.rb +66 -0
  251. data/spec/trema/flow-removed_spec.rb +146 -0
  252. data/spec/trema/get-config-reply_spec.rb +43 -0
  253. data/spec/trema/get-config-request_spec.rb +82 -0
  254. data/spec/trema/hello_spec.rb +49 -0
  255. data/spec/trema/host_spec.rb +193 -0
  256. data/spec/trema/link_spec.rb +64 -0
  257. data/spec/trema/list-switches-reply_spec.rb +48 -0
  258. data/spec/trema/logger_spec.rb +48 -0
  259. data/spec/trema/mac_spec.rb +115 -0
  260. data/spec/trema/match_spec.rb +113 -0
  261. data/spec/trema/open-vswitch_spec.rb +123 -0
  262. data/spec/trema/openflow-error_spec.rb +141 -0
  263. data/spec/trema/openflow-switch_spec.rb +56 -0
  264. data/spec/trema/packet-in_spec.rb +168 -0
  265. data/spec/trema/packet-out_spec.rb +128 -0
  266. data/spec/trema/packetin-filter_spec.rb +41 -0
  267. data/spec/trema/port-mod_spec.rb +101 -0
  268. data/spec/trema/port-status_spec.rb +108 -0
  269. data/spec/trema/port_spec.rb +61 -0
  270. data/spec/trema/process_spec.rb +71 -0
  271. data/spec/trema/queue-get-config-reply_spec.rb +66 -0
  272. data/spec/trema/queue-get-config-request_spec.rb +69 -0
  273. data/spec/trema/set-config_spec.rb +80 -0
  274. data/spec/trema/shell/vhost_spec.rb +57 -0
  275. data/spec/trema/shell/vswitch_spec.rb +89 -0
  276. data/spec/trema/stats-reply_spec.rb +306 -0
  277. data/spec/trema/stats-request_spec.rb +151 -0
  278. data/spec/trema/switch-disconnected_spec.rb +58 -0
  279. data/spec/trema/switch-manager_spec.rb +43 -0
  280. data/spec/trema/tremashark_spec.rb +41 -0
  281. data/spec/trema/util_spec.rb +93 -0
  282. data/spec/trema/vendor-request_spec.rb +79 -0
  283. data/src/examples/cbench_switch/README +21 -0
  284. data/src/examples/cbench_switch/cbench-switch.rb +39 -0
  285. data/src/examples/cbench_switch/cbench_switch.c +68 -0
  286. data/src/examples/dumper/dumper.c +370 -0
  287. data/src/examples/dumper/dumper.conf +7 -0
  288. data/src/examples/dumper/dumper.rb +196 -0
  289. data/src/examples/hello_trema/README +13 -0
  290. data/src/examples/hello_trema/hello_trema.c +51 -0
  291. data/src/examples/hello_trema/hello_trema.conf +3 -0
  292. data/src/examples/hello_trema/hello_trema.rb +35 -0
  293. data/src/examples/learning_switch/README +15 -0
  294. data/src/examples/learning_switch/fdb.rb +112 -0
  295. data/src/examples/learning_switch/learning-switch.rb +88 -0
  296. data/src/examples/learning_switch/learning_switch.c +236 -0
  297. data/src/examples/learning_switch/learning_switch.conf +18 -0
  298. data/src/examples/list_switches/README +19 -0
  299. data/src/examples/list_switches/list-switches.rb +45 -0
  300. data/src/examples/list_switches/list_switches.c +81 -0
  301. data/src/examples/list_switches/list_switches.conf +15 -0
  302. data/src/examples/match_compare/match-compare.conf +30 -0
  303. data/src/examples/match_compare/match-compare.rb +99 -0
  304. data/src/examples/multi_learning_switch/README +14 -0
  305. data/src/examples/multi_learning_switch/multi-learning-switch.rb +96 -0
  306. data/src/examples/multi_learning_switch/multi_learning_switch.c +296 -0
  307. data/src/examples/multi_learning_switch/multi_learning_switch.conf +17 -0
  308. data/src/examples/openflow_message/README +11 -0
  309. data/src/examples/openflow_message/echo-reply.rb +59 -0
  310. data/src/examples/openflow_message/echo-request.rb +58 -0
  311. data/src/examples/openflow_message/echo_reply.c +70 -0
  312. data/src/examples/openflow_message/echo_request.c +70 -0
  313. data/src/examples/openflow_message/example.rb +63 -0
  314. data/src/examples/openflow_message/features-request.rb +97 -0
  315. data/src/examples/openflow_message/features_request.c +168 -0
  316. data/src/examples/openflow_message/hello.c +70 -0
  317. data/src/examples/openflow_message/hello.rb +58 -0
  318. data/src/examples/openflow_message/set-config.rb +59 -0
  319. data/src/examples/openflow_message/set_config.c +70 -0
  320. data/src/examples/packet_in/README +15 -0
  321. data/src/examples/packet_in/packet_in.c +55 -0
  322. data/src/examples/packet_in/packet_in.conf +15 -0
  323. data/src/examples/packet_in/packet_in.rb +34 -0
  324. data/src/examples/packetin_filter_config/README +12 -0
  325. data/src/examples/packetin_filter_config/add_filter.c +73 -0
  326. data/src/examples/packetin_filter_config/delete_filter.c +65 -0
  327. data/src/examples/packetin_filter_config/delete_filter_strict.c +75 -0
  328. data/src/examples/packetin_filter_config/dump_filter.c +65 -0
  329. data/src/examples/packetin_filter_config/dump_filter_strict.c +75 -0
  330. data/src/examples/packetin_filter_config/packetin_filter_config.c +134 -0
  331. data/src/examples/packetin_filter_config/packetin_filter_config.conf +7 -0
  332. data/src/examples/packetin_filter_config/utils.c +102 -0
  333. data/src/examples/packetin_filter_config/utils.h +42 -0
  334. data/src/examples/repeater_hub/README +8 -0
  335. data/src/examples/repeater_hub/repeater-hub.rb +43 -0
  336. data/src/examples/repeater_hub/repeater-hub_spec.rb +156 -0
  337. data/src/examples/repeater_hub/repeater_hub.c +83 -0
  338. data/src/examples/repeater_hub/repeater_hub.conf +28 -0
  339. data/src/examples/switch_info/README +13 -0
  340. data/src/examples/switch_info/switch_info.c +80 -0
  341. data/src/examples/switch_info/switch_info.conf +3 -0
  342. data/src/examples/switch_info/switch_info.rb +46 -0
  343. data/src/examples/switch_monitor/switch-monitor.conf +3 -0
  344. data/src/examples/switch_monitor/switch-monitor.rb +58 -0
  345. data/src/examples/switch_monitor/switch_monitor.c +154 -0
  346. data/src/examples/traffic_monitor/counter.c +74 -0
  347. data/src/examples/traffic_monitor/counter.h +48 -0
  348. data/src/examples/traffic_monitor/counter.rb +46 -0
  349. data/src/examples/traffic_monitor/fdb.c +76 -0
  350. data/src/examples/traffic_monitor/fdb.h +50 -0
  351. data/src/examples/traffic_monitor/fdb.rb +44 -0
  352. data/src/examples/traffic_monitor/traffic-monitor.rb +100 -0
  353. data/src/examples/traffic_monitor/traffic_monitor.c +163 -0
  354. data/src/examples/traffic_monitor/traffic_monitor.conf +16 -0
  355. data/src/lib/arp.h +61 -0
  356. data/src/lib/bool.h +49 -0
  357. data/src/lib/buffer.c +305 -0
  358. data/src/lib/buffer.h +56 -0
  359. data/src/lib/byteorder.c +547 -0
  360. data/src/lib/byteorder.h +110 -0
  361. data/src/lib/checks.h +42 -0
  362. data/src/lib/daemon.c +302 -0
  363. data/src/lib/daemon.h +42 -0
  364. data/src/lib/doubly_linked_list.c +281 -0
  365. data/src/lib/doubly_linked_list.h +88 -0
  366. data/src/lib/ether.c +48 -0
  367. data/src/lib/ether.h +94 -0
  368. data/src/lib/etherip.h +46 -0
  369. data/src/lib/event_handler.c +389 -0
  370. data/src/lib/event_handler.h +64 -0
  371. data/src/lib/hash_table.c +417 -0
  372. data/src/lib/hash_table.h +138 -0
  373. data/src/lib/icmp.h +74 -0
  374. data/src/lib/igmp.h +50 -0
  375. data/src/lib/ipv4.h +50 -0
  376. data/src/lib/linked_list.c +199 -0
  377. data/src/lib/linked_list.h +84 -0
  378. data/src/lib/log.c +402 -0
  379. data/src/lib/log.h +78 -0
  380. data/src/lib/match.h +84 -0
  381. data/src/lib/match_table.c +608 -0
  382. data/src/lib/match_table.h +51 -0
  383. data/src/lib/message_queue.c +143 -0
  384. data/src/lib/message_queue.h +61 -0
  385. data/src/lib/messenger.c +1714 -0
  386. data/src/lib/messenger.h +145 -0
  387. data/src/lib/openflow_application_interface.c +1673 -0
  388. data/src/lib/openflow_application_interface.h +329 -0
  389. data/src/lib/openflow_message.c +4051 -0
  390. data/src/lib/openflow_message.h +288 -0
  391. data/src/lib/openflow_service_interface.h +59 -0
  392. data/src/lib/packet_info.c +230 -0
  393. data/src/lib/packet_info.h +209 -0
  394. data/src/lib/packet_parser.c +502 -0
  395. data/src/lib/packetin_filter_interface.c +294 -0
  396. data/src/lib/packetin_filter_interface.h +127 -0
  397. data/src/lib/persistent_storage.c +480 -0
  398. data/src/lib/persistent_storage.h +46 -0
  399. data/src/lib/stat.c +213 -0
  400. data/src/lib/stat.h +44 -0
  401. data/src/lib/tcp.h +67 -0
  402. data/src/lib/timer.c +350 -0
  403. data/src/lib/timer.h +53 -0
  404. data/src/lib/trema.c +710 -0
  405. data/src/lib/trema.h +79 -0
  406. data/src/lib/trema_private.c +177 -0
  407. data/src/lib/trema_private.h +60 -0
  408. data/src/lib/trema_wrapper.c +56 -0
  409. data/src/lib/trema_wrapper.h +64 -0
  410. data/src/lib/udp.h +43 -0
  411. data/src/lib/utility.c +515 -0
  412. data/src/lib/utility.h +67 -0
  413. data/src/lib/wrapper.c +100 -0
  414. data/src/lib/wrapper.h +76 -0
  415. data/src/packetin_filter/README +17 -0
  416. data/src/packetin_filter/packetin_filter.c +575 -0
  417. data/src/switch_manager/README +20 -0
  418. data/src/switch_manager/cookie_table.c +292 -0
  419. data/src/switch_manager/cookie_table.h +72 -0
  420. data/src/switch_manager/dpid_table.c +110 -0
  421. data/src/switch_manager/dpid_table.h +46 -0
  422. data/src/switch_manager/management_interface.h +44 -0
  423. data/src/switch_manager/ofpmsg_recv.c +482 -0
  424. data/src/switch_manager/ofpmsg_recv.h +42 -0
  425. data/src/switch_manager/ofpmsg_send.c +235 -0
  426. data/src/switch_manager/ofpmsg_send.h +50 -0
  427. data/src/switch_manager/secure_channel_listener.c +281 -0
  428. data/src/switch_manager/secure_channel_listener.h +42 -0
  429. data/src/switch_manager/secure_channel_receiver.c +126 -0
  430. data/src/switch_manager/secure_channel_receiver.h +43 -0
  431. data/src/switch_manager/secure_channel_sender.c +126 -0
  432. data/src/switch_manager/secure_channel_sender.h +43 -0
  433. data/src/switch_manager/service_interface.c +181 -0
  434. data/src/switch_manager/service_interface.h +46 -0
  435. data/src/switch_manager/switch.c +538 -0
  436. data/src/switch_manager/switch.h +51 -0
  437. data/src/switch_manager/switch_manager.c +448 -0
  438. data/src/switch_manager/switch_manager.h +63 -0
  439. data/src/switch_manager/switchinfo.h +72 -0
  440. data/src/switch_manager/xid_table.c +184 -0
  441. data/src/switch_manager/xid_table.h +56 -0
  442. data/src/tremashark/README +78 -0
  443. data/src/tremashark/packet_capture.c +357 -0
  444. data/src/tremashark/pcap_private.h +47 -0
  445. data/src/tremashark/pcap_queue.c +197 -0
  446. data/src/tremashark/pcap_queue.h +58 -0
  447. data/src/tremashark/plugin/.gitignore +6 -0
  448. data/src/tremashark/plugin/packet-trema/.gitignore +5 -0
  449. data/src/tremashark/plugin/packet-trema/Makefile +77 -0
  450. data/src/tremashark/plugin/packet-trema/Makefile.am +110 -0
  451. data/src/tremashark/plugin/packet-trema/Makefile.common +31 -0
  452. data/src/tremashark/plugin/packet-trema/moduleinfo.h +41 -0
  453. data/src/tremashark/plugin/packet-trema/packet-trema.c +1659 -0
  454. data/src/tremashark/plugin/packet-trema/plugin.c +31 -0
  455. data/src/tremashark/plugin/user_dlts +2 -0
  456. data/src/tremashark/queue.c +168 -0
  457. data/src/tremashark/queue.h +60 -0
  458. data/src/tremashark/stdin_relay.c +257 -0
  459. data/src/tremashark/syslog_relay.c +247 -0
  460. data/src/tremashark/tremashark.c +556 -0
  461. data/trema +93 -0
  462. data/trema-config +61 -0
  463. data/unittests/buffer_stubs.c +74 -0
  464. data/unittests/cmockery_trema.c +123 -0
  465. data/unittests/cmockery_trema.h +96 -0
  466. data/unittests/lib/buffer_test.c +370 -0
  467. data/unittests/lib/byteorder_test.c +1717 -0
  468. data/unittests/lib/daemon_test.c +664 -0
  469. data/unittests/lib/doubly_linked_list_test.c +346 -0
  470. data/unittests/lib/ether_test.c +127 -0
  471. data/unittests/lib/hash_table_test.c +278 -0
  472. data/unittests/lib/linked_list_test.c +343 -0
  473. data/unittests/lib/log_test.c +459 -0
  474. data/unittests/lib/match_table_test.c +1509 -0
  475. data/unittests/lib/message_queue_test.c +379 -0
  476. data/unittests/lib/messenger_test.c +438 -0
  477. data/unittests/lib/openflow_application_interface_test.c +3488 -0
  478. data/unittests/lib/openflow_message_test.c +7337 -0
  479. data/unittests/lib/packet_info_test.c +544 -0
  480. data/unittests/lib/packet_parser_test.c +703 -0
  481. data/unittests/lib/packetin_filter_interface_test.c +723 -0
  482. data/unittests/lib/persistent_storage_test.c +802 -0
  483. data/unittests/lib/stat_test.c +291 -0
  484. data/unittests/lib/test_packets/arp_rep.cap +0 -0
  485. data/unittests/lib/test_packets/arp_req.cap +0 -0
  486. data/unittests/lib/test_packets/icmp_echo_rep.cap +0 -0
  487. data/unittests/lib/test_packets/icmp_echo_req.cap +0 -0
  488. data/unittests/lib/test_packets/igmp_query_v2.cap +0 -0
  489. data/unittests/lib/test_packets/ipx.cap +0 -0
  490. data/unittests/lib/test_packets/lldp.cap +0 -0
  491. data/unittests/lib/test_packets/lldp_over_ip.cap +0 -0
  492. data/unittests/lib/test_packets/tcp.cap +0 -0
  493. data/unittests/lib/test_packets/tcp_syn.cap +0 -0
  494. data/unittests/lib/test_packets/udp.cap +0 -0
  495. data/unittests/lib/test_packets/udp_frag_head.cap +0 -0
  496. data/unittests/lib/test_packets/udp_frag_next.cap +0 -0
  497. data/unittests/lib/test_packets/vtag_icmp_echo_rep.cap +0 -0
  498. data/unittests/lib/test_packets/vtag_icmp_echo_req.cap +0 -0
  499. data/unittests/lib/timer_test.c +248 -0
  500. data/unittests/lib/trema_private_test.c +323 -0
  501. data/unittests/lib/trema_test.c +985 -0
  502. data/unittests/lib/utility_test.c +628 -0
  503. data/unittests/lib/wrapper_test.c +201 -0
  504. data/unittests/packetin_filter/packetin_filter_test.c +477 -0
  505. data/unittests/switch_manager/switch_manager_test.c +1178 -0
  506. data/unittests/wrapper_stubs.c +39 -0
  507. data/vendor/.gitignore +6 -0
  508. data/vendor/README +30 -0
  509. data/vendor/cmockery-20110428.tar.gz +0 -0
  510. data/vendor/oflops-0.03.tar.gz +0 -0
  511. data/vendor/oflops_no_snmp+1.0.0.patch +340 -0
  512. data/vendor/openflow-1.0.0.tar.gz +0 -0
  513. data/vendor/openflow.git.tar.gz +0 -0
  514. data/vendor/openvswitch-1.2.2.tar.gz +0 -0
  515. data/vendor/ruby-ifconfig-1.2/COPYING +340 -0
  516. data/vendor/ruby-ifconfig-1.2/Changelog +16 -0
  517. data/vendor/ruby-ifconfig-1.2/INSTALL +239 -0
  518. data/vendor/ruby-ifconfig-1.2/README +38 -0
  519. data/vendor/ruby-ifconfig-1.2/Rakefile +14 -0
  520. data/vendor/ruby-ifconfig-1.2/TODO +8 -0
  521. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/darwin.txt +17 -0
  522. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd.txt +10 -0
  523. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/dragonflybsd_netstat.txt +14 -0
  524. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd.txt +17 -0
  525. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/freebsd_netstat.txt +24 -0
  526. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux.txt +60 -0
  527. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/linux_ethernet.txt +20 -0
  528. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/netbsd.txt +10 -0
  529. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/openbsd.txt +36 -0
  530. data/vendor/ruby-ifconfig-1.2/ifconfig_examples/sunos.txt +10 -0
  531. data/vendor/ruby-ifconfig-1.2/lib/ifconfig.rb +71 -0
  532. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/ifconfig.rb +72 -0
  533. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/interface_types.rb +69 -0
  534. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/bsd/network_types.rb +3 -0
  535. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/ifconfig.rb +84 -0
  536. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/interface_types.rb +130 -0
  537. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/common/network_types.rb +49 -0
  538. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/ifconfig.rb +43 -0
  539. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/interface_types.rb +112 -0
  540. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/linux/network_types.rb +55 -0
  541. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/ifconfig.rb +38 -0
  542. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/interface_types.rb +77 -0
  543. data/vendor/ruby-ifconfig-1.2/lib/ifconfig/sunos/network_types.rb +4 -0
  544. data/vendor/ruby-ifconfig-1.2/setup.rb +1306 -0
  545. data/vendor/ruby-ifconfig-1.2/test/test_bsd.rb +35 -0
  546. data/vendor/ruby-ifconfig-1.2/test/test_darwin.rb +33 -0
  547. data/vendor/ruby-ifconfig-1.2/test/test_dragonflybsd.rb +35 -0
  548. data/vendor/ruby-ifconfig-1.2/test/test_helper.rb +4 -0
  549. data/vendor/ruby-ifconfig-1.2/test/test_linux.rb +31 -0
  550. data/vendor/ruby-ifconfig-1.2/test/test_netbsd.rb +33 -0
  551. data/vendor/ruby-ifconfig-1.2/test/test_openbsd.rb +33 -0
  552. data/vendor/ruby-ifconfig-1.2/test/test_sunos.rb +35 -0
  553. data/vendor/ruby-ifconfig-1.2/test/unit/tc_darwin.rb +40 -0
  554. data/vendor/ruby-ifconfig-1.2/test/unit/tc_dragonflybsd.rb +39 -0
  555. data/vendor/ruby-ifconfig-1.2/test/unit/tc_freebsd.rb +40 -0
  556. data/vendor/ruby-ifconfig-1.2/test/unit/tc_linux.rb +49 -0
  557. data/vendor/ruby-ifconfig-1.2/test/unit/tc_netbsd.rb +39 -0
  558. data/vendor/ruby-ifconfig-1.2/test/unit/tc_openbsd.rb +39 -0
  559. data/vendor/ruby-ifconfig-1.2/test/unit/tc_sunos.rb +44 -0
  560. metadata +856 -0
@@ -0,0 +1,49 @@
1
+ # $Id: network_types.rb,v 1.1.1.1 2005/07/02 19:10:58 hobe Exp $
2
+ #
3
+
4
+ # base type to hold information about the kinds of networks
5
+ # on to each adapter. ipv4,6 ppp etc
6
+ class BasicNetworkType
7
+ def initialize
8
+ @nettype = nil
9
+ end
10
+ attr_reader :nettype
11
+ end
12
+
13
+ #
14
+ # Ipv4 Network type
15
+ # Optional Broadcast and Point to Point Arguments
16
+ #
17
+ class Ipv4Network < BasicNetworkType
18
+ def initialize(addr,mask,bcast=nil,ptp=nil)
19
+ super()
20
+ @nettype = 'inet'
21
+ @addr = IPAddr.new(addr)
22
+ @bcast = bcast
23
+ @mask = mask
24
+ @ptp = ptp
25
+ end
26
+ attr_reader :addr, :bcast, :mask, :ptp
27
+
28
+ def to_s
29
+ a = [" #{@nettype} Address: #{@addr}","Mask: #{@mask}"]
30
+ a.push "Broadcast: #{@bcast}" unless @bcast.nil?
31
+ a.push "P-t-P: #{@ptp}" unless @ptp.nil?
32
+ return a.join(', ')
33
+ end
34
+
35
+ end
36
+
37
+ class Ipv6Network < BasicNetworkType
38
+ def initialize(addr,scope=nil)
39
+ super()
40
+ @nettype = 'inet6'
41
+ @addr = IPAddr.new(addr)
42
+ @scope = scope
43
+ end
44
+ attr_reader :addr, :scope
45
+
46
+ def to_s
47
+ " #{@nettype} Address: #{@addr}"
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ # $Id: ifconfig.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/ifconfig'
5
+ require 'ifconfig/linux/network_types'
6
+ require 'ifconfig/linux/interface_types'
7
+
8
+ class Ifconfig
9
+ #
10
+ # Can manually specify the platform (should be output of the 'uname' command)
11
+ # and the ifconfig input
12
+ #
13
+ def initialize(input=nil,verbose=nil)
14
+ if input.nil?
15
+ # [PATCH] Avoid parse failures if using m17n'ed ifconfig
16
+ old_lc_all = ENV[ 'LC_ALL' ]
17
+ ENV[ 'LC_ALL' ] = 'C'
18
+ @ifconfig = IO.popen("/sbin/ifconfig -a"){ |f| f.readlines.join }
19
+ ENV[ 'LC_ALL' ] = old_lc_all
20
+ else
21
+ @ifconfig = input
22
+ end
23
+ @verbose = verbose
24
+ @ifaces = {}
25
+ split_interfaces(@ifconfig).each do |iface|
26
+ iface_name = get_iface_name(iface)
27
+ case iface
28
+ when /encap\:ethernet/im
29
+ @ifaces[iface_name] = EthernetAdapter.new(iface_name,iface)
30
+ when /encap\:Local Loopback/im
31
+ @ifaces[iface_name] = LoopbackInterface.new(iface_name,iface)
32
+ when /encap\:IPv6-in-IPv4/im
33
+ @ifaces[iface_name] = IPv6_in_IPv4.new(iface_name,iface)
34
+ when /encap\:Point-to-Point Protocol/im
35
+ @ifaces[iface_name] = PPP.new(iface_name,iface)
36
+ when /encap\:Serial Line IP/im
37
+ @ifaces[iface_name] = SerialLineIP.new(iface_name,iface)
38
+ else
39
+ puts "Unknown Adapter Type on Linux: #{iface}" if @verbose
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,112 @@
1
+ # $Id: interface_types.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/interface_types'
5
+
6
+ class NetworkAdapter
7
+ # Parse activity on interface
8
+ #
9
+ def parse_activity(line)
10
+ atr = %w(packets,errors,dropped,overruns)
11
+ case line.strip!
12
+
13
+ when /^RX packets/
14
+ @rx = array_to_hash_elem(
15
+ line.match(/^RX\s+(\w+)\:(\d+)\s+(\w+)\:(\d+)\s+(\w+)\:(\d+)\s+(\w+)\:(\d)/i)[1..8])
16
+ match = line.match(/\s+frame\:(\d+)/i)
17
+ @rx['frame'] = match[1] unless match.nil?
18
+
19
+ when /^TX packets/
20
+ @tx = array_to_hash_elem(
21
+ line.match(/^TX\s+(\w+)\:(\d+)\s+(\w+)\:(\d+)\s+(\w+)\:(\d+)\s+(\w+)\:(\d+)/i)[1..8])
22
+ match = line.match(/\s+carrier\:(\d+)/i)
23
+ @tx['carrier'] = match[1] unless match.nil?
24
+
25
+ when /^RX bytes/
26
+ match = line.match(/RX\s+(\w+)\:(\d+).*TX\s+(\w+)\:(\d+)/i)[1..4]
27
+ @rx.merge!(array_to_hash_elem(match[0..1]))
28
+ @tx.merge!(array_to_hash_elem(match[2..3]))
29
+ end
30
+ end
31
+
32
+ # iterate line by line and dispatch to helper functions
33
+ # for lines that match a pattern
34
+ #
35
+ def parse_ifconfig
36
+ @ifconfig.split("\n").each { |line|
37
+ case line
38
+ when /^\s+#{@protos}/
39
+ add_network(line)
40
+ when /MTU\:\d+\s+Metric\:/
41
+ parse_flags(line)
42
+ when /^\s+RX|TX/
43
+ parse_activity(line)
44
+ end
45
+ }
46
+ end
47
+
48
+ # parses the "UP LOOPBACK RUNNING MTU:3924 Metric:1" line
49
+ #
50
+ def parse_flags(line)
51
+ flags = line.strip.split
52
+ @metric = flags.pop.split(':')[1].to_i
53
+ @mtu = flags.pop.split(':')[1].to_i
54
+ @flags = flags
55
+ @status = true if @flags.include?('UP')
56
+ end
57
+
58
+ # Parses networks on an interface based on the first token in the line.
59
+ # eg: inet or inet6
60
+ #
61
+ def add_network(line)
62
+ case line
63
+ when /^\s+inet\s/
64
+ addr = line.match(/\s+addr\:([\d\d?\d?\.]{4,})/i)[1]
65
+ mask = line.match(/\s+mask\:([\d\d?\d?\.]{4,})/i)[1]
66
+ bcast = line.match(/\s+bcast\:([\d\d?\d?\.]{4,})/i)
67
+ bcast = bcast[1] unless bcast.nil?
68
+ ptp = line.match(/\s+P-t-P\:([\d\d?\d?\.]{4,})/i)
69
+ ptp = ptp[1] unless ptp.nil?
70
+ @networks['inet'] = Ipv4Network.new(addr, mask, bcast, ptp)
71
+
72
+ when /^\s+inet6\s/
73
+ # there can be multiple inet6 entries
74
+ addr,scope = line.match(/\s+addr\:\s+(\S+)\s+scope\:\s*(\w+)/i)[1..2]
75
+ @networks["inet6:#{addr}"] = Ipv6Network.new(addr,scope)
76
+
77
+ when /^\s+#{Regexp.escape('IPX/Ethernet II')}\s/
78
+ addr = line.match(/\s+addr\:\s*(\S+)/)[1]
79
+ @networks["IPX/Ethernet II"] = IPX_EthernetII.new(addr)
80
+
81
+ when /^\s+#{Regexp.escape('IPX/Ethernet 802.2')}\s/
82
+ addr = line.match(/\s+addr\:\s*(\S+)/)[1]
83
+ @networks["IPX/Ethernet 802.2"] = IPX_Ethernet802_2.new(addr)
84
+
85
+ when /^\s+#{Regexp.escape('IPX/Ethernet 802.3')}\s/
86
+ addr = line.match(/\s+addr\:\s*(\S+)/)[1]
87
+ @networks["IPX/Ethernet 802.3"] = IPX_Ethernet802_3.new(addr)
88
+
89
+ when /^\s+#{Regexp.escape('EtherTalk Phase 2')}\s/
90
+ addr = line.match(/\s+addr\:\s*(\S+)/)[1]
91
+ @networks["EtherTalk Phase 2"] = EtherTalkPhase2.new(addr)
92
+
93
+ when /^\s+#{Regexp.escape('IPX/Ethernet SNAP')}\s/
94
+ addr = line.match(/\s+addr\:\s*(\S+)/)[1]
95
+ @networks["IPX/Ethernet SNAP"] = IPX_EthernetSNAP.new(addr)
96
+
97
+ else
98
+ puts "unknown network type: #{line}"
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+ class EthernetAdapter
105
+ def set_mac
106
+ begin
107
+ return @ifconfig.match(/\s+hwaddr\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im)[1]
108
+ rescue NoMethodError
109
+ puts "Couldn't Parse MAC Address for: #{@name}: #{$!}"
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,55 @@
1
+ # $Id: network_types.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/network_types'
5
+
6
+ #
7
+ # Base class for IPX and Appletalk classes
8
+ # Shouldn't be used directly
9
+ #
10
+ class MiscEthernet < BasicNetworkType
11
+ def initialize(addr)
12
+ super()
13
+ @addr = addr
14
+ end
15
+ attr_reader :addr
16
+ def to_s
17
+ " #{@nettype} Address: #{@addr}"
18
+ end
19
+ end
20
+
21
+ class IPX_EthernetII < MiscEthernet
22
+ def initialize(addr)
23
+ super(addr)
24
+ @nettype = 'IPX/Ethernet II'
25
+ end
26
+ end
27
+
28
+ class IPX_Ethernet802_2 < MiscEthernet
29
+ def initialize(addr)
30
+ super(addr)
31
+ @nettype = 'IPX/Ethernet 802.2'
32
+ end
33
+ end
34
+
35
+ class IPX_Ethernet802_3 < MiscEthernet
36
+ def initialize(addr)
37
+ super(addr)
38
+ @nettype = 'IPX/Ethernet 802.3'
39
+ end
40
+ end
41
+
42
+ class EtherTalkPhase2 < MiscEthernet
43
+ def initialize(addr)
44
+ super(addr)
45
+ @nettype = 'EtherTalk Phase 2'
46
+ end
47
+ end
48
+
49
+ class IPX_EthernetSNAP < MiscEthernet
50
+ def initialize(addr)
51
+ super(addr)
52
+ @nettype = 'IPX/Ethernet SNAP'
53
+ end
54
+ end
55
+
@@ -0,0 +1,38 @@
1
+ # $Id: ifconfig.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/ifconfig'
5
+
6
+ class Ifconfig
7
+ #
8
+ # Can manually specify the platform (should be output of the 'uname' command)
9
+ # and the ifconfig input
10
+ #
11
+ def initialize(input=nil,verbose=nil)
12
+ if input.nil?
13
+ cmd = IO.popen('which ifconfig'){ |f| f.readlines[0] }
14
+ exit unless !cmd.nil?
15
+ @ifconfig = IO.popen("/sbin/ifconfig -a"){ |f| f.readlines.join }
16
+ else
17
+ @ifconfig = input
18
+ end
19
+ @verbose = verbose
20
+
21
+ require 'ifconfig/sunos/network_types'
22
+ require 'ifconfig/sunos/interface_types'
23
+
24
+ @ifaces = {}
25
+
26
+ split_interfaces(@ifconfig).each do |iface|
27
+ iface_name = get_iface_name(iface)
28
+ case iface
29
+ when /^lo\d\:/im
30
+ @ifaces[iface_name] = LoopbackInterface.new(iface_name,iface)
31
+ when /\s+ether\s+/im
32
+ @ifaces[iface_name] = EthernetAdapter.new(iface_name,iface)
33
+ else
34
+ puts "Unknown Adapter Type: #{iface}" if @verbose
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,77 @@
1
+ # $Id: interface_types.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/interface_types'
5
+
6
+ # base class for network adapters
7
+ class NetworkAdapter
8
+ # Parse activity on interface
9
+ #
10
+ def parse_activity
11
+ #imaptest1# netstat -in
12
+ #Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue
13
+ #lo0 8232 0.0.0.0 0.0.0.4 267824 0 267824 0 0 0
14
+ #bge0 1500 10.0.0.0 10.32.4.138 10935939 0 7741167 0 0 0
15
+ cmd = "netstat -in | grep #{@name}"
16
+ line = IO.popen(cmd).gets
17
+ return if line.nil?
18
+ name,@mtu,dfgw,addr,@rx['packets'],@rx['errors'],
19
+ @tx['packets'],@tx['errors'],collisions,queue = line.split
20
+ @mtu = @mtu.to_i
21
+ end
22
+
23
+ # iterate line by line and dispatch to helper functions
24
+ # for lines that match a pattern
25
+ #
26
+ def parse_ifconfig
27
+ @ifconfig.split("\n").each { |line|
28
+ case line
29
+ when /^\s+#{@protos}/
30
+ add_network(line)
31
+ when /flags\=/i
32
+ parse_flags(line)
33
+ end
34
+ }
35
+ parse_activity
36
+ end
37
+
38
+ # parses the "UP LOOPBACK RUNNING MTU:3924 Metric:1" line
39
+ #
40
+ def parse_flags(line)
41
+ flags = Regexp.compile(/\<(\S+)\>/i).match(line)[1]
42
+ flags = flags.strip.split(',')
43
+ @flags = flags
44
+ @status = true if @flags.include?('UP')
45
+ end
46
+
47
+ # Parses networks on an interface based on the first token in the line.
48
+ # eg: inet or inet6
49
+ #
50
+ def add_network(line)
51
+ case line
52
+ when /^\s+inet\s/
53
+ addr,mask = Regexp.compile(/\s+([\d\d?\d?\.]{4,})\s+netmask\s+(\S+)/i).match(line)[1..2]
54
+ bcast = Regexp.compile(/\s+broadcast\s([\d\d?\d?\.]{4,})/i).match(line)
55
+ bcast = bcast[1] unless bcast.nil?
56
+ @networks['inet'] = Ipv4Network.new(addr, mask, bcast)
57
+ when /^\s+inet6\s/
58
+ # there can be multiple inet6 entries
59
+ addr,scope =
60
+ Regexp.compile(/inet6\s+(\S+)/i).match(line)[1]
61
+ @networks["inet6:#{addr}"] = Ipv6Network.new(addr)
62
+ else
63
+ puts "unknown network type: #{line}"
64
+ end
65
+ end
66
+ end
67
+
68
+
69
+ class EthernetAdapter
70
+ def set_mac
71
+ begin
72
+ @mac = Regexp.compile(/\s+ether\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im).match(@ifconfig)[1]
73
+ rescue NoMethodError
74
+ puts "Couldn't Parse MAC Address for: "+@name
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,4 @@
1
+ # $Id: network_types.rb,v 1.1.1.1 2005/07/02 19:10:57 hobe Exp $
2
+ #
3
+
4
+ require 'ifconfig/common/network_types'
@@ -0,0 +1,1306 @@
1
+ #
2
+ # This file is automatically generated. DO NOT MODIFY!
3
+ #
4
+ # setup.rb
5
+ #
6
+ # Copyright (c) 2000-2003 Minero Aoki <aamine@loveruby.net>
7
+ #
8
+ # This program is free software.
9
+ # You can distribute/modify this program under the terms of
10
+ # the GNU Lesser General Public License version 2.
11
+ #
12
+
13
+ def multipackage_install?
14
+ FileTest.directory?(File.dirname($0) + '/packages')
15
+ end
16
+
17
+ #
18
+ # compat.rb
19
+ #
20
+
21
+ unless Enumerable.method_defined?(:map)
22
+ module Enumerable
23
+ alias map collect
24
+ end
25
+ end
26
+
27
+ unless Enumerable.method_defined?(:select)
28
+ module Enumerable
29
+ alias select find_all
30
+ end
31
+ end
32
+
33
+ unless Enumerable.method_defined?(:reject)
34
+ module Enumerable
35
+ def reject
36
+ result = []
37
+ each do |i|
38
+ result.push i unless yield(i)
39
+ end
40
+ result
41
+ end
42
+ end
43
+ end
44
+
45
+ unless Enumerable.method_defined?(:inject)
46
+ module Enumerable
47
+ def inject(result)
48
+ each do |i|
49
+ result = yield(result, i)
50
+ end
51
+ result
52
+ end
53
+ end
54
+ end
55
+
56
+ unless Enumerable.method_defined?(:any?)
57
+ module Enumerable
58
+ def any?
59
+ each do |i|
60
+ return true if yield(i)
61
+ end
62
+ false
63
+ end
64
+ end
65
+ end
66
+
67
+ unless File.respond_to?(:read)
68
+ def File.read(fname)
69
+ File.open(fname, 'rb') {|f|
70
+ return f.read
71
+ }
72
+ end
73
+ end
74
+ #
75
+ # fileop.rb
76
+ #
77
+
78
+ module FileOperations
79
+
80
+ def mkdir_p(dirname, prefix = nil)
81
+ dirname = prefix + dirname if prefix
82
+ $stderr.puts "mkdir -p #{dirname}" if verbose?
83
+ return if no_harm?
84
+
85
+ # does not check '/'... it's too abnormal case
86
+ dirs = dirname.split(%r<(?=/)>)
87
+ if /\A[a-z]:\z/i =~ dirs[0]
88
+ disk = dirs.shift
89
+ dirs[0] = disk + dirs[0]
90
+ end
91
+ dirs.each_index do |idx|
92
+ path = dirs[0..idx].join('')
93
+ Dir.mkdir path unless File.dir?(path)
94
+ end
95
+ end
96
+
97
+ def rm_f(fname)
98
+ $stderr.puts "rm -f #{fname}" if verbose?
99
+ return if no_harm?
100
+
101
+ if File.exist?(fname) or File.symlink?(fname)
102
+ File.chmod 0777, fname
103
+ File.unlink fname
104
+ end
105
+ end
106
+
107
+ def rm_rf(dn)
108
+ $stderr.puts "rm -rf #{dn}" if verbose?
109
+ return if no_harm?
110
+
111
+ Dir.chdir dn
112
+ Dir.foreach('.') do |fn|
113
+ next if fn == '.'
114
+ next if fn == '..'
115
+ if File.dir?(fn)
116
+ verbose_off {
117
+ rm_rf fn
118
+ }
119
+ else
120
+ verbose_off {
121
+ rm_f fn
122
+ }
123
+ end
124
+ end
125
+ Dir.chdir '..'
126
+ Dir.rmdir dn
127
+ end
128
+
129
+ def move_file(src, dest)
130
+ File.unlink dest if File.exist?(dest)
131
+ begin
132
+ File.rename src, dest
133
+ rescue
134
+ File.open(dest, 'wb') {|f| f.write File.read(src) }
135
+ File.chmod File.stat(src).mode, dest
136
+ File.unlink src
137
+ end
138
+ end
139
+
140
+ def install(from, dest, mode, prefix = nil)
141
+ $stderr.puts "install #{from} #{dest}" if verbose?
142
+ return if no_harm?
143
+
144
+ realdest = prefix + dest if prefix
145
+ realdest += '/' + File.basename(from) if File.dir?(realdest)
146
+ str = File.read(from)
147
+ if diff?(str, realdest)
148
+ verbose_off {
149
+ rm_f realdest if File.exist?(realdest)
150
+ }
151
+ File.open(realdest, 'wb') {|f| f.write str }
152
+ File.chmod mode, realdest
153
+
154
+ File.open("#{objdir_root()}/InstalledFiles", 'a') {|f| f.puts dest }
155
+ end
156
+ end
157
+
158
+ def diff?(orig, targ)
159
+ return true unless File.exist?(targ)
160
+ orig != File.read(targ)
161
+ end
162
+
163
+ def command(str)
164
+ $stderr.puts str if verbose?
165
+ system str or raise RuntimeError, "'system #{str}' failed"
166
+ end
167
+
168
+ def ruby(str)
169
+ command config('ruby-prog') + ' ' + str
170
+ end
171
+
172
+ def make(task = '')
173
+ command config('make-prog') + ' ' + task
174
+ end
175
+
176
+ def extdir?(dir)
177
+ File.exist?(dir + '/MANIFEST')
178
+ end
179
+
180
+ def all_files_in(dirname)
181
+ Dir.open(dirname) {|d|
182
+ return d.select {|ent| File.file?("#{dirname}/#{ent}") }
183
+ }
184
+ end
185
+
186
+ REJECT_DIRS = %w(
187
+ CVS SCCS RCS CVS.adm
188
+ )
189
+
190
+ def all_dirs_in(dirname)
191
+ Dir.open(dirname) {|d|
192
+ return d.select {|n| File.dir?("#{dirname}/#{n}") } - %w(. ..) - REJECT_DIRS
193
+ }
194
+ end
195
+
196
+ end
197
+
198
+
199
+ class File
200
+
201
+ def File.dir?(path)
202
+ # for corrupted windows stat()
203
+ File.directory?((path[-1,1] == '/') ? path : path + '/')
204
+ end
205
+
206
+ end
207
+ #
208
+ # config.rb
209
+ #
210
+
211
+ if idx = ARGV.index(/\A--rbconfig=/)
212
+ require ARGV.delete_at(idx).split(/=/, 2)[1]
213
+ else
214
+ require 'rbconfig'
215
+ end
216
+
217
+ class ConfigTable
218
+
219
+ c = ::Config::CONFIG
220
+
221
+ rubypath = c['bindir'] + '/' + c['ruby_install_name']
222
+
223
+ major = c['MAJOR'].to_i
224
+ minor = c['MINOR'].to_i
225
+ teeny = c['TEENY'].to_i
226
+ version = "#{major}.#{minor}"
227
+
228
+ # ruby ver. >= 1.4.4?
229
+ newpath_p = ((major >= 2) or
230
+ ((major == 1) and
231
+ ((minor >= 5) or
232
+ ((minor == 4) and (teeny >= 4)))))
233
+
234
+ subprefix = lambda {|path|
235
+ path.sub(/\A#{Regexp.quote(c['prefix'])}/o, '$prefix')
236
+ }
237
+
238
+ if c['rubylibdir']
239
+ # V < 1.6.3
240
+ stdruby = subprefix.call(c['rubylibdir'])
241
+ siteruby = subprefix.call(c['sitedir'])
242
+ versite = subprefix.call(c['sitelibdir'])
243
+ sodir = subprefix.call(c['sitearchdir'])
244
+ elsif newpath_p
245
+ # 1.4.4 <= V <= 1.6.3
246
+ stdruby = "$prefix/lib/ruby/#{version}"
247
+ siteruby = subprefix.call(c['sitedir'])
248
+ versite = siteruby + '/' + version
249
+ sodir = "$site-ruby/#{c['arch']}"
250
+ else
251
+ # V < 1.4.4
252
+ stdruby = "$prefix/lib/ruby/#{version}"
253
+ siteruby = "$prefix/lib/ruby/#{version}/site_ruby"
254
+ versite = siteruby
255
+ sodir = "$site-ruby/#{c['arch']}"
256
+ end
257
+
258
+ common_descripters = [
259
+ [ 'prefix', [ c['prefix'],
260
+ 'path',
261
+ 'path prefix of target environment' ] ],
262
+ [ 'std-ruby', [ stdruby,
263
+ 'path',
264
+ 'the directory for standard ruby libraries' ] ],
265
+ [ 'site-ruby-common', [ siteruby,
266
+ 'path',
267
+ 'the directory for version-independent non-standard ruby libraries' ] ],
268
+ [ 'site-ruby', [ versite,
269
+ 'path',
270
+ 'the directory for non-standard ruby libraries' ] ],
271
+ [ 'bin-dir', [ '$prefix/bin',
272
+ 'path',
273
+ 'the directory for commands' ] ],
274
+ [ 'rb-dir', [ '$site-ruby',
275
+ 'path',
276
+ 'the directory for ruby scripts' ] ],
277
+ [ 'so-dir', [ sodir,
278
+ 'path',
279
+ 'the directory for ruby extentions' ] ],
280
+ [ 'data-dir', [ '$prefix/share',
281
+ 'path',
282
+ 'the directory for shared data' ] ],
283
+ [ 'ruby-path', [ rubypath,
284
+ 'path',
285
+ 'path to set to #! line' ] ],
286
+ [ 'ruby-prog', [ rubypath,
287
+ 'name',
288
+ 'the ruby program using for installation' ] ],
289
+ [ 'make-prog', [ 'make',
290
+ 'name',
291
+ 'the make program to compile ruby extentions' ] ],
292
+ [ 'without-ext', [ 'no',
293
+ 'yes/no',
294
+ 'does not compile/install ruby extentions' ] ]
295
+ ]
296
+ multipackage_descripters = [
297
+ [ 'with', [ '',
298
+ 'name,name...',
299
+ 'package names that you want to install',
300
+ 'ALL' ] ],
301
+ [ 'without', [ '',
302
+ 'name,name...',
303
+ 'package names that you do not want to install',
304
+ 'NONE' ] ]
305
+ ]
306
+ if multipackage_install?
307
+ DESCRIPTER = common_descripters + multipackage_descripters
308
+ else
309
+ DESCRIPTER = common_descripters
310
+ end
311
+
312
+ SAVE_FILE = 'config.save'
313
+
314
+ def ConfigTable.each_name(&block)
315
+ keys().each(&block)
316
+ end
317
+
318
+ def ConfigTable.keys
319
+ DESCRIPTER.map {|name, *dummy| name }
320
+ end
321
+
322
+ def ConfigTable.each_definition(&block)
323
+ DESCRIPTER.each(&block)
324
+ end
325
+
326
+ def ConfigTable.get_entry(name)
327
+ name, ent = DESCRIPTER.assoc(name)
328
+ ent
329
+ end
330
+
331
+ def ConfigTable.get_entry!(name)
332
+ get_entry(name) or raise ArgumentError, "no such config: #{name}"
333
+ end
334
+
335
+ def ConfigTable.add_entry(name, vals)
336
+ ConfigTable::DESCRIPTER.push [name,vals]
337
+ end
338
+
339
+ def ConfigTable.remove_entry(name)
340
+ get_entry(name) or raise ArgumentError, "no such config: #{name}"
341
+ DESCRIPTER.delete_if {|n, arr| n == name }
342
+ end
343
+
344
+ def ConfigTable.config_key?(name)
345
+ get_entry(name) ? true : false
346
+ end
347
+
348
+ def ConfigTable.bool_config?(name)
349
+ ent = get_entry(name) or return false
350
+ ent[1] == 'yes/no'
351
+ end
352
+
353
+ def ConfigTable.value_config?(name)
354
+ ent = get_entry(name) or return false
355
+ ent[1] != 'yes/no'
356
+ end
357
+
358
+ def ConfigTable.path_config?(name)
359
+ ent = get_entry(name) or return false
360
+ ent[1] == 'path'
361
+ end
362
+
363
+
364
+ class << self
365
+ alias newobj new
366
+ end
367
+
368
+ def ConfigTable.new
369
+ c = newobj()
370
+ c.initialize_from_table
371
+ c
372
+ end
373
+
374
+ def ConfigTable.load
375
+ c = newobj()
376
+ c.initialize_from_file
377
+ c
378
+ end
379
+
380
+ def initialize_from_table
381
+ @table = {}
382
+ DESCRIPTER.each do |k, (default, vname, desc, default2)|
383
+ @table[k] = default
384
+ end
385
+ end
386
+
387
+ def initialize_from_file
388
+ raise InstallError, "#{File.basename $0} config first"\
389
+ unless File.file?(SAVE_FILE)
390
+ @table = {}
391
+ File.foreach(SAVE_FILE) do |line|
392
+ k, v = line.split(/=/, 2)
393
+ @table[k] = v.strip
394
+ end
395
+ end
396
+
397
+ def save
398
+ File.open(SAVE_FILE, 'w') {|f|
399
+ @table.each do |k, v|
400
+ f.printf "%s=%s\n", k, v if v
401
+ end
402
+ }
403
+ end
404
+
405
+ def []=(k, v)
406
+ raise InstallError, "unknown config option #{k}"\
407
+ unless ConfigTable.config_key?(k)
408
+ @table[k] = v
409
+ end
410
+
411
+ def [](key)
412
+ return nil unless @table[key]
413
+ @table[key].gsub(%r<\$([^/]+)>) { self[$1] }
414
+ end
415
+
416
+ def set_raw(key, val)
417
+ @table[key] = val
418
+ end
419
+
420
+ def get_raw(key)
421
+ @table[key]
422
+ end
423
+
424
+ end
425
+
426
+
427
+ module MetaConfigAPI
428
+
429
+ def eval_file_ifexist(fname)
430
+ instance_eval File.read(fname), fname, 1 if File.file?(fname)
431
+ end
432
+
433
+ def config_names
434
+ ConfigTable.keys
435
+ end
436
+
437
+ def config?(name)
438
+ ConfigTable.config_key?(name)
439
+ end
440
+
441
+ def bool_config?(name)
442
+ ConfigTable.bool_config?(name)
443
+ end
444
+
445
+ def value_config?(name)
446
+ ConfigTable.value_config?(name)
447
+ end
448
+
449
+ def path_config?(name)
450
+ ConfigTable.path_config?(name)
451
+ end
452
+
453
+ def add_config(name, argname, default, desc)
454
+ ConfigTable.add_entry name,[default,argname,desc]
455
+ end
456
+
457
+ def add_path_config(name, default, desc)
458
+ add_config name, 'path', default, desc
459
+ end
460
+
461
+ def add_bool_config(name, default, desc)
462
+ add_config name, 'yes/no', default ? 'yes' : 'no', desc
463
+ end
464
+
465
+ def set_config_default(name, default)
466
+ if bool_config?(name)
467
+ ConfigTable.get_entry!(name)[0] = (default ? 'yes' : 'no')
468
+ else
469
+ ConfigTable.get_entry!(name)[0] = default
470
+ end
471
+ end
472
+
473
+ def remove_config(name)
474
+ ent = ConfigTable.get_entry(name)
475
+ ConfigTable.remove_entry name
476
+ ent
477
+ end
478
+
479
+ end
480
+ #
481
+ # base.rb
482
+ #
483
+
484
+ require 'rbconfig'
485
+
486
+
487
+ class InstallError < StandardError; end
488
+
489
+
490
+ module HookUtils
491
+
492
+ def run_hook(name)
493
+ try_run_hook "#{curr_srcdir()}/#{name}" or
494
+ try_run_hook "#{curr_srcdir()}/#{name}.rb"
495
+ end
496
+
497
+ def try_run_hook(fname)
498
+ return false unless File.file?(fname)
499
+ begin
500
+ instance_eval File.read(fname), fname, 1
501
+ rescue
502
+ raise InstallError, "hook #{fname} failed:\n" + $!.message
503
+ end
504
+ true
505
+ end
506
+
507
+ end
508
+
509
+
510
+ module HookScriptAPI
511
+
512
+ def get_config(key)
513
+ @config[key]
514
+ end
515
+
516
+ alias config get_config
517
+
518
+ def set_config(key, val)
519
+ @config[key] = val
520
+ end
521
+
522
+ #
523
+ # srcdir/objdir (works only in the package directory)
524
+ #
525
+
526
+ #abstract srcdir_root
527
+ #abstract objdir_root
528
+ #abstract relpath
529
+
530
+ def curr_srcdir
531
+ "#{srcdir_root()}/#{relpath()}"
532
+ end
533
+
534
+ def curr_objdir
535
+ "#{objdir_root()}/#{relpath()}"
536
+ end
537
+
538
+ def srcfile(path)
539
+ "#{curr_srcdir()}/#{path}"
540
+ end
541
+
542
+ def srcexist?(path)
543
+ File.exist?(srcfile(path))
544
+ end
545
+
546
+ def srcdirectory?(path)
547
+ File.dir?(srcfile(path))
548
+ end
549
+
550
+ def srcfile?(path)
551
+ File.file? srcfile(path)
552
+ end
553
+
554
+ def srcentries(path = '.')
555
+ Dir.open("#{curr_srcdir()}/#{path}") {|d|
556
+ return d.to_a - %w(. ..)
557
+ }
558
+ end
559
+
560
+ def srcfiles(path = '.')
561
+ srcentries(path).select {|fname|
562
+ File.file?(File.join(curr_srcdir(), path, fname))
563
+ }
564
+ end
565
+
566
+ def srcdirectories(path = '.')
567
+ srcentries(path).select {|fname|
568
+ File.dir?(File.join(curr_srcdir(), path, fname))
569
+ }
570
+ end
571
+
572
+ end
573
+
574
+
575
+ class Installer
576
+
577
+ FILETYPES = %w( bin lib ext data )
578
+
579
+ include HookScriptAPI
580
+ include HookUtils
581
+ include FileOperations
582
+
583
+ def initialize(config, opt, srcroot, objroot)
584
+ @config = config
585
+ @options = opt
586
+ @srcdir = File.expand_path(srcroot)
587
+ @objdir = File.expand_path(objroot)
588
+ @currdir = '.'
589
+ end
590
+
591
+ def inspect
592
+ "#<#{self.class} #{File.basename(@srcdir)}>"
593
+ end
594
+
595
+ #
596
+ # Hook Script API bases
597
+ #
598
+
599
+ def srcdir_root
600
+ @srcdir
601
+ end
602
+
603
+ def objdir_root
604
+ @objdir
605
+ end
606
+
607
+ def relpath
608
+ @currdir
609
+ end
610
+
611
+ #
612
+ # configs/options
613
+ #
614
+
615
+ def no_harm?
616
+ @options['no-harm']
617
+ end
618
+
619
+ def verbose?
620
+ @options['verbose']
621
+ end
622
+
623
+ def verbose_off
624
+ begin
625
+ save, @options['verbose'] = @options['verbose'], false
626
+ yield
627
+ ensure
628
+ @options['verbose'] = save
629
+ end
630
+ end
631
+
632
+ #
633
+ # TASK config
634
+ #
635
+
636
+ def exec_config
637
+ exec_task_traverse 'config'
638
+ end
639
+
640
+ def config_dir_bin(rel)
641
+ end
642
+
643
+ def config_dir_lib(rel)
644
+ end
645
+
646
+ def config_dir_ext(rel)
647
+ extconf if extdir?(curr_srcdir())
648
+ end
649
+
650
+ def extconf
651
+ opt = @options['config-opt'].join(' ')
652
+ command "#{config('ruby-prog')} #{curr_srcdir()}/extconf.rb #{opt}"
653
+ end
654
+
655
+ def config_dir_data(rel)
656
+ end
657
+
658
+ #
659
+ # TASK setup
660
+ #
661
+
662
+ def exec_setup
663
+ exec_task_traverse 'setup'
664
+ end
665
+
666
+ def setup_dir_bin(rel)
667
+ all_files_in(curr_srcdir()).each do |fname|
668
+ adjust_shebang "#{curr_srcdir()}/#{fname}"
669
+ end
670
+ end
671
+
672
+ # modify: #!/usr/bin/ruby
673
+ # modify: #! /usr/bin/ruby
674
+ # modify: #!ruby
675
+ # not modify: #!/usr/bin/env ruby
676
+ SHEBANG_RE = /\A\#!\s*\S*ruby\S*/
677
+
678
+ def adjust_shebang(path)
679
+ return if no_harm?
680
+
681
+ tmpfile = File.basename(path) + '.tmp'
682
+ begin
683
+ File.open(path, 'rb') {|r|
684
+ File.open(tmpfile, 'wb') {|w|
685
+ first = r.gets
686
+ return unless SHEBANG_RE =~ first
687
+
688
+ $stderr.puts "adjusting shebang: #{File.basename path}" if verbose?
689
+ w.print first.sub(SHEBANG_RE, '#!' + config('ruby-path'))
690
+ w.write r.read
691
+ }
692
+ }
693
+ move_file tmpfile, File.basename(path)
694
+ ensure
695
+ File.unlink tmpfile if File.exist?(tmpfile)
696
+ end
697
+ end
698
+
699
+ def setup_dir_lib(rel)
700
+ end
701
+
702
+ def setup_dir_ext(rel)
703
+ make if extdir?(curr_srcdir())
704
+ end
705
+
706
+ def setup_dir_data(rel)
707
+ end
708
+
709
+ #
710
+ # TASK install
711
+ #
712
+
713
+ def exec_install
714
+ exec_task_traverse 'install'
715
+ end
716
+
717
+ def install_dir_bin(rel)
718
+ install_files collect_filenames_auto(), config('bin-dir') + '/' + rel, 0755
719
+ end
720
+
721
+ def install_dir_lib(rel)
722
+ install_files ruby_scripts(), config('rb-dir') + '/' + rel, 0644
723
+ end
724
+
725
+ def install_dir_ext(rel)
726
+ return unless extdir?(curr_srcdir())
727
+ install_files ruby_extentions('.'),
728
+ config('so-dir') + '/' + File.dirname(rel),
729
+ 0555
730
+ end
731
+
732
+ def install_dir_data(rel)
733
+ install_files collect_filenames_auto(), config('data-dir') + '/' + rel, 0644
734
+ end
735
+
736
+ def install_files(list, dest, mode)
737
+ mkdir_p dest, @options['install-prefix']
738
+ list.each do |fname|
739
+ install fname, dest, mode, @options['install-prefix']
740
+ end
741
+ end
742
+
743
+ def ruby_scripts
744
+ collect_filenames_auto().select {|n| /\.rb\z/ =~ n }
745
+ end
746
+
747
+ # picked up many entries from cvs-1.11.1/src/ignore.c
748
+ reject_patterns = %w(
749
+ core RCSLOG tags TAGS .make.state
750
+ .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
751
+ *~ *.old *.bak *.BAK *.orig *.rej _$* *$
752
+
753
+ *.org *.in .*
754
+ )
755
+ mapping = {
756
+ '.' => '\.',
757
+ '$' => '\$',
758
+ '#' => '\#',
759
+ '*' => '.*'
760
+ }
761
+ REJECT_PATTERNS = Regexp.new('\A(?:' +
762
+ reject_patterns.map {|pat|
763
+ pat.gsub(/[\.\$\#\*]/) {|ch| mapping[ch] }
764
+ }.join('|') +
765
+ ')\z')
766
+
767
+ def collect_filenames_auto
768
+ mapdir((existfiles() - hookfiles()).reject {|fname|
769
+ REJECT_PATTERNS =~ fname
770
+ })
771
+ end
772
+
773
+ def existfiles
774
+ all_files_in(curr_srcdir()) | all_files_in('.')
775
+ end
776
+
777
+ def hookfiles
778
+ %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
779
+ %w( config setup install clean ).map {|t| sprintf(fmt, t) }
780
+ }.flatten
781
+ end
782
+
783
+ def mapdir(filelist)
784
+ filelist.map {|fname|
785
+ if File.exist?(fname) # objdir
786
+ fname
787
+ else # srcdir
788
+ File.join(curr_srcdir(), fname)
789
+ end
790
+ }
791
+ end
792
+
793
+ def ruby_extentions(dir)
794
+ _ruby_extentions(dir) or
795
+ raise InstallError, "no ruby extention exists: 'ruby #{$0} setup' first"
796
+ end
797
+
798
+ DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/
799
+
800
+ def _ruby_extentions(dir)
801
+ Dir.open(dir) {|d|
802
+ return d.select {|fname| DLEXT =~ fname }
803
+ }
804
+ end
805
+
806
+ #
807
+ # TASK clean
808
+ #
809
+
810
+ def exec_clean
811
+ exec_task_traverse 'clean'
812
+ rm_f 'config.save'
813
+ rm_f 'InstalledFiles'
814
+ end
815
+
816
+ def clean_dir_bin(rel)
817
+ end
818
+
819
+ def clean_dir_lib(rel)
820
+ end
821
+
822
+ def clean_dir_ext(rel)
823
+ return unless extdir?(curr_srcdir())
824
+ make 'clean' if File.file?('Makefile')
825
+ end
826
+
827
+ def clean_dir_data(rel)
828
+ end
829
+
830
+ #
831
+ # TASK distclean
832
+ #
833
+
834
+ def exec_distclean
835
+ exec_task_traverse 'distclean'
836
+ rm_f 'config.save'
837
+ rm_f 'InstalledFiles'
838
+ end
839
+
840
+ def distclean_dir_bin(rel)
841
+ end
842
+
843
+ def distclean_dir_lib(rel)
844
+ end
845
+
846
+ def distclean_dir_ext(rel)
847
+ return unless extdir?(curr_srcdir())
848
+ make 'distclean' if File.file?('Makefile')
849
+ end
850
+
851
+ #
852
+ # lib
853
+ #
854
+
855
+ def exec_task_traverse(task)
856
+ run_hook "pre-#{task}"
857
+ FILETYPES.each do |type|
858
+ if config('without-ext') == 'yes' and type == 'ext'
859
+ $stderr.puts 'skipping ext/* by user option' if verbose?
860
+ next
861
+ end
862
+ traverse task, type, "#{task}_dir_#{type}"
863
+ end
864
+ run_hook "post-#{task}"
865
+ end
866
+
867
+ def traverse(task, rel, mid)
868
+ dive_into(rel) {
869
+ run_hook "pre-#{task}"
870
+ __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
871
+ all_dirs_in(curr_srcdir()).each do |d|
872
+ traverse task, "#{rel}/#{d}", mid
873
+ end
874
+ run_hook "post-#{task}"
875
+ }
876
+ end
877
+
878
+ def dive_into(rel)
879
+ return unless File.dir?("#{@srcdir}/#{rel}")
880
+
881
+ dir = File.basename(rel)
882
+ Dir.mkdir dir unless File.dir?(dir)
883
+ prevdir = Dir.pwd
884
+ Dir.chdir dir
885
+ $stderr.puts '---> ' + rel if verbose?
886
+ @currdir = rel
887
+ yield
888
+ Dir.chdir prevdir
889
+ $stderr.puts '<--- ' + rel if verbose?
890
+ @currdir = File.dirname(rel)
891
+ end
892
+
893
+ end
894
+ #
895
+ # toplevel.rb
896
+ #
897
+
898
+ class ToplevelInstaller
899
+
900
+ Version = '3.2.2'
901
+ Copyright = 'Copyright (c) 2000-2003 Minero Aoki'
902
+
903
+ TASKS = [
904
+ [ 'config', 'saves your configurations' ],
905
+ [ 'show', 'shows current configuration' ],
906
+ [ 'setup', 'compiles ruby extentions and others' ],
907
+ [ 'install', 'installs files' ],
908
+ [ 'clean', "does `make clean' for each extention" ],
909
+ [ 'distclean',"does `make distclean' for each extention" ]
910
+ ]
911
+
912
+ def ToplevelInstaller.invoke
913
+ instance().invoke
914
+ end
915
+
916
+ @singleton = nil
917
+
918
+ def ToplevelInstaller.instance
919
+ @singleton ||= new(File.dirname($0))
920
+ @singleton
921
+ end
922
+
923
+ include MetaConfigAPI
924
+
925
+ def initialize(ardir_root)
926
+ @config = nil
927
+ @options = { 'verbose' => true }
928
+ @ardir = File.expand_path(ardir_root)
929
+ end
930
+
931
+ def inspect
932
+ "#<#{self.class} #{__id__()}>"
933
+ end
934
+
935
+ def invoke
936
+ run_metaconfigs
937
+ task = parsearg_global()
938
+ @config = load_config(task)
939
+ __send__ "parsearg_#{task}"
940
+ init_installers
941
+ __send__ "exec_#{task}"
942
+ end
943
+
944
+ def run_metaconfigs
945
+ eval_file_ifexist "#{@ardir}/metaconfig"
946
+ end
947
+
948
+ def load_config(task)
949
+ case task
950
+ when 'config'
951
+ ConfigTable.new
952
+ when 'clean', 'distclean'
953
+ if File.exist?('config.save')
954
+ then ConfigTable.load
955
+ else ConfigTable.new
956
+ end
957
+ else
958
+ ConfigTable.load
959
+ end
960
+ end
961
+
962
+ def init_installers
963
+ @installer = Installer.new(@config, @options, @ardir, File.expand_path('.'))
964
+ end
965
+
966
+ #
967
+ # Hook Script API bases
968
+ #
969
+
970
+ def srcdir_root
971
+ @ardir
972
+ end
973
+
974
+ def objdir_root
975
+ '.'
976
+ end
977
+
978
+ def relpath
979
+ '.'
980
+ end
981
+
982
+ #
983
+ # Option Parsing
984
+ #
985
+
986
+ def parsearg_global
987
+ valid_task = /\A(?:#{TASKS.map {|task,desc| task }.join '|'})\z/
988
+
989
+ while arg = ARGV.shift
990
+ case arg
991
+ when /\A\w+\z/
992
+ raise InstallError, "invalid task: #{arg}" unless valid_task =~ arg
993
+ return arg
994
+
995
+ when '-q', '--quiet'
996
+ @options['verbose'] = false
997
+
998
+ when '--verbose'
999
+ @options['verbose'] = true
1000
+
1001
+ when '-h', '--help'
1002
+ print_usage $stdout
1003
+ exit 0
1004
+
1005
+ when '-v', '--version'
1006
+ puts "#{File.basename($0)} version #{Version}"
1007
+ exit 0
1008
+
1009
+ when '--copyright'
1010
+ puts Copyright
1011
+ exit 0
1012
+
1013
+ else
1014
+ raise InstallError, "unknown global option '#{arg}'"
1015
+ end
1016
+ end
1017
+
1018
+ raise InstallError, <<EOS
1019
+ No task or global option given.
1020
+ Typical installation procedure is:
1021
+ $ ruby #{File.basename($0)} config
1022
+ $ ruby #{File.basename($0)} setup
1023
+ # ruby #{File.basename($0)} install (may require root privilege)
1024
+ EOS
1025
+ end
1026
+
1027
+
1028
+ def parsearg_no_options
1029
+ raise InstallError, "#{task}: unknown options: #{ARGV.join ' '}"\
1030
+ unless ARGV.empty?
1031
+ end
1032
+
1033
+ alias parsearg_show parsearg_no_options
1034
+ alias parsearg_setup parsearg_no_options
1035
+ alias parsearg_clean parsearg_no_options
1036
+ alias parsearg_distclean parsearg_no_options
1037
+
1038
+ def parsearg_config
1039
+ re = /\A--(#{ConfigTable.keys.join '|'})(?:=(.*))?\z/
1040
+ @options['config-opt'] = []
1041
+
1042
+ while i = ARGV.shift
1043
+ if /\A--?\z/ =~ i
1044
+ @options['config-opt'] = ARGV.dup
1045
+ break
1046
+ end
1047
+ m = re.match(i) or raise InstallError, "config: unknown option #{i}"
1048
+ name, value = m.to_a[1,2]
1049
+ if value
1050
+ if ConfigTable.bool_config?(name)
1051
+ raise InstallError, "config: --#{name} allows only yes/no for argument"\
1052
+ unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ value
1053
+ value = (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'
1054
+ end
1055
+ else
1056
+ raise InstallError, "config: --#{name} requires argument"\
1057
+ unless ConfigTable.bool_config?(name)
1058
+ value = 'yes'
1059
+ end
1060
+ @config[name] = value
1061
+ end
1062
+ end
1063
+
1064
+ def parsearg_install
1065
+ @options['no-harm'] = false
1066
+ @options['install-prefix'] = ''
1067
+ while a = ARGV.shift
1068
+ case a
1069
+ when /\A--no-harm\z/
1070
+ @options['no-harm'] = true
1071
+ when /\A--prefix=(.*)\z/
1072
+ path = $1
1073
+ path = File.expand_path(path) unless path[0,1] == '/'
1074
+ @options['install-prefix'] = path
1075
+ else
1076
+ raise InstallError, "install: unknown option #{a}"
1077
+ end
1078
+ end
1079
+ end
1080
+
1081
+ def print_usage(out)
1082
+ out.puts 'Typical Installation Procedure:'
1083
+ out.puts " $ ruby #{File.basename $0} config"
1084
+ out.puts " $ ruby #{File.basename $0} setup"
1085
+ out.puts " # ruby #{File.basename $0} install (may require root privilege)"
1086
+ out.puts
1087
+ out.puts 'Detailed Usage:'
1088
+ out.puts " ruby #{File.basename $0} <global option>"
1089
+ out.puts " ruby #{File.basename $0} [<global options>] <task> [<task options>]"
1090
+
1091
+ fmt = " %-20s %s\n"
1092
+ out.puts
1093
+ out.puts 'Global options:'
1094
+ out.printf fmt, '-q,--quiet', 'suppress message outputs'
1095
+ out.printf fmt, ' --verbose', 'output messages verbosely'
1096
+ out.printf fmt, '-h,--help', 'print this message'
1097
+ out.printf fmt, '-v,--version', 'print version and quit'
1098
+ out.printf fmt, ' --copyright', 'print copyright and quit'
1099
+
1100
+ out.puts
1101
+ out.puts 'Tasks:'
1102
+ TASKS.each do |name, desc|
1103
+ out.printf " %-10s %s\n", name, desc
1104
+ end
1105
+
1106
+ out.puts
1107
+ out.puts 'Options for config:'
1108
+ ConfigTable.each_definition do |name, (default, arg, desc, default2)|
1109
+ out.printf " %-20s %s [%s]\n",
1110
+ '--'+ name + (ConfigTable.bool_config?(name) ? '' : '='+arg),
1111
+ desc,
1112
+ default2 || default
1113
+ end
1114
+ out.printf " %-20s %s [%s]\n",
1115
+ '--rbconfig=path', 'your rbconfig.rb to load', "running ruby's"
1116
+
1117
+ out.puts
1118
+ out.puts 'Options for install:'
1119
+ out.printf " %-20s %s [%s]\n",
1120
+ '--no-harm', 'only display what to do if given', 'off'
1121
+ out.printf " %-20s %s [%s]\n",
1122
+ '--prefix', 'install path prefix', '$prefix'
1123
+
1124
+ out.puts
1125
+ end
1126
+
1127
+ #
1128
+ # Task Handlers
1129
+ #
1130
+
1131
+ def exec_config
1132
+ @installer.exec_config
1133
+ @config.save # must be final
1134
+ end
1135
+
1136
+ def exec_setup
1137
+ @installer.exec_setup
1138
+ end
1139
+
1140
+ def exec_install
1141
+ @installer.exec_install
1142
+ end
1143
+
1144
+ def exec_show
1145
+ ConfigTable.each_name do |k|
1146
+ v = @config.get_raw(k)
1147
+ if not v or v.empty?
1148
+ v = '(not specified)'
1149
+ end
1150
+ printf "%-10s %s\n", k, v
1151
+ end
1152
+ end
1153
+
1154
+ def exec_clean
1155
+ @installer.exec_clean
1156
+ end
1157
+
1158
+ def exec_distclean
1159
+ @installer.exec_distclean
1160
+ end
1161
+
1162
+ end
1163
+
1164
+
1165
+ class ToplevelInstallerMulti < ToplevelInstaller
1166
+
1167
+ include HookUtils
1168
+ include HookScriptAPI
1169
+ include FileOperations
1170
+
1171
+ def initialize(ardir)
1172
+ super
1173
+ @packages = all_dirs_in("#{@ardir}/packages")
1174
+ raise 'no package exists' if @packages.empty?
1175
+ end
1176
+
1177
+ def run_metaconfigs
1178
+ eval_file_ifexist "#{@ardir}/metaconfig"
1179
+ @packages.each do |name|
1180
+ eval_file_ifexist "#{@ardir}/packages/#{name}/metaconfig"
1181
+ end
1182
+ end
1183
+
1184
+ def init_installers
1185
+ @installers = {}
1186
+ @packages.each do |pack|
1187
+ @installers[pack] = Installer.new(@config, @options,
1188
+ "#{@ardir}/packages/#{pack}",
1189
+ "packages/#{pack}")
1190
+ end
1191
+
1192
+ with = extract_selection(config('with'))
1193
+ without = extract_selection(config('without'))
1194
+ @selected = @installers.keys.select {|name|
1195
+ (with.empty? or with.include?(name)) \
1196
+ and not without.include?(name)
1197
+ }
1198
+ end
1199
+
1200
+ def extract_selection(list)
1201
+ a = list.split(/,/)
1202
+ a.each do |name|
1203
+ raise InstallError, "no such package: #{name}" \
1204
+ unless @installers.key?(name)
1205
+ end
1206
+ a
1207
+ end
1208
+
1209
+ def print_usage(f)
1210
+ super
1211
+ f.puts 'Inluded packages:'
1212
+ f.puts ' ' + @packages.sort.join(' ')
1213
+ f.puts
1214
+ end
1215
+
1216
+ #
1217
+ # multi-package metaconfig API
1218
+ #
1219
+
1220
+ attr_reader :packages
1221
+
1222
+ def declare_packages(list)
1223
+ raise 'package list is empty' if list.empty?
1224
+ list.each do |name|
1225
+ raise "directory packages/#{name} does not exist"\
1226
+ unless File.dir?("#{@ardir}/packages/#{name}")
1227
+ end
1228
+ @packages = list
1229
+ end
1230
+
1231
+ #
1232
+ # Task Handlers
1233
+ #
1234
+
1235
+ def exec_config
1236
+ run_hook 'pre-config'
1237
+ each_selected_installers {|inst| inst.exec_config }
1238
+ run_hook 'post-config'
1239
+ @config.save # must be final
1240
+ end
1241
+
1242
+ def exec_setup
1243
+ run_hook 'pre-setup'
1244
+ each_selected_installers {|inst| inst.exec_setup }
1245
+ run_hook 'post-setup'
1246
+ end
1247
+
1248
+ def exec_install
1249
+ run_hook 'pre-install'
1250
+ each_selected_installers {|inst| inst.exec_install }
1251
+ run_hook 'post-install'
1252
+ end
1253
+
1254
+ def exec_clean
1255
+ rm_f 'config.save'
1256
+ run_hook 'pre-clean'
1257
+ each_selected_installers {|inst| inst.exec_clean }
1258
+ run_hook 'post-clean'
1259
+ end
1260
+
1261
+ def exec_distclean
1262
+ rm_f 'config.save'
1263
+ run_hook 'pre-distclean'
1264
+ each_selected_installers {|inst| inst.exec_distclean }
1265
+ run_hook 'post-distclean'
1266
+ end
1267
+
1268
+ #
1269
+ # lib
1270
+ #
1271
+
1272
+ def each_selected_installers
1273
+ Dir.mkdir 'packages' unless File.dir?('packages')
1274
+ @selected.each do |pack|
1275
+ $stderr.puts "Processing the package `#{pack}' ..." if @options['verbose']
1276
+ Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}")
1277
+ Dir.chdir "packages/#{pack}"
1278
+ yield @installers[pack]
1279
+ Dir.chdir '../..'
1280
+ end
1281
+ end
1282
+
1283
+ def verbose?
1284
+ @options['verbose']
1285
+ end
1286
+
1287
+ def no_harm?
1288
+ @options['no-harm']
1289
+ end
1290
+
1291
+ end
1292
+
1293
+ if $0 == __FILE__
1294
+ begin
1295
+ if multipackage_install?
1296
+ ToplevelInstallerMulti.invoke
1297
+ else
1298
+ ToplevelInstaller.invoke
1299
+ end
1300
+ rescue
1301
+ raise if $DEBUG
1302
+ $stderr.puts $!.message
1303
+ $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
1304
+ exit 1
1305
+ end
1306
+ end