2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.util;
11 import javax.annotation.Nonnull;
12 import org.apache.commons.net.util.SubnetUtils;
13 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.IpPrefixEqualCommand;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
17 * Purpose: provide equal using {@link SubnetUtils.SubnetInfo#isInRange(String)} method
19 public class IpPrefixEqualCommandSubnetImpl implements IpPrefixEqualCommand {
20 private final SubnetUtils.SubnetInfo myValue;
22 public IpPrefixEqualCommandSubnetImpl(@Nonnull final IpPrefix myValue) {
23 this.myValue = new SubnetUtils(stripToCidr(myValue)).getInfo();
27 public boolean isEqualTo(final IpPrefix value) {
28 return myValue.isInRange(stripToCidr(value));
31 private String stripToCidr(final IpPrefix value) {
32 return value.getIpv4Prefix().getValue();