diff options
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java | 9 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java | 17 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java (renamed from v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java) | 50 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java | 2 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java | 34 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java | 8 |
6 files changed, 61 insertions, 59 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java index 574a42eb5..8ab5b6b62 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4AddressCustomizer.java @@ -45,7 +45,8 @@ import org.slf4j.LoggerFactory; /** * Customizer for writing {@link Address} */ -public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Address, AddressKey> { +public class Ipv4AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer<Address, AddressKey>, Ipv4Writer { private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); private final NamingContext interfaceContext; @@ -131,8 +132,8 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListW final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); - final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); @@ -148,7 +149,7 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer implements ListW LOG.debug("Setting Subnet(prefix-length) for interface: {}(id={}). Subnet: {}, address: {}", interfaceName, interfaceIndex, subnet, address); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnet.getPrefixLength().byteValue()); LOG.debug("Subnet(prefix-length) set successfully for interface: {}(id={}). Subnet: {}, address: {}", diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java index 72d8277fc..ab25970e7 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java @@ -20,14 +20,16 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.v3po.util.AddressTranslator; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.NamingContext; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; @@ -45,7 +47,8 @@ import org.slf4j.LoggerFactory; * Customizer for writing {@link Neighbor} for {@link Ipv4}. */ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer<Neighbor, NeighborKey> { + implements ListWriterCustomizer<Neighbor, NeighborKey>, ByteDataTranslator, AddressTranslator, + JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(Ipv4NeighbourCustomizer.class); @@ -119,15 +122,15 @@ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer IpNeighborAddDel request = new IpNeighborAddDel(); - request.isAdd = TranslateUtils.booleanToByte(add); + request.isAdd = booleanToByte(add); request.isIpv6 = 0; request.isStatic = 1; - request.dstAddress = TranslateUtils.ipv4AddressNoZoneToArray(data.getIp()); - request.macAddress = TranslateUtils.parseMac(data.getLinkLayerAddress().getValue()); + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); request.swIfIndex = parentInterfaceIndex; //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid //request.vrfId - TranslateUtils.getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); + getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java index 412030200..a950d45de 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4WriteUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv4Writer.java @@ -19,7 +19,9 @@ package io.fd.honeycomb.translate.v3po.interfaces.ip; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +import io.fd.honeycomb.translate.v3po.util.Ipv4Translator; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.WriteTimeoutException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnegative; @@ -34,37 +36,33 @@ import org.openvpp.jvpp.core.future.FutureJVppCore; /** * Utility class providing Ipv4 CUD support. */ -// TODO HONEYCOMB-175 replace with interface with default methods or abstract class -public final class Ipv4WriteUtils { +public interface Ipv4Writer extends ByteDataTranslator, Ipv4Translator, JvppReplyConsumer { - private static final int DOTTED_QUAD_MASK_LENGTH = 4; - private static final int IPV4_ADDRESS_PART_BITS_COUNT = 8; - private static final int NETMASK_PART_LIMIT = 256; // 2 power to 8 + int DOTTED_QUAD_MASK_LENGTH = 4; + int IPV4_ADDRESS_PART_BITS_COUNT = 8; + int NETMASK_PART_LIMIT = 256; // 2 power to 8 - private Ipv4WriteUtils() { - throw new UnsupportedOperationException("This utility class cannot be instantiated"); - } - - static void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, final InstanceIdentifier<?> id, - @Nonnegative final int ifaceId, - @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) - throws VppBaseCallException, WriteTimeoutException { + default void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, + final InstanceIdentifier<?> id, + @Nonnegative final int ifaceId, + @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) + throws VppBaseCallException, WriteTimeoutException { checkArgument(prefixLength > 0, "Invalid prefix length"); checkNotNull(address, "address should not be null"); - final byte[] addressBytes = TranslateUtils.ipv4AddressNoZoneToArray(address); + final byte[] addressBytes = ipv4AddressNoZoneToArray(address); final CompletionStage<SwInterfaceAddDelAddressReply> swInterfaceAddDelAddressReplyCompletionStage = - futureJVppCore.swInterfaceAddDelAddress( - getSwInterfaceAddDelAddressRequest(ifaceId, TranslateUtils.booleanToByte(add) /* isAdd */, - (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); + futureJVppCore.swInterfaceAddDelAddress( + getSwInterfaceAddDelAddressRequest(ifaceId, booleanToByte(add) /* isAdd */, + (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); - TranslateUtils.getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); } - static SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, - final byte ipv6, final byte deleteAll, - final byte length, final byte[] addr) { + default SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, + final byte ipv6, final byte deleteAll, + final byte length, final byte[] addr) { final SwInterfaceAddDelAddress swInterfaceAddDelAddress = new SwInterfaceAddDelAddress(); swInterfaceAddDelAddress.swIfIndex = swIfc; swInterfaceAddDelAddress.isAdd = isAdd; @@ -83,11 +81,11 @@ public final class Ipv4WriteUtils { * @param mask the subnet mask in dot notation 255.255.255.255 * @return the prefix length as number of bits */ - public static byte getSubnetMaskLength(final String mask) { + default byte getSubnetMaskLength(final String mask) { String[] maskParts = mask.split("\\."); checkArgument(maskParts.length == DOTTED_QUAD_MASK_LENGTH, - "Network mask %s is not in Quad Dotted Decimal notation!", mask); + "Network mask %s is not in Quad Dotted Decimal notation!", mask); long maskAsNumber = 0; for (int i = 0; i < DOTTED_QUAD_MASK_LENGTH; i++) { @@ -100,11 +98,11 @@ public final class Ipv4WriteUtils { String bits = Long.toBinaryString(maskAsNumber); checkArgument(bits.length() == IPV4_ADDRESS_PART_BITS_COUNT * DOTTED_QUAD_MASK_LENGTH, - "Incorrect network mask %s", mask); + "Incorrect network mask %s", mask); final int leadingOnes = bits.indexOf('0'); checkArgument(leadingOnes != -1, "Broadcast address %s is not allowed!", mask); checkArgument(bits.substring(leadingOnes).indexOf('1') == -1, - "Non-contiguous network mask %s is not allowed!", mask); + "Non-contiguous network mask %s is not allowed!", mask); return (byte) leadingOnes; } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java index 192906854..c04d14604 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/Ipv6Customizer.java @@ -16,9 +16,9 @@ package io.fd.honeycomb.translate.v3po.interfaces.ip; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java index e0fa46335..3fbb493af 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java @@ -21,9 +21,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.translate.v3po.util.NamingContext; +import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.honeycomb.translate.v3po.util.SubInterfaceUtils; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; @@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory; * Write customizer for sub-interface {@link Address} */ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer<Address, AddressKey> { + implements ListWriterCustomizer<Address, AddressKey>, Ipv4Writer { private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); private final NamingContext interfaceContext; @@ -58,7 +58,7 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer @Override public void writeCurrentAttributes(InstanceIdentifier<Address> id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { setAddress(true, id, dataAfter, writeContext); } @@ -66,12 +66,12 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer public void updateCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, Address dataAfter, WriteContext writeContext) throws WriteFailedException { throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Operation not supported")); + new UnsupportedOperationException("Operation not supported")); } @Override public void deleteCurrentAttributes(InstanceIdentifier<Address> id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { setAddress(false, id, dataBefore, writeContext); } @@ -98,26 +98,26 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); return SubInterfaceUtils - .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); + .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); } private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier<Address> id, @Nonnull final String subInterfaceName, final int subInterfaceIndex, @Nonnull final Address address, @Nonnull final Netmask subnet) - throws WriteFailedException { + throws WriteFailedException { try { LOG.debug("Setting Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); final DottedQuad netmask = subnet.getNetmask(); checkNotNull(netmask, "netmask value should not be null"); - final byte subnetLength = Ipv4WriteUtils.getSubnetMaskLength(netmask.getValue()); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } } @@ -125,19 +125,19 @@ public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier<Address> id, @Nonnull final String subInterfaceName, final int subInterfaceIndex, @Nonnull final Address address, @Nonnull final PrefixLength subnet) - throws WriteFailedException { + throws WriteFailedException { try { LOG.debug("Setting Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); - Ipv4WriteUtils.addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), - subnet.getPrefixLength().byteValue()); + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), + subnet.getPrefixLength().byteValue()); LOG.debug("Subnet(prefix-length) set successfully for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); } catch (VppBaseCallException e) { LOG.warn("Failed to set Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); + subInterfaceName, subInterfaceIndex, subnet, address); throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass(), e); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java index 361113858..a314eaf14 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/interfaces/ip/subnet/validation/SubnetValidator.java @@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Function; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4WriteUtils; +import io.fd.honeycomb.translate.v3po.interfaces.ip.Ipv4Writer; import java.util.List; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; @@ -32,7 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061 /** * Validator for detecting if there is an attempt to assign multiple addresses from same subnet */ -public class SubnetValidator { +public class SubnetValidator implements Ipv4Writer { /** * Checks whether data provided for writing are not in collision with already existing data @@ -60,7 +60,7 @@ public class SubnetValidator { .forConflictingData(conflictingPrefix, prefixLengthRegister.get(conflictingPrefix)); } - private static Function<Address, Short> toPrefixLength() { + private Function<Address, Short> toPrefixLength() { return (final Address address) -> { final Subnet subnet = address.getSubnet(); @@ -69,7 +69,7 @@ public class SubnetValidator { } if (address.getSubnet() instanceof Netmask) { - return (short) Ipv4WriteUtils.getSubnetMaskLength( + return (short) getSubnetMaskLength( checkNotNull(((Netmask) subnet).getNetmask(), "No netmask defined for %s", subnet) .getValue()); } |