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
@@ -30,7 +30,7 @@ module Trema
30
30
  before { @vhost = Vhost.new }
31
31
 
32
32
  subject { @vhost[ :name ] }
33
-
33
+
34
34
  context "and IP address empty" do
35
35
  it { should be_nil }
36
36
  end
@@ -65,7 +65,7 @@ module Trema
65
65
  before { @vhost = Vhost.new( "Yutaro's host" ) }
66
66
 
67
67
  subject { @vhost[ :promisc ] }
68
-
68
+
69
69
  context "when promisc off" do
70
70
  before { @vhost.promisc "off" }
71
71
 
@@ -78,7 +78,7 @@ module Trema
78
78
 
79
79
  it { should be_false }
80
80
  end
81
-
81
+
82
82
 
83
83
  context "when promisc on" do
84
84
  before { @vhost.promisc "on" }
@@ -102,13 +102,13 @@ module Trema
102
102
  end
103
103
  end
104
104
  end
105
-
106
-
105
+
106
+
107
107
  describe :netmask do
108
108
  before { @vhost = Vhost.new( "Yutaro's host" ) }
109
109
 
110
110
  subject { @vhost[ :netmask ] }
111
-
111
+
112
112
  context "when netmask empty" do
113
113
  it { should be_nil }
114
114
  end
@@ -119,8 +119,8 @@ module Trema
119
119
  it { should == "255.255.255.0" }
120
120
  end
121
121
  end
122
-
123
-
122
+
123
+
124
124
  describe :mac do
125
125
  before { @vhost = Vhost.new( "Yutaro's host" ) }
126
126
 
@@ -28,6 +28,7 @@ shared_examples_for "echo reply message" do
28
28
  vswitch( "echo" ) { datapath_id 0xabc }
29
29
  }.run( EchoReplyController ) {
30
30
  controller( "EchoReplyController" ).send_message( 0xabc, subject )
31
+ sleep 2 # FIXME: wait to send_message
31
32
  IO.read( File.join( Trema.log, "openflowd.echo.log" ) ).should include( "OFPT_ECHO_REPLY" )
32
33
  }
33
34
  end
@@ -28,6 +28,7 @@ shared_examples_for "features request message" do
28
28
  vswitch( "features-request" ) { datapath_id 0xabc }
29
29
  }.run( FeaturesRequestController ) {
30
30
  controller( "FeaturesRequestController" ).send_message( 0xabc, subject )
31
+ sleep 2 # FIXME: wait to send_message
31
32
  IO.read( File.join( Trema.log, "openflowd.features-request.log" ) ).should include( "OFPT_FEATURES_REQUEST" )
32
33
  }
33
34
  end
@@ -39,7 +39,7 @@ describe Trema::FlowRemoved, ".new( VALID OPTIONS )" do
39
39
  :tp_src => 1,
40
40
  :tp_dst => 1
41
41
  )
42
-
42
+
43
43
  FlowRemoved.new(
44
44
  :datapath_id=>2748,
45
45
  :transaction_id=>0,
@@ -47,9 +47,9 @@ describe Trema::FlowRemoved, ".new( VALID OPTIONS )" do
47
47
  :cookie => 123456789,
48
48
  :priority => 65535,
49
49
  :reason => 0,
50
- :duration_sec=>1,
50
+ :duration_sec=>1,
51
51
  :duration_nsec=>779000000,
52
- :idle_timeout=>1,
52
+ :idle_timeout=>1,
53
53
  :packet_count=> 6,
54
54
  :byte_count => 256
55
55
  )
@@ -66,8 +66,8 @@ describe Trema::FlowRemoved, ".new( VALID OPTIONS )" do
66
66
  its ( :packet_count ) { should == 6 }
67
67
  its ( :byte_count ) { should == 256 }
68
68
  end
69
-
70
-
69
+
70
+
71
71
  context "when a flow expires" do
72
72
  it "should #flow_removed" do
73
73
  class FlowRemovedController < Controller; end
@@ -83,12 +83,12 @@ describe Trema::FlowRemoved, ".new( VALID OPTIONS )" do
83
83
  sleep 2 # FIXME: wait to receive flow_removed
84
84
  }
85
85
  end
