backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / packet / test_mpls.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 import unittest
18 import logging
19 import inspect
20
21 from nose.tools import eq_
22 from ryu.lib.packet import mpls
23
24
25 LOG = logging.getLogger(__name__)
26
27
28 class Test_mpls(unittest.TestCase):
29
30     label = 29
31     exp = 6
32     bsb = 1
33     ttl = 64
34     mp = mpls.mpls(label, exp, bsb, ttl)
35
36     def setUp(self):
37         pass
38
39     def tearDown(self):
40         pass
41
42     def test_to_string(self):
43         mpls_values = {'label': self.label,
44                        'exp': self.exp,
45                        'bsb': self.bsb,
46                        'ttl': self.ttl}
47         _mpls_str = ','.join(['%s=%s' % (k, repr(mpls_values[k]))
48                               for k, v in inspect.getmembers(self.mp)
49                               if k in mpls_values])
50         mpls_str = '%s(%s)' % (mpls.mpls.__name__, _mpls_str)
51
52         eq_(str(self.mp), mpls_str)
53         eq_(repr(self.mp), mpls_str)
54
55     def test_json(self):
56         jsondict = self.mp.to_jsondict()
57         mp = mpls.mpls.from_jsondict(jsondict['mpls'])
58         eq_(str(self.mp), str(mp))
59
60     def test_label_from_bin_true(self):
61         mpls_label = 0xfffff
62         is_bos = True
63         buf = b'\xff\xff\xf1'
64         mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
65
66         eq_(mpls_label, mpls_label_out)
67         eq_(is_bos, is_bos_out)
68
69     def test_label_from_bin_false(self):
70         mpls_label = 0xfffff
71         is_bos = False
72         buf = b'\xff\xff\xf0'
73         mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
74
75         eq_(mpls_label, mpls_label_out)
76         eq_(is_bos, is_bos_out)
77
78     def test_label_to_bin_true(self):
79         mpls_label = 0xfffff
80         is_bos = True
81         label = b'\xff\xff\xf1'
82         label_out = mpls.label_to_bin(mpls_label, is_bos)
83
84         eq_(label, label_out)
85
86     def test_label_to_bin_false(self):
87         mpls_label = 0xfffff
88         is_bos = False
89         label = b'\xff\xff\xf0'
90         label_out = mpls.label_to_bin(mpls_label, is_bos)
91
92         eq_(label, label_out)