From dbd9b296ccaa0ea6782c5a419d55045ac469af4a Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 11 Jul 2016 09:26:38 +0200 Subject: [PATCH] Bug 5540 - ConvertorManager DataContainer source, one Convertor interface - Changed source type for Convertor interface and ConvertorManager to must extend YANG DataContainer - Started using getImplementedInterface() to get source type Change-Id: Ic229c278516074f42218b45a5040d3601b386bd7 Signed-off-by: Tomas Slusny --- .../impl/services/SalFlowServiceImplTest.java | 44 +++-- .../FlowDirectStatisticsServiceTest.java | 26 +-- .../GroupDirectStatisticsServiceTest.java | 21 ++- .../MeterDirectStatisticsServiceTest.java | 21 ++- .../core/sal/convertor/ConvertorExecutor.java | 12 +- .../core/sal/convertor/ConvertorManager.java | 119 ++++++------- .../sal/convertor/ConvertorRegistrator.java | 9 - .../md/core/sal/convertor/GroupConvertor.java | 9 +- .../GroupDescStatsResponseConvertor.java | 8 +- .../GroupStatsResponseConvertor.java | 12 +- .../MeterConfigStatsResponseConvertor.java | 8 +- .../md/core/sal/convertor/MeterConvertor.java | 7 +- .../MeterStatsResponseConvertor.java | 9 +- .../sal/convertor/PacketOutConvertor.java | 7 +- .../md/core/sal/convertor/PortConvertor.java | 7 +- .../sal/convertor/TableFeaturesConvertor.java | 9 +- .../TableFeaturesResponseConvertor.java | 8 +- .../sal/convertor/action/ActionConvertor.java | 7 +- .../action/ActionResponseConvertor.java | 7 +- .../sal/convertor/common/ConvertReactor.java | 10 +- .../core/sal/convertor/common/Convertor.java | 10 +- .../common/ParametrizedConvertor.java | 36 ---- .../sal/convertor/flow/FlowConvertor.java | 7 +- .../FlowInstructionResponseConvertor.java | 7 +- .../flow/FlowStatsResponseConvertor.java | 7 +- .../flow/flowflag/FlowFlagConvertor.java | 15 +- .../flow/flowflag/FlowFlagReactor.java | 2 +- .../FlowFlagReactorMappingFactory.java | 2 +- .../sal/convertor/match/MatchConvertor.java | 13 +- .../sal/convertor/match/MatchReactor.java | 2 +- .../match/MatchReactorMappingFactory.java | 2 +- .../match/MatchResponseConvertor.java | 7 +- .../match/MatchV10ResponseConvertor.java | 7 +- .../sal/convertor/ConvertorManagerTest.java | 161 ------------------ .../sal/convertor/GroupConvertorTest.java | 10 +- .../convertor/TableFeaturesConvertorTest.java | 13 +- .../sal/convertor/flow/FlowConvertorTest.java | 2 +- 37 files changed, 266 insertions(+), 397 deletions(-) delete mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java delete mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java index 6600c9e8a5..070cf5e32b 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java @@ -45,12 +45,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -145,7 +149,11 @@ public class SalFlowServiceImplTest extends TestCase { @Test public void testAddFlowFailCallback() throws Exception { - AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class); + AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder() + .setMatch(match) + .setTableId((short)1) + .build(); + Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) .when(requestContext).getFuture(); @@ -160,7 +168,10 @@ public class SalFlowServiceImplTest extends TestCase { @Test public void testRemoveFlowFailCallback() throws Exception { - RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class); + RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder() + .setMatch(match) + .build(); + Mockito.doReturn(Futures.>immediateFailedFuture(new Exception("ut-failed-response"))) .when(requestContext).getFuture(); @@ -178,7 +189,11 @@ public class SalFlowServiceImplTest extends TestCase { } private void addFlow(final ItemLifecycleListener itemLifecycleListener) throws ExecutionException, InterruptedException { - AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class); + AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder() + .setMatch(match) + .setTableId((short)1) + .build(); + salFlowService.setItemLifecycleListener(itemLifecycleListener); mockingFlowRegistryLookup(); @@ -199,7 +214,10 @@ public class SalFlowServiceImplTest extends TestCase { } private void removeFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception { - RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class); + RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder() + .setMatch(match) + .setTableId((short)1) + .build(); if (itemLifecycleListener != null) { salFlowService.setItemLifecycleListener(itemLifecycleListener); @@ -227,14 +245,22 @@ public class SalFlowServiceImplTest extends TestCase { private void updateFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception { UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class); - UpdatedFlow mockedUpdateFlow = createFlowMock(UpdatedFlow.class); + UpdatedFlow mockedUpdateFlow = new UpdatedFlowBuilder() + .setMatch(match) + .setTableId((short)1) + .build(); + when(mockedUpdateFlowInput.getUpdatedFlow()).thenReturn(mockedUpdateFlow); FlowRef mockedFlowRef = mock(FlowRef.class); Mockito.doReturn(TABLE_II.child(Flow.class, new FlowKey(new FlowId(DUMMY_FLOW_ID)))).when(mockedFlowRef).getValue(); when(mockedUpdateFlowInput.getFlowRef()).thenReturn(mockedFlowRef); - OriginalFlow mockedOriginalFlow = createFlowMock(OriginalFlow.class); + OriginalFlow mockedOriginalFlow = new OriginalFlowBuilder() + .setMatch(match) + .setTableId((short)1) + .build(); + when(mockedUpdateFlowInput.getOriginalFlow()).thenReturn(mockedOriginalFlow); if (itemLifecycleListener != null) { @@ -266,10 +292,4 @@ public class SalFlowServiceImplTest extends TestCase { assertNotNull(addFlowOutputRpcResult); assertTrue(addFlowOutputRpcResult.isSuccessful()); } - - private T createFlowMock(Class flowClazz) { - T mockedFlow = mock(flowClazz); - when(mockedFlow.getMatch()).thenReturn(match); - return mockedFlow; - } } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsServiceTest.java index b2f39f30e7..0d234bb31e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/FlowDirectStatisticsServiceTest.java @@ -33,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow; @@ -66,22 +67,25 @@ public class FlowDirectStatisticsServiceTest extends AbstractDirectStatisticsSer final MultipartReply reply = mock(MultipartReply.class); final MultipartReplyFlowCase flowCase = mock(MultipartReplyFlowCase.class); final MultipartReplyFlow flow = mock(MultipartReplyFlow.class); - final FlowStats flowStat = mock(FlowStats.class); - final List flowStats = Arrays.asList(flowStat); - final List input = Arrays.asList(reply); + final FlowStats flowStat = new FlowStatsBuilder() + .setDurationSec(1L) + .setDurationNsec(1L) + .setTableId(TABLE_NO) + .setByteCount(BigInteger.ONE) + .setPacketCount(BigInteger.ONE) + .setFlags(mock(FlowModFlags.class)) + .setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder() + .setMatchEntry(Collections.emptyList()) + .build()) + .build(); + + final List flowStats = Collections.singletonList(flowStat); + final List input = Collections.singletonList(reply); when(flow.getFlowStats()).thenReturn(flowStats); when(flowCase.getMultipartReplyFlow()).thenReturn(flow); when(reply.getMultipartReplyBody()).thenReturn(flowCase); - when(flowStat.getTableId()).thenReturn(TABLE_NO); - when(flowStat.getByteCount()).thenReturn(BigInteger.ONE); - when(flowStat.getPacketCount()).thenReturn(BigInteger.ONE); - when(flowStat.getFlags()).thenReturn(mock(FlowModFlags.class)); - when(flowStat.getMatch()).thenReturn(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder() - .setMatchEntry(Collections.emptyList()) - .build()); - final GetFlowStatisticsOutput output = service.buildReply(input, true); assertTrue(output.getFlowAndStatisticsMapList().size() > 0); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/GroupDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/GroupDirectStatisticsServiceTest.java index 87811f1b92..6b8af6873b 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/GroupDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/GroupDirectStatisticsServiceTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.when; import java.math.BigInteger; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetGroupStatisticsInput; @@ -27,6 +28,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.MultipartReplyGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroup; @@ -57,18 +59,23 @@ public class GroupDirectStatisticsServiceTest extends AbstractDirectStatisticsSe final MultipartReply reply = mock(MultipartReply.class); final MultipartReplyGroupCase groupCase = mock(MultipartReplyGroupCase.class); final MultipartReplyGroup group = mock(MultipartReplyGroup.class); - final GroupStats groupStat = mock(GroupStats.class); - final List groupStats = Arrays.asList(groupStat); - final List input = Arrays.asList(reply); + final GroupStats groupStat = new GroupStatsBuilder() + .setGroupId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId(GROUP_NO)) + .setByteCount(BigInteger.ONE) + .setPacketCount(BigInteger.ONE) + .setBucketStats(Collections.emptyList()) + .setDurationSec(1L) + .setDurationNsec(1L) + .setRefCount(0L) + .build(); + + final List groupStats = Collections.singletonList(groupStat); + final List input = Collections.singletonList(reply); when(group.getGroupStats()).thenReturn(groupStats); when(groupCase.getMultipartReplyGroup()).thenReturn(group); when(reply.getMultipartReplyBody()).thenReturn(groupCase); - when(groupStat.getGroupId()).thenReturn(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId(GROUP_NO)); - when(groupStat.getByteCount()).thenReturn(BigInteger.ONE); - when(groupStat.getPacketCount()).thenReturn(BigInteger.ONE); - final GetGroupStatisticsOutput output = service.buildReply(input, true); assertTrue(output.getGroupStats().size() > 0); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/MeterDirectStatisticsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/MeterDirectStatisticsServiceTest.java index b923cff068..c3da98efdc 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/MeterDirectStatisticsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/MeterDirectStatisticsServiceTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.when; import java.math.BigInteger; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput; @@ -27,6 +28,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeter; @@ -57,18 +59,23 @@ public class MeterDirectStatisticsServiceTest extends AbstractDirectStatisticsSe final MultipartReply reply = mock(MultipartReply.class); final MultipartReplyMeterCase MeterCase = mock(MultipartReplyMeterCase.class); final MultipartReplyMeter meter = mock(MultipartReplyMeter.class); - final MeterStats meterStat = mock(MeterStats.class); - final List meterStats = Arrays.asList(meterStat); - final List input = Arrays.asList(reply); + final MeterStats meterStat = new MeterStatsBuilder() + .setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId(METER_NO)) + .setByteInCount(BigInteger.ONE) + .setPacketInCount(BigInteger.ONE) + .setDurationSec(1L) + .setDurationNsec(1L) + .setFlowCount(0L) + .setMeterBandStats(Collections.emptyList()) + .build(); + + final List meterStats = Collections.singletonList(meterStat); + final List input = Collections.singletonList(reply); when(meter.getMeterStats()).thenReturn(meterStats); when(MeterCase.getMultipartReplyMeter()).thenReturn(meter); when(reply.getMultipartReplyBody()).thenReturn(MeterCase); - when(meterStat.getMeterId()).thenReturn(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId(METER_NO)); - when(meterStat.getByteInCount()).thenReturn(BigInteger.ONE); - when(meterStat.getPacketInCount()).thenReturn(BigInteger.ONE); - final GetMeterStatisticsOutput output = service.buildReply(input, true); assertTrue(output.getMeterStats().size() > 0); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorExecutor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorExecutor.java index 191ad4bb29..1e28a5498d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorExecutor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorExecutor.java @@ -8,8 +8,10 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +import java.util.Collection; import java.util.Optional; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; +import org.opendaylight.yangtools.yang.binding.DataContainer; public interface ConvertorExecutor { /** @@ -17,20 +19,22 @@ public interface ConvertorExecutor { * * @param the source type * @param the result type + * @param the data type * @param source the source + * @param data convertor data * @return the result (can be empty, if no convertor was found) */ - Optional convert(final FROM source); + Optional convert(final FROM source, final DATA data); /** - * Lookup and use convertor by specified type, then converts source and returns converted result + * Lookup and use convertor by specified type, then converts source collection and returns converted result * * @param the source type * @param the result type * @param the data type - * @param source the source + * @param source the source collection * @param data convertor data * @return the result (can be empty, if no convertor was found) */ - Optional convert(final FROM source, final DATA data); + Optional convert(final Collection source, final DATA data); } \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java index b9981b46fb..8669e5df21 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java @@ -15,23 +15,24 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nullable; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowInstructionResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.FlowStatsResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchV10ResponseConvertor; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Manages various convertors and allows to use them all in one generic way */ -public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor { +public class ConvertorManager implements ConvertorExecutor, ConvertorRegistrator { private static final Logger LOG = LoggerFactory.getLogger(ConvertorManager.class); private static ConvertorManager INSTANCE; @@ -59,13 +60,11 @@ public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor } // Actual convertor keys - private List> convertorKeys = new ArrayList<>(); - private List> parametrizedConvertorKeys = new ArrayList<>(); + private List> convertorKeys = new ArrayList<>(); // Cache, that holds all registered convertors, but they can have multiple keys, // based on instanceof checks in the convert method - private Map, Convertor> convertors = new ConcurrentHashMap<>(); - private Map, ParametrizedConvertor> parametrizedConvertors = new ConcurrentHashMap<>(); + private Map, Convertor> convertors = new ConcurrentHashMap<>(); private ConvertorManager() { // Hiding implicit constructor @@ -81,8 +80,9 @@ public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor } @Override + @SuppressWarnings("unchecked") public Convertor registerConvertor(final Convertor convertor) { - final Class type = convertor.getType(); + final Class type = convertor.getType(); final Convertor result = convertors.get(type); if (Objects.isNull(result)) { @@ -96,37 +96,31 @@ public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor return result; } - @Override - public ParametrizedConvertor registerConvertor(final ParametrizedConvertor convertor) { - final Class type = convertor.getType(); - final ParametrizedConvertor result = parametrizedConvertors.get(type); - - if (Objects.isNull(result)) { - parametrizedConvertorKeys.add(type); - parametrizedConvertors.put(type, convertor); - LOG.debug("{} is now converted by {}", type, convertor); - } else { - LOG.warn("Convertor for type {} is already registered", type); - } - - return result; + public Optional convert(final FROM source) { + return convert(source, null); } @Override @SuppressWarnings("unchecked") - public Optional convert(final FROM source) { - final Optional> optionalType = extractType(source); + public Optional convert(final FROM source, @Nullable final DATA data) { + Optional result = Optional.empty(); - if (!optionalType.isPresent()) { - LOG.trace("Cannot convert {}", source); - return Optional.empty(); + if (Objects.isNull(source)) { + LOG.trace("Cannot extract type from null source"); + return result; + } + + final Class type = source.getImplementedInterface(); + + if (Objects.isNull(type)) { + LOG.warn("Cannot extract type from source, because getImplementedInterface() returns null"); + return result; } - final Class type = optionalType.get(); Convertor convertor = convertors.get(type); if (Objects.isNull(convertor)) { - for (final Class key : convertorKeys) { + for (final Class key : convertorKeys) { if (key.isAssignableFrom(type)) { convertor = convertors.get(key); convertors.put(type, convertor); @@ -137,31 +131,49 @@ public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor if (Objects.isNull(convertor)) { LOG.warn("Convertor for {} not found", type); - return Optional.empty(); + return result; } } - return Optional.of((TO) convertor.convert(source)); + result = Optional.of((TO) convertor.convert(source, data)); + return result; + } + + public Optional convert(final Collection source) { + return convert(source, null); } @Override @SuppressWarnings("unchecked") - public Optional convert(final FROM source, final DATA data) { - final Optional> optionalType = extractType(source); + public Optional convert(final Collection source, @Nullable final DATA data) { + Optional result = Optional.empty(); - if (!optionalType.isPresent()) { - LOG.trace("Cannot convert {}", source); - return Optional.empty(); + if (Objects.isNull(source)) { + LOG.trace("Cannot extract type from null source"); + return result; } - final Class type = optionalType.get(); - ParametrizedConvertor convertor = parametrizedConvertors.get(type); + final Optional first = source.stream().findFirst(); + + if (!first.isPresent()) { + LOG.trace("Cannot extract type from empty collection"); + return result; + } + + final Class type = first.get().getImplementedInterface(); + + if (Objects.isNull(type)) { + LOG.warn("Cannot extract type from source, because getImplementedInterface() returns null"); + return result; + } + + Convertor convertor = convertors.get(type); if (Objects.isNull(convertor)) { - for (final Class key : parametrizedConvertorKeys) { + for (final Class key : convertorKeys) { if (key.isAssignableFrom(type)) { - convertor = parametrizedConvertors.get(key); - parametrizedConvertors.put(type, convertor); + convertor = convertors.get(key); + convertors.put(type, convertor); LOG.debug("{} is now converted by {}", type, convertor); break; } @@ -169,32 +181,11 @@ public class ConvertorManager implements ConvertorRegistrator, ConvertorExecutor if (Objects.isNull(convertor)) { LOG.warn("Convertor for {} not found", type); - return Optional.empty(); + return result; } } - return Optional.of((TO) convertor.convert(source, data)); - } - - private Optional> extractType(FROM source) { - if (Objects.isNull(source)) { - LOG.trace("Cannot extract type from source, because it is null"); - return Optional.empty(); - } - - Class type = source.getClass(); - - if (source instanceof Collection) { - final Optional first = ((Collection) source).stream().findFirst(); - - if (!first.isPresent()) { - LOG.trace("Cannot extract type {}, because it is empty collection", type); - return Optional.empty(); - } - - type = first.get().getClass(); - } - - return Optional.of(type); + result = Optional.of((TO) convertor.convert(source, data)); + return result; } } \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorRegistrator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorRegistrator.java index bc889dc11f..9fbd844ab6 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorRegistrator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorRegistrator.java @@ -9,7 +9,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; public interface ConvertorRegistrator { /** @@ -19,12 +18,4 @@ public interface ConvertorRegistrator { * @return previous convertor if already registered or null */ Convertor registerConvertor(final Convertor convertor); - - /** - * Register convertor. - * - * @param convertor the convertor - * @return previous convertor if already registered or null - */ - ParametrizedConvertor registerConvertor(final ParametrizedConvertor convertor); } \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java index 6250fa2ae2..7a17a790a6 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -16,7 +16,7 @@ import java.util.List; import java.util.Optional; import org.opendaylight.openflowjava.protocol.api.util.BinContent; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; @@ -33,6 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,7 @@ import org.slf4j.LoggerFactory; * } * */ -public class GroupConvertor implements ParametrizedConvertor { +public class GroupConvertor implements Convertor { /** * Create default empty group mod input builder * Use this method, if result from convertor is empty. @@ -132,7 +133,7 @@ public class GroupConvertor implements ParametrizedConvertor getType() { + public Class getType() { return Group.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupDescStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupDescStatsResponseConvertor.java index 2556e8722e..05cd849e6c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupDescStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupDescStatsResponseConvertor.java @@ -13,8 +13,9 @@ import java.util.Collections; import java.util.List; import java.util.Optional; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; @@ -30,6 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStatsKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts GroupDesc message from library to MD SAL defined GroupDescStats @@ -42,7 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * } * */ -public class GroupDescStatsResponseConvertor implements ParametrizedConvertor, List, VersionConvertorData> { +public class GroupDescStatsResponseConvertor implements Convertor, List, VersionConvertorData> { private org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets toSALBucketsDesc(List bucketDescStats, short version) { final ActionResponseConvertorData data = new ActionResponseConvertorData(version); @@ -94,7 +96,7 @@ public class GroupDescStatsResponseConvertor implements ParametrizedConvertor
  • getType() { + public Class getType() { return GroupDesc.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java index 7326adbcf4..8bf6524bb7 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved. + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,11 +9,11 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.Buckets; @@ -26,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts group related statistics messages coming from switch to MD-SAL messages. @@ -39,7 +40,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GroupStatsResponseConvertor implements Convertor< List, - List> { + List, + VersionConvertorData> { private Buckets toSALBuckets(List bucketStats) { BucketsBuilder salBuckets = new BucketsBuilder(); @@ -63,12 +65,12 @@ public class GroupStatsResponseConvertor implements Convertor< } @Override - public Class getType() { + public Class getType() { return org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats.class; } @Override - public List convert(List source) { + public List convert(List source, VersionConvertorData data) { List convertedSALGroups = new ArrayList<>(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConfigStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConfigStatsResponseConvertor.java index 9fbb8cd9c4..6108b4f43b 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConfigStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConfigStatsResponseConvertor.java @@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.util.ArrayList; import java.util.List; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags; @@ -34,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts list of OF library config meter stats to MD-SAL config meter stats. @@ -46,15 +48,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * } * */ -public class MeterConfigStatsResponseConvertor implements Convertor, List> { +public class MeterConfigStatsResponseConvertor implements Convertor, List, VersionConvertorData> { @Override - public Class getType() { + public Class getType() { return MeterConfig.class; } @Override - public List convert(List source) { + public List convert(List source, VersionConvertorData data) { List listMeterConfigStats = new ArrayList<>(); for (MeterConfig meterConfig : source) { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConvertor.java index 07e8dd46ba..ff50aae6d0 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterConvertor.java @@ -10,7 +10,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.util.ArrayList; import java.util.List; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter; @@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,7 @@ import org.slf4j.LoggerFactory; * } * */ -public class MeterConvertor implements ParametrizedConvertor { +public class MeterConvertor implements Convertor { private static final Logger LOG = LoggerFactory.getLogger(MeterConvertor.class); /** @@ -141,7 +142,7 @@ public class MeterConvertor implements ParametrizedConvertor getType() { + public Class getType() { return Meter.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterStatsResponseConvertor.java index b9fd336692..bc1e024447 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/MeterStatsResponseConvertor.java @@ -13,6 +13,7 @@ import java.util.List; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder; @@ -24,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts list of OF library meter stats to MD-SAL meter stats. @@ -39,15 +41,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class MeterStatsResponseConvertor implements Convertor< List, - List> { + List, + VersionConvertorData> { @Override - public Class getType() { + public Class getType() { return org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats.class; } @Override - public List convert(List source) { + public List convert(List source, VersionConvertorData data) { List convertedSALMeters = new ArrayList<>(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply. diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java index 3db52261d8..706c0f9f4a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java @@ -17,7 +17,7 @@ import org.opendaylight.controller.sal.common.util.Arguments; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; @@ -30,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.slf4j.Logger; @@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory; * } * */ -public class PacketOutConvertor implements ParametrizedConvertor { +public class PacketOutConvertor implements Convertor { private static final Logger LOG = LoggerFactory.getLogger(PacketOutConvertor.class); /** @@ -75,7 +76,7 @@ public class PacketOutConvertor implements ParametrizedConvertor getType() { + public Class getType() { return TransmitPacketInput.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertor.java index e644a090fb..2e49cdedae 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertor.java @@ -11,7 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import com.google.common.annotations.VisibleForTesting; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port; @@ -25,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts port mod, port status and port description MD-SAL messages to OF library data @@ -37,7 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * } * */ -public class PortConvertor implements ParametrizedConvertor { +public class PortConvertor implements Convertor { /** * Create default empty port mod input @@ -144,7 +145,7 @@ public class PortConvertor implements ParametrizedConvertor getType() { + public Class getType() { return Port.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java index d5699ed0ad..a77cf1f05a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertor.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; @@ -144,6 +145,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.match.MatchSetfield; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.next.table.miss.TablesMiss; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfield; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,7 +161,8 @@ import org.slf4j.LoggerFactory; */ public class TableFeaturesConvertor implements Convertor< org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures, - List> { + List, + VersionConvertorData> { private static final Logger LOG = LoggerFactory.getLogger(TableFeaturesConvertor.class); private static final Ordering TABLE_FEATURE_PROPS_ORDERING = @@ -592,12 +595,12 @@ public class TableFeaturesConvertor implements Convertor< } @Override - public Class getType() { + public Class getType() { return org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures.class; } @Override - public List convert(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures source) { + public List convert(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures source, VersionConvertorData data) { List ofTableFeaturesList = new ArrayList<>(); TableFeaturesBuilder ofTableFeatures = new TableFeaturesBuilder(); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesResponseConvertor.java index 63e53a1de7..576bced2a5 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesResponseConvertor.java @@ -18,6 +18,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder; @@ -162,6 +163,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TableProperties; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder; +import org.opendaylight.yangtools.yang.binding.DataContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -175,7 +177,7 @@ import org.slf4j.LoggerFactory; * } * */ -public class TableFeaturesResponseConvertor implements Convertor> { +public class TableFeaturesResponseConvertor implements Convertor, VersionConvertorData> { private static final Logger LOG = LoggerFactory.getLogger(TableFeaturesResponseConvertor.class); private static final Map TABLE_FEATURE_PROPERTY_TYPE_TO_ACTION; private static final Map, org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> OF_TO_SAL_ACTION; @@ -481,12 +483,12 @@ public class TableFeaturesResponseConvertor implements Convertor getType() { + public Class getType() { return MultipartReplyTableFeatures.class; } @Override - public List convert(MultipartReplyTableFeatures source) { + public List convert(MultipartReplyTableFeatures source, VersionConvertorData data) { if (source == null || source.getTableFeatures() == null) { return Collections.emptyList(); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java index 3d7c5f0204..4fd3a7f66a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java @@ -53,9 +53,10 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cas import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfStripVlanActionV10Case; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfVendorCodecCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts SAL actions into OF Library actions @@ -70,7 +71,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 * } * */ -public final class ActionConvertor implements ParametrizedConvertor< +public final class ActionConvertor implements Convertor< List, List, ActionConvertorData> { @@ -126,7 +127,7 @@ public final class ActionConvertor implements ParametrizedConvertor< .addCase(new SalToOfGeneralExtensionGroupingCase()); @Override - public Class getType() { + public Class getType() { return org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java index 1ddf48088b..1128ef6ae0 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java @@ -32,10 +32,11 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cas import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetQueueCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalStripVlanCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts OF actions associated with bucket to SAL Actions. @@ -49,7 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 * } * */ -public final class ActionResponseConvertor implements ParametrizedConvertor< +public final class ActionResponseConvertor implements Convertor< List, List, ActionResponseConvertorData> { @@ -79,7 +80,7 @@ public final class ActionResponseConvertor implements ParametrizedConvertor< .addCase(new OfToSalStripVlanCase()); @Override - public Class getType() { + public Class getType() { return Action.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertReactor.java index 5127570a2a..0ff50e7c24 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertReactor.java @@ -18,10 +18,10 @@ import java.util.Map; */ public abstract class ConvertReactor { private final Map> injectionMapping; - private final Map> conversionMapping; + private final Map> conversionMapping; protected ConvertReactor() { - final Map> conversions = new HashMap<>(); + final Map> conversions = new HashMap<>(); final Map> injections = new HashMap<>(); initMappings(conversions, injections); @@ -35,7 +35,7 @@ public abstract class ConvertReactor { * @param conversions convert from * @param injections injection */ - protected abstract void initMappings(Map> conversions, + protected abstract void initMappings(Map> conversions, Map> injections); /** @@ -49,11 +49,11 @@ public abstract class ConvertReactor { public void convert(final FROM source, final short version, final TARGET target) { //lookup converter - Convertor convertor = (Convertor) conversionMapping.get(version); + Convertor convertor = (Convertor) conversionMapping.get(version); if (convertor == null) { throw new IllegalArgumentException("convertor for given version ["+version+"] not found"); } - RESULT convertedItem = convertor.convert(source); + RESULT convertedItem = convertor.convert(source, null); //lookup injection InjectionKey key = buildInjectionKey(version, convertedItem, target); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/Convertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/Convertor.java index 0e94005c07..6cc21c4dc2 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/Convertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/Convertor.java @@ -8,13 +8,16 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; +import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.binding.DataContainer; + /** * Converts OpenflowJava to MDSal model and vice versa * * @param type of source * @param type of result */ -public interface Convertor { +public interface Convertor { /** * Gets type of convertor, used in @@ -22,13 +25,14 @@ public interface Convertor { * * @return the type of convertor */ - Class getType(); + Class getType(); /** * Converts source to result * * @param source source + * @param data convertor data * @return converted source */ - TO convert(FROM source); + TO convert(FROM source, @Nullable DATA data); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java deleted file mode 100644 index 885d924296..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; - -/** - * Converts OpenflowJava to MDSal model and vice versa - * - * @param type of source - * @param type of result - * @param type of convertor data - */ -public interface ParametrizedConvertor { - - /** - * Gets type of convertor, used in - * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager}. - * - * @return the type of convertor - */ - Class getType(); - - /** - * Converts source to result - * - * @param source source - * @param data convertor data - * @return converted source - */ - TO convert(FROM source, DATA data); -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java index 758fc27a47..56badf14fe 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertor.java @@ -19,9 +19,9 @@ import java.util.Optional; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.ApplyActionsCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.cases.ClearActionsCase; @@ -64,6 +64,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmMatchType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts the SAL Flow to OF Flow. It checks if there is a set-vlan-id (1.0) action made on OF1.3. @@ -78,7 +79,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * } * */ -public class FlowConvertor implements ParametrizedConvertor, VersionDatapathIdConvertorData> { +public class FlowConvertor implements Convertor, VersionDatapathIdConvertorData> { /** * Default idle timeout */ @@ -511,7 +512,7 @@ public class FlowConvertor implements ParametrizedConvertor getType() { + public Class getType() { return Flow.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java index 9a160f69d0..aa5177e7c3 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowInstructionResponseConvertor.java @@ -17,7 +17,7 @@ import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; @@ -41,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts Openflow 1.3+ specific instructions to MD-SAL format flow instruction @@ -53,13 +54,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction * } * */ -public final class FlowInstructionResponseConvertor implements ParametrizedConvertor< +public final class FlowInstructionResponseConvertor implements Convertor< List, Instructions, VersionConvertorData> { @Override - public Class getType() { + public Class getType() { return org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java index 7da1a33b30..9e6ddf2aed 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowStatsResponseConvertor.java @@ -20,7 +20,7 @@ import org.opendaylight.openflowplugin.extension.api.path.MatchPath; import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; @@ -40,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts flow related statistics messages coming from openflow switch to MD-SAL messages. @@ -53,7 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 * } * */ -public class FlowStatsResponseConvertor implements ParametrizedConvertor, List, VersionDatapathIdConvertorData> { +public class FlowStatsResponseConvertor implements Convertor, List, VersionDatapathIdConvertorData> { /** * Method wraps openflow 1.0 actions list to Apply Action Instructions @@ -89,7 +90,7 @@ public class FlowStatsResponseConvertor implements ParametrizedConvertor getType() { + public Class getType() { return FlowStats.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java index a22808d049..3faf75132d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagConvertor.java @@ -9,23 +9,30 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flow.flowflag; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * converting from MD-SAL match model into appropriate OF-API match model * * @param type of converted match */ -public interface FlowFlagConvertor extends Convertor { +public interface FlowFlagConvertor extends Convertor { - default Class getType() { - return FlowModFlags.class; + @Override + default Class getType() { + return DataContainer.class; + } + + @Override + default E convert(FlowModFlags source, VersionConvertorData data) { + return convert(source); } /** * @param source flow mode flags * @return converted match (into OF-API model) */ - @Override E convert(FlowModFlags source); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java index f4e51a8e9b..7cd4b5d685 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactor.java @@ -34,7 +34,7 @@ public class FlowFlagReactor extends ConvertReactor { } @Override - protected void initMappings(final Map> conversions, + protected void initMappings(final Map> conversions, final Map> injections) { FlowFlagReactorMappingFactory.addFlowFlagsConvertors(conversions); FlowFlagReactorMappingFactory.addFlowFlagsIjectors(injections); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java index fac616de9e..b7b3e00b92 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/flowflag/FlowFlagReactorMappingFactory.java @@ -27,7 +27,7 @@ public class FlowFlagReactorMappingFactory { /** * @param conversionMapping conversion mapping */ - public static void addFlowFlagsConvertors(final Map> conversionMapping) { + public static void addFlowFlagsConvertors(final Map> conversionMapping) { conversionMapping.put(OFConstants.OFP_VERSION_1_3, new FlowFlagsConvertorImpl()); conversionMapping.put(OFConstants.OFP_VERSION_1_0, new FlowFlagsConvertorV10Impl()); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertor.java index 2524e64e12..6187709363 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertor.java @@ -9,23 +9,30 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * converting from MD-SAL match model into appropriate OF-API match model * * @param type of converted match */ -public interface MatchConvertor extends Convertor { +public interface MatchConvertor extends Convertor { - default Class getType() { + @Override + default Class getType() { return Match.class; } + + @Override + default E convert(Match source, VersionConvertorData data) { + return convert(source); + } /** * @param source match input * @return converted match (into OF-API model) */ - @Override E convert(Match source); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java index 3f285cd0df..28203dff18 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java @@ -34,7 +34,7 @@ public class MatchReactor extends ConvertReactor { } @Override - protected void initMappings(final Map> conversions, + protected void initMappings(final Map> conversions, final Map> injections) { MatchReactorMappingFactory.addMatchConvertors(conversions); MatchReactorMappingFactory.addMatchIjectors(injections); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java index 6dfeeb3b5f..5cc91b3748 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorMappingFactory.java @@ -34,7 +34,7 @@ public class MatchReactorMappingFactory { /** * @param conversionMapping conversion mapping */ - public static void addMatchConvertors(final Map> conversionMapping) { + public static void addMatchConvertors(final Map> conversionMapping) { conversionMapping.put(OFConstants.OFP_VERSION_1_3, new MatchConvertorImpl()); conversionMapping.put(OFConstants.OFP_VERSION_1_0, new MatchConvertorV10Impl()); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchResponseConvertor.java index 1ba9bdc771..d40f70811c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchResponseConvertor.java @@ -8,8 +8,8 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases.OfToSalArpOpCase; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.cases.OfToSalArpShaCase; @@ -77,6 +77,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.MatchEntryValue; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Dst; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TunnelIpv4Src; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts Openflow 1.3+ specific flow match to MD-SAL format flow @@ -91,7 +92,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Tunne * } * */ -public class MatchResponseConvertor implements ParametrizedConvertor { +public class MatchResponseConvertor implements Convertor { private static final ConvertorProcessor OF_TO_SAL_PROCESSOR = new ConvertorProcessor() .addCase(new OfToSalInPortCase()) .addCase(new OfToSalInPhyPortCase()) @@ -140,7 +141,7 @@ public class MatchResponseConvertor implements ParametrizedConvertor getType() { + public Class getType() { return MatchEntriesGrouping.class; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchV10ResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchV10ResponseConvertor.java index b47be384b9..9e8b707cc8 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchV10ResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchV10ResponseConvertor.java @@ -10,7 +10,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; import java.math.BigInteger; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; @@ -30,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10; +import org.opendaylight.yangtools.yang.binding.DataContainer; /** * Converts Openflow 1.0 specific flow match to MD-SAL format flow @@ -44,14 +45,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc * } * */ -public class MatchV10ResponseConvertor implements ParametrizedConvertor { +public class MatchV10ResponseConvertor implements Convertor { private static final short PROTO_TCP = 6; private static final short PROTO_UDP = 17; private static final short PROTO_ICMPV4 = 1; private static final String NO_IP = "0.0.0.0/0"; @Override - public Class getType() { + public Class getType() { return MatchV10.class; } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java deleted file mode 100644 index a35f08516e..0000000000 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; - -public class ConvertorManagerTest { - private static final String CONVERT_INPUT = "10"; - private static final Integer CONVERT_EXPECTED_RESULT = 10; - private static final Short P_CONVERT_INPUT = 0x01; - private static final String P_CONVERT_RESULT = "12"; - private static final Short P_CONVERT_VERSION = 0x02; - - private Convertor convertor; - private ParametrizedConvertor parametrizedConvertor; - - @Before - public void setUp() throws Exception { - convertor = new Convertor() { - @Override - public Class getType() { - return CharSequence.class; - } - - @Override - public Integer convert(CharSequence source) { - return Integer.valueOf(source.toString()); - } - }; - - parametrizedConvertor = new ParametrizedConvertor() { - @Override - public Class getType() { - return Number.class; - } - - @Override - public String convert(Number source, TestConvertorData testConvertorData) { - return String.valueOf(source) + String.valueOf(testConvertorData.getVersion()); - } - }; - - ConvertorManager.getInstance().registerConvertor(convertor); - ConvertorManager.getInstance().registerConvertor(parametrizedConvertor); - } - - @Test - public void testRegisterConvertor() throws Exception { - Convertor result = ConvertorManager.getInstance().registerConvertor(convertor); - assertNotNull("Convertor should be already registered", result); - } - - @Test - public void testRegisterParametrizedConvertor() throws Exception { - ParametrizedConvertor result = ConvertorManager.getInstance().registerConvertor(parametrizedConvertor); - assertNotNull("Parametrized convertor should be already registered", result); - } - - @Test - public void testConvert() throws Exception { - final Optional result = ConvertorManager.getInstance().convert(CONVERT_INPUT); - - assertTrue("Failed to convert string to integer", result.isPresent()); - assertEquals("Wrong conversion between string and integer", CONVERT_EXPECTED_RESULT, result.get()); - } - - @Test - public void testCollectionConvert() throws Exception { - final Optional> result = ConvertorManager.getInstance().convert( - Collections.singletonList(Boolean.TRUE)); - - assertFalse("Convertor result should be empty on wrong convertor", result.isPresent()); - } - - @Test - public void testEmptyCollectionConvert() throws Exception { - final Optional> result = ConvertorManager.getInstance().convert(Collections.emptyList()); - - assertFalse("Convertor result should be empty on empty collection", result.isPresent()); - } - - @Test - public void testFailedConvert() throws Exception { - final Optional result = ConvertorManager.getInstance().convert(null); - - assertFalse("Convertor result should be empty on null input", result.isPresent()); - } - - @Test - public void testNotFoundConvert() throws Exception { - final Optional result = ConvertorManager.getInstance().convert(Boolean.TRUE); - - assertFalse("Convertor result should be empty on wrong input", result.isPresent()); - } - - @Test - public void testParametrizedConvert() throws Exception { - final TestConvertorData data = new TestConvertorData(P_CONVERT_VERSION); - final Optional result = ConvertorManager.getInstance().convert(P_CONVERT_INPUT, data); - - assertTrue("Failed to convert short with data to string", result.isPresent()); - assertEquals("Wrong conversion between short with data and string", P_CONVERT_RESULT, result.get()); - } - - @Test - public void testCollectionParametrizedConvert() throws Exception { - final TestConvertorData data = new TestConvertorData(P_CONVERT_VERSION); - final Optional> result = ConvertorManager.getInstance().convert( - Collections.singletonList(Boolean.TRUE), data); - - assertFalse("Convertor result should be empty on wrong convertor", result.isPresent()); - } - - @Test - public void testEmptyCollectionParametrizedConvert() throws Exception { - final TestConvertorData data = new TestConvertorData(P_CONVERT_VERSION); - final Optional> result = ConvertorManager.getInstance().convert(Collections.emptyList(), data); - - assertFalse("Convertor result should be empty on empty collection", result.isPresent()); - } - - @Test - public void testFailedParametrizedConvert() throws Exception { - final TestConvertorData data = new TestConvertorData(P_CONVERT_VERSION); - final Optional result = ConvertorManager.getInstance().convert(null, data); - - assertFalse("Parametrized convertor result should be empty on null input", result.isPresent()); - } - - @Test - public void testNotFoundParametrizedConvert() throws Exception { - final TestConvertorData data = new TestConvertorData(P_CONVERT_VERSION); - final Optional result = ConvertorManager.getInstance().convert(Boolean.TRUE, data); - - assertFalse("Parametrized convertor result should be empty on wrong input", result.isPresent()); - } - - private class TestConvertorData extends ConvertorData { - TestConvertorData(short version) { - super(version); - } - } -} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertorTest.java index 73174ede70..778e87e5d5 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertorTest.java @@ -49,7 +49,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 public class GroupConvertorTest { /** - * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } + * test of {@link GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testGroupModConvertorwithallParameters() { @@ -172,7 +172,7 @@ public class GroupConvertorTest { } /** - * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } + * test of {@link GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testGroupModConvertorNoBucket() { @@ -191,7 +191,7 @@ public class GroupConvertorTest { } /** - * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } + * test of {@link GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeFastFailure() { @@ -271,7 +271,7 @@ public class GroupConvertorTest { } /** - * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } + * test of {@link GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testGroupModConvertSortedBuckets() { @@ -426,7 +426,7 @@ public class GroupConvertorTest { } /** - * test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } + * test of {@link GroupConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)} } */ @Test public void testGroupModConvertorBucketwithNOWieghtValuesForGroupTypeAll() { diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java index fb3c14babb..4b2f64f5ed 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesConvertorTest.java @@ -8,8 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; -import static org.mockito.Mockito.when; - import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; @@ -22,7 +20,6 @@ import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder; @@ -49,6 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatchBuilder; @@ -88,9 +86,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table @RunWith(MockitoJUnitRunner.class) public class TableFeaturesConvertorTest extends TestCase { - - @Mock - private TableFeatures tableFeatures; private static final TablePropertiesBuilder tablePropertiesBuilder = new TablePropertiesBuilder(); private static final Map, TableFeaturePropType> augmentationsMap = new HashMap<>(); private static final List instructionsList = new ArrayList<>(); @@ -334,7 +329,11 @@ public class TableFeaturesConvertorTest extends TestCase { tableFeaturesBuilder.setTableProperties(getTableProperties()); tableFeaturesList.add(tableFeaturesBuilder.build()); } - when(tableFeatures.getTableFeatures()).thenReturn(tableFeaturesList); + + TableFeatures tableFeatures = new UpdatedTableBuilder() + .setTableFeatures(tableFeaturesList) + .build(); + Optional> tableFeaturesesOptional = ConvertorManager.getInstance().convert(tableFeatures); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java index e51a13ca9b..5cf33ef409 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flow/FlowConvertorTest.java @@ -421,7 +421,7 @@ public class FlowConvertorTest { @Override public Class getImplementedInterface() { - return null; + return Flow.class; } } } \ No newline at end of file -- 2.36.6