86
-
87
-
86
+
87
+
88
88
  it "should #flow_removed with valid attributes as per flow mod add" do
89
89
  class FlowRemovedController < Controller; end
90
- match = Match.new(
91
- :in_port=> 1,
90
+ match = Match.new(
91
+ :in_port=> 1,
92
92
  :dl_src => "00:00:00:00:00:01",
93
93
  :dl_dst => "00:00:00:00:00:02",
94
94
  :dl_type => 0x800,
@@ -20,56 +20,68 @@ require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
20
20
  require "trema"
21
21
 
22
22
 
23
- describe GetConfigRequest, ".new( OPTIONAL OPTION MISSING )" do
24
- it_should_behave_like "any Openflow message with default transaction ID"
23
+ shared_examples_for "get config request message" do
24
+ class GetConfigRequestController < Controller; end
25
+
26
+ it "should be logged to the switch's log", :sudo => true do
27
+ network {
28
+ vswitch( "get-config-request" ) { datapath_id 0xabc }
29
+ }.run( GetConfigRequestController ) {
30
+ controller( "GetConfigRequestController" ).send_message( 0xabc, subject )
31
+ sleep 2 # FIXME: wait to send_message
32
+ IO.read( File.join( Trema.log, "openflowd.get-config-request.log" ) ).should include( "OFPT_GET_CONFIG_REQUEST" )
33
+ }
34
+ end
25
35
  end
26
36
 
27
37
 
28
- describe GetConfigRequest, ".new( INVALID OPTION )" do
29
- subject { GetConfigRequest.new "INVALID OPTION" }
30
- it "should raise TypeError" do
31
- expect { subject }.to raise_error( TypeError )
38
+ module Trema
39
+ describe GetConfigRequest, ".new" do
40
+ it_should_behave_like "any Openflow message with default transaction ID"
41
+ it_should_behave_like "get config request message"
32
42
  end
33
- end
34
43
 
35
44
 
36
- describe GetConfigRequest, ".new( VALID OPTION )" do
37
- subject { GetConfigRequest.new :transaction_id => transaction_id }
38
- it_should_behave_like "any OpenFlow message with transaction_id option"
45
+ describe GetConfigRequest, ".new(nil)" do
46
+ subject { GetConfigRequest.new( nil ) }
47
+ it_should_behave_like "any Openflow message with default transaction ID"
48
+ it_should_behave_like "get config request message"
49
+ end
50
+
51
+
52
+ describe GetConfigRequest, ".new(transaction_id)" do
53
+ subject { GetConfigRequest.new( transaction_id ) }
54
+ it_should_behave_like "any Openflow message with transaction ID"
55
+ context "when sent to a switch" do
56
+ let( :transaction_id ) { 123 }
57
+ it_should_behave_like "get config request message"
58
+ end
59
+ end
39
60
 
40
61
 
41
- context "when #get_config_request is sent" do
42
- it "should #get_config_reply" do
43
- class GetConfigController < Controller; end
44
- network {
45
- vswitch { datapath_id 0xabc }
46
- }.run( GetConfigController ) {
47
- get_config_request = GetConfigRequest.new( :transaction_id => 1234 )
48
- controller( "GetConfigController" ).should_receive( :get_config_reply )
49
- sleep 1 # FIXME
50
- controller( "GetConfigController" ).send_message( 0xabc, get_config_request )
51
- sleep 2 # FIXME: wait to send_message
52
- }
62
+ describe GetConfigRequest, ".new(:transaction_id => value)" do
63
+ subject { GetConfigRequest.new( :transaction_id => transaction_id ) }
64
+ it_should_behave_like "any Openflow message with transaction ID"
65
+ context "when sent to a switch" do
66
+ let( :transaction_id ) { 123 }
67
+ it_should_behave_like "get config request message"
53
68
  end
54
-
55
-
56
- it "should #get_config_reply with valid attributes" do
57
- class GetConfigController < Controller; end
58
- network {
59
- vswitch { datapath_id 0xabc }
60
- }.run( GetConfigController ) {
61
- get_config_request = GetConfigRequest.new( :transaction_id => 1234 )
62
- controller( "GetConfigController" ).should_receive( :get_config_reply ) do | datapath_id, message |
63
- datapath_id.should == 0xabc
64
- message.transaction_id.should == 1234
65
- message.flags.should >= 0 and message.flags.should <= 3
66
- message.miss_send_len.should == 65535
67
- end
68
- controller( "GetConfigController" ).send_message( 0xabc, get_config_request )
69
- sleep 2 # FIXME: wait to send_message
70
- }
69
+ end
70
+
71
+
72
+ describe GetConfigRequest, ".new(:xid => value)" do
73
+ subject { GetConfigRequest.new( :xid => xid ) }
74
+ it_should_behave_like "any Openflow message with xid"
75
+ context "when sent to a switch" do
76
+ let( :xid ) { 123 }
77
+ it_should_behave_like "get config request message"
71
78
  end
72
79
  end
80
+
81
+
82
+ describe GetConfigRequest, '.new("INVALID OPTION")', :nosudo => true do
83
+ it { expect { GetConfigRequest.new "INVALID OPTION" }.to raise_error( TypeError ) }
84
+ end
73
85
  end
74
86
 
75
87
 
@@ -53,7 +53,7 @@ describe Match, ".new" do
53
53
  its( :nw_dst ) { subject.prefixlen.should == 24 }
54
54
  its( :tp_src ) { should == 10 }
55
55
  its( :tp_dst ) { should == 20 }
56
- its( :to_s ) { should == "wildcards = 0x20000(nw_dst(8)), in_port = 1, dl_src = 00:00:00:00:00:01, dl_dst = 00:00:00:00:00:02, dl_vlan = 65535, dl_vlan_pcp = 0, dl_type = 0x800, nw_tos = 0, nw_proto = 17, nw_src = 192.168.0.1/32, nw_dst = 192.168.0.0/24, tp_src = 10, tp_dst = 20" }
56
+ its( :to_s ) { should == "wildcards = 0x20000(nw_dst(8)), in_port = 1, dl_src = 00:00:00:00:00:01, dl_dst = 00:00:00:00:00:02, dl_vlan = 0xffff, dl_vlan_pcp = 0, dl_type = 0x800, nw_tos = 0, nw_proto = 17, nw_src = 192.168.0.1/32, nw_dst = 192.168.0.0/24, tp_src = 10, tp_dst = 20" }
57
57
  end
58
58
 
59
59
 
@@ -27,7 +27,7 @@ describe Trema::OpenflowError, "new" do
27
27
  network {
28
28
  vswitch( "error-port") { datapath_id 0xabc }
29
29
  }.run( OpenflowErrorController ) {
30
- port_mod = Trema::PortMod.new( :port_no => 2,
30
+ port_mod = Trema::PortMod.new( :port_no => 2,
31
31
  :hw_addr => Trema::Mac.new( "11:22:33:44:55:66" ),
32
32
  :config => 1,
33
33
  :mask => 1,
@@ -36,15 +36,15 @@ describe Trema::OpenflowError, "new" do
36
36
  controller( "OpenflowErrorController" ).should_receive( :openflow_error ) do | datapath_id, message |
37
37
  datapath_id.should == 0xabc
38
38
  message.type.should == Error::OFPET_PORT_MOD_FAILED
39
- message.code.should == Error::OFPPMFC_BAD_PORT
39
+ message.code.should == Error::OFPPMFC_BAD_PORT
40
40
  end
41
41
  controller( "OpenflowErrorController" ).send_message( 0xabc, port_mod )
42
42
  sleep 2 # FIXME: wait to send_message
43
43
  }
44
44
  end
45
45
  end
46
-
47
-
46
+
47
+
48
48
  context "when #port_mod with an invalid(hw_addr) is sent" do
49
49
  it "should receive #error(type=Error::OFPET_PORT_MOD_FAILED,code=Error::OFPPMFC_BAD_HW_ADDR)" do
50
50
  class OpenflowErrorController < Controller; end
@@ -55,7 +55,7 @@ describe Trema::OpenflowError, "new" do
55
55
  link "host1", "error-hw-addr"
56
56
  link "host2", "error-hw-addr"
57
57
  }.run( OpenflowErrorController ) {
58
- port_mod = Trema::PortMod.new( :port_no => 1,
58
+ port_mod = Trema::PortMod.new( :port_no => 1,
59
59
  :hw_addr => Trema::Mac.new( "11:22:33:44:55:66" ),
60
60
  :config => 1,
61
61
  :mask => 1,
@@ -71,8 +71,8 @@ describe Trema::OpenflowError, "new" do
71
71
  }
72
72
  end
73
73
  end
74
-
75
-
74
+
75
+
76
76
  context "when #flow_mod(add) message with an invalid(action_port) is sent" do
77
77
  it "should receive #error(type=Error::OFPET_BAD_ACTION,code=Error::OFPBAC_BAD_OUT_PORT)" do
78
78
  class OpenflowErrorController < Controller; end
@@ -93,9 +93,9 @@ describe Trema::OpenflowError, "new" do
93
93
  }
94
94
  end
95
95
  end
96
-
97
-
98
- context "when an unsupported message is sent" do
96
+
97
+
98
+ context "when an unsupported message is sent" do
99
99
  it "should receive an openflow error with valid attributes" do
100
100
  class OpenflowController < Controller; end
101
101
  network {
@@ -111,7 +111,7 @@ describe Trema::OpenflowError, "new" do
111
111
  when 0,4
112
112
  message.code.should include 0,1
113
113
  when 1,2
114
- message.code.should satisfy { | n |
114
+ message.code.should satisfy { | n |
115
115
  n >= 0 && n <= 8
116
116
  }
117
117
  when 3
@@ -22,7 +22,7 @@ require File.join( File.dirname( __FILE__ ), "..", "spec_helper" )
22
22
  require "trema"
23
23
 
24
24
 
25
- class PacketOutController < Controller
25
+ class PacketOutController < Controller
26
26
  def packet_in datapath_id, message
27
27
  send_flow_mod_add(
28
28
  datapath_id,
@@ -44,8 +44,8 @@ describe "packet-out" do
44
44
  PacketOutController.new.should respond_to(:send_packet_out)
45
45
  end
46
46
  end
47
-
48
-
47
+
48
+
49
49
  context "when invoked with no datapath_id" do
50
50
  it "should raise an error" do
51
51
  lambda do
@@ -53,8 +53,8 @@ describe "packet-out" do
53
53
  end.should raise_error("wrong number of arguments (0 for 1)")
54
54
  end
55
55
  end
56
-
57
-
56
+
57
+
58
58
  context "when #packet_in" do
59
59
  it "should #packet_out" do
60
60
  network {
@@ -23,7 +23,7 @@ require "trema"
23
23
 
24
24
 
25
25
  describe QueueGetConfigReply, ".new( VALID OPTIONS )" do
26
- subject do
26
+ subject do
27
27
  for i in 1..2 do
28
28
  pq = PacketQueue.new( :queue_id => i, :len => i * 64 )
29
29
  mr = MinRateQueue.new( i, i * 64, 1024 * i, pq)
@@ -25,7 +25,7 @@ require "trema"
25
25
  describe QueueGetConfigRequest, ".new( OPTIONAL OPTION MISSING )" do
26
26
  its( :port ) { should == 1 }
27
27
  it_should_behave_like "any Openflow message with default transaction ID"
28
- end
28
+ end
29
29
 
30
30
 
31
31
  describe QueueGetConfigRequest, ".new( VALID OPTIONS )" do
@@ -59,7 +59,7 @@ describe SetEthDstAddr, ".new( VALID OPTION )" do
59
59
  0xabc,
60
60
  :actions => SetEthDstAddr.new( "52:54:00:a8:ad:8c" )
61
61
  )
62
- sleep 2 # FIXME: wait to send_flow_mod
62
+ sleep 6 # FIXME: wait to send_flow_mod
63
63
  vswitch( "0xabc" ).should have( 1 ).flows
64
64
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_dl_dst:52:54:00:a8:ad:8c/ )
65
65
  }
@@ -56,7 +56,7 @@ describe SetEthSrcAddr, ".new( VALID OPTION )" do
56
56
  vswitch { datapath_id 0xabc }
57
57
  }.run( FlowModAddController ) {
58
58
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetEthSrcAddr.new( "52:54:00:a8:ad:8c" ) )
59
- sleep 2 # FIXME: wait to send_flow_mod
59
+ sleep 6 # FIXME: wait to send_flow_mod
60
60
  vswitch( "0xabc" ).should have( 1 ).flows
61
61
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_dl_src:52:54:00:a8:ad:8c/ )
62
62
  }
@@ -43,6 +43,7 @@ describe SetIpDstAddr, ".new( VALID OPTION )" do
43
43
  vswitch { datapath_id 0xabc }
44
44
  }.run( FlowModAddController ) {
45
45
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetIpDstAddr.new( "192.168.1.1" ) )
46
+ sleep 2 # FIXME: wait to send_flow_mod_add
46
47
  vswitch( "0xabc" ).should have( 1 ).flows
47
48
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_nw_dst:192.168.1.1/ )
48
49
  }
