From da3f0b2b4aeaa10d327583965d64ab05f7576abd Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 27 Jun 2016 13:36:16 +0200 Subject: [PATCH] Bug 5540 - ConvertorManager base - Added base for ConvertorManager - Removed datapathId from Convertor interface (as it was not needed anymore) - Updated usages and tests accordingly - Moved IPProtocols and IPConversionUtil to package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common Change-Id: I22940403495be5f0398682cab4e3377ee86ce7be Signed-off-by: Tomas Slusny --- .../services/FlowsInTableService.java | 3 +- .../services/MatchingFlowsInTableService.java | 2 +- .../direct/FlowDirectStatisticsService.java | 2 +- .../md/core/sal/OFRpcTaskFactory.java | 6 +- .../core/sal/convertor/ActionConvertor.java | 7 +- .../core/sal/convertor/ConvertorManager.java | 224 ++++++++++++++++++ .../md/core/sal/convertor/FlowConvertor.java | 4 +- .../action/ActionSetNwDstConvertorImpl.java | 12 +- .../ActionSetNwDstConvertorV10Impl.java | 8 +- .../ActionSetNwDstReactorMappingFactory.java | 2 +- .../action/ActionSetNwSrcConvertorImpl.java | 12 +- .../ActionSetNwSrcConvertorV10Impl.java | 8 +- .../ActionSetNwSrcReactorMappingFactory.java | 2 +- .../sal/convertor/common/ConvertReactor.java | 9 +- .../core/sal/convertor/common/Convertor.java | 33 ++- .../sal/convertor/common/ConvertorCase.java | 89 +++++++ .../sal/convertor/common/ConvertorData.java | 34 +++ .../convertor/common/ConvertorProcessor.java | 114 +++++++++ .../convertor/{ => common}/IPProtocols.java | 5 +- .../{ => common}/IpConversionUtil.java | 4 +- .../common/ParametrizedConvertor.java | 36 +++ .../convertor/flowflag/FlowFlagConvertor.java | 9 +- .../flowflag/FlowFlagsConvertorImpl.java | 4 +- .../flowflag/FlowFlagsConvertorV10Impl.java | 4 +- .../sal/convertor/match/MatchConvertor.java | 9 +- .../convertor/match/MatchConvertorImpl.java | 89 ++++++- .../match/MatchConvertorV10Impl.java | 8 +- .../translator/FlowRemovedTranslator.java | 2 +- .../sal/convertor/ConvertorManagerTest.java | 160 +++++++++++++ .../action/ActionSetNwDstReactorTest.java | 7 +- .../action/ActionSetNwSrcReactorTest.java | 7 +- .../{ => common}/IpConversionUtilTest.java | 1 + .../flowflag/FlowFlagReactorTest.java | 5 +- .../match/MatchConvertorImpl2Test.java | 52 ++-- .../match/MatchConvertorV10ImplTest.java | 16 +- .../sal/convertor/match/MatchReactorTest.java | 17 +- 36 files changed, 875 insertions(+), 131 deletions(-) create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorCase.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorData.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorProcessor.java rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => common}/IPProtocols.java (93%) rename openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => common}/IpConversionUtil.java (99%) create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java rename openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/{ => common}/IpConversionUtilTest.java (96%) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/FlowsInTableService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/FlowsInTableService.java index 70b458daaa..12641266b0 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/FlowsInTableService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/FlowsInTableService.java @@ -73,8 +73,7 @@ public final class FlowsInTableService extends AbstractCompatibleStatService> convertorKeys = new ArrayList<>(); + private List> parametrizedConvertorKeys = 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 HashMap<>(); + private Map, ParametrizedConvertor> parametrizedConvertors = new HashMap<>(); + + private ConvertorManager() { + // Hiding implicit constructor + } + + /** + * Gets instance of Convertor Manager. + * + * @return the instance + */ + public static ConvertorManager getInstance() { + return INSTANCE; + } + + /** + * Register convertor. + * + * @param convertor the convertor + * @return if registration was successful + */ + public boolean registerConvertor(final Convertor convertor) { + final Class type = convertor.getType(); + + if (convertors.containsKey(type)) { + LOG.warn("Convertor for type {} is already registered", type); + return false; + } + + convertorKeys.add(type); + convertors.put(type, convertor); + LOG.debug("{} is now converted by {}", type, convertor); + return true; + } + + /** + * Register convertor. + * + * @param convertor the convertor + * @return if registration was successful + */ + public boolean registerConvertor(final ParametrizedConvertor convertor) { + final Class type = convertor.getType(); + + if (parametrizedConvertors.containsKey(type)) { + LOG.warn("Convertor for type {} is already registered", type); + return false; + } + + parametrizedConvertorKeys.add(type); + parametrizedConvertors.put(type, convertor); + LOG.debug("{} is now converted by {}", type, convertor); + return true; + } + + /** + * Lookup and use convertor by specified type, then converts source and returns converted result + * + * @param the source type + * @param the result type + * @param source the source + * @return the result (can be empty, if no convertor was found) + */ + @SuppressWarnings("unchecked") + public Optional convert(final FROM source) { + if (Objects.isNull(source)) { + LOG.trace("Cannot convert source, because it is null"); + return Optional.empty(); + } + + Class type = source.getClass(); + + if (source instanceof Collection) { + final Iterator it = ((Collection) source).iterator(); + Object next = null; + + if (it.hasNext()) { + next = it.next(); + } + + if (Objects.isNull(next)) { + LOG.trace("Cannot convert {}, because it is empty collection", type); + return Optional.empty(); + } + + type = next.getClass(); + } + + Convertor convertor = null; + + if (!convertors.containsKey(type)) { + boolean found = false; + + for (Class key : convertorKeys) { + if (key.isAssignableFrom(type)) { + convertor = convertors.get(key); + convertors.put(type, convertor); + LOG.debug("{} is now converted by {}", type, convertor); + found = true; + break; + } + } + + if (!found) { + LOG.error("Convertor for {} not found", type); + return Optional.empty(); + } + } + + if (Objects.isNull(convertor)) { + convertor = convertors.get(type); + } + + final Object result = convertor.convert(source); + return Optional.of((TO) result); + } + + /** + * Lookup and use convertor by specified type, then converts source and returns converted result + * + * @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) + */ + @SuppressWarnings("unchecked") + public Optional convert(final FROM source, final DATA data) { + if (Objects.isNull(source)) { + LOG.trace("Cannot convert source, because it is null"); + return Optional.empty(); + } + + Class type = source.getClass(); + + if (source instanceof Collection) { + final Iterator it = ((Collection) source).iterator(); + Object next = null; + + if (it.hasNext()) { + next = it.next(); + } + + if (Objects.isNull(next)) { + LOG.trace("Cannot convert {}, because it is empty collection", type); + return Optional.empty(); + } + + type = next.getClass(); + } + + ParametrizedConvertor convertor = null; + + if (!parametrizedConvertors.containsKey(type)) { + boolean found = false; + + for (Class key : parametrizedConvertorKeys) { + if (key.isAssignableFrom(type)) { + convertor = parametrizedConvertors.get(key); + parametrizedConvertors.put(type, convertor); + LOG.debug("{} is now converted by {}", type, convertor); + found = true; + break; + } + } + + if (!found) { + LOG.error("Convertor for {} not found", type); + return Optional.empty(); + } + } + + if (Objects.isNull(convertor)) { + convertor = parametrizedConvertors.get(type); + } + + final Object result = convertor.convert(source, data); + return Optional.of((TO) result); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java index 0115b55560..401227b800 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java @@ -198,10 +198,10 @@ public class FlowConvertor { salToOFFlowOutGroup(flow, flowMod); // convert and inject flowFlags - FlowFlagReactor.getInstance().convert(flow.getFlags(), version, flowMod, datapathid); + FlowFlagReactor.getInstance().convert(flow.getFlags(), version, flowMod); // convert and inject match - MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod, datapathid); + MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod); if (flow.getInstructions() != null) { flowMod.setInstruction(toInstructions(flow, version, datapathid)); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java index 0ea9d72add..15909e8fa0 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java @@ -8,8 +8,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; - +import com.google.common.base.Splitter; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; @@ -18,8 +17,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; -import com.google.common.base.Splitter; - /** * Utility class for converting a MD-SAL action subelement into the OF subelement */ @@ -27,7 +24,12 @@ public class ActionSetNwDstConvertorImpl implements Convertor getType() { + return SetNwDstActionCase.class; + } + + @Override + public Object convert(final SetNwDstActionCase source) { Address address = source.getSetNwDstAction().getAddress(); if (address instanceof Ipv4) { Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java index 576a995a8c..0a3293495d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java @@ -8,7 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; @@ -21,7 +20,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr public class ActionSetNwDstConvertorV10Impl implements Convertor { @Override - public Object convert(SetNwDstActionCase source, BigInteger datapathid) { + public Class getType() { + return SetNwDstActionCase.class; + } + + @Override + public Object convert(SetNwDstActionCase source) { Address address = source.getSetNwDstAction().getAddress(); if (address instanceof Ipv4) { //FIXME use of substring should be removed and OF models should distinguish where diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java index 766970502c..afbdb4a56b 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.IpConversionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java index 6702c0524a..0b58ae0c5d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java @@ -8,8 +8,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; - +import com.google.common.base.Splitter; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; @@ -18,8 +17,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; -import com.google.common.base.Splitter; - /** * Utility class for converting a MD-SAL action subelement into the OF subelement */ @@ -28,7 +25,12 @@ public class ActionSetNwSrcConvertorImpl implements Convertor getType() { + return SetNwSrcActionCase.class; + } + + @Override + public Object convert(final SetNwSrcActionCase source) { Address address = source.getSetNwSrcAction().getAddress(); if (address instanceof Ipv4) { Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java index d7e8e8c32c..fc988aa2bc 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java @@ -8,7 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; @@ -21,7 +20,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr public class ActionSetNwSrcConvertorV10Impl implements Convertor { @Override - public Object convert(SetNwSrcActionCase source, BigInteger datapathid) { + public Class getType() { + return SetNwSrcActionCase.class; + } + + @Override + public Object convert(SetNwSrcActionCase source) { Address address = source.getSetNwSrcAction().getAddress(); if (address instanceof Ipv4) { //FIXME use of substring should be removed and OF models should distinguish where diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java index 675a913eee..a7d43108f1 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java @@ -13,7 +13,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.IpConversionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; 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 d6e60b2a42..5127570a2a 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 @@ -8,12 +8,10 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; -import java.math.BigInteger; +import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.Map; -import com.google.common.collect.ImmutableMap; - /** * @param source type for conversion * @@ -44,19 +42,18 @@ public abstract class ConvertReactor { * @param source convert from * @param version openflow version * @param target convert to - * @param datapathid datapath id * @param result * @param target */ @SuppressWarnings("unchecked") - public void convert(final FROM source, final short version, final TARGET target, final BigInteger datapathid) { + public void convert(final FROM source, final short version, final TARGET target) { //lookup converter Convertor convertor = (Convertor) conversionMapping.get(version); if (convertor == null) { throw new IllegalArgumentException("convertor for given version ["+version+"] not found"); } - RESULT convertedItem = convertor.convert(source,datapathid); + RESULT convertedItem = convertor.convert(source); //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 4583a15587..0e94005c07 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 @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. 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, @@ -8,20 +8,27 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; -import java.math.BigInteger; - - /** - * converting from MD-SAL model into appropriate OF-API model - * @param type of source - * @param type of result + * Converts OpenflowJava to MDSal model and vice versa + * + * @param type of source + * @param type of result */ public interface Convertor { - + + /** + * Gets type of convertor, used in + * {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager}. + * + * @return the type of convertor + */ + Class getType(); + /** - * @param source source type - * @param datapathid datapath id - * @return converted match (into OF-API model) + * Converts source to result + * + * @param source source + * @return converted source */ - TO convert(FROM source,BigInteger datapathid); + TO convert(FROM source); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorCase.java new file mode 100644 index 0000000000..aa9ea1f96e --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorCase.java @@ -0,0 +1,89 @@ +/* + * 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; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; + +/** + * The Convertor case used in {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor}. + * + * @param the source type + * @param the result type + * @param the data type + */ +public abstract class ConvertorCase { + private final List supportedVersions; + private final Class type; + private final boolean errorOnEmpty; + + /** + * Instantiates a new Convertor case. + * + * @param type the type + * @param errorOnEmpty the error on empty + * @param supportedVersions the supported versions + */ + protected ConvertorCase(Class type, boolean errorOnEmpty, Short... supportedVersions) { + this.type = type; + this.errorOnEmpty = errorOnEmpty; + this.supportedVersions = Arrays.asList(Preconditions.checkNotNull(supportedVersions)); + } + + /** + * Process source and return result, what can be empty + * + * @param source the source + * @param data the data + * @return the optional + */ + public abstract Optional process(@Nonnull final FROM source, final DATA data); + + /** + * Should {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor} + * throw error when result of process method is empty? + * + * @return the boolean + */ + boolean isErrorOnEmpty() { + return errorOnEmpty; + } + + /** + * Cast untyped source to type of this case and sends it to actual process method. + * + * @param source the source + * @param data the data + * @return the optional + */ + Optional processRaw(@Nonnull final Object source, final DATA data) { + return process(getType().cast(source), data); + } + + /** + * Gets type of this convertor case. + * + * @return the type + */ + Class getType() { + return type; + } + + /** + * Gets supported Openflow versions. + * + * @return the supported versions + */ + List getSupportedVersions() { + return supportedVersions; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorData.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorData.java new file mode 100644 index 0000000000..43f87012ab --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorData.java @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * The base class for all convertor data. + */ +public abstract class ConvertorData { + private short version; + + /** + * Instantiates a new Convertor data. + * + * @param version the version + */ + public ConvertorData(final short version) { + this.version = version; + } + + /** + * Gets Openflow version. + * + * @return the version + */ + public short getVersion() { + return version; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorProcessor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorProcessor.java new file mode 100644 index 0000000000..b42db61322 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ConvertorProcessor.java @@ -0,0 +1,114 @@ +/* + * 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; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Processes source and return result based on convertor cases added to this processor. + * + * @param the source type + * @param the result type + * @param the type of convertor data + */ +public class ConvertorProcessor { + private static final short OFP_VERSION_ALL = 0x00; + private static final Logger LOG = LoggerFactory.getLogger(ConvertorProcessor.class); + + private final Map> conversions = new HashMap<>(); + private ConvertorCase defaultCase; + + /** + * Add convertor processor case. + * + * @param processorCase the processor case + * @return the convertor processor + */ + public ConvertorProcessor addCase(final ConvertorCase processorCase) { + if (processorCase.getSupportedVersions().isEmpty()) { + final InjectionKey key = new InjectionKey(OFP_VERSION_ALL, processorCase.getType()); + conversions.putIfAbsent(key, processorCase); + } else { + for (short supportedVersion : processorCase.getSupportedVersions()) { + final InjectionKey key = new InjectionKey(supportedVersion, processorCase.getType()); + conversions.putIfAbsent(key, processorCase); + } + } + + return this; + } + + /** + * Process source and return result based on convertor cases, or empty if no match is found. + * + * @param source the source + * @return the optional + */ + public Optional process(final FROM source) { + return process(source, null); + } + + /** + * Process source and return result based on convertor cases, or empty if no match is found. + * + * @param source the source + * @param data the data + * @return the optional + */ + public Optional process(final FROM source, final DATA data) { + Optional result = Optional.empty(); + final short version = data != null ? data.getVersion() : OFP_VERSION_ALL; + + if (source == null) { + LOG.trace("Failed to convert null for version {}", version); + return result; + } + + Class clazz = source.getClass(); + final Class[] interfaces = clazz.getInterfaces(); + + if (interfaces.length > 0) { + clazz = interfaces[0]; + } + + final InjectionKey key = new InjectionKey(version, clazz); + ConvertorCase rule = defaultCase; + + if (conversions.containsKey(key)) { + rule = conversions.get(key); + } + + if (rule != null) { + result = rule.processRaw(source, data); + + if (rule.isErrorOnEmpty() && !result.isPresent()) { + LOG.error("Failed to convert {} for version {}", clazz, version); + } + } else { + LOG.trace("Failed to convert {} for version {}", clazz, version); + } + + return result; + } + + /** + * Sets default case, what will be used when we do not find any matching convertor case for source. + * + * @param defaultCase the default case + * @return the default case + */ + public ConvertorProcessor setDefaultCase(final ConvertorCase defaultCase) { + this.defaultCase = defaultCase; + return this; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IPProtocols.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IPProtocols.java similarity index 93% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IPProtocols.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IPProtocols.java index 2e6a386204..caec87b676 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IPProtocols.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IPProtocols.java @@ -1,11 +1,12 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. 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, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; + +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java similarity index 99% rename from openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtil.java rename to openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java index fe4ad06c9f..ea4815a16c 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtil.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc., Brocade, Communications Systems, Inc. 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, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; 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 new file mode 100644 index 0000000000..885d924296 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/ParametrizedConvertor.java @@ -0,0 +1,36 @@ +/* + * 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/flowflag/FlowFlagConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java index fc798c9fbf..d1011f3042 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagConvertor.java @@ -8,8 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; -import java.math.BigInteger; - import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; @@ -18,12 +16,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMo * @param type of converted match */ public interface FlowFlagConvertor extends Convertor { + + default Class getType() { + return FlowModFlags.class; + } /** * @param source flow mode flags - * @param datapathid datapath id * @return converted match (into OF-API model) */ @Override - E convert(FlowModFlags source,BigInteger datapathid); + E convert(FlowModFlags source); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java index af119b1bd9..2dfb2acf85 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorImpl.java @@ -8,8 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; -import java.math.BigInteger; - import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; @@ -20,7 +18,7 @@ public class FlowFlagsConvertorImpl implements FlowFlagConvertor { @Override public FlowModFlags convert( - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags source, BigInteger datapathid) { + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags source) { FlowModFlags ofFlowModFlags = null; if (source != null) { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java index 478b0c00c2..ee5dac9b1d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagsConvertorV10Impl.java @@ -8,8 +8,6 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; -import java.math.BigInteger; - import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; @@ -20,7 +18,7 @@ public class FlowFlagsConvertorV10Impl implements FlowFlagConvertor type of converted match */ public interface MatchConvertor extends Convertor { + + default Class getType() { + return Match.class; + } /** * @param source match input - * @param datapathid datapath id * @return converted match (into OF-API model) */ @Override - E convert(Match source,BigInteger datapathid); + E convert(Match source); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java index fd1e7c94ea..7c32695445 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java @@ -23,8 +23,8 @@ import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey; import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionResolvers; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.OFApprovedExperimenterIds; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil; @@ -36,8 +36,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6FlowLabel; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; @@ -94,8 +94,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.Pbb; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.opendaylight.ipv6.arbitrary.bitmask.fields.rev160224.Ipv6ArbitraryMask; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlagsContainer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.TcpFlagsContainerBuilder; @@ -155,7 +155,86 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpOpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpOpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpShaCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpShaCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpSpaCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpSpaCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpThaCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpThaCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpTpaCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ArpTpaCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthTypeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthTypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6CodeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6CodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPhyPortCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpDscpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpDscpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpEcnCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpEcnCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpProtoCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.IpProtoCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6ExthdrCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6ExthdrCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6FlabelCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6FlabelCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdSllCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdSllCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTargetCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTargetCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTllCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdTllCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MetadataCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MetadataCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsBosCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsBosCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsLabelCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsLabelCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsTcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.MplsTcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.PbbIsidCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.PbbIsidCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpDstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpSrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.SctpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpDstCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanPcpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanPcpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.op._case.ArpOpBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.sha._case.ArpShaBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.arp.spa._case.ArpSpaBuilder; @@ -230,7 +309,7 @@ public class MatchConvertorImpl implements MatchConvertor> { @Override public List convert( - final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match, final BigInteger datapathid) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match) { List matchEntryList = new ArrayList<>(); if (match == null) { return matchEntryList; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java index 43a46c4121..70fcc02812 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10Impl.java @@ -8,13 +8,11 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match; -import java.math.BigInteger; import java.util.Iterator; - -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.IpConversionUtil; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; @@ -55,7 +53,7 @@ public class MatchConvertorV10Impl implements MatchConvertor { * @author avishnoi@in.ibm.com */ @Override - public MatchV10 convert(final Match match,final BigInteger datapathid) { + public MatchV10 convert(final Match match) { MatchV10Builder matchBuilder = new MatchV10Builder(); boolean _dLDST = true; boolean _dLSRC = true; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java index d104f030f0..557fc1016a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java @@ -23,7 +23,7 @@ import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.extension.api.AugmentTuple; 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.IpConversionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl; import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; 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 new file mode 100644 index 0000000000..df20423dc6 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManagerTest.java @@ -0,0 +1,160 @@ +/* + * 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.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 { + boolean success = ConvertorManager.getInstance().registerConvertor(convertor); + assertFalse("Convertor should be already registered", success); + } + + @Test + public void testRegisterParametrizedConvertor() throws Exception { + boolean success = ConvertorManager.getInstance().registerConvertor(parametrizedConvertor); + assertFalse("Parametrized convertor should be already registered", success); + } + + @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/action/ActionSetNwDstReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java index 5ec41c55f4..d3f51e9cc4 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java @@ -7,7 +7,6 @@ */ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -52,7 +51,7 @@ public class ActionSetNwDstReactorTest { for (final Address address : addresses) { final SetNwDstActionCase action = prepareSetNwDstActionCase(address); ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_3, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_3, target); final Object mEntry = target.getActionChoice(); /* Assert.assertNotNull(mEntry); @@ -89,12 +88,12 @@ public class ActionSetNwDstReactorTest { if (address instanceof Ipv4) { ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_0, target); // Assert.assertNotNull(target.getAugmentation(IpAddressAction.class).getIpAddress()); } else { try { ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_0, target); Assert.fail("address of this type must not pass the reactor: " + address.getClass().getName()); } catch (final Exception e) { //expected diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java index b326b0f960..fc15fb46c9 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java @@ -7,7 +7,6 @@ */ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; -import java.math.BigInteger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -53,7 +52,7 @@ public class ActionSetNwSrcReactorTest { for (final Address address : addresses) { final SetNwSrcActionCase action = prepareSetNwSrcActionCase(address); ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_3, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_3, target); /* MatchEntry mEntry = target.getActionChoice() getAugmentation(OxmFieldsAction.class).getMatchEntry().get(0); Assert.assertNotNull(mEntry); @@ -90,11 +89,11 @@ public class ActionSetNwSrcReactorTest { if (address instanceof Ipv4) { ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_0, target); } else { try { ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target, BigInteger.ONE); + OFConstants.OFP_VERSION_1_0, target); Assert.fail("address of this type must not pass the reactor: " + address.getClass().getName()); } catch (final Exception e) { //expected diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtilTest.java similarity index 96% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtilTest.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtilTest.java index d99abfc13a..c360171190 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/IpConversionUtilTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/IpConversionUtilTest.java @@ -12,6 +12,7 @@ import java.util.Arrays; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java index 0e2c685b5a..ac54c827bb 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactorTest.java @@ -7,7 +7,6 @@ */ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag; -import java.math.BigInteger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -43,7 +42,7 @@ public class FlowFlagReactorTest { for (FlowModFlags fFlag : flowFlags) { target.setFlags(null); FlowFlagReactor.getInstance().convert(fFlag, - OFConstants.OFP_VERSION_1_3, target,BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_3, target); Assert.assertNotNull(target.getFlags()); } } @@ -57,7 +56,7 @@ public class FlowFlagReactorTest { for (FlowModFlags fFlag : flowFlags) { target.setFlagsV10(null); FlowFlagReactor.getInstance().convert(fFlag, - OFConstants.OFP_VERSION_1_0, target,BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_0, target); Assert.assertNotNull(target.getFlagsV10()); } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl2Test.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl2Test.java index f6e9ba27e5..09da99443d 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl2Test.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl2Test.java @@ -151,22 +151,22 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testEmptyAndNullInput() { MatchBuilder builder = new MatchBuilder(); Match match = builder.build(); - List entries = convertor.convert(null, new BigInteger("42")); + List entries = convertor.convert(null); Assert.assertEquals("Wrong entries size", 0, entries.size()); - entries = convertor.convert(match, new BigInteger("42")); + entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 0, entries.size()); } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testConversion() { @@ -228,7 +228,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv4MatchBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 24, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, InPort.class, false); @@ -338,7 +338,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testIpv4MatchArbitraryBitMaskwithNoMask(){ @@ -349,7 +349,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); @@ -361,7 +361,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testIpv4MatchArbitraryBitMaskwithMask(){ @@ -374,7 +374,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); @@ -386,7 +386,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testUdpMatchConversion() { @@ -397,7 +397,7 @@ public class MatchConvertorImpl2Test { builder.setLayer4Match(udpMatchBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, UdpSrc.class, false); @@ -410,7 +410,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testSctpMatchConversion() { @@ -421,7 +421,7 @@ public class MatchConvertorImpl2Test { builder.setLayer4Match(sctpMatchBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, SctpSrc.class, false); @@ -434,7 +434,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testArpMatchConversion() { @@ -452,7 +452,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(arpBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 5, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, ArpOp.class, false); @@ -477,7 +477,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testArpMatchConversionWithMasks() { @@ -497,7 +497,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(arpBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 4, entries.size()); MatchEntry entry = entries.get(0); entry = entries.get(0); @@ -527,7 +527,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testIpv6MatchConversion() { @@ -547,7 +547,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv6Builder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 7, entries.size()); MatchEntry entry = entries.get(0); /* Due to conversion ambiguities, we always get "has mask" because @@ -583,7 +583,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testIpv6MatchConversionWithMasks() { @@ -594,7 +594,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv6Builder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, Ipv6Src.class, true); @@ -612,7 +612,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testIpv6ExtHeaderConversion() { @@ -625,7 +625,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv6Builder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 1, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, Ipv6Exthdr.class, true); @@ -636,7 +636,7 @@ public class MatchConvertorImpl2Test { } /** - * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match, java.math.BigInteger)} + * Test {@link MatchConvertorImpl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)} */ @Test public void testConversionWithMasks() { @@ -677,7 +677,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv4MatchBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 8, entries.size()); MatchEntry entry = entries.get(0); checkEntryHeader(entry, Metadata.class, true); @@ -745,7 +745,7 @@ public class MatchConvertorImpl2Test { builder.setLayer3Match(ipv6MatchArbitraryBitMaskBuilder.build()); Match match = builder.build(); - List entries = convertor.convert(match, new BigInteger("42")); + List entries = convertor.convert(match); Assert.assertEquals("Wrong entries size", 2, entries.size()); MatchEntry entry = entries.get(0); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10ImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10ImplTest.java index 223988bb03..f454f4de00 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10ImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorV10ImplTest.java @@ -68,7 +68,7 @@ public class MatchConvertorV10ImplTest { * Test method for {@link MatchConvertorV10Impl#convert(Match,BigInteger)} */ public void testConvert() { - MatchV10 matchV10 = matchConvertorV10.convert(createL4UdpMatch().build(), dataPathId); + MatchV10 matchV10 = matchConvertorV10.convert(createL4UdpMatch().build()); assertEquals(ZERO_MAC, matchV10.getDlDst()); assertEquals(FF_MAC, matchV10.getDlSrc()); @@ -83,24 +83,24 @@ public class MatchConvertorV10ImplTest { assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpSrc().intValue()); assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpDst().intValue()); - matchV10 = matchConvertorV10.convert(createL4TcpMatch().build(), dataPathId); + matchV10 = matchConvertorV10.convert(createL4TcpMatch().build()); assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpSrc().intValue()); assertEquals(DEFAULT_PORT.getValue().intValue(), matchV10.getTpDst().intValue()); - matchV10 = matchConvertorV10.convert(createVlanTcpMatch().build(), dataPathId); + matchV10 = matchConvertorV10.convert(createVlanTcpMatch().build()); assertEquals(DEFAULT_VLAN_ID.getValue().intValue(), matchV10.getDlVlan().intValue()); } /** * ICMPv4 match test for - * {@link MatchConvertorV10Impl#convert(Match,BigInteger)}. + * {@link MatchConvertorV10Impl#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)}. */ @Test public void testConvertIcmpv4() { MatchBuilder matchBuilder = createMatchBuilderWithDefaults(); Match match = matchBuilder.build(); - MatchV10 matchV10 = matchConvertorV10.convert(match, dataPathId); + MatchV10 matchV10 = matchConvertorV10.convert(match); Integer zero = 0; boolean wcTpSrc = true; boolean wcTpDst = true; @@ -131,7 +131,7 @@ public class MatchConvertorV10ImplTest { wcTpDst, wcTpSrc); match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()). build(); - matchV10 = matchConvertorV10.convert(match, dataPathId); + matchV10 = matchConvertorV10.convert(match); assertEquals(ZERO_MAC, matchV10.getDlDst()); assertEquals(FF_MAC, matchV10.getDlSrc()); assertEquals(0, matchV10.getDlType().intValue()); @@ -157,7 +157,7 @@ public class MatchConvertorV10ImplTest { wcTpDst, wcTpSrc); match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()). build(); - matchV10 = matchConvertorV10.convert(match, dataPathId); + matchV10 = matchConvertorV10.convert(match); assertEquals(ZERO_MAC, matchV10.getDlDst()); assertEquals(FF_MAC, matchV10.getDlSrc()); assertEquals(0, matchV10.getDlType().intValue()); @@ -185,7 +185,7 @@ public class MatchConvertorV10ImplTest { wcTpDst, wcTpSrc); match = matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build()). build(); - matchV10 = matchConvertorV10.convert(match, dataPathId); + matchV10 = matchConvertorV10.convert(match); assertEquals(ZERO_MAC, matchV10.getDlDst()); assertEquals(FF_MAC, matchV10.getDlSrc()); assertEquals(0, matchV10.getDlType().intValue()); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorTest.java index e32dfe53b0..e2d7de2439 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactorTest.java @@ -18,7 +18,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder; -import java.math.BigInteger; /** * match conversion and injection test @@ -47,7 +46,7 @@ public class MatchReactorTest { public void testMatchConvertorV13_flow() { FlowModInputBuilder target = new FlowModInputBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_3, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_3, target); Assert.assertNotNull(target.getMatch()); } @@ -58,7 +57,7 @@ public class MatchReactorTest { public void testMatchConvertorV10_flow() { FlowModInputBuilder target = new FlowModInputBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_0, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_0, target); Assert.assertNotNull(target.getMatchV10()); } @@ -70,7 +69,7 @@ public class MatchReactorTest { public void testMatchConvertorV13_mpRequestFlow() { MultipartRequestFlowBuilder target = new MultipartRequestFlowBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_3, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_3, target); Assert.assertNotNull(target.getMatch()); } @@ -81,7 +80,7 @@ public class MatchReactorTest { public void testMatchConvertorV10_mpRequestFlow() { MultipartRequestFlowBuilder target = new MultipartRequestFlowBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_0, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_0, target); Assert.assertNotNull(target.getMatchV10()); } @@ -89,7 +88,7 @@ public class MatchReactorTest { public void testMatchConvertorV10_null() { MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder(); MatchReactor.getInstance().convert(null, - OFConstants.OFP_VERSION_1_0, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_0, target); Assert.assertNotNull(target.getMatchV10()); } @@ -100,7 +99,7 @@ public class MatchReactorTest { public void testMatchConvertorV13_mpRequestAggregate() { MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_3, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_3, target); Assert.assertNotNull(target.getMatch()); } @@ -108,7 +107,7 @@ public class MatchReactorTest { public void testMatchConvertorV13_null() { MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder(); MatchReactor.getInstance().convert(null, - OFConstants.OFP_VERSION_1_3, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_3, target); Assert.assertNotNull(target.getMatch()); Assert.assertEquals(0, target.getMatch().getMatchEntry().size()); } @@ -120,7 +119,7 @@ public class MatchReactorTest { public void testMatchConvertorV10_mpRequestAggregate() { MultipartRequestAggregateBuilder target = new MultipartRequestAggregateBuilder(); MatchReactor.getInstance().convert(matchBuilder.build(), - OFConstants.OFP_VERSION_1_0, target, BigInteger.valueOf(1)); + OFConstants.OFP_VERSION_1_0, target); Assert.assertNotNull(target.getMatchV10()); } -- 2.36.6