backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / services / protocols / bgp / utils / test_validation.py
1 # Copyright (C) 2016 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 import logging
17 import unittest
18
19 from nose.tools import eq_, ok_
20
21 from ryu.services.protocols.bgp.utils import validation
22
23
24 LOG = logging.getLogger(__name__)
25
26
27 class Test_Utils_Validation(unittest.TestCase):
28     """
29     Test case for ryu.services.protocols.bgp.utils.validation
30     """
31
32     def test_is_valid_mac(self):
33         ok_(validation.is_valid_mac('aa:bb:cc:dd:ee:ff'))
34
35     def test_is_valid_mac_hyphenation(self):
36         ok_(validation.is_valid_mac('aa-bb-cc-dd-ee-ff'))
37
38     def test_is_valid_mac_short(self):
39         eq_(False, validation.is_valid_mac('aa:bb:cc:dd:ee'))
40
41     def test_is_valid_ip_prefix(self):
42         ok_(validation.is_valid_ip_prefix(24, 32))
43
44     def test_is_valid_ip_prefix_str(self):
45         ok_(validation.is_valid_ip_prefix('24', 32))
46
47     def test_is_valid_ip_prefix_not_digit(self):
48         eq_(False, validation.is_valid_ip_prefix('foo', 32))
49
50     def test_is_valid_ip_prefix_over(self):
51         eq_(False, validation.is_valid_ip_prefix(100, 32))
52
53     def test_is_valid_ipv4(self):
54         ok_(validation.is_valid_ipv4('10.0.0.1'))
55
56     def test_is_valid_ipv4_not_dot(self):
57         eq_(False, validation.is_valid_ipv4('192:168:0:1'))
58
59     def test_is_valid_ipv4_prefix(self):
60         ok_(validation.is_valid_ipv4_prefix('10.0.0.1/24'))
61
62     def test_is_valid_ipv4_prefix_not_str(self):
63         eq_(False, validation.is_valid_ipv4_prefix(1234))
64
65     def test_is_valid_ipv4_prefix_without_prefix(self):
66         eq_(False, validation.is_valid_ipv4_prefix('10.0.0.1'))
67
68     def test_is_valid_ipv4_prefix_invalid_addr(self):
69         eq_(False, validation.is_valid_ipv4_prefix('xxx.xxx.xxx.xxx/24'))
70
71     def test_is_valid_ipv6(self):
72         ok_(validation.is_valid_ipv6('fe80::0011:aabb:ccdd:eeff'))
73
74     def test_is_valid_ipv6_not_colon(self):
75         eq_(False, validation.is_valid_ipv6('fe80--0011-aabb-ccdd-eeff'))
76
77     def test_is_valid_ipv6_prefix(self):
78         ok_(validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff/64'))
79
80     def test_is_valid_ipv6_prefix_not_str(self):
81         eq_(False, validation.is_valid_ipv6_prefix(1234))
82
83     def test_is_valid_ipv6_prefix_without_prefix(self):
84         eq_(False,
85             validation.is_valid_ipv6_prefix('fe80::0011:aabb:ccdd:eeff'))
86
87     def test_is_valid_ipv6_prefix_invalid_addr(self):
88         eq_(False, validation.is_valid_ipv6_prefix('xxxx::xxxx/64'))
89
90     def test_is_valid_old_asn(self):
91         ok_(validation.is_valid_old_asn(65000))
92
93     def test_is_valid_old_asn_negative(self):
94         eq_(False, validation.is_valid_old_asn(-1))
95
96     def test_is_valid_old_asn_over(self):
97         eq_(False, validation.is_valid_old_asn(0xffff + 1))
98
99     def test_is_valid_asn(self):
100         ok_(validation.is_valid_asn(6553800))
101
102     def test_is_valid_asn_old(self):
103         ok_(validation.is_valid_asn(65000))
104
105     def test_is_valid_asn_negative(self):
106         eq_(False, validation.is_valid_asn(-1))
107
108     def test_is_valid_asn_over(self):
109         eq_(False, validation.is_valid_asn(0xffffffff + 1))
110
111     def test_is_valid_vpnv4_prefix(self):
112         ok_(validation.is_valid_vpnv4_prefix('100:200:10.0.0.1/24'))
113
114     def test_is_valid_vpnv4_prefix_not_str(self):
115         eq_(False, validation.is_valid_vpnv4_prefix(1234))
116
117     def test_is_valid_vpnv4_prefix_short_rd(self):
118         eq_(False, validation.is_valid_vpnv4_prefix('100:10.0.0.1/24'))
119
120     def test_is_valid_vpnv4_prefix_invalid_rd(self):
121         eq_(False, validation.is_valid_vpnv4_prefix('foo:bar:10.0.0.1/24'))
122
123     def test_is_valid_vpnv6_prefix(self):
124         ok_(validation.is_valid_vpnv6_prefix(
125             '100:200:fe80::0011:aabb:ccdd:eeff/64'))
126
127     def test_is_valid_vpnv6_prefix_not_str(self):
128         eq_(False, validation.is_valid_vpnv6_prefix(1234))
129
130     def test_is_valid_vpnv6_prefix_short_rd(self):
131         eq_(False, validation.is_valid_vpnv6_prefix('100:eeff/64'))
132
133     def test_is_valid_vpnv6_prefix_invalid_rd(self):
134         eq_(False, validation.is_valid_vpnv6_prefix('foo:bar:10.0.0.1/24'))
135
136     def test_is_valid_med(self):
137         ok_(validation.is_valid_med(100))
138
139     def test_is_valid_med_not_num(self):
140         eq_(False, validation.is_valid_med('foo'))
141
142     def test_is_valid_med_negative(self):
143         eq_(False, validation.is_valid_med(-1))
144
145     def test_is_valid_med_over(self):
146         eq_(False, validation.is_valid_med(0xffffffff + 1))
147
148     def test_is_valid_mpls_label(self):
149         ok_(validation.is_valid_mpls_label(100))
150
151     def test_is_valid_mpls_label_reserved(self):
152         eq_(False, validation.is_valid_mpls_label(4))
153
154     def test_is_valid_mpls_label_not_num(self):
155         eq_(False, validation.is_valid_mpls_label('foo'))
156
157     def test_is_valid_mpls_label_negative(self):
158         eq_(False, validation.is_valid_mpls_label(-1))
159
160     def test_is_valid_mpls_label_over(self):
161         eq_(False, validation.is_valid_mpls_label(0x100000 + 1))
162
163     def test_is_valid_mpls_labels(self):
164         ok_(validation.is_valid_mpls_labels([100, 200]))
165
166     def test_is_valid_mpls_labels_not_list(self):
167         eq_(False, validation.is_valid_mpls_labels(100))
168
169     def test_is_valid_mpls_labels_with_invalid_label(self):
170         eq_(False, validation.is_valid_mpls_labels(['foo', 200]))
171
172     def test_is_valid_route_dist(self):
173         ok_(validation.is_valid_route_dist('65000:222'))
174
175     def test_is_valid_route_dist_ipv4_based(self):
176         ok_(validation.is_valid_route_dist('10.0.0.1:333'))
177
178     def test_is_valid_route_not_str(self):
179         eq_(False, validation.is_valid_route_dist(65000))
180
181     def test_is_valid_route_dist_short(self):
182         eq_(False, validation.is_valid_route_dist('65000'))
183
184     def test_is_valid_route_dist_invalid_ipv4_addr(self):
185         eq_(False, validation.is_valid_route_dist('xxx.xxx.xxx.xxx:333'))
186
187     def test_is_valid_esi(self):
188         ok_(validation.is_valid_esi(100))
189
190     def test_is_valid_esi_not_int(self):
191         eq_(False, validation.is_valid_esi('foo'))
192
193     def test_is_valid_ethernet_tag_id(self):
194         ok_(validation.is_valid_ethernet_tag_id(100))
195
196     def test_is_valid_ethernet_tag_id_not_int(self):
197         eq_(False, validation.is_valid_ethernet_tag_id('foo'))
198
199     def test_is_valid_ethernet_tag_id_negative(self):
200         eq_(False, validation.is_valid_ethernet_tag_id(-1))
201
202     def test_is_valid_ethernet_tag_id_over(self):
203         eq_(False, validation.is_valid_ethernet_tag_id(0xffffffff + 1))
204
205     def test_is_valid_vni(self):
206         ok_(validation.is_valid_vni(100))
207
208     def test_is_valid_vni_not_int(self):
209         eq_(False, validation.is_valid_vni('foo'))
210
211     def test_is_valid_vni_negative(self):
212         eq_(False, validation.is_valid_vni(-1))
213
214     def test_is_valid_vni_over(self):
215         eq_(False, validation.is_valid_vni(0xffffff + 1))