From 0a9c0f91cccc371c802a47ac25443f3c7837f939 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 13 Aug 2018 12:17:29 +0200 Subject: Explicitly fail when classify table for given session is missing Change-Id: Ied737af2eb650f54fbaa5413eb0a586793d34e43 Signed-off-by: Marek Gradzki --- .../vpp/classifier/write/ClassifySessionWriter.java | 15 +++++++++------ .../vpp/classifier/write/ClassifySessionWriterTest.java | 9 +++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriter.java b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriter.java index 11a48ef14..1e56afb5f 100644 --- a/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriter.java +++ b/vpp-classifier/impl/src/main/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriter.java @@ -113,8 +113,7 @@ public class ClassifySessionWriter extends VppNodeWriter "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); + final ClassifyTable classifyTable = getClassifyTable(writeContext, id, isAdd); final ClassifyAddDelSession request = getClassifyAddDelSessionRequest(isAdd, classifySession, tableIndex); // TODO(HC2VPP-9): registry of next_node translators would allow to weaken dependency between policer @@ -143,14 +142,18 @@ public class ClassifySessionWriter extends VppNodeWriter request.opaqueIndex = policer.getColorClassfier().getIntValue(); } - private ClassifyTable getClassifyTable(final WriteContext writeContext, - @Nonnull final InstanceIdentifier id, + private ClassifyTable getClassifyTable(@Nonnull final WriteContext writeContext, + @Nonnull final InstanceIdentifier id, final boolean isAdd) { + final InstanceIdentifier tableId = id.firstIdentifierOf(ClassifyTable.class); final Optional classifyTable; if (isAdd) { - classifyTable = writeContext.readAfter(id); + classifyTable = writeContext.readAfter(tableId); } else { - classifyTable = writeContext.readBefore(id); + classifyTable = writeContext.readBefore(tableId); + } + if (!classifyTable.isPresent()) { + throw new IllegalStateException("Missing classify table for session " + id); } return classifyTable.get(); } diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java index b59acdb4e..ccb02708e 100644 --- a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java +++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java @@ -181,4 +181,13 @@ public class ClassifySessionWriterTest extends WriterCustomizerTest { customizer.deleteCurrentAttributes(id, classifySession, writeContext); } + + @Test(expected = IllegalStateException.class) + public void testDeleteMisssingTable() throws WriteFailedException { + when(writeContext.readAfter(ArgumentMatchers.any())).thenReturn(Optional.absent()); + final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00"; + final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match); + final InstanceIdentifier id = getClassifySessionId(TABLE_NAME, match); + customizer.writeCurrentAttributes(id, classifySession, writeContext); + } } \ No newline at end of file -- cgit 1.2.3-korg