From: Michal Rehak Date: Fri, 13 Mar 2015 13:33:55 +0000 (+0100) Subject: Fix of port-number model X-Git-Tag: release/lithium~646 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=25fd0c6b562cfe8115fb18c3eab07a8ab5270b2d;p=openflowplugin.git Fix of port-number model - reason: default union builder changed name (caused by generators change) (avoiding anonymous inner type is safer way) - fix: - promoted port-number inner type to typedef - renamed type in order to avoid name collisions (with leaf name and inet type) Change-Id: I30b0532b5c74d52aa74b334e5f6d017cc116915f Signed-off-by: Michal Rehak --- diff --git a/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java b/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java index 482230bdb2..6f3120cf86 100644 --- a/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java +++ b/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java @@ -27,7 +27,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -180,7 +180,7 @@ public class LLDPSpeakerTest { // Call nodeConnectorAdded with local port FlowCapableNodeConnector fcnc = TestUtils .createFlowCapableNodeConnector() - .setPortNumber(new CommonPort.PortNumber("LOCAL")).build(); + .setPortNumber(new PortNumberUni("LOCAL")).build(); lldpSpeaker.nodeConnectorAdded(id, fcnc); // Verify that nothing happened for local port diff --git a/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java b/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java index 7445f3fe1e..5e8771474a 100644 --- a/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java +++ b/applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java @@ -10,8 +10,8 @@ package org.opendaylight.openflowplugin.applications.lldpspeaker; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; @@ -49,7 +49,7 @@ public class TestUtils { MacAddress mac, long port) { return new FlowCapableNodeConnectorBuilder() .setHardwareAddress(mac) - .setPortNumber(new CommonPort.PortNumber(port)) + .setPortNumber(new PortNumberUni(port)) .setState(new StateBuilder().setLinkDown(linkDown).build()) .setConfiguration(new PortConfig(false, false, false, adminDown)); } diff --git a/applications/statistics-manager/src/test/java/test/mock/util/PortMockGenerator.java b/applications/statistics-manager/src/test/java/test/mock/util/PortMockGenerator.java index 4c972173fb..931d3d29e0 100644 --- a/applications/statistics-manager/src/test/java/test/mock/util/PortMockGenerator.java +++ b/applications/statistics-manager/src/test/java/test/mock/util/PortMockGenerator.java @@ -1,14 +1,14 @@ package test.mock.util; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; +import java.util.Random; + import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortKey; -import java.util.Random; - public class PortMockGenerator { private static final Random rnd = new Random(); private static final PortBuilder portBuilder = new PortBuilder(); @@ -16,7 +16,7 @@ public class PortMockGenerator { public static Port getRandomPort() { portBuilder.setKey(new PortKey(TestUtils.nextLong(0, 4294967295L))); portBuilder.setBarrier(rnd.nextBoolean()); - portBuilder.setPortNumber(new CommonPort.PortNumber(TestUtils.nextLong(0, 4294967295L))); + portBuilder.setPortNumber(new PortNumberUni(TestUtils.nextLong(0, 4294967295L))); portBuilder.setConfiguration(new PortConfig(rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean())); return portBuilder.build(); } diff --git a/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberBuilder.java b/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberBuilder.java deleted file mode 100644 index ff78a7478d..0000000000 --- a/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2014 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.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort.PortNumber; - - -public class PortNumberBuilder { - - public static PortNumber getDefaultInstance(java.lang.String defaultValue) { - try { - long uint32 = Long.parseLong(defaultValue); - return new PortNumber(uint32); - } catch(NumberFormatException e){ - return new PortNumber(defaultValue); - } - } - -} diff --git a/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberUniBuilder.java b/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberUniBuilder.java new file mode 100644 index 0000000000..6eaa4b15b6 --- /dev/null +++ b/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberUniBuilder.java @@ -0,0 +1,24 @@ +package org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925; + + +/** + * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation. + * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32). + * + * The reason behind putting it under src/main/java is: + * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent + * loss of user code. + * + */ +public class PortNumberUniBuilder { + + public static PortNumberUni getDefaultInstance(java.lang.String defaultValue) { + try { + long uint32 = Long.parseLong(defaultValue); + return new PortNumberUni(uint32); + } catch(NumberFormatException e){ + return new PortNumberUni(defaultValue); + } + } + +} diff --git a/model/model-flow-base/src/main/yang/opendaylight-port-types.yang b/model/model-flow-base/src/main/yang/opendaylight-port-types.yang index 9e88098752..134b0190b1 100644 --- a/model/model-flow-base/src/main/yang/opendaylight-port-types.yang +++ b/model/model-flow-base/src/main/yang/opendaylight-port-types.yang @@ -59,13 +59,17 @@ module opendaylight-port-types { } } + typedef port-number-uni { + type union { + type uint32; + type string; + } + } + grouping common-port { leaf port-number { - type union { - type uint32; - type string; - } + type port-number-uni; } leaf hardware-address { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java index 0859133c3d..1ea183432a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java @@ -100,6 +100,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder; @@ -170,6 +171,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ge import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -992,7 +994,8 @@ public final class ActionConvertor { OutputActionBuilder outputAction = new OutputActionBuilder(); PortAction port = action.getAugmentation(PortAction.class); if (port != null) { - CommonPort.PortNumber protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort( + PortNumberUni protocolAgnosticPort = + OpenflowPortsUtil.getProtocolAgnosticPort( ofVersion, port.getPort().getValue()); String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort); outputAction.setOutputNodeConnector(new Uri(portNumberAsString)); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtil.java index d397a35c1b..a8d830b542 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtil.java @@ -1,14 +1,14 @@ package org.opendaylight.openflowplugin.openflow.md.util; -import com.google.common.collect.ImmutableBiMap; - import org.opendaylight.openflowjava.protocol.api.util.BinContent; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValues; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValuesV10; +import com.google.common.collect.ImmutableBiMap; + /** * Class which integrates the port constants defined and used by MDSAL and the ports defined in openflow java * @@ -85,13 +85,13 @@ public class OpenflowPortsUtil { return port; } - public static CommonPort.PortNumber getProtocolAgnosticPort(OpenflowVersion ofVersion, Long portNumber) { + public static PortNumberUni getProtocolAgnosticPort(OpenflowVersion ofVersion, Long portNumber) { String reservedPortLogicalName = getPortLogicalName(ofVersion, portNumber); - return (reservedPortLogicalName == null ? new CommonPort.PortNumber(portNumber) : - new CommonPort.PortNumber(reservedPortLogicalName)); + return (reservedPortLogicalName == null ? new PortNumberUni(portNumber) : + new PortNumberUni(reservedPortLogicalName)); } - public static Long getProtocolPortNumber(OpenflowVersion ofVersion, CommonPort.PortNumber port) { + public static Long getProtocolPortNumber(OpenflowVersion ofVersion, PortNumberUni port) { String portLogicalName = port.getString(); if (portLogicalName != null) { @@ -132,7 +132,7 @@ public class OpenflowPortsUtil { * @param portNumber * @return string containing number or logical name */ - public static String portNumberToString(CommonPort.PortNumber portNumber) { + public static String portNumberToString(PortNumberUni portNumber) { String result = null; if (portNumber.getUint32() != null) { result = String.valueOf(portNumber.getUint32()); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImplTest.java index 209e8101a0..cd58c8787c 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImplTest.java @@ -28,10 +28,10 @@ import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor; import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService; -import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext; -import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.openflowplugin.api.statistics.MessageSpy; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; @@ -53,9 +53,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.G import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.PortBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.PortKey; @@ -798,7 +798,7 @@ public class ModelDrivenSwitchImplTest { false, false, false, false, true, true, true, true, false, false, false, false)); - port.setPortNumber(new PortNumber(42L)); + port.setPortNumber(new PortNumberUni(42L)); port.setHardwareAddress(new MacAddress("01:23:45:67:89:ab")); port.setBarrier(true); port.setContainerName("TestContainer"); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertorTest.java index f2438d8ec0..59298ef395 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PortConvertorTest.java @@ -14,7 +14,7 @@ import org.junit.Test; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State; @@ -56,7 +56,7 @@ public class PortConvertorTest { PortBuilder portBld = new PortBuilder(); portBld.setAdvertisedFeatures(features); portBld.setConfiguration(config); - portBld.setPortNumber(new PortNumber(42L)); + portBld.setPortNumber(new PortNumberUni(42L)); portBld.setHardwareAddress(new MacAddress(DEFAULT_MAC_ADDRESS)); PortModInput portOut = PortConvertor.toPortModInput(portBld.build(), EncodeConstants.OF13_VERSION_ID); @@ -101,7 +101,7 @@ public class PortConvertorTest { flowCapableNodeConnectorBuilder.setMaximumSpeed(null); flowCapableNodeConnectorBuilder.setName("foo"); flowCapableNodeConnectorBuilder.setPeerFeatures(features); - flowCapableNodeConnectorBuilder.setPortNumber(new PortNumber(42L)); + flowCapableNodeConnectorBuilder.setPortNumber(new PortNumberUni(42L)); flowCapableNodeConnectorBuilder.setState(state); flowCapableNodeConnectorBuilder.setSupported(features); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtilTest.java index cb179535f2..5cb08f8bb9 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtilTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/util/OpenflowPortsUtilTest.java @@ -1,16 +1,16 @@ package org.opendaylight.openflowplugin.openflow.md.util; +import java.util.HashMap; +import java.util.Map; + import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues; -import java.util.HashMap; -import java.util.Map; - /** * @author: Kamal Rameshan (kramesha@cisco.com) * @since : 6/2/14 @@ -176,20 +176,20 @@ public class OpenflowPortsUtilTest { } /** - * test for method {@link OpenflowPortsUtil#portNumberToString(CommonPort.PortNumber)} + * test for method {@link OpenflowPortsUtil#portNumberToString(PortNumber)} */ @Test public void testPortNumberToString() { - CommonPort.PortNumber portNumber; + PortNumberUni portNumber; - portNumber = new CommonPort.PortNumber(42L); + portNumber = new PortNumberUni(42L); Assert.assertEquals("42", OpenflowPortsUtil.portNumberToString(portNumber)); - portNumber = new CommonPort.PortNumber(OutputPortValues.FLOOD.toString()); + portNumber = new PortNumberUni(OutputPortValues.FLOOD.toString()); Assert.assertEquals("FLOOD", OpenflowPortsUtil.portNumberToString(portNumber)); try { - portNumber = new CommonPort.PortNumber((String) null); + portNumber = new PortNumberUni((String) null); Assert.fail("NPE was expected - due to value type"); } catch (Exception e) { // expected