@@ -43,6 +43,7 @@ describe SetIpSrcAddr, ".new( VALID OPTION )" do
43
43
  vswitch { datapath_id 0xabc }
44
44
  }.run( FlowModAddController ) {
45
45
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetIpSrcAddr.new( "192.168.1.1" ) )
46
+ sleep 2 # FIXME: wait to send_flow_mod_add
46
47
  vswitch( "0xabc" ).should have( 1 ).flows
47
48
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_nw_src:192.168.1.1/ )
48
49
  }
@@ -50,6 +50,7 @@ describe SetIpTos, ".new( VALID OPTION )" do
50
50
  vswitch { datapath_id 0xabc }
51
51
  }.run( FlowModAddController ) {
52
52
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetIpTos.new( 4 ) )
53
+ sleep 2 # FIXME: wait to send_flow_mod_add
53
54
  vswitch( "0xabc" ).should have( 1 ).flows
54
55
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_nw_tos:4/ )
55
56
  }
@@ -50,6 +50,7 @@ describe SetTransportDstPort, ".new( VALID OPTION )" do
50
50
  vswitch { datapath_id 0xabc }
51
51
  }.run( FlowModAddController ) {
52
52
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetTransportDstPort.new( 5555 ) )
53
+ sleep 2 # FIXME: wait to send_flow_mod_add
53
54
  vswitch( "0xabc" ).should have( 1 ).flows
54
55
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_tp_dst:5555/ )
55
56
  }
@@ -50,6 +50,7 @@ describe SetTransportSrcPort, ".new( VALID OPTION )" do
50
50
  vswitch { datapath_id 0xabc }
51
51
  }.run( FlowModAddController ) {
52
52
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetTransportSrcPort.new( 5555 ) )
53
+ sleep 2 # FIXME: wait to send_flow_mod_add
53
54
  vswitch( "0xabc" ).should have( 1 ).flows
54
55
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_tp_src:5555/ )
55
56
  }
@@ -50,6 +50,7 @@ describe SetVlanPriority, ".new( VALID OPTION )" do
50
50
  vswitch { datapath_id 0xabc }
51
51
  }.run( FlowModAddController ) {
52
52
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetVlanPriority.new( 7 ) )
53
+ sleep 2 # FIXME: wait to send_flow_mod_add
53
54
  vswitch( "0xabc" ).should have( 1 ).flows
54
55
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_vlan_pcp:7/ )
55
56
  }
@@ -28,7 +28,7 @@ describe SetVlanVid, ".new( number )" do
28
28
  its( :vlan_id ) { should == 1024 }
29
29
  end
30
30
 
31
- it_validates "option range", :vlan_id, 1..4096
31
+ it_validates "option range", :vlan_id, 1..4095
32
32
  end
33
33
 
34
34
 
@@ -50,6 +50,7 @@ describe SetVlanVid, ".new( VALID OPTION )" do
50
50
  vswitch { datapath_id 0xabc }
51
51
  }.run( FlowModAddController ) {
52
52
  controller( "FlowModAddController" ).send_flow_mod_add( 0xabc, :actions => SetVlanVid.new( 1024 ) )
53
+ sleep 2 # FIXME: wait to send_flow_mod_add
53
54
  vswitch( "0xabc" ).should have( 1 ).flows
54
55
  vswitch( "0xabc" ).flows[0].actions.should match( /mod_vlan_vid:1024/ )
55
56
  }