backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / lib / test_of_config_classes.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2014 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 #
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
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import unittest
18 from nose.tools import eq_
19 from nose.tools import ok_
20
21 import sys
22 import lxml.etree as ET
23 from formencode.doctest_xml_compare import xml_compare
24
25 from ryu.lib.of_config import classes as ofc
26
27
28 GET = """<ns0:capable-switch xmlns:ns0="urn:onf:of111:config:yang">
29   <ns0:id>CapableSwitch0</ns0:id>
30   <ns0:resources>
31     <ns0:port>
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>
37       <ns0:configuration>
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>
42       </ns0:configuration>
43       <ns0:state>
44         <ns0:oper-state>up</ns0:oper-state>
45         <ns0:blocked>false</ns0:blocked>
46         <ns0:live>true</ns0:live>
47       </ns0:state>
48       <ns0:features>
49         <ns0:current>
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>
54         </ns0:current>
55         <ns0:advertised>
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>
60         </ns0:advertised>
61         <ns0:supported>
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>
66         </ns0:supported>
67         <ns0:advertised-peer>
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>
73       </ns0:features>
74     </ns0:port>
75     <ns0:port>
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>
81       <ns0:configuration>
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>
86       </ns0:configuration>
87       <ns0:state>
88         <ns0:oper-state>up</ns0:oper-state>
89         <ns0:blocked>false</ns0:blocked>
90         <ns0:live>true</ns0:live>
91       </ns0:state>
92       <ns0:features>
93         <ns0:current>
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>
98         </ns0:current>
99         <ns0:advertised>
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>
104         </ns0:advertised>
105         <ns0:supported>
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>
110         </ns0:supported>
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>
117       </ns0:features>
118     </ns0:port>
119     <ns0:port>
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>
125       <ns0:configuration>
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>
130       </ns0:configuration>
131       <ns0:state>
132         <ns0:oper-state>up</ns0:oper-state>
133         <ns0:blocked>false</ns0:blocked>
134         <ns0:live>true</ns0:live>
135       </ns0:state>
136       <ns0:features>
137         <ns0:current>
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>
142         </ns0:current>
143         <ns0:advertised>
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>
148         </ns0:advertised>
149         <ns0:supported>
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>
154         </ns0:supported>
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>
161       </ns0:features>
162     </ns0:port>
163     <ns0:port>
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>
169       <ns0:configuration>
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>
174       </ns0:configuration>
175       <ns0:state>
176         <ns0:oper-state>up</ns0:oper-state>
177         <ns0:blocked>false</ns0:blocked>
178         <ns0:live>true</ns0:live>
179       </ns0:state>
180       <ns0:features>
181         <ns0:current>
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>
186         </ns0:current>
187         <ns0:advertised>
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>
192         </ns0:advertised>
193         <ns0:supported>
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>
198         </ns0:supported>
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>
205       </ns0:features>
206     </ns0:port>
207     <ns0:queue>
208       <ns0:resource-id>LogicalSwitch9-Port4-Queue992</ns0:resource-id>
209       <ns0:id>992</ns0:id>
210       <ns0:port>4</ns0:port>
211       <ns0:properties>
212         <ns0:min-rate>10</ns0:min-rate>
213         <ns0:max-rate>130</ns0:max-rate>
214       </ns0:properties>
215     </ns0:queue>
216     <ns0:queue>
217       <ns0:resource-id>LogicalSwitch9-Port4-Queue991</ns0:resource-id>
218       <ns0:id>991</ns0:id>
219       <ns0:port>4</ns0:port>
220       <ns0:properties>
221         <ns0:min-rate>10</ns0:min-rate>
222         <ns0:max-rate>120</ns0:max-rate>
223       </ns0:properties>
224     </ns0:queue>
225     <ns0:queue>
226       <ns0:resource-id>LogicalSwitch7-Port2-Queue994</ns0:resource-id>
227       <ns0:id>994</ns0:id>
228       <ns0:port>2</ns0:port>
229       <ns0:properties>
230         <ns0:min-rate>400</ns0:min-rate>
231         <ns0:max-rate>900</ns0:max-rate>
232       </ns0:properties>
233     </ns0:queue>
234     <ns0:queue>
235       <ns0:resource-id>LogicalSwitch7-Port2-Queue993</ns0:resource-id>
236       <ns0:id>993</ns0:id>
237       <ns0:port>2</ns0:port>
238       <ns0:properties>
239         <ns0:min-rate>200</ns0:min-rate>
240         <ns0:max-rate>300</ns0:max-rate>
241       </ns0:properties>
242     </ns0:queue>
243   </ns0:resources>
244   <ns0:logical-switches>
245     <ns0:switch>
246       <ns0:id>LogicalSwitch9</ns0:id>
247       <ns0:capabilities>
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>
265         <ns0:group-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>
270         </ns0:group-types>
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>
276         <ns0:action-types>
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>
293         </ns0:action-types>
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>
302       </ns0:capabilities>
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>
309       <ns0:controllers>
310         <ns0:controller>
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>
316           <ns0:state>
317             <ns0:connection-state>down</ns0:connection-state>
318             <ns0:supported-versions>1.3</ns0:supported-versions>
319           </ns0:state>
320         </ns0:controller>
321       </ns0:controllers>
322       <ns0:resources>
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>
327       </ns0:resources>
328     </ns0:switch>
329     <ns0:switch>
330       <ns0:id>LogicalSwitch7</ns0:id>
331       <ns0:capabilities>
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>
349         <ns0:group-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>
354         </ns0:group-types>
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>
360         <ns0:action-types>
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>
375         </ns0:action-types>
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>
383       </ns0:capabilities>
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>
390       <ns0:controllers>
391         <ns0:controller>
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>
397           <ns0:state>
398             <ns0:connection-state>down</ns0:connection-state>
399             <ns0:supported-versions>1.2</ns0:supported-versions>
400           </ns0:state>
401         </ns0:controller>
402       </ns0:controllers>
403       <ns0:resources>
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>
408       </ns0:resources>
409     </ns0:switch>
410   </ns0:logical-switches>
411 </ns0:capable-switch>
412 """
413
414
415 class Test_of_config_classes(unittest.TestCase):
416     """ Test case for ryu.lib.of_config.classes
417     """
418
419     def setUp(self):
420         pass
421
422     def tearDown(self):
423         pass
424
425     def test_parse(self):
426         for xml0 in [GET]:
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))
431
432     def test_alt_names(self):
433         xml0 = GET
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'))
437
438     def test_iterate(self):
439         xml0 = GET
440         o = ofc.OFCapableSwitchType.from_xml(xml0)
441         for lsw in o.logical_switches.switch:
442             ok_(str(lsw.id).startswith('LogicalSwitch'))