backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / ofproto / test_nx_flow_spec.py
1 # Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2015 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
19 import ryu.ofproto.ofproto_v1_3_parser as ofpp
20
21
22 class Test_FlowSpec(unittest.TestCase):
23     def test_flowspec_src_0_dst_0(self):
24         user = ofpp.NXFlowSpecMatch(src=('in_port', 0),
25                                     dst=('in_port', 0),
26                                     n_bits=16)
27         on_wire = (
28             b'\x00\x10'
29             b'\x80\x00\x00\x04\x00\x00'
30             b'\x80\x00\x00\x04\x00\x00'
31         )
32         self.assertEqual(on_wire, user.serialize())
33         (o, rest) = ofpp._NXFlowSpec.parse(on_wire)
34         self.assertEqual(user.to_jsondict(), o.to_jsondict())
35         self.assertEqual(str(user), str(o))
36         self.assertEqual(b'', rest)
37
38     def test_flowspec_src_1_dst_0(self):
39         user = ofpp.NXFlowSpecMatch(src=99,
40                                     dst=('in_port', 0),
41                                     n_bits=16)
42         on_wire = (
43             b'\x20\x10'
44             b'\x00\x63'
45             b'\x80\x00\x00\x04\x00\x00'
46         )
47         self.assertEqual(on_wire, user.serialize())
48         (o, rest) = ofpp._NXFlowSpec.parse(on_wire)
49         self.assertEqual(user.to_jsondict(), o.to_jsondict())
50         self.assertEqual(str(user), str(o))
51         self.assertEqual(b'', rest)
52
53     def test_flowspec_src_0_dst_1(self):
54         user = ofpp.NXFlowSpecLoad(src=('in_port', 0),
55                                    dst=('in_port', 0),
56                                    n_bits=16)
57         on_wire = (
58             b'\x08\x10'
59             b'\x80\x00\x00\x04\x00\x00'
60             b'\x80\x00\x00\x04\x00\x00'
61         )
62         self.assertEqual(on_wire, user.serialize())
63         (o, rest) = ofpp._NXFlowSpec.parse(on_wire)
64         self.assertEqual(user.to_jsondict(), o.to_jsondict())
65         self.assertEqual(str(user), str(o))
66         self.assertEqual(b'', rest)
67
68     def test_flowspec_src_1_dst_1(self):
69         user = ofpp.NXFlowSpecLoad(src=99,
70                                    dst=('in_port', 0),
71                                    n_bits=16)
72         on_wire = (
73             b'\x28\x10'
74             b'\x00\x63'
75             b'\x80\x00\x00\x04\x00\x00'
76         )
77         self.assertEqual(on_wire, user.serialize())
78         (o, rest) = ofpp._NXFlowSpec.parse(on_wire)
79         self.assertEqual(user.to_jsondict(), o.to_jsondict())
80         self.assertEqual(str(user), str(o))
81         self.assertEqual(b'', rest)
82
83     def test_flowspec_src_0_dst_2(self):
84         user = ofpp.NXFlowSpecOutput(src=('in_port', 0),
85                                      dst='',
86                                      n_bits=16)
87         on_wire = (
88             b'\x10\x10'
89             b'\x80\x00\x00\x04\x00\x00'
90         )
91         self.assertEqual(on_wire, user.serialize())
92         (o, rest) = ofpp._NXFlowSpec.parse(on_wire)
93         self.assertEqual(user.to_jsondict(), o.to_jsondict())
94         self.assertEqual(str(user), str(o))
95         self.assertEqual(b'', rest)