From: Juraj Sebin Date: Mon, 2 Dec 2013 11:29:08 +0000 (+0100) Subject: fix port update - honor message version X-Git-Tag: jenkins-openflowplugin-bulk-release-prepare-only-4~100 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ba8eda47b29eca3d5d7e38f1267456bfc1d610fa;p=openflowplugin.git fix port update - honor message version rebased Change-Id: If0337c03de70d5788385095c2eaa26b54d8669b7 Signed-off-by: Juraj Sebin Signed-off-by: Michal Rehak --- diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java index b42597a5cd..ef87f96dad 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java @@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener; import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager; import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeper; @@ -35,9 +36,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestDescBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortDescBuilder; @@ -81,6 +83,8 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener, private HandshakeManager handshakeManager; private boolean firstHelloProcessed; + + private PortFeaturesUtil portFeaturesUtils; /** * @param connectionAdapter @@ -94,6 +98,7 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener, ConnectionConductor.versionOrder.get(0), ConnectionConductor.versionOrder); handshakeManager.setUseVersionBitmap(isBitmapNegotiationEnable); handshakeManager.setHandshakeListener(this); + portFeaturesUtils = PortFeaturesUtil.getInstance(); } @Override @@ -198,9 +203,38 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener, @Override public void onPortStatusMessage(PortStatusMessage message) { - this.getSessionContext().processPortStatusMsg(message); + processPortStatusMsg(message); queueKeeper.push(message, this); } + + protected void processPortStatusMsg(PortStatus msg) { + if (msg.getReason().getIntValue() == 2) { + updatePort(msg); + } else if (msg.getReason().getIntValue() == 0) { + updatePort(msg); + } else if (msg.getReason().getIntValue() == 1) { + deletePort(msg); + } + } + + protected void updatePort(PortStatus msg) { + Long portNumber = msg.getPortNo(); + Boolean portBandwidth = portFeaturesUtils.getPortBandwidth(msg); + + if(portBandwidth == null) { + LOG.warn("can't get bandwidth info from port: {}, aborting port update", msg.toString()); + } else { + this.getSessionContext().getPhysicalPorts().put(portNumber, msg); + this.getSessionContext().getPortsBandwidth().put(portNumber, portBandwidth); + } + } + + protected void deletePort(Port port) { + Long portNumber = port.getPortNo(); + + this.getSessionContext().getPhysicalPorts().remove(portNumber); + this.getSessionContext().getPortsBandwidth().remove(portNumber); + } @Override public void onSwitchIdleEvent(SwitchIdleEvent notification) { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV10Bandwidth.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV10Bandwidth.java new file mode 100644 index 0000000000..4162d0c20f --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV10Bandwidth.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2013 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.session; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port; + +/** + * + * @author jsebin + * + * Singleton for extracting port features for OF 1.0 + */ +public class FeaturesV10Bandwidth implements IGetBandwith { + + private static FeaturesV10Bandwidth instance = new FeaturesV10Bandwidth(); + + private FeaturesV10Bandwidth() {} + + /** + * + * @return instance of class + */ + public static FeaturesV10Bandwidth getInstance(){ + return instance; + } + + @Override + public boolean getBandwidth(Port port) { + return (port.getCurrentFeaturesV10().is_100mbFd() | port.getCurrentFeaturesV10().is_100mbHd() | port.getCurrentFeaturesV10().is_10gbFd() | + port.getCurrentFeaturesV10().is_10mbFd() | port.getCurrentFeaturesV10().is_10mbHd() | port.getCurrentFeaturesV10().is_1gbFd() | + port.getCurrentFeaturesV10().is_1gbHd() | port.getCurrentFeaturesV10().isAutoneg() | port.getCurrentFeaturesV10().isCopper() | + port.getCurrentFeaturesV10().isFiber() | port.getCurrentFeaturesV10().isPause() | port.getCurrentFeaturesV10().isPauseAsym()); + } + + + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV13Bandwidth.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV13Bandwidth.java new file mode 100644 index 0000000000..275819bb96 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV13Bandwidth.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2013 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.session; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port; + +/** + * + * @author jsebin + * + * Singleton for extracting port features for OF 1.3 + */ +public class FeaturesV13Bandwidth implements IGetBandwith { + + private static FeaturesV13Bandwidth instance = new FeaturesV13Bandwidth(); + + private FeaturesV13Bandwidth() {} + + /** + * + * @return instance of class + */ + public static FeaturesV13Bandwidth getInstance(){ + return instance; + } + + @Override + public boolean getBandwidth(Port port) { + return (port.getCurrentFeatures().is_100gbFd() | port.getCurrentFeatures().is_100mbFd() | port.getCurrentFeatures().is_100mbHd() | + port.getCurrentFeatures().is_10gbFd() | port.getCurrentFeatures().is_10mbFd() | port.getCurrentFeatures().is_10mbHd() | + port.getCurrentFeatures().is_1gbFd() | port.getCurrentFeatures().is_1gbHd() | port.getCurrentFeatures().is_1tbFd() | + port.getCurrentFeatures().is_40gbFd() | port.getCurrentFeatures().isAutoneg() | port.getCurrentFeatures().isCopper() | + port.getCurrentFeatures().isFiber() | port.getCurrentFeatures().isOther() | port.getCurrentFeatures().isPause() | + port.getCurrentFeatures().isPauseAsym()); + } + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/IGetBandwith.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/IGetBandwith.java new file mode 100644 index 0000000000..8b7fcc9b12 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/IGetBandwith.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2013 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.session; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port; + +/** + * Utility for extracting bandwith from port according to port version + * + * @author jsebin + * + */ +public interface IGetBandwith { + + /** + * + * @param port + * @return port bandwidth + */ + public boolean getBandwidth(Port port); +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtil.java new file mode 100644 index 0000000000..209515f0a8 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtil.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2013 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.session; + +import java.util.HashMap; +import java.util.Map; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Wrapper for bandwidth extracting utilities + * + * @author jsebin + * + */ +public class PortFeaturesUtil { + + private static PortFeaturesUtil instance = new PortFeaturesUtil(); + + private final Map portVersionBandwidth; + protected static final Logger LOG = LoggerFactory.getLogger(PortFeaturesUtil.class); + + private PortFeaturesUtil() { + this.portVersionBandwidth = new HashMap<>(); + + portVersionBandwidth.put((short) 1, FeaturesV10Bandwidth.getInstance()); + portVersionBandwidth.put((short) 4, FeaturesV13Bandwidth.getInstance()); + } + + /** + * + * @return instance + */ + public static PortFeaturesUtil getInstance() { + return instance; + } + + /** + * + * @param msg {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus} + * @return port bandwidth + */ + public Boolean getPortBandwidth(PortStatus msg) { + + if(portVersionBandwidth.containsKey(msg.getVersion()) == true) { + try { + return portVersionBandwidth.get(msg.getVersion()).getBandwidth(msg); + } catch (NullPointerException e) { + LOG.error("error while getting port features {}", e); + } + } + else { + LOG.warn("unknown port version: {}", msg.getVersion()); + } + + return null; + } + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java index f9a858ed72..e939ea0cb9 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java @@ -83,6 +83,12 @@ public interface SessionContext { * @return The Map of OFPhysicalPort */ public Map getPhysicalPorts(); + + /** + * Returns a map containing all bandwidths for all OFPorts of this switch. + * @return The Map of bandwidths for all OFPorts + */ + public Map getPortsBandwidth(); /** * Returns a Set containing all port IDs of this switch. @@ -124,9 +130,6 @@ public interface SessionContext { */ public List getEnabledPorts(); - public void processPortStatusMsg(PortStatus arg0); - - // TODO:: add listeners here, manager will set them and conductor use them /** diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java index f53ca2676f..ee7189cbe1 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java @@ -22,7 +22,6 @@ import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus; /** * @author mirehak @@ -136,6 +135,11 @@ public class SessionContextOFImpl implements SessionContext { public Map getPhysicalPorts() { return this.physicalPorts; } + + @Override + public Map getPortsBandwidth() { + return this.portBandwidth; + } @Override public Set getPorts() { @@ -186,39 +190,4 @@ public class SessionContextOFImpl implements SessionContext { } return result; } - - @Override - public void processPortStatusMsg(PortStatus msg) { - Port port = msg; - if (msg.getReason().getIntValue() == 2) { - updatePhysicalPort(port); - } else if (msg.getReason().getIntValue() == 0) { - updatePhysicalPort(port); - } else if (msg.getReason().getIntValue() == 1) { - deletePhysicalPort(port); - } - - } - - private void updatePhysicalPort(Port port) { - Long portNumber = port.getPortNo(); - physicalPorts.put(portNumber, port); - portBandwidth - .put(portNumber, - ( (port.getCurrentFeatures().is_100gbFd()) - |(port.getCurrentFeatures().is_100mbFd()) | (port.getCurrentFeatures().is_100mbHd()) - | (port.getCurrentFeatures().is_10gbFd()) | (port.getCurrentFeatures().is_10mbFd()) - | (port.getCurrentFeatures().is_10mbHd()) | (port.getCurrentFeatures().is_1gbFd()) - | (port.getCurrentFeatures().is_1gbHd()) | (port.getCurrentFeatures().is_1tbFd()) - | (port.getCurrentFeatures().is_40gbFd()) | (port.getCurrentFeatures().isAutoneg()) - | (port.getCurrentFeatures().isCopper()) | (port.getCurrentFeatures().isFiber()) - | (port.getCurrentFeatures().isOther()) | (port.getCurrentFeatures().isPause()) - | (port.getCurrentFeatures().isPauseAsym()) ) ); - } - - private void deletePhysicalPort(Port port) { - Long portNumber = port.getPortNo(); - physicalPorts.remove(portNumber); - portBandwidth.remove(portNumber); - } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java index 03b30abaa9..525c29acc0 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java @@ -26,12 +26,14 @@ import org.opendaylight.openflowplugin.openflow.md.core.plan.ConnectionAdapterSt import org.opendaylight.openflowplugin.openflow.md.core.plan.EventFactory; import org.opendaylight.openflowplugin.openflow.md.core.plan.SwitchTestEvent; import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContextOFImpl; import org.opendaylight.openflowplugin.openflow.md.queue.PopListener; import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ErrorType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; @@ -892,4 +894,65 @@ public class ConnectionConductorImplTest { return translatorMapping; } + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl#processPortStatusMsg(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)} + *

+ * Tests for getting features from port status message by port version + *
    + *
  • features are malformed - one of them is null
  • + *
  • mismatch between port version and port features
  • + *
  • mismatch between port version and port features
  • + *
  • non-existing port version
  • + *
  • port version OF 1.0
  • + *
  • port version OF 1.3
  • + *
+ * + */ + @Test + public void testProcessPortStatusMsg() { + SessionContextOFImpl ctx = new SessionContextOFImpl(); + connectionConductor.setSessionContext(ctx); + + long portNumber = 90L; + long portNumberV10 = 91L; + PortStatusMessage msg; + + PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); + PortFeatures features = new PortFeatures(true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false); + PortFeatures featuresMal = new PortFeatures(true,false,false,false,null,false,false,false,false,false,false,false,false,false,false,false); + PortFeaturesV10 featuresV10 = new PortFeaturesV10(true,false,false,false,false,false,false,false,false,false,false,false); + + //Malformed features + builder.setVersion((short) 1).setPortNo(portNumber).setReason(PortReason.OFPPRADD).setCurrentFeatures(featuresMal); + connectionConductor.processPortStatusMsg(builder.build()); + Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty()); + Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty()); + + //Version-features mismatch + builder.setCurrentFeatures(features); + connectionConductor.processPortStatusMsg(builder.build()); + Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty()); + Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty()); + + //Non existing version + builder.setVersion((short) 0); + connectionConductor.processPortStatusMsg(builder.build()); + Assert.assertTrue(connectionConductor.getSessionContext().getPortsBandwidth().isEmpty()); + Assert.assertTrue(connectionConductor.getSessionContext().getPhysicalPorts().isEmpty()); + + //Version OF 1.3 + builder.setVersion((short) 4); + msg = builder.build(); + connectionConductor.processPortStatusMsg(builder.build()); + Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumber)); + Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumber), msg); + + //Version OF 1.0 + builder.setVersion((short) 1).setPortNo(portNumberV10).setCurrentFeatures(null).setCurrentFeaturesV10(featuresV10); + msg = builder.build(); + connectionConductor.processPortStatusMsg(builder.build()); + Assert.assertTrue(connectionConductor.getSessionContext().getPortBandwidth(portNumberV10)); + Assert.assertEquals(connectionConductor.getSessionContext().getPhysicalPort(portNumberV10), msg); + } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java index da49bdd431..fe5c625549 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java @@ -282,9 +282,9 @@ class MockSessionContext implements SessionContext { } @Override - public void processPortStatusMsg(PortStatus arg0) { + public Map getPortsBandwidth() { // TODO Auto-generated method stub - + return null; } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtilTest.java new file mode 100644 index 0000000000..fcb412ad47 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtilTest.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2013 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.session; + +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; + +/** + * @author jsebin + */ +public class PortFeaturesUtilTest { + + private PortStatusMessageBuilder portStatusMessageBuilder; + private PortFeaturesUtil portUtil; + + + /** + * initialization of {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder.PortStatusMessageBuilder} + * and {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil} + * @throws Exception + */ + @Before + public void setUp() throws Exception { + portStatusMessageBuilder = new PortStatusMessageBuilder(); + portUtil = PortFeaturesUtil.getInstance(); + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + portStatusMessageBuilder = null; + portUtil = null; + } + + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil#getPortBandwidth()} for OF 1.0 version + * and features + * . + */ + @Test + public void testFeaturesV10() { + PortFeaturesV10 features = new PortFeaturesV10(true, true, true, false, true, false, true, true, true, false, true, false); + portStatusMessageBuilder.setReason(PortReason.OFPPRMODIFY).setVersion((short) 1).setCurrentFeaturesV10(features); + + Assert.assertNotNull(portUtil.getPortBandwidth(portStatusMessageBuilder.build())); + } + + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil#getPortBandwidth()} for OF 1.3 version + * and features + * . + */ + @Test + public void testFeaturesV13() { + PortFeatures features = new PortFeatures(true, true, true, false, true, false, true, true, true, false, true, false, false, true, false, false); + portStatusMessageBuilder.setReason(PortReason.OFPPRMODIFY).setVersion((short) 4).setCurrentFeatures(features); + + Assert.assertNotNull(portUtil.getPortBandwidth(portStatusMessageBuilder.build())); + } + + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil#getPortBandwidth()} for malformed features + * - at least one feature is null + * . + */ + @Test + public void testFeaturesMalformed() { + PortFeaturesV10 features = new PortFeaturesV10(true, true, true, true, true, true, false, false, false, false, true, null); + portStatusMessageBuilder.setReason(PortReason.OFPPRMODIFY).setVersion((short) 1).setCurrentFeaturesV10(features); + + Assert.assertNull(portUtil.getPortBandwidth(portStatusMessageBuilder.build())); + } + + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil#getPortBandwidth()} for mismatch between + * port version and port features + * . + */ + @Test + public void testFeaturesVersionMismatch() { + PortFeatures features = new PortFeatures(true, true, true, false, true, false, true, true, true, false, true, false, false, true, false, false); + portStatusMessageBuilder.setReason(PortReason.OFPPRMODIFY).setVersion((short) 1).setCurrentFeatures(features); + + Assert.assertNull(portUtil.getPortBandwidth(portStatusMessageBuilder.build())); + } + + /** + * Test method for + * {@link org.opendaylight.openflowplugin.openflow.md.core.session.PortFeaturesUtil#getPortBandwidth()} for nonexisting port version + * . + */ + @Test + public void testFeaturesNonexistingVersion() { + PortFeatures features = new PortFeatures(true, true, true, false, true, false, true, true, true, false, true, false, false, true, false, false); + portStatusMessageBuilder.setReason(PortReason.OFPPRMODIFY).setVersion((short) 0).setCurrentFeatures(features); + + Assert.assertNull(portUtil.getPortBandwidth(portStatusMessageBuilder.build())); + } + +} diff --git a/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java b/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java index e997988c5a..1dab8ac682 100644 --- a/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java +++ b/samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java @@ -4,8 +4,8 @@ import java.util.Collections; import java.util.List; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; @@ -13,7 +13,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddF import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; @@ -55,15 +56,15 @@ public class SimpleDropFirewallCli { ret.setMatch(match.build()); - DropAction dropAction = new DropActionBuilder().build(); + DropActionCase dropAction = new DropActionCaseBuilder().build(); ActionBuilder action = new ActionBuilder(); action.setAction(dropAction); List actions = Collections.singletonList(action.build()); // - ApplyActionsBuilder aaBldr = new ApplyActionsBuilder(); - aaBldr.setAction(actions); + ApplyActionsCaseBuilder aaBldr = new ApplyActionsCaseBuilder(); + aaBldr.setApplyActions(new ApplyActionsBuilder().setAction(actions).build()); InstructionBuilder instructionBldr = new InstructionBuilder(); instructionBldr.setInstruction(aaBldr.build());