From a7147d16c31d9028c6b5dc557264433de0f11c91 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 23 Sep 2016 16:39:09 +0200 Subject: HONEYCOMB-145 - Utility Class Refactoring problematic mockito-all changed to mockito-core( https://github.com/mockito/mockito/issues/324) Translate Utils Splitted to multiple Trait Interfaces Ipv4Translator - Logic for translation of ipv4-based data Ipv6Translator - Logic for translation of ipv6-based data MacTranslator - Logic for translation of mac-based data AddressTranslator - Aggregation trait for Ipv4/Ipv6/Mac JvppReplyConsumer - Logic for extracting replies from jvpp calls ByteDataTranslator - any byte-based conversions Plus some existing utility classes changed to traits Change-Id: I342b625954223966802e65dca0fabf8456c89345 Signed-off-by: Jan Srnicek --- .../v3po/vppclassifier/ClassifySessionReader.java | 38 ++++++++++++---------- .../v3po/vppclassifier/ClassifySessionWriter.java | 38 +++++++++++----------- .../v3po/vppclassifier/ClassifyTableReader.java | 24 ++++++++------ .../v3po/vppclassifier/ClassifyTableWriter.java | 26 ++++++++------- .../v3po/vppclassifier/VppNodeWriter.java | 20 +++++++----- 5 files changed, 78 insertions(+), 68 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReader.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReader.java index 558e6ba41..62f69d646 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReader.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionReader.java @@ -19,7 +19,6 @@ package io.fd.honeycomb.translate.v3po.vppclassifier; 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 static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.printHexBinary; import com.google.common.base.Optional; import com.google.common.primitives.UnsignedInts; @@ -27,8 +26,9 @@ import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceDataTranslator; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -61,7 +61,8 @@ import org.slf4j.LoggerFactory; * class table verbose} command. */ public class ClassifySessionReader extends FutureJVppCustomizer - implements ListReaderCustomizer, VppNodeReader { + implements ListReaderCustomizer, + InterfaceDataTranslator, VppNodeReader, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(ClassifySessionReader.class); static final String CACHE_KEY = ClassifySessionReader.class.getName(); @@ -89,7 +90,7 @@ public class ClassifySessionReader extends FutureJVppCustomizer @Override public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final ClassifySessionBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { + throws ReadFailedException { LOG.debug("Reading attributes for classify session: {}", id); final ClassifySessionKey key = id.firstKeyOf(ClassifySession.class); @@ -98,12 +99,13 @@ public class ClassifySessionReader extends FutureJVppCustomizer final ClassifySessionDetailsReplyDump classifySessionDump = dumpClassifySessions(id, ctx); final byte[] match = DatatypeConverter.parseHexBinary(key.getMatch().getValue().replace(":", "")); final Optional classifySession = - findClassifySessionDetailsByMatch(classifySessionDump, match); + findClassifySessionDetailsByMatch(classifySessionDump, match); if (classifySession.isPresent()) { final ClassifySessionDetails detail = classifySession.get(); builder.setHitNext( - readVppNode(detail.tableId, detail.hitNextIndex, classifyTableContext, ctx.getMappingContext(), LOG).get()); + readVppNode(detail.tableId, detail.hitNextIndex, classifyTableContext, ctx.getMappingContext(), LOG) + .get()); if (detail.opaqueIndex != ~0) { // value is specified: builder.setOpaqueIndex(readOpaqueIndex(detail.tableId, detail.opaqueIndex, ctx.getMappingContext())); @@ -133,14 +135,14 @@ public class ClassifySessionReader extends FutureJVppCustomizer @Nullable private ClassifySessionDetailsReplyDump dumpClassifySessions(@Nonnull final InstanceIdentifier id, @Nonnull final ReadContext ctx) - throws ReadFailedException { + throws ReadFailedException { final ClassifyTableKey tableKey = id.firstKeyOf(ClassifyTable.class); checkArgument(tableKey != null, "could not find ClassifyTable key in {}", id); final String cacheKey = CACHE_KEY + tableKey; ClassifySessionDetailsReplyDump classifySessionDump = - (ClassifySessionDetailsReplyDump) ctx.getModificationCache().get(cacheKey); + (ClassifySessionDetailsReplyDump) ctx.getModificationCache().get(cacheKey); if (classifySessionDump != null) { LOG.debug("Classify sessions is present in cache: {}", cacheKey); return classifySessionDump; @@ -148,16 +150,16 @@ public class ClassifySessionReader extends FutureJVppCustomizer final String tableName = tableKey.getName(); checkState(classifyTableContext.containsTable(tableName, ctx.getMappingContext()), - "Reading classify sessions for table {}, but table index could not be found in the classify table context", - tableName); + "Reading classify sessions for table {}, but table index could not be found in the classify table context", + tableName); final int tableId = classifyTableContext.getTableIndex(tableName, ctx.getMappingContext()); LOG.debug("Dumping classify sessions for classify table id={}", tableId); try { final ClassifySessionDump dumpRequest = new ClassifySessionDump(); dumpRequest.tableId = tableId; - classifySessionDump = TranslateUtils - .getReplyForRead(getFutureJVpp().classifySessionDump(dumpRequest).toCompletableFuture(), id); + classifySessionDump = + getReplyForRead(getFutureJVpp().classifySessionDump(dumpRequest).toCompletableFuture(), id); if (classifySessionDump != null) { // update the cache: @@ -171,19 +173,19 @@ public class ClassifySessionReader extends FutureJVppCustomizer } private static Optional findClassifySessionDetailsByMatch( - @Nullable final ClassifySessionDetailsReplyDump classifySessionDump, @Nonnull final byte[] match) { + @Nullable final ClassifySessionDetailsReplyDump classifySessionDump, @Nonnull final byte[] match) { if (classifySessionDump != null && classifySessionDump.classifySessionDetails != null) { final List details = classifySessionDump.classifySessionDetails; final List filteredSessions = details.stream() - .filter(singleDetail -> Arrays.equals(singleDetail.match, match)).collect(Collectors.toList()); + .filter(singleDetail -> Arrays.equals(singleDetail.match, match)).collect(Collectors.toList()); if (filteredSessions.isEmpty()) { return Optional.absent(); } else if (filteredSessions.size() == 1) { return Optional.of(filteredSessions.get(0)); } else { throw new IllegalStateException(String.format( - "Found %d classify sessions witch given match. Single session expected.", - filteredSessions.size())); + "Found %d classify sessions witch given match. Single session expected.", + filteredSessions.size())); } } return Optional.absent(); @@ -198,8 +200,8 @@ public class ClassifySessionReader extends FutureJVppCustomizer final ClassifySessionDetailsReplyDump classifySessionDump = dumpClassifySessions(id, ctx); if (classifySessionDump != null && classifySessionDump.classifySessionDetails != null) { return classifySessionDump.classifySessionDetails.stream() - .map(detail -> new ClassifySessionKey(new HexString(printHexBinary(detail.match)))) - .collect(Collectors.toList()); + .map(detail -> new ClassifySessionKey(new HexString(printHexBinary(detail.match)))) + .collect(Collectors.toList()); } else { return Collections.emptyList(); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriter.java index d2029a368..e4870aecf 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifySessionWriter.java @@ -19,12 +19,12 @@ package io.fd.honeycomb.translate.v3po.vppclassifier; 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 static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte; import com.google.common.base.Optional; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; @@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory; * to VPP.
Equivalent to invoking {@code vppctl classify table} command. */ public class ClassifySessionWriter extends VppNodeWriter - implements ListWriterCustomizer { + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(ClassifySessionWriter.class); private final VppClassifierContextManager classifyTableContext; @@ -97,32 +97,32 @@ public class ClassifySessionWriter extends VppNodeWriter private void classifyAddDelSession(final boolean isAdd, @Nonnull final InstanceIdentifier id, @Nonnull final ClassifySession classifySession, @Nonnull final WriteContext writeContext) - throws VppBaseCallException, WriteFailedException { + throws VppBaseCallException, WriteFailedException { final ClassifyTableKey tableKey = id.firstKeyOf(ClassifyTable.class); checkArgument(tableKey != null, "could not find classify table key in {}", id); final String tableName = tableKey.getName(); checkState(classifyTableContext.containsTable(tableName, writeContext.getMappingContext()), - "Could not find classify table index for {} in the classify table context", tableName); + "Could not find classify table index for {} in the classify table context", tableName); final int tableIndex = classifyTableContext.getTableIndex(tableName, writeContext.getMappingContext()); final ClassifyTable classifyTable = - getClassifyTable(writeContext, id.firstIdentifierOf(ClassifyTable.class), isAdd); + getClassifyTable(writeContext, id.firstIdentifierOf(ClassifyTable.class), isAdd); final int hitNextIndex = getNodeIndex(classifySession.getHitNext(), classifyTable, classifyTableContext, - writeContext.getMappingContext(), id); + writeContext.getMappingContext(), id); final int opaqueIndex = - getOpaqueIndex(classifySession.getOpaqueIndex(), classifyTable, writeContext.getMappingContext(), id); + getOpaqueIndex(classifySession.getOpaqueIndex(), classifyTable, writeContext.getMappingContext(), id); final CompletionStage createClassifyTableReplyCompletionStage = getFutureJVpp() - .classifyAddDelSession( - getClassifyAddDelSessionRequest(isAdd, classifySession, tableIndex, hitNextIndex, opaqueIndex)); + .classifyAddDelSession( + getClassifyAddDelSessionRequest(isAdd, classifySession, tableIndex, hitNextIndex, opaqueIndex)); - TranslateUtils.getReplyForWrite(createClassifyTableReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(createClassifyTableReplyCompletionStage.toCompletableFuture(), id); } private ClassifyTable getClassifyTable(final WriteContext writeContext, - @Nonnull final InstanceIdentifier id, - final boolean isAdd) { + @Nonnull final InstanceIdentifier id, + final boolean isAdd) { final Optional classifyTable; if (isAdd) { classifyTable = writeContext.readAfter(id); @@ -132,11 +132,11 @@ public class ClassifySessionWriter extends VppNodeWriter return classifyTable.get(); } - private static ClassifyAddDelSession getClassifyAddDelSessionRequest(final boolean isAdd, - @Nonnull final ClassifySession classifySession, - final int tableIndex, - final int hitNextIndex, - final int opaqueIndex) { + private ClassifyAddDelSession getClassifyAddDelSessionRequest(final boolean isAdd, + @Nonnull final ClassifySession classifySession, + final int tableIndex, + final int hitNextIndex, + final int opaqueIndex) { ClassifyAddDelSession request = new ClassifyAddDelSession(); request.isAdd = booleanToByte(isAdd); request.tableIndex = tableIndex; @@ -152,7 +152,7 @@ public class ClassifySessionWriter extends VppNodeWriter private int getOpaqueIndex(@Nullable final OpaqueIndex opaqueIndex, final ClassifyTable classifyTable, final MappingContext ctx, final InstanceIdentifier id) - throws VppBaseCallException, WriteFailedException { + throws VppBaseCallException, WriteFailedException { if (opaqueIndex == null) { return ~0; // value not specified } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReader.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReader.java index ad238d8bb..70af10eb7 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReader.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableReader.java @@ -18,15 +18,16 @@ package io.fd.honeycomb.translate.v3po.vppclassifier; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceUtils.printHexBinary; import com.google.common.base.Optional; import com.google.common.primitives.UnsignedInts; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.v3po.interfacesstate.InterfaceDataTranslator; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.v3po.util.MacTranslator; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -55,7 +56,9 @@ import org.slf4j.LoggerFactory; * class table} command. */ public class ClassifyTableReader extends FutureJVppCustomizer - implements ListReaderCustomizer, VppNodeReader { + implements ListReaderCustomizer, VppNodeReader, + MacTranslator, + InterfaceDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(ClassifyTableReader.class); private final VppClassifierContextManager classifyTableContext; @@ -82,7 +85,7 @@ public class ClassifyTableReader extends FutureJVppCustomizer @Override public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final ClassifyTableBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { + throws ReadFailedException { LOG.debug("Reading attributes for classify table: {}", id); final ClassifyTableKey key = id.firstKeyOf(ClassifyTable.class); @@ -98,7 +101,7 @@ public class ClassifyTableReader extends FutureJVppCustomizer try { final ClassifyTableInfoReply reply = - TranslateUtils.getReplyForRead(getFutureJVpp().classifyTableInfo(request).toCompletableFuture(), id); + getReplyForRead(getFutureJVpp().classifyTableInfo(request).toCompletableFuture(), id); // mandatory values: builder.setName(tableName); @@ -108,14 +111,14 @@ public class ClassifyTableReader extends FutureJVppCustomizer // optional value read from context final Optional tableBaseNode = - classifyTableContext.getTableBaseNode(tableName, ctx.getMappingContext()); + classifyTableContext.getTableBaseNode(tableName, ctx.getMappingContext()); if (tableBaseNode.isPresent()) { builder.setClassifierNode(new VppNodeName(tableBaseNode.get())); } builder.setMissNext( - readVppNode(reply.tableId, reply.missNextIndex, classifyTableContext, ctx.getMappingContext(), LOG) - .get()); + readVppNode(reply.tableId, reply.missNextIndex, classifyTableContext, ctx.getMappingContext(), LOG) + .get()); builder.setMask(new HexString(printHexBinary(reply.mask))); builder.setActiveSessions(UnsignedInts.toLong(reply.activeSessions)); @@ -138,8 +141,9 @@ public class ClassifyTableReader extends FutureJVppCustomizer @Nonnull final ReadContext context) throws ReadFailedException { LOG.debug("Reading list of keys for classify tables: {}", id); try { - final ClassifyTableIdsReply classifyTableIdsReply = TranslateUtils - .getReplyForRead(getFutureJVpp().classifyTableIds(new ClassifyTableIds()).toCompletableFuture(), id); + final ClassifyTableIdsReply classifyTableIdsReply = + getReplyForRead(getFutureJVpp().classifyTableIds(new ClassifyTableIds()).toCompletableFuture(), + id); if (classifyTableIdsReply.ids != null) { return Arrays.stream(classifyTableIdsReply.ids).mapToObj(i -> { final String tableName = classifyTableContext.getTableName(i, context.getMappingContext()); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriter.java index 3dc3cf7d1..6f4959c23 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/ClassifyTableWriter.java @@ -19,11 +19,11 @@ package io.fd.honeycomb.translate.v3po.vppclassifier; 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 static io.fd.honeycomb.translate.v3po.util.TranslateUtils.booleanToByte; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; +import io.fd.honeycomb.translate.v3po.util.ByteDataTranslator; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; @@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory; * VPP.
Equivalent to invoking {@code vppctl classify table} command. */ public class ClassifyTableWriter extends VppNodeWriter - implements ListWriterCustomizer { + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(ClassifyTableWriter.class); private final VppClassifierContextManager classifyTableContext; @@ -58,14 +58,16 @@ public class ClassifyTableWriter extends VppNodeWriter @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final ClassifyTable dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { + throws WriteFailedException { LOG.debug("Creating classify table: iid={} dataAfter={}", id, dataAfter); try { final int newTableIndex = - classifyAddDelTable(true, id, dataAfter, ~0 /* value not present */, writeContext.getMappingContext()); + classifyAddDelTable(true, id, dataAfter, ~0 /* value not present */, + writeContext.getMappingContext()); // Add classify table name <-> vpp index mapping to the naming context: - classifyTableContext.addTable(newTableIndex, dataAfter.getName(), dataAfter.getClassifierNode(), writeContext.getMappingContext()); + classifyTableContext.addTable(newTableIndex, dataAfter.getName(), dataAfter.getClassifierNode(), + writeContext.getMappingContext()); LOG.debug("Successfully created classify table(id={]): iid={} dataAfter={}", newTableIndex, id, dataAfter); } catch (VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); @@ -86,7 +88,7 @@ public class ClassifyTableWriter extends VppNodeWriter LOG.debug("Removing classify table: iid={} dataBefore={}", id, dataBefore); final String tableName = dataBefore.getName(); checkState(classifyTableContext.containsTable(tableName, writeContext.getMappingContext()), - "Removing classify table {}, but index could not be found in the classify table context", tableName); + "Removing classify table {}, but index could not be found in the classify table context", tableName); final int tableIndex = classifyTableContext.getTableIndex(tableName, writeContext.getMappingContext()); try { @@ -102,17 +104,17 @@ public class ClassifyTableWriter extends VppNodeWriter private int classifyAddDelTable(final boolean isAdd, @Nonnull final InstanceIdentifier id, @Nonnull final ClassifyTable table, final int tableId, final MappingContext ctx) - throws VppBaseCallException, WriteFailedException { + throws VppBaseCallException, WriteFailedException { final int missNextIndex = - getNodeIndex(table.getMissNext(), table, classifyTableContext, ctx, id); + getNodeIndex(table.getMissNext(), table, classifyTableContext, ctx, id); final CompletionStage createClassifyTableReplyCompletionStage = - getFutureJVpp() - .classifyAddDelTable(getClassifyAddDelTableRequest(isAdd, tableId, table, missNextIndex, ctx)); + getFutureJVpp() + .classifyAddDelTable(getClassifyAddDelTableRequest(isAdd, tableId, table, missNextIndex, ctx)); final ClassifyAddDelTableReply reply = - TranslateUtils.getReplyForWrite(createClassifyTableReplyCompletionStage.toCompletableFuture(), id); + getReplyForWrite(createClassifyTableReplyCompletionStage.toCompletableFuture(), id); return reply.newTableIndex; } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppNodeWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppNodeWriter.java index a4667bf4d..abc49cccb 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppNodeWriter.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/translate/v3po/vppclassifier/VppNodeWriter.java @@ -20,8 +20,8 @@ import static com.google.common.base.Preconditions.checkArgument; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.v3po.util.JvppReplyConsumer; import io.fd.honeycomb.translate.v3po.util.ReadTimeoutException; -import io.fd.honeycomb.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -33,7 +33,7 @@ import org.openvpp.jvpp.core.dto.GetNextIndex; import org.openvpp.jvpp.core.dto.GetNextIndexReply; import org.openvpp.jvpp.core.future.FutureJVppCore; -abstract class VppNodeWriter extends FutureJVppCustomizer { +abstract class VppNodeWriter extends FutureJVppCustomizer implements JvppReplyConsumer { protected VppNodeWriter(@Nonnull final FutureJVppCore futureJvpp) { super(futureJvpp); @@ -42,35 +42,37 @@ abstract class VppNodeWriter extends FutureJVppCustomizer { protected int getNodeIndex(@Nonnull final VppNode node, @Nonnull final ClassifyTable classifyTable, @Nonnull final VppClassifierContextManager vppClassifierContextManager, @Nonnull final MappingContext ctx, @Nonnull final InstanceIdentifier id) - throws VppBaseCallException, WriteFailedException { + throws VppBaseCallException, WriteFailedException { if (node.getPacketHandlingAction() != null) { return node.getPacketHandlingAction().getIntValue(); } else { - return nodeNameToIndex(classifyTable, node.getVppNodeName().getValue(), vppClassifierContextManager, ctx, id); + return nodeNameToIndex(classifyTable, node.getVppNodeName().getValue(), vppClassifierContextManager, ctx, + id); } } private int nodeNameToIndex(@Nonnull final ClassifyTable classifyTable, @Nonnull final String nextNodeName, @Nonnull final VppClassifierContextManager vppClassifierContextManager, @Nonnull final MappingContext ctx, @Nonnull final InstanceIdentifier id) - throws VppBaseCallException, WriteFailedException { - checkArgument(classifyTable != null && classifyTable.getClassifierNode() != null, "to use relative node names, table classifier node needs to be provided"); + throws VppBaseCallException, WriteFailedException { + checkArgument(classifyTable != null && classifyTable.getClassifierNode() != null, + "to use relative node names, table classifier node needs to be provided"); final GetNextIndex request = new GetNextIndex(); request.nodeName = classifyTable.getClassifierNode().getValue().getBytes(); request.nextName = nextNodeName.getBytes(); final CompletionStage getNextIndexCompletionStage = - getFutureJVpp().getNextIndex(request); + getFutureJVpp().getNextIndex(request); final GetNextIndexReply reply; try { - reply = TranslateUtils.getReplyForRead(getNextIndexCompletionStage.toCompletableFuture(), id); + reply = getReplyForRead(getNextIndexCompletionStage.toCompletableFuture(), id); // vpp does not provide relative node index to node name conversion (https://jira.fd.io/browse/VPP-219) // as a workaround we need to add mapping to vpp-classfier-context vppClassifierContextManager.addNodeName(classifyTable.getName(), reply.nextIndex, nextNodeName, ctx); } catch (ReadTimeoutException e) { throw new WriteFailedException(id, String.format("Failed to get node index for %s relative to %s", - nextNodeName, classifyTable.getClassifierNode()), e); + nextNodeName, classifyTable.getClassifierNode()), e); } return reply.nextIndex; } -- cgit 1.2.3-korg