1 # Copyright (C) 2016 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.
19 from ryu.lib import ofctl_utils
20 from ryu.ofproto import ofproto_v1_3
23 LOG = logging.getLogger(__name__)
26 class Test_ofctl_utils(unittest.TestCase):
28 util = ofctl_utils.OFCtlUtil(ofproto_v1_3)
30 def _test_str_to_int(self, input_value, expected_value):
31 output_value = ofctl_utils.str_to_int(input_value)
32 self.assertEqual(expected_value, output_value)
34 def test_str_to_int(self):
35 self._test_str_to_int(1, 1) # int
36 self._test_str_to_int('0b10', 2) # binary digit
37 self._test_str_to_int('0o10', 8) # octal digit
38 self._test_str_to_int('0x10', 16) # hexadecimal digit
40 def test_ofp_port_from_user(self):
42 ofproto_v1_3.OFPP_CONTROLLER,
43 self.util.ofp_port_from_user(ofproto_v1_3.OFPP_CONTROLLER) # int
46 ofproto_v1_3.OFPP_CONTROLLER,
47 self.util.ofp_port_from_user('CONTROLLER') # str without prefix
50 ofproto_v1_3.OFPP_CONTROLLER,
51 self.util.ofp_port_from_user('OFPP_CONTROLLER') # str with prefix
54 def test_ofp_port_to_user(self):
57 self.util.ofp_port_to_user(ofproto_v1_3.OFPP_CONTROLLER)
61 self.util.ofp_port_to_user(1) # not matched
64 def test_ofp_table_from_user(self):
66 ofproto_v1_3.OFPTT_ALL,
67 self.util.ofp_table_from_user('ALL')
70 def test_ofp_table_to_user(self):
73 self.util.ofp_table_to_user(ofproto_v1_3.OFPTT_ALL)
76 def test_ofp_cml_from_user(self):
78 ofproto_v1_3.OFPCML_NO_BUFFER,
79 self.util.ofp_cml_from_user('NO_BUFFER')
82 def test_ofp_cml_to_user(self):
85 self.util.ofp_cml_to_user(ofproto_v1_3.OFPCML_NO_BUFFER)
88 def test_ofp_group_from_user(self):
90 ofproto_v1_3.OFPG_ANY,
91 self.util.ofp_group_from_user('ANY')
94 def test_ofp_group_to_user(self):
97 self.util.ofp_group_to_user(ofproto_v1_3.OFPG_ANY)
100 def test_ofp_buffer_from_user(self):
102 ofproto_v1_3.OFP_NO_BUFFER,
103 self.util.ofp_buffer_from_user('NO_BUFFER')
107 self.util.ofp_buffer_from_user(1) # not matched
110 def test_ofp_buffer_to_user(self):
113 self.util.ofp_buffer_to_user(ofproto_v1_3.OFP_NO_BUFFER)
117 self.util.ofp_buffer_to_user(1) # not matched
120 def test_ofp_meter_from_user(self):
122 ofproto_v1_3.OFPM_ALL,
123 self.util.ofp_meter_from_user('ALL')
126 def test_ofp_meter_to_user(self):
129 self.util.ofp_meter_to_user(ofproto_v1_3.OFPM_ALL)
132 def test_ofp_queue_from_user(self):
134 ofproto_v1_3.OFPQ_ALL,
135 self.util.ofp_queue_from_user('ALL')
138 def test_ofp_queue_to_user(self):
141 self.util.ofp_queue_to_user(ofproto_v1_3.OFPQ_ALL)