blob: 810c6f0af504f62ba54bb430a648d86ea123876d [file] [log] [blame]
Jian Li9b199162019-02-10 18:00:35 +09001/*
2 * Copyright 2019-present Open Networking Foundation
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 implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.k8snetworking.util;
17
18import org.junit.Test;
19import org.onlab.packet.IpAddress;
20
21import java.util.Set;
22
23import static junit.framework.TestCase.assertEquals;
24import static org.onosproject.k8snetworking.util.K8sNetworkingUtil.getSubnetIps;
25
26/**
27 * Unit tests for kubernetes networking utils.
28 */
29public final class K8sNetworkUtilTest {
30
31 /**
32 * Tests the getSubnetIps method.
33 */
34 @Test
35 public void testGetSubnetIps() {
36 String bClassCidr = "10.10.0.0/16";
37 Set<IpAddress> bClassIps = getSubnetIps(bClassCidr);
38 assertEquals(((Double) Math.pow(2, 16)).intValue() - 2, bClassIps.size());
39
40 String cClassCidr = "10.10.10.0/24";
41 Set<IpAddress> cClassIps = getSubnetIps(cClassCidr);
42 assertEquals(((Double) Math.pow(2, 8)).intValue() - 2, cClassIps.size());
43
44 String dClassCidr = "10.10.10.10/32";
45 Set<IpAddress> dClassIps = getSubnetIps(dClassCidr);
46 assertEquals(1, dClassIps.size());
47 }
48}