Add implementation for flat L3 overlay
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / util / IpAddressUtil.java
1 /*
2  * Copyright (c) 2017 Cisco Systems. 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.renderer.vpp.lisp.util;
10
11 import org.apache.commons.lang3.tuple.ImmutablePair;
12 import org.apache.commons.lang3.tuple.Pair;
13 import org.apache.commons.net.util.SubnetUtils;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
16
17 /**
18  * Created by Shakib Ahmed on 5/3/17.
19  */
20 public class IpAddressUtil {
21
22     public static Pair<Ipv4Address, Ipv4Address> getStartAndEndIp(Ipv4Prefix ipv4Prefix) {
23         SubnetUtils subnetUtils = new SubnetUtils(ipv4Prefix.getValue());
24         SubnetUtils.SubnetInfo prefixSubnetInfo = subnetUtils.getInfo();
25         Ipv4Address lowIp = new Ipv4Address(prefixSubnetInfo.getLowAddress());
26         Ipv4Address highIp = new Ipv4Address(prefixSubnetInfo.getHighAddress());
27         return new ImmutablePair<>(lowIp, highIp);
28     }
29 }