1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 from nose.tools import eq_
19 from nose.tools import ok_
22 import lxml.etree as ET
23 from formencode.doctest_xml_compare import xml_compare
25 from ryu.lib.of_config import classes as ofc
28 GET = """<ns0:capable-switch xmlns:ns0="urn:onf:of111:config:yang">
29 <ns0:id>CapableSwitch0</ns0:id>
32 <ns0:resource-id>LogicalSwitch9-Port4</ns0:resource-id>
33 <ns0:number>4</ns0:number>
34 <ns0:name>Port4</ns0:name>
35 <ns0:current-rate>5000</ns0:current-rate>
36 <ns0:max-rate>5000</ns0:max-rate>
38 <ns0:admin-state>up</ns0:admin-state>
39 <ns0:no-receive>false</ns0:no-receive>
40 <ns0:no-forward>false</ns0:no-forward>
41 <ns0:no-packet-in>false</ns0:no-packet-in>
44 <ns0:oper-state>up</ns0:oper-state>
45 <ns0:blocked>false</ns0:blocked>
46 <ns0:live>true</ns0:live>
50 <ns0:rate>100Mb-FD</ns0:rate>
51 <ns0:auto-negotiate>true</ns0:auto-negotiate>
52 <ns0:medium>copper</ns0:medium>
53 <ns0:pause>unsupported</ns0:pause>
56 <ns0:rate>other</ns0:rate>
57 <ns0:auto-negotiate>true</ns0:auto-negotiate>
58 <ns0:medium>copper</ns0:medium>
59 <ns0:pause>unsupported</ns0:pause>
62 <ns0:rate>100Mb-FD</ns0:rate>
63 <ns0:auto-negotiate>true</ns0:auto-negotiate>
64 <ns0:medium>copper</ns0:medium>
65 <ns0:pause>unsupported</ns0:pause>
68 <ns0:rate>100Mb-FD</ns0:rate>
69 <ns0:auto-negotiate>true</ns0:auto-negotiate>
70 <ns0:medium>copper</ns0:medium>
71 <ns0:pause>unsupported</ns0:pause>
72 </ns0:advertised-peer>
76 <ns0:resource-id>LogicalSwitch9-Port3</ns0:resource-id>
77 <ns0:number>3</ns0:number>
78 <ns0:name>Port3</ns0:name>
79 <ns0:current-rate>5000</ns0:current-rate>
80 <ns0:max-rate>5000</ns0:max-rate>
82 <ns0:admin-state>up</ns0:admin-state>
83 <ns0:no-receive>false</ns0:no-receive>
84 <ns0:no-forward>false</ns0:no-forward>
85 <ns0:no-packet-in>false</ns0:no-packet-in>
88 <ns0:oper-state>up</ns0:oper-state>
89 <ns0:blocked>false</ns0:blocked>
90 <ns0:live>true</ns0:live>
94 <ns0:rate>100Mb-FD</ns0:rate>
95 <ns0:auto-negotiate>true</ns0:auto-negotiate>
96 <ns0:medium>copper</ns0:medium>
97 <ns0:pause>unsupported</ns0:pause>
100 <ns0:rate>other</ns0:rate>
101 <ns0:auto-negotiate>true</ns0:auto-negotiate>
102 <ns0:medium>copper</ns0:medium>
103 <ns0:pause>unsupported</ns0:pause>
106 <ns0:rate>100Mb-FD</ns0:rate>
107 <ns0:auto-negotiate>true</ns0:auto-negotiate>
108 <ns0:medium>copper</ns0:medium>
109 <ns0:pause>unsupported</ns0:pause>
111 <ns0:advertised-peer>
112 <ns0:rate>100Mb-FD</ns0:rate>
113 <ns0:auto-negotiate>true</ns0:auto-negotiate>
114 <ns0:medium>copper</ns0:medium>
115 <ns0:pause>unsupported</ns0:pause>
116 </ns0:advertised-peer>
120 <ns0:resource-id>LogicalSwitch7-Port2</ns0:resource-id>
121 <ns0:number>2</ns0:number>
122 <ns0:name>Port2</ns0:name>
123 <ns0:current-rate>5000</ns0:current-rate>
124 <ns0:max-rate>5000</ns0:max-rate>
126 <ns0:admin-state>up</ns0:admin-state>
127 <ns0:no-receive>false</ns0:no-receive>
128 <ns0:no-forward>false</ns0:no-forward>
129 <ns0:no-packet-in>false</ns0:no-packet-in>
132 <ns0:oper-state>up</ns0:oper-state>
133 <ns0:blocked>false</ns0:blocked>
134 <ns0:live>true</ns0:live>
138 <ns0:rate>100Mb-FD</ns0:rate>
139 <ns0:auto-negotiate>true</ns0:auto-negotiate>
140 <ns0:medium>copper</ns0:medium>
141 <ns0:pause>unsupported</ns0:pause>
144 <ns0:rate>other</ns0:rate>
145 <ns0:auto-negotiate>true</ns0:auto-negotiate>
146 <ns0:medium>copper</ns0:medium>
147 <ns0:pause>unsupported</ns0:pause>
150 <ns0:rate>100Mb-FD</ns0:rate>
151 <ns0:auto-negotiate>true</ns0:auto-negotiate>
152 <ns0:medium>copper</ns0:medium>
153 <ns0:pause>unsupported</ns0:pause>
155 <ns0:advertised-peer>
156 <ns0:rate>100Mb-FD</ns0:rate>
157 <ns0:auto-negotiate>true</ns0:auto-negotiate>
158 <ns0:medium>copper</ns0:medium>
159 <ns0:pause>unsupported</ns0:pause>
160 </ns0:advertised-peer>
164 <ns0:resource-id>LogicalSwitch7-Port1</ns0:resource-id>
165 <ns0:number>1</ns0:number>
166 <ns0:name>Port1</ns0:name>
167 <ns0:current-rate>5000</ns0:current-rate>
168 <ns0:max-rate>5000</ns0:max-rate>
170 <ns0:admin-state>up</ns0:admin-state>
171 <ns0:no-receive>false</ns0:no-receive>
172 <ns0:no-forward>false</ns0:no-forward>
173 <ns0:no-packet-in>false</ns0:no-packet-in>
176 <ns0:oper-state>up</ns0:oper-state>
177 <ns0:blocked>false</ns0:blocked>
178 <ns0:live>true</ns0:live>
182 <ns0:rate>100Mb-FD</ns0:rate>
183 <ns0:auto-negotiate>true</ns0:auto-negotiate>
184 <ns0:medium>copper</ns0:medium>
185 <ns0:pause>unsupported</ns0:pause>
188 <ns0:rate>other</ns0:rate>
189 <ns0:auto-negotiate>true</ns0:auto-negotiate>
190 <ns0:medium>copper</ns0:medium>
191 <ns0:pause>unsupported</ns0:pause>
194 <ns0:rate>100Mb-FD</ns0:rate>
195 <ns0:auto-negotiate>true</ns0:auto-negotiate>
196 <ns0:medium>copper</ns0:medium>
197 <ns0:pause>unsupported</ns0:pause>
199 <ns0:advertised-peer>
200 <ns0:rate>100Mb-FD</ns0:rate>
201 <ns0:auto-negotiate>true</ns0:auto-negotiate>
202 <ns0:medium>copper</ns0:medium>
203 <ns0:pause>unsupported</ns0:pause>
204 </ns0:advertised-peer>
208 <ns0:resource-id>LogicalSwitch9-Port4-Queue992</ns0:resource-id>
210 <ns0:port>4</ns0:port>
212 <ns0:min-rate>10</ns0:min-rate>
213 <ns0:max-rate>130</ns0:max-rate>
217 <ns0:resource-id>LogicalSwitch9-Port4-Queue991</ns0:resource-id>
219 <ns0:port>4</ns0:port>
221 <ns0:min-rate>10</ns0:min-rate>
222 <ns0:max-rate>120</ns0:max-rate>
226 <ns0:resource-id>LogicalSwitch7-Port2-Queue994</ns0:resource-id>
228 <ns0:port>2</ns0:port>
230 <ns0:min-rate>400</ns0:min-rate>
231 <ns0:max-rate>900</ns0:max-rate>
235 <ns0:resource-id>LogicalSwitch7-Port2-Queue993</ns0:resource-id>
237 <ns0:port>2</ns0:port>
239 <ns0:min-rate>200</ns0:min-rate>
240 <ns0:max-rate>300</ns0:max-rate>
244 <ns0:logical-switches>
246 <ns0:id>LogicalSwitch9</ns0:id>
248 <ns0:max-buffered-packets>0</ns0:max-buffered-packets>
249 <ns0:max-tables>255</ns0:max-tables>
250 <ns0:max-ports>16777216</ns0:max-ports>
251 <ns0:flow-statistics>true</ns0:flow-statistics>
252 <ns0:table-statistics>true</ns0:table-statistics>
253 <ns0:port-statistics>true</ns0:port-statistics>
254 <ns0:group-statistics>true</ns0:group-statistics>
255 <ns0:queue-statistics>true</ns0:queue-statistics>
256 <ns0:reassemble-ip-fragments>false</ns0:reassemble-ip-fragments>
257 <ns0:block-looping-ports>false</ns0:block-looping-ports>
258 <ns0:reserved-port-types>
259 <ns0:type>all</ns0:type>
260 <ns0:type>controller</ns0:type>
261 <ns0:type>table</ns0:type>
262 <ns0:type>inport</ns0:type>
263 <ns0:type>any</ns0:type>
264 </ns0:reserved-port-types>
266 <ns0:type>all</ns0:type>
267 <ns0:type>select</ns0:type>
268 <ns0:type>indirect</ns0:type>
269 <ns0:type>fast-failover</ns0:type>
271 <ns0:group-capabilities>
272 <ns0:capability>select-weight</ns0:capability>
273 <ns0:capability>select-liveness</ns0:capability>
274 <ns0:capability>chaining</ns0:capability>
275 </ns0:group-capabilities>
277 <ns0:type>output</ns0:type>
278 <ns0:type>group</ns0:type>
279 <ns0:type>set-queue</ns0:type>
280 <ns0:type>set-mpls-ttl</ns0:type>
281 <ns0:type>dec-mpls-ttl</ns0:type>
282 <ns0:type>set-nw-ttl</ns0:type>
283 <ns0:type>dec-nw-ttl</ns0:type>
284 <ns0:type>copy-ttl-out</ns0:type>
285 <ns0:type>copy-ttl-in</ns0:type>
286 <ns0:type>push-vlan</ns0:type>
287 <ns0:type>pop-vlan</ns0:type>
288 <ns0:type>push-mpls</ns0:type>
289 <ns0:type>pop-mpls</ns0:type>
290 <ns0:type>push-pbb</ns0:type>
291 <ns0:type>pop-pbb</ns0:type>
292 <ns0:type>set-field</ns0:type>
294 <ns0:instruction-types>
295 <ns0:type>goto-table</ns0:type>
296 <ns0:type>write-metadata</ns0:type>
297 <ns0:type>write-actions</ns0:type>
298 <ns0:type>apply-actions</ns0:type>
299 <ns0:type>clear-actions</ns0:type>
300 <ns0:type>meter</ns0:type>
301 </ns0:instruction-types>
303 <ns0:datapath-id>08:60:6E:7F:74:E7:00:09</ns0:datapath-id>
304 <ns0:enabled>true</ns0:enabled>
305 <ns0:check-controller-certificate>false
306 </ns0:check-controller-certificate>
307 <ns0:lost-connection-behavior>failSecureMode
308 </ns0:lost-connection-behavior>
311 <ns0:id>Switch9-Controller</ns0:id>
312 <ns0:role>equal</ns0:role>
313 <ns0:ip-address>127.0.0.1</ns0:ip-address>
314 <ns0:port>6633</ns0:port>
315 <ns0:protocol>tcp</ns0:protocol>
317 <ns0:connection-state>down</ns0:connection-state>
318 <ns0:supported-versions>1.3</ns0:supported-versions>
323 <ns0:port>LogicalSwitch9-Port4</ns0:port>
324 <ns0:port>LogicalSwitch9-Port3</ns0:port>
325 <ns0:queue>LogicalSwitch9-Port4-Queue992</ns0:queue>
326 <ns0:queue>LogicalSwitch9-Port4-Queue991</ns0:queue>
330 <ns0:id>LogicalSwitch7</ns0:id>
332 <ns0:max-buffered-packets>0</ns0:max-buffered-packets>
333 <ns0:max-tables>255</ns0:max-tables>
334 <ns0:max-ports>16777216</ns0:max-ports>
335 <ns0:flow-statistics>true</ns0:flow-statistics>
336 <ns0:table-statistics>true</ns0:table-statistics>
337 <ns0:port-statistics>true</ns0:port-statistics>
338 <ns0:group-statistics>true</ns0:group-statistics>
339 <ns0:queue-statistics>true</ns0:queue-statistics>
340 <ns0:reassemble-ip-fragments>false</ns0:reassemble-ip-fragments>
341 <ns0:block-looping-ports>false</ns0:block-looping-ports>
342 <ns0:reserved-port-types>
343 <ns0:type>all</ns0:type>
344 <ns0:type>controller</ns0:type>
345 <ns0:type>table</ns0:type>
346 <ns0:type>inport</ns0:type>
347 <ns0:type>any</ns0:type>
348 </ns0:reserved-port-types>
350 <ns0:type>all</ns0:type>
351 <ns0:type>select</ns0:type>
352 <ns0:type>indirect</ns0:type>
353 <ns0:type>fast-failover</ns0:type>
355 <ns0:group-capabilities>
356 <ns0:capability>select-weight</ns0:capability>
357 <ns0:capability>select-liveness</ns0:capability>
358 <ns0:capability>chaining</ns0:capability>
359 </ns0:group-capabilities>
361 <ns0:type>output</ns0:type>
362 <ns0:type>group</ns0:type>
363 <ns0:type>set-queue</ns0:type>
364 <ns0:type>set-mpls-ttl</ns0:type>
365 <ns0:type>dec-mpls-ttl</ns0:type>
366 <ns0:type>set-nw-ttl</ns0:type>
367 <ns0:type>dec-nw-ttl</ns0:type>
368 <ns0:type>copy-ttl-out</ns0:type>
369 <ns0:type>copy-ttl-in</ns0:type>
370 <ns0:type>push-vlan</ns0:type>
371 <ns0:type>pop-vlan</ns0:type>
372 <ns0:type>push-mpls</ns0:type>
373 <ns0:type>pop-mpls</ns0:type>
374 <ns0:type>set-field</ns0:type>
376 <ns0:instruction-types>
377 <ns0:type>goto-table</ns0:type>
378 <ns0:type>write-metadata</ns0:type>
379 <ns0:type>write-actions</ns0:type>
380 <ns0:type>apply-actions</ns0:type>
381 <ns0:type>clear-actions</ns0:type>
382 </ns0:instruction-types>
384 <ns0:datapath-id>08:60:6E:7F:74:E7:00:07</ns0:datapath-id>
385 <ns0:enabled>true</ns0:enabled>
386 <ns0:check-controller-certificate>false
387 </ns0:check-controller-certificate>
388 <ns0:lost-connection-behavior>failSecureMode
389 </ns0:lost-connection-behavior>
392 <ns0:id>Switch7-Controller</ns0:id>
393 <ns0:role>equal</ns0:role>
394 <ns0:ip-address>127.0.0.1</ns0:ip-address>
395 <ns0:port>6633</ns0:port>
396 <ns0:protocol>tcp</ns0:protocol>
398 <ns0:connection-state>down</ns0:connection-state>
399 <ns0:supported-versions>1.2</ns0:supported-versions>
404 <ns0:port>LogicalSwitch7-Port2</ns0:port>
405 <ns0:port>LogicalSwitch7-Port1</ns0:port>
406 <ns0:queue>LogicalSwitch7-Port2-Queue994</ns0:queue>
407 <ns0:queue>LogicalSwitch7-Port2-Queue993</ns0:queue>
410 </ns0:logical-switches>
411 </ns0:capable-switch>
415 class Test_of_config_classes(unittest.TestCase):
416 """ Test case for ryu.lib.of_config.classes
425 def test_parse(self):
427 o = ofc.OFCapableSwitchType.from_xml(xml0)
428 xml1 = o.to_xml('capable-switch')
429 ok_(xml_compare(ET.fromstring(xml0), ET.fromstring(xml1),
430 reporter=sys.stderr.write))
432 def test_alt_names(self):
434 o = ofc.OFCapableSwitchType.from_xml(xml0)
435 eq_(o.logical_switches, getattr(o, 'logical_switches'))
436 eq_(o.logical_switches, getattr(o, 'logical-switches'))
438 def test_iterate(self):
440 o = ofc.OFCapableSwitchType.from_xml(xml0)
441 for lsw in o.logical_switches.switch:
442 ok_(str(lsw.id).startswith('LogicalSwitch'))