1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 from nose.tools import eq_
22 from ryu.lib.packet import mpls
25 LOG = logging.getLogger(__name__)
28 class Test_mpls(unittest.TestCase):
34 mp = mpls.mpls(label, exp, bsb, ttl)
42 def test_to_string(self):
43 mpls_values = {'label': self.label,
47 _mpls_str = ','.join(['%s=%s' % (k, repr(mpls_values[k]))
48 for k, v in inspect.getmembers(self.mp)
50 mpls_str = '%s(%s)' % (mpls.mpls.__name__, _mpls_str)
52 eq_(str(self.mp), mpls_str)
53 eq_(repr(self.mp), mpls_str)
56 jsondict = self.mp.to_jsondict()
57 mp = mpls.mpls.from_jsondict(jsondict['mpls'])
58 eq_(str(self.mp), str(mp))
60 def test_label_from_bin_true(self):
64 mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
66 eq_(mpls_label, mpls_label_out)
67 eq_(is_bos, is_bos_out)
69 def test_label_from_bin_false(self):
73 mpls_label_out, is_bos_out = mpls.label_from_bin(buf)
75 eq_(mpls_label, mpls_label_out)
76 eq_(is_bos, is_bos_out)
78 def test_label_to_bin_true(self):
81 label = b'\xff\xff\xf1'
82 label_out = mpls.label_to_bin(mpls_label, is_bos)
86 def test_label_to_bin_false(self):
89 label = b'\xff\xff\xf0'
90 label_out = mpls.label_to_bin(mpls_label, is_bos)