trema 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (292) hide show
  1. data/.gitignore +1 -1
  2. data/Doxyfile +1 -1
  3. data/Gemfile +18 -6
  4. data/README.md +112 -5
  5. data/Rakefile +3 -1
  6. data/Rantfile +88 -1
  7. data/bin/trema +248 -0
  8. data/bin/trema-config +59 -0
  9. data/cruise.rb +1 -1
  10. data/features/example.dumper.feature +45 -65
  11. data/features/example.hello_trema.feature +21 -0
  12. data/features/example.learning_switch.feature +26 -28
  13. data/features/example.list_switches.feature +19 -33
  14. data/features/example.message.echo_reply.feature +10 -10
  15. data/features/example.message.echo_request.feature +2 -2
  16. data/features/example.message.features_request.feature +6 -5
  17. data/features/example.message.hello.feature +47 -13
  18. data/features/example.message.set_config.feature +4 -4
  19. data/features/example.message.vendor-action.feature +23 -0
  20. data/features/example.multi_learning_switch.feature +14 -42
  21. data/features/example.packet_in.feature +31 -0
  22. data/features/example.packetin_filter_config.feature +11 -7
  23. data/features/example.patch_panel.feature +29 -0
  24. data/features/example.repeater_hub.feature +43 -40
  25. data/features/example.switch_info.feature +51 -0
  26. data/features/example.switch_monitor.feature +24 -42
  27. data/features/packetin_filter.feature +28 -22
  28. data/features/step_definitions/misc_steps.rb +19 -8
  29. data/features/step_definitions/send_packets_steps.rb +1 -10
  30. data/features/step_definitions/stats_steps.rb +4 -4
  31. data/features/support/env.rb +2 -1
  32. data/features/support/hooks.rb +35 -2
  33. data/features/switch_manager.feature +18 -12
  34. data/features/trema-config.feature +26 -39
  35. data/features/trema.dump_flows.feature +26 -12
  36. data/features/trema.help.feature +26 -0
  37. data/features/trema.kill.feature +39 -41
  38. data/features/trema.killall.feature +23 -23
  39. data/features/trema.reset_stats.feature +50 -10
  40. data/features/trema.run.feature +28 -39
  41. data/features/trema.send_packets.feature +29 -40
  42. data/features/trema.show_stats.feature +30 -33
  43. data/features/trema.up.feature +33 -0
  44. data/features/trema.version.feature +9 -0
  45. data/ruby/extconf.rb +7 -0
  46. data/ruby/trema/aggregate-stats-reply.rb +3 -3
  47. data/ruby/trema/app.rb +5 -1
  48. data/ruby/trema/barrier-request.c +55 -30
  49. data/ruby/trema/cli.rb +8 -8
  50. data/ruby/trema/command.rb +1 -3
  51. data/ruby/trema/command/dump_flows.rb +5 -24
  52. data/ruby/trema/command/kill.rb +31 -36
  53. data/ruby/trema/command/killall.rb +1 -19
  54. data/{features/step_definitions/kill_steps.rb → ruby/trema/command/netns.rb} +13 -5
  55. data/ruby/trema/command/reset_stats.rb +3 -23
  56. data/ruby/trema/command/ruby.rb +2 -19
  57. data/ruby/trema/command/run.rb +6 -27
  58. data/ruby/trema/command/send_packets.rb +6 -90
  59. data/ruby/trema/command/show_stats.rb +21 -40
  60. data/ruby/trema/command/up.rb +5 -26
  61. data/ruby/trema/command/version.rb +1 -5
  62. data/ruby/trema/controller.c +14 -16
  63. data/ruby/trema/custom-switch.rb +56 -0
  64. data/ruby/trema/desc-stats-reply.rb +5 -5
  65. data/ruby/trema/dsl/configuration.rb +4 -0
  66. data/{features/step_definitions/up_steps.rb → ruby/trema/dsl/custom-switch.rb} +18 -4
  67. data/ruby/trema/dsl/netns.rb +78 -0
  68. data/ruby/trema/dsl/parser.rb +2 -0
  69. data/ruby/trema/dsl/runner.rb +8 -0
  70. data/ruby/trema/dsl/syntax.rb +18 -0
  71. data/ruby/trema/echo-reply.h +2 -2
  72. data/ruby/trema/echo-request.c +3 -5
  73. data/ruby/trema/enqueue.rb +2 -2
  74. data/ruby/trema/error.c +3 -3
  75. data/ruby/trema/executables.rb +26 -2
  76. data/ruby/trema/features-request.c +3 -5
  77. data/ruby/trema/flow-removed.c +6 -6
  78. data/ruby/trema/flow-stats-reply.rb +6 -8
  79. data/ruby/trema/flow.rb +12 -1
  80. data/ruby/trema/get-config-request.c +55 -28
  81. data/ruby/trema/hello.c +3 -5
  82. data/ruby/trema/host.rb +8 -0
  83. data/ruby/trema/list-switches-reply.c +1 -1
  84. data/ruby/trema/mac.rb +1 -1
  85. data/ruby/trema/match.c +15 -14
  86. data/ruby/trema/monkey-patch/module/deprecation.rb +0 -2
  87. data/ruby/trema/netns.rb +127 -0
  88. data/ruby/trema/ordered-hash.rb +5 -4
  89. data/ruby/trema/packet-in.c +136 -113
  90. data/ruby/trema/packet-queue.rb +9 -9
  91. data/ruby/trema/packetin-filter.rb +1 -1
  92. data/ruby/trema/phost.rb +16 -7
  93. data/ruby/trema/port-mod.c +6 -5
  94. data/ruby/trema/port-stats-reply.rb +2 -2
  95. data/ruby/trema/process.rb +29 -0
  96. data/ruby/trema/queue-stats-reply.rb +2 -4
  97. data/ruby/trema/send-out-port.rb +5 -3
  98. data/ruby/trema/set-eth-addr.rb +4 -0
  99. data/ruby/trema/set-ip-addr.rb +4 -2
  100. data/ruby/trema/set-ip-dst-addr.rb +2 -1
  101. data/ruby/trema/set-ip-src-addr.rb +2 -1
  102. data/ruby/trema/set-ip-tos.rb +3 -2
  103. data/ruby/trema/set-transport-port.rb +3 -2
  104. data/ruby/trema/set-vlan-priority.rb +3 -2
  105. data/ruby/trema/set-vlan-vid.rb +5 -4
  106. data/ruby/trema/shell/reset_stats.rb +2 -1
  107. data/ruby/trema/shell/run.rb +1 -1
  108. data/ruby/trema/shell/send_packets.rb +1 -1
  109. data/ruby/trema/shell/show_stats.rb +1 -1
  110. data/ruby/trema/stats-helper.rb +3 -3
  111. data/ruby/trema/stats-reply.c +26 -17
  112. data/ruby/trema/stats-request.c +39 -41
  113. data/ruby/trema/switch-daemon.rb +36 -31
  114. data/ruby/trema/switch.c +1 -1
  115. data/ruby/trema/table-stats-reply.rb +1 -1
  116. data/ruby/trema/timers.rb +13 -13
  117. data/ruby/trema/trema.c +3 -3
  118. data/ruby/trema/tremashark.rb +9 -2
  119. data/ruby/trema/util.rb +39 -15
  120. data/ruby/trema/vendor-action.rb +8 -3
  121. data/ruby/trema/vendor-stats-reply.rb +4 -6
  122. data/ruby/trema/vendor.c +1 -1
  123. data/ruby/trema/version.rb +1 -1
  124. data/spec/trema/barrier-request_spec.rb +47 -37
  125. data/spec/trema/controller_spec.rb +1 -0
  126. data/spec/trema/dsl/runner_spec.rb +8 -3
  127. data/spec/trema/dsl/vhost_spec.rb +8 -8
  128. data/spec/trema/echo-request_spec.rb +1 -0
  129. data/spec/trema/features-request_spec.rb +1 -0
  130. data/spec/trema/flow-removed_spec.rb +9 -9
  131. data/spec/trema/get-config-request_spec.rb +51 -39
  132. data/spec/trema/match_spec.rb +1 -1
  133. data/spec/trema/openflow-error_spec.rb +11 -11
  134. data/spec/trema/packet-out_spec.rb +5 -5
  135. data/spec/trema/queue-get-config-reply_spec.rb +1 -1
  136. data/spec/trema/queue-get-config-request_spec.rb +1 -1
  137. data/spec/trema/set-eth-dst-addr_spec.rb +1 -1
  138. data/spec/trema/set-eth-src-addr_spec.rb +1 -1
  139. data/spec/trema/set-ip-dst-addr_spec.rb +1 -0
  140. data/spec/trema/set-ip-src-addr_spec.rb +1 -0
  141. data/spec/trema/set-ip-tos_spec.rb +1 -0
  142. data/spec/trema/set-transport-dst-port_spec.rb +1 -0
  143. data/spec/trema/set-transport-src-port_spec.rb +1 -0
  144. data/spec/trema/set-vlan-priority_spec.rb +1 -0
  145. data/spec/trema/set-vlan-vid_spec.rb +2 -1
  146. data/spec/trema/stats-reply_spec.rb +38 -36
  147. data/spec/trema/stats-request_spec.rb +6 -6
  148. data/spec/trema/strip-vlan-header_spec.rb +1 -0
  149. data/spec/trema/util_spec.rb +3 -2
  150. data/spec/trema/vendor-action_spec.rb +9 -8
  151. data/src/examples/dumper/dumper.c +8 -6
  152. data/src/examples/dumper/dumper.rb +1 -1
  153. data/{features/step_definitions/killall_steps.rb → src/examples/hello_trema/hello-trema.rb} +6 -5
  154. data/src/examples/hello_trema/hello_trema.c +4 -4
  155. data/src/examples/learning_switch/learning_switch.c +1 -1
  156. data/src/examples/list_switches/list_switches.c +2 -2
  157. data/src/examples/match_compare/match-compare.rb +2 -2
  158. data/src/examples/multi_learning_switch/multi-learning-switch.rb +1 -1
  159. data/src/examples/multi_learning_switch/multi_learning_switch.c +3 -3
  160. data/src/examples/openflow_message/README +1 -1
  161. data/src/examples/openflow_message/echo-request.rb +1 -1
  162. data/src/examples/openflow_message/features_request.c +21 -21
  163. data/src/examples/openflow_message/hello.c +1 -3
  164. data/src/examples/openflow_message/hello.rb +9 -24
  165. data/src/examples/{hello_trema/hello_trema.rb → openflow_message/vendor-action.rb} +17 -7
  166. data/src/examples/openflow_message/vendor_action.c +105 -0
  167. data/src/examples/openflow_switch/hello_switch.c +81 -0
  168. data/src/examples/packet_in/packet-in.rb +9 -13
  169. data/src/examples/packetin_filter_config/packetin_filter_config.c +2 -2
  170. data/src/examples/patch_panel/network.conf +14 -0
  171. data/src/examples/patch_panel/patch-panel.conf +1 -0
  172. data/{features/step_definitions/show_stats_steps.rb → src/examples/patch_panel/patch-panel.rb} +29 -13
  173. data/src/examples/switch_info/{switch_info.rb → switch-info.rb} +2 -2
  174. data/src/examples/switch_info/switch_info.c +4 -4
  175. data/src/examples/switch_monitor/switch_monitor.c +3 -3
  176. data/src/examples/traffic_monitor/counter.c +9 -9
  177. data/src/examples/traffic_monitor/fdb.c +9 -9
  178. data/src/lib/arp.h +1 -1
  179. data/src/lib/buffer.c +4 -3
  180. data/src/lib/byteorder.c +31 -5
  181. data/src/lib/byteorder.h +2 -2
  182. data/src/lib/chibach.c +8 -6
  183. data/src/lib/daemon.c +29 -3
  184. data/src/lib/doubly_linked_list.c +6 -1
  185. data/src/lib/ether.c +1 -1
  186. data/src/lib/ether.h +1 -1
  187. data/src/lib/event_handler.c +3 -3
  188. data/src/lib/hash_table.c +1 -1
  189. data/src/lib/linked_list.c +50 -2
  190. data/src/lib/linked_list.h +2 -2
  191. data/src/lib/log.c +122 -22
  192. data/src/lib/log.h +13 -9
  193. data/src/lib/management_interface.c +361 -0
  194. data/src/lib/management_interface.h +42 -0
  195. data/src/lib/management_service_interface.c +104 -0
  196. data/src/lib/management_service_interface.h +136 -0
  197. data/src/lib/match_table.c +5 -5
  198. data/src/lib/message_queue.c +5 -3
  199. data/src/lib/message_queue.h +1 -1
  200. data/src/lib/messenger.c +73 -39
  201. data/src/lib/messenger.h +3 -2
  202. data/src/lib/openflow_application_interface.c +17 -17
  203. data/src/lib/openflow_message.c +175 -23
  204. data/src/lib/openflow_message.h +2 -1
  205. data/src/lib/openflow_switch_interface.c +12 -12
  206. data/src/lib/packet_parser.c +11 -32
  207. data/src/lib/packetin_filter_interface.c +5 -5
  208. data/src/lib/persistent_storage.c +7 -7
  209. data/src/lib/secure_channel.c +6 -6
  210. data/src/lib/secure_channel.h +1 -1
  211. data/src/lib/stat.c +54 -17
  212. data/src/lib/stat.h +9 -0
  213. data/src/lib/timer.c +11 -10
  214. data/src/lib/trema.c +38 -9
  215. data/src/lib/trema.h +1 -0
  216. data/src/lib/trema_private.h +6 -0
  217. data/src/lib/trema_wrapper.c +4 -4
  218. data/src/lib/trema_wrapper.h +10 -10
  219. data/src/lib/utility.c +6 -6
  220. data/src/management/application.c +224 -0
  221. data/src/management/echo.c +185 -0
  222. data/src/management/set_logging_level.c +153 -0
  223. data/src/management/show_stats.c +150 -0
  224. data/src/management/trema_manager +184 -0
  225. data/src/packetin_filter/packetin_filter.c +31 -29
  226. data/src/switch_manager/cookie_table.c +7 -7
  227. data/src/switch_manager/dpid_table.c +3 -3
  228. data/src/switch_manager/dpid_table.h +0 -1
  229. data/src/switch_manager/management_interface.h +0 -1
  230. data/src/switch_manager/ofpmsg_recv.c +3 -3
  231. data/src/switch_manager/ofpmsg_recv.h +0 -1
  232. data/src/switch_manager/ofpmsg_send.c +2 -2
  233. data/src/switch_manager/ofpmsg_send.h +0 -1
  234. data/src/switch_manager/secure_channel_listener.c +2 -2
  235. data/src/switch_manager/secure_channel_receiver.c +2 -2
  236. data/src/switch_manager/secure_channel_receiver.h +0 -1
  237. data/src/switch_manager/secure_channel_sender.c +8 -1
  238. data/src/switch_manager/service_interface.c +5 -4
  239. data/src/switch_manager/switch.c +79 -53
  240. data/src/switch_manager/switch_manager.c +24 -22
  241. data/src/switch_manager/xid_table.c +6 -6
  242. data/src/switch_manager/xid_table.h +0 -1
  243. data/src/tremashark/README +4 -3
  244. data/src/tremashark/packet_capture.c +11 -9
  245. data/src/tremashark/pcap_queue.c +2 -2
  246. data/src/tremashark/pcap_queue.h +2 -2
  247. data/src/tremashark/plugin/packet-trema/Makefile +1 -1
  248. data/src/tremashark/plugin/packet-trema/Makefile.common +1 -1
  249. data/src/tremashark/plugin/packet-trema/packet-trema.c +50 -37
  250. data/src/tremashark/queue.c +5 -4
  251. data/src/tremashark/queue.h +1 -1
  252. data/src/tremashark/stdin_relay.c +10 -8
  253. data/src/tremashark/syslog_relay.c +14 -12
  254. data/src/tremashark/tremashark.c +15 -18
  255. data/trema +2 -96
  256. data/trema-config +2 -52
  257. data/trema.gemspec +12 -1
  258. data/unittests/cmockery_trema.h +14 -13
  259. data/unittests/lib/buffer_test.c +1 -1
  260. data/unittests/lib/byteorder_test.c +108 -25
  261. data/unittests/lib/daemon_test.c +141 -5
  262. data/unittests/lib/doubly_linked_list_test.c +5 -1
  263. data/unittests/lib/ether_test.c +4 -4
  264. data/unittests/lib/hash_table_test.c +5 -3
  265. data/unittests/lib/linked_list_test.c +82 -4
  266. data/unittests/lib/log_test.c +96 -5
  267. data/unittests/lib/management_interface_test.c +240 -0
  268. data/unittests/lib/management_service_interface_test.c +319 -0
  269. data/unittests/lib/message_queue_test.c +6 -2
  270. data/unittests/lib/messenger_test.c +167 -2
  271. data/unittests/lib/openflow_application_interface_test.c +16 -22
  272. data/unittests/lib/openflow_message_test.c +721 -24
  273. data/unittests/lib/packet_info_test.c +2 -2
  274. data/unittests/lib/packet_parser_test.c +15 -16
  275. data/unittests/lib/packetin_filter_interface_test.c +6 -6
  276. data/unittests/lib/persistent_storage_test.c +11 -11
  277. data/unittests/lib/stat_test.c +151 -7
  278. data/unittests/lib/timer_test.c +1 -1
  279. data/unittests/lib/trema_private_test.c +2 -2
  280. data/unittests/lib/trema_test.c +40 -12
  281. data/unittests/lib/utility_test.c +3 -3
  282. data/unittests/lib/wrapper_test.c +3 -3
  283. data/unittests/packetin_filter/packetin_filter_test.c +12 -11
  284. data/unittests/switch_manager/switch_manager_test.c +29 -22
  285. metadata +99 -20
  286. data/features/step_definitions/log_steps.rb +0 -90
  287. data/features/step_definitions/run_steps.rb +0 -91
  288. data/features/trema.feature +0 -27
  289. data/features/tutorial.hello_trema.feature +0 -27
  290. data/features/tutorial.packet_in.feature +0 -47
  291. data/features/tutorial.switch_info.feature +0 -55
  292. data/ruby/trema/command/usage.rb +0 -63
@@ -1,8 +1,4 @@
1
1
  #
2
- # Dumps packet-in message.
3
- #
4
- # Author: Yasuhito Takamiya <yasuhito@gmail.com>
5
- #
6
2
  # Copyright (C) 2008-2012 NEC Corporation
7
3
  #
8
4
  # This program is free software; you can redistribute it and/or modify
@@ -20,16 +16,16 @@
20
16
  #
21
17
 
22
18
 
23
- class PacketinDumper < Controller
24
- def packet_in datapath_id, event
25
- puts "received a packet_in"
19
+ class PacketInDumper < Controller
20
+ def packet_in datapath_id, message
21
+ info "received a packet_in"
26
22
  info "datapath_id: #{ datapath_id.to_hex }"
27
- info "transaction_id: #{ event.transaction_id.to_hex }"
28
- info "buffer_id: #{ event.buffer_id.to_hex }"
29
- info "total_len: #{ event.total_len }"
30
- info "in_port: #{ event.in_port }"
31
- info "reason: #{ event.reason.to_hex }"
32
- info "data: #{ event.data.unpack "H*" }"
23
+ info "transaction_id: #{ message.transaction_id.to_hex }"
24
+ info "buffer_id: #{ message.buffer_id.to_hex }"
25
+ info "total_len: #{ message.total_len }"
26
+ info "in_port: #{ message.in_port }"
27
+ info "reason: #{ message.reason.to_hex }"
28
+ info "data: #{ message.data.unpack "H*" }"
33
29
  end
34
30
  end
35
31
 
@@ -62,7 +62,7 @@ dump_and_delete_filters( int status, int n_entries, packetin_filter_entry *entri
62
62
  dump_filters( status, n_entries, entries, user_data );
63
63
 
64
64
  struct ofp_match *match = user_data;
65
- char *service_name = xstrdup( get_trema_name() );
65
+ char *service_name = xstrdup( get_trema_name() );
66
66
  bool ret = delete_packetin_filter( *match, UINT16_MAX, service_name, true, delete_filter_completed, user_data );
67
67
  xfree( service_name );
68
68
  if ( ret == false ) {
@@ -83,7 +83,7 @@ add_filter_completed( int status, void *user_data ) {
83
83
  info( "A packetin filter was added successfully." );
84
84
 
85
85
  struct ofp_match *match = user_data;
86
- char *service_name = xstrdup( get_trema_name() );
86
+ char *service_name = xstrdup( get_trema_name() );
87
87
  bool ret = dump_packetin_filter( *match, UINT16_MAX, service_name, true, dump_filters, user_data );
88
88
  xfree( service_name );
89
89
  if ( ret == false ) {
@@ -0,0 +1,14 @@
1
+ vswitch("patch") {
2
+ datapath_id "0xabc"
3
+ }
4
+
5
+ vhost ("host1") {
6
+ ip "192.168.0.1"
7
+ }
8
+
9
+ vhost ("host2") {
10
+ ip "192.168.0.2"
11
+ }
12
+
13
+ link "patch", "host1"
14
+ link "patch", "host2"
@@ -0,0 +1 @@
1
+ 1 2
@@ -1,6 +1,4 @@
1
1
  #
2
- # Author: Yasuhito Takamiya <yasuhito@gmail.com>
3
- #
4
2
  # Copyright (C) 2008-2012 NEC Corporation
5
3
  #
6
4
  # This program is free software; you can redistribute it and/or modify
@@ -18,21 +16,39 @@
18
16
  #
19
17
 
20
18
 
21
- Then /^the stats of "([^"]*)" should be:$/ do | host, string |
22
- step %{I try to run "./trema show_stats #{ host }" (log = "show_stats.log")}
23
- step %{the content of "show_stats.log" should be:}, string
24
- end
19
+ class PatchPanel < Controller
20
+ def start
21
+ @patch = []
22
+ File.open( "./patch-panel.conf" ).each_line do | each |
23
+ if /^(\d+)\s+(\d+)$/=~ each
24
+ @patch << [ $1.to_i, $2.to_i ]
25
+ end
26
+ end
27
+ end
25
28
 
26
29
 
27
- Then /^the tx stats of "([^"]*)" should be:$/ do | host, string |
28
- step %{I try to run "./trema show_stats #{ host } --tx" (log = "show_stats.log")}
29
- step %{the content of "show_stats.log" should be:}, string
30
- end
30
+ def switch_ready datapath_id
31
+ @patch.each do | port_a, port_b |
32
+ make_patch datapath_id, port_a, port_b
33
+ end
34
+ end
35
+
36
+
37
+ private
31
38
 
32
39
 
33
- Then /^the rx stats of "([^"]*)" should be:$/ do | host, string |
34
- step %{I try to run "./trema show_stats #{ host } --rx" (log = "show_stats.log")}
35
- step %{the content of "show_stats.log" should be:}, string
40
+ def make_patch datapath_id, port_a, port_b
41
+ send_flow_mod_add(
42
+ datapath_id,
43
+ :match => Match.new( :in_port => port_a ),
44
+ :actions => SendOutPort.new( port_b )
45
+ )
46
+ send_flow_mod_add(
47
+ datapath_id,
48
+ :match => Match.new( :in_port => port_b ),
49
+ :actions => SendOutPort.new( port_a )
50
+ )
51
+ end
36
52
  end
37
53
 
38
54
 
@@ -20,7 +20,7 @@
20
20
  #
21
21
 
22
22
 
23
- class SwitchInfoController < Controller
23
+ class SwitchInfo < Controller
24
24
  def switch_ready datapath_id
25
25
  send_message datapath_id, FeaturesRequest.new
26
26
  end
@@ -33,7 +33,7 @@ class SwitchInfoController < Controller
33
33
  info "n_tables: %u" % message.n_tables
34
34
  info "capabilities: %u" % message.capabilities
35
35
  info "actions: %u" % message.actions
36
- info "ports: %s" % message.ports.collect { | each | each.number }.sort.join( ", " )
36
+ info "#ports: %d" % message.ports.size
37
37
  shutdown!
38
38
  end
39
39
  end
@@ -48,11 +48,11 @@ handle_features_reply (
48
48
  UNUSED( user_data );
49
49
 
50
50
  info( "datapath_id: %#" PRIx64, datapath_id );
51
- info( "transaction_id: %#lx", transaction_id );
52
- info( "n_buffers: %lu", n_buffers );
51
+ info( "transaction_id: %#" PRIx32 "", transaction_id );
52
+ info( "n_buffers: %" PRIu32 "", n_buffers );
53
53
  info( "n_tables: %u", n_tables );
54
- info( "capabilities: %lu", capabilities );
55
- info( "actions: %lu", actions );
54
+ info( "capabilities: %" PRIu32 "", capabilities );
55
+ info( "actions: %" PRIu32 "", actions );
56
56
  info( "#ports: %d", list_length_of( phy_ports ) );
57
57
 
58
58
  stop_trema();
@@ -30,7 +30,7 @@ join( char *result, const list_element *switches ) {
30
30
  const list_element *element;
31
31
  for ( element = switches; element != NULL; element = element->next ) {
32
32
  char tmp[ 19 ]; // "0x" + 64bits in hex + '\0'
33
- snprintf( tmp, sizeof( tmp ), "%#" PRIx64, * ( uint64_t *) element->data );
33
+ snprintf( tmp, sizeof( tmp ), "%#" PRIx64, *( uint64_t * ) element->data );
34
34
  strcat( result, tmp );
35
35
  strcat( result, comma );
36
36
  }
@@ -56,7 +56,7 @@ delete_switches( list_element *switches ) {
56
56
  }
57
57
 
58
58
 
59
- static void
59
+ static void
60
60
  insert_datapath_id( list_element **switches, uint64_t datapath_id ) {
61
61
  list_element *element = NULL;
62
62
  for ( element = *switches; element != NULL; element = element->next ) {
@@ -121,7 +121,7 @@ show_switches( void *user_data ) {
121
121
  char *list = xmalloc( 20 * num_switch + 1 ); // 20 = dpid string (18 chars) + ", "
122
122
  list[ 0 ] = '\0';
123
123
  join( list, *switches );
124
- info( "All switches = %s", list );
124
+ info( "All switches = %s", list );
125
125
  xfree( list );
126
126
  }
127
127
 
@@ -32,16 +32,16 @@ create_counter() {
32
32
 
33
33
  void
34
34
  add_counter( hash_table *db, uint8_t *mac, uint64_t packet_count, uint64_t byte_count ) {
35
- counter *counter = lookup_hash_entry( db, mac );
36
- if ( counter == NULL ) {
37
- counter = xmalloc( sizeof( counter ) );
38
- memcpy( counter->mac, mac, ETH_ADDRLEN );
39
- counter->packet_count = 0;
40
- counter->byte_count = 0;
41
- insert_hash_entry( db, counter->mac, counter );
35
+ counter *entry = lookup_hash_entry( db, mac );
36
+ if ( entry == NULL ) {
37
+ entry = xmalloc( sizeof( counter ) );
38
+ memcpy( entry->mac, mac, ETH_ADDRLEN );
39
+ entry->packet_count = 0;
40
+ entry->byte_count = 0;
41
+ insert_hash_entry( db, entry->mac, entry );
42
42
  }
43
- counter->packet_count += packet_count;
44
- counter->byte_count += byte_count;
43
+ entry->packet_count += packet_count;
44
+ entry->byte_count += byte_count;
45
45
  }
46
46
 
47
47
 
@@ -32,23 +32,23 @@ create_fdb() {
32
32
 
33
33
  uint16_t
34
34
  lookup_fdb( hash_table *db, uint8_t *mac ) {
35
- fdb *fdb = lookup_hash_entry( db, mac );
36
- return ( uint16_t ) ( fdb == NULL ? ENTRY_NOT_FOUND_IN_FDB : fdb->port_number );
35
+ fdb *entry = lookup_hash_entry( db, mac );
36
+ return ( uint16_t ) ( entry == NULL ? ENTRY_NOT_FOUND_IN_FDB : entry->port_number );
37
37
 
38
38
  }
39
39
 
40
40
 
41
41
  void
42
42
  learn_fdb( hash_table *db, uint8_t *mac, uint16_t port_number ) {
43
- fdb *fdb = lookup_hash_entry( db, mac );
44
- if ( fdb == NULL ) {
45
- fdb = xmalloc( sizeof( fdb ) );
46
- memcpy( fdb->mac, mac, ETH_ADDRLEN );
47
- fdb->port_number = port_number;
48
- insert_hash_entry( db, fdb->mac, fdb );
43
+ fdb *entry = lookup_hash_entry( db, mac );
44
+ if ( entry == NULL ) {
45
+ entry = xmalloc( sizeof( fdb ) );
46
+ memcpy( entry->mac, mac, ETH_ADDRLEN );
47
+ entry->port_number = port_number;
48
+ insert_hash_entry( db, entry->mac, entry );
49
49
  }
50
50
  else {
51
- fdb->port_number = port_number;
51
+ entry->port_number = port_number;
52
52
  }
53
53
  }
54
54
 
data/src/lib/arp.h CHANGED
@@ -46,7 +46,7 @@ typedef struct arp_header {
46
46
  uint32_t sip;
47
47
  uint8_t tha[ ETH_ADDRLEN ];
48
48
  uint32_t tip;
49
- } __attribute__((packed)) arp_header_t;
49
+ } __attribute__( ( packed ) ) arp_header_t;
50
50
 
51
51
 
52
52
  #define ARP_OP_REQUEST 1
data/src/lib/buffer.c CHANGED
@@ -191,7 +191,8 @@ append_front_buffer( buffer *buf, size_t length ) {
191
191
  if ( already_allocated( pbuf, length ) ) {
192
192
  memmove( ( char * ) b->data + length, b->data, b->length );
193
193
  memset( b->data, 0, length );
194
- } else {
194
+ }
195
+ else {
195
196
  append_front( pbuf, length );
196
197
  }
197
198
  b->length += length;
@@ -235,7 +236,7 @@ append_back_buffer( buffer *buf, size_t length ) {
235
236
  pthread_mutex_unlock( pbuf->mutex );
236
237
  return ( char * ) pbuf->public.data;
237
238
  }
238
-
239
+
239
240
  if ( !already_allocated( pbuf, length ) ) {
240
241
  append_back( pbuf, length );
241
242
  }
@@ -284,7 +285,7 @@ dump_buffer( const buffer *buf, void dump_function( const char *format, ... ) )
284
285
  pthread_mutex_lock( ( ( const private_buffer * ) buf )->mutex );
285
286
 
286
287
  char *hex = xmalloc( sizeof( char ) * ( buf->length * 2 + 1 ) );
287
- char *datap = buf->data;
288
+ uint8_t *datap = buf->data;
288
289
  char *hexp = hex;
289
290
  for ( unsigned int i = 0; i < buf->length; i++, datap++, hexp += 2 ) {
290
291
  snprintf( hexp, 3, "%02x", *datap );
data/src/lib/byteorder.c CHANGED
@@ -178,6 +178,19 @@ ntoh_action_enqueue( struct ofp_action_enqueue *dst, const struct ofp_action_enq
178
178
  }
179
179
 
180
180
 
181
+ static void
182
+ copy_action_vendor_body( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src, size_t body_length ) {
183
+ assert( src != NULL );
184
+ assert( dst != NULL );
185
+
186
+ if ( body_length > 0 ) {
187
+ const void *body_src = ( const char * ) src + sizeof( struct ofp_action_vendor_header );
188
+ void *body_dst = ( char * ) dst + sizeof( struct ofp_action_vendor_header );
189
+ bcopy( body_src, body_dst, body_length );
190
+ }
191
+ }
192
+
193
+
181
194
  void
182
195
  ntoh_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src ) {
183
196
  assert( src != NULL );
@@ -186,6 +199,19 @@ ntoh_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_actio
186
199
  dst->type = ntohs( src->type );
187
200
  dst->len = ntohs( src->len );
188
201
  dst->vendor = ntohl( src->vendor );
202
+ copy_action_vendor_body( dst, src, dst->len - sizeof( struct ofp_action_vendor_header ) );
203
+ }
204
+
205
+
206
+ void
207
+ hton_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src ) {
208
+ assert( src != NULL );
209
+ assert( dst != NULL );
210
+
211
+ dst->type = htons( src->type );
212
+ dst->len = htons( src->len );
213
+ dst->vendor = htonl( src->vendor );
214
+ copy_action_vendor_body( dst, src, src->len - sizeof( struct ofp_action_vendor_header ) );
189
215
  }
190
216
 
191
217
 
@@ -302,12 +328,12 @@ ntoh_flow_stats( struct ofp_flow_stats *dst, const struct ofp_flow_stats *src )
302
328
  dst->cookie = ntohll( fs->cookie );
303
329
  dst->packet_count = ntohll( fs->packet_count );
304
330
  dst->byte_count = ntohll( fs->byte_count );
305
-
331
+
306
332
  uint16_t actions_length = ( uint16_t ) ( ntohs( fs->length ) - offsetof( struct ofp_flow_stats, actions ) );
307
333
 
308
334
  struct ofp_action_header *ah_src = fs->actions;
309
335
  struct ofp_action_header *ah_dst = dst->actions;
310
-
336
+
311
337
  while ( actions_length >= sizeof( struct ofp_action_header ) ) {
312
338
  ntoh_action( ah_dst, ah_src );
313
339
  actions_length = ( uint16_t ) ( actions_length - ah_dst->len );
@@ -345,7 +371,7 @@ hton_flow_stats( struct ofp_flow_stats *dst, const struct ofp_flow_stats *src )
345
371
 
346
372
  struct ofp_action_header *ah_src = fs->actions;
347
373
  struct ofp_action_header *ah_dst = dst->actions;
348
-
374
+
349
375
  while ( actions_length >= sizeof( struct ofp_action_header ) ) {
350
376
  hton_action( ah_dst, ah_src );
351
377
  actions_length = ( uint16_t ) ( actions_length - ah_src->len );
@@ -433,7 +459,7 @@ ntoh_queue_property( struct ofp_queue_prop_header *dst, const struct ofp_queue_p
433
459
 
434
460
  dst->property = ntohs( ph->property );
435
461
  dst->len = ntohs( ph->len );
436
-
462
+
437
463
  if ( dst->property == OFPQT_MIN_RATE ) {
438
464
  struct ofp_queue_prop_min_rate *mr_src = ( struct ofp_queue_prop_min_rate * ) ph;
439
465
  struct ofp_queue_prop_min_rate *mr_dst = ( struct ofp_queue_prop_min_rate * ) dst;
@@ -457,7 +483,7 @@ hton_queue_property( struct ofp_queue_prop_header *dst, const struct ofp_queue_p
457
483
 
458
484
  dst->property = htons( ph->property );
459
485
  dst->len = htons( ph->len );
460
-
486
+
461
487
  if ( src->property == OFPQT_MIN_RATE ) {
462
488
  struct ofp_queue_prop_min_rate *mr_src = ( struct ofp_queue_prop_min_rate * ) ph;
463
489
  struct ofp_queue_prop_min_rate *mr_dst = ( struct ofp_queue_prop_min_rate * ) dst;
data/src/lib/byteorder.h CHANGED
@@ -24,8 +24,8 @@
24
24
  #define BYTEORDER_H
25
25
 
26
26
 
27
- #include <endian.h>
28
27
  #include <byteswap.h>
28
+ #include <endian.h>
29
29
  #include <openflow.h>
30
30
 
31
31
 
@@ -72,7 +72,7 @@ void ntoh_action_enqueue( struct ofp_action_enqueue *dst, const struct ofp_actio
72
72
  #define hton_action_enqueue ntoh_action_enqueue
73
73
 
74
74
  void ntoh_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src );
75
- #define hton_action_vendor ntoh_action_vendor
75
+ void hton_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src );
76
76
 
77
77
  void ntoh_action( struct ofp_action_header *dst, const struct ofp_action_header *src );
78
78
  void hton_action( struct ofp_action_header *dst, const struct ofp_action_header *src );
data/src/lib/chibach.c CHANGED
@@ -78,12 +78,14 @@ usage() {
78
78
  printf(
79
79
  "Usage: %s [OPTION]...\n"
80
80
  "\n"
81
- " -i, --datapath_id=DATAPATH_ID set datapath id\n"
82
- " -c, --controller=IP_ADDR set controller host\n"
83
- " -p, --port=TCP_PORT set controller TCP port\n"
84
- " -d, --daemonize run in the background\n"
85
- " -l, --logging_level=LEVEL set logging level\n"
86
- " -h, --help display this help and exit\n",
81
+ " -i, --datapath_id=DATAPATH_ID set datapath id\n"
82
+ " -c, --controller=IP_ADDR set controller host\n"
83
+ " -p, --port=TCP_PORT set controller TCP port\n"
84
+ " -d, --daemonize run in the background\n"
85
+ " -l, --logging_level=LEVEL set logging level\n"
86
+ " -g, --syslog output log messages to syslog\n"
87
+ " -f, --logging_facility=FACILITY set syslog facility\n"
88
+ " -h, --help display this help and exit\n",
87
89
  get_chibach_name()
88
90
  );
89
91
  }
data/src/lib/daemon.c CHANGED
@@ -1,6 +1,4 @@
1
1
  /*
2
- * Author: Yasuhito Takamiya <yasuhito@gmail.com>
3
- *
4
2
  * Copyright (C) 2008-2012 NEC Corporation
5
3
  *
6
4
  * This program is free software; you can redistribute it and/or modify
@@ -125,6 +123,18 @@ extern ssize_t mock_read( int fd, void *buf, size_t count );
125
123
  #define kill mock_kill
126
124
  extern int mock_kill( pid_t pid, int sig );
127
125
 
126
+ #ifdef readlink
127
+ #undef readlink
128
+ #endif // readlink
129
+ #define readlink mock_readlink
130
+ extern ssize_t mock_readlink( const char *path, char *buf, size_t bufsiz );
131
+
132
+ #ifdef basename
133
+ #undef basename
134
+ #endif // basename
135
+ #define basename mock_basename
136
+ extern char *mock_basename( char *path );
137
+
128
138
  #ifdef rename
129
139
  #undef rename
130
140
  #endif // rename
@@ -193,7 +203,7 @@ write_pid( const char *directory, const char *name ) {
193
203
  }
194
204
 
195
205
  char str[ PID_STRING_LENGTH ];
196
- snprintf( str, sizeof( str ),"%d\n", getpid() );
206
+ snprintf( str, sizeof( str ), "%d\n", getpid() );
197
207
  str[ sizeof( str ) - 1 ] = '\0';
198
208
  ssize_t ret = write( fd, str, strlen( str ) );
199
209
  if ( ret == -1 ) {
@@ -269,6 +279,22 @@ read_pid( const char *directory, const char *name ) {
269
279
  return -1;
270
280
  }
271
281
 
282
+ char proc_path[ 32 ];
283
+ char exe_path[ PATH_MAX ];
284
+ sprintf( proc_path, "/proc/%d/exe", pid );
285
+ ssize_t readsiz = readlink( proc_path, exe_path, sizeof( exe_path ) - 1 );
286
+ if ( readsiz == -1 ) {
287
+ warn( "Failed to check process id %d ( %s [%d] ).", pid, strerror( errno ), errno );
288
+ return -1;
289
+ }
290
+ exe_path[ readsiz ] = '\0';
291
+
292
+ char *exe_name = basename( exe_path );
293
+ if ( strcmp( name, exe_name ) != 0 ) {
294
+ warn( "Failed to check process name %s ( %s [%d] ).", name, strerror( errno ), errno );
295
+ return -1;
296
+ }
297
+
272
298
  return pid;
273
299
  }
274
300