BUG-6650: ep-sgt/ip, propose initial sxp-ep-provider
[groupbasedpolicy.git] / sxp-integration / sxp-ep-provider / src / test / java / org / opendaylight / groupbasedpolicy / sxp / ep / provider / impl / util / EPTemplateUtilTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.util;
10
11 import org.apache.commons.net.util.SubnetUtils;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
16
17 /**
18  * Test for {@link EPTemplateUtil}.
19  */
20 public class EPTemplateUtilTest {
21
22     public static final IpPrefix IP_PREFIX_24 = new IpPrefix(new Ipv4Prefix("1.2.3.0/24"));
23     public static final IpPrefix IP_PREFIX_32 = new IpPrefix(new Ipv4Prefix("1.2.3.4/32"));
24
25     @Test
26     public void testIsPlain() throws Exception {
27         Assert.assertFalse(EPTemplateUtil.isPlain(IP_PREFIX_24));
28         Assert.assertTrue(EPTemplateUtil.isPlain(IP_PREFIX_32));
29     }
30
31     @Test
32     public void testBuildSubnetInfoKey() throws Exception {
33         checkSubnetInfoBuilder(IP_PREFIX_24, "1.2.3.1", "1.2.3.254", 254);
34         checkSubnetInfoBuilder(IP_PREFIX_32, "0.0.0.0", "0.0.0.0", 0);
35     }
36
37     private void checkSubnetInfoBuilder(final IpPrefix ipPrefix, final String expectedLow, final String expectedHigh, final int expectedCount) {
38         final SubnetInfoKeyDecorator subnetInfoKey = EPTemplateUtil.buildSubnetInfoKey(ipPrefix);
39         final SubnetUtils.SubnetInfo subnetInfo = subnetInfoKey.getDelegate();
40         Assert.assertEquals(expectedLow, subnetInfo.getLowAddress());
41         Assert.assertEquals(expectedHigh, subnetInfo.getHighAddress());
42         Assert.assertEquals(expectedCount, subnetInfo.getAddressCount());
43         Assert.assertEquals(ipPrefix.getIpv4Prefix().getValue(), subnetInfo.getCidrSignature());
44     }
45 }