fix port update - honor message version 80/3580/3
authorJuraj Sebin <jsebin@cisco.com>
Mon, 2 Dec 2013 11:29:08 +0000 (12:29 +0100)
committerMichal Rehak <mirehak@cisco.com>
Tue, 10 Dec 2013 18:52:25 +0000 (19:52 +0100)
rebased

Change-Id: If0337c03de70d5788385095c2eaa26b54d8669b7
Signed-off-by: Juraj Sebin <jsebin@cisco.com>
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV10Bandwidth.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/FeaturesV13Bandwidth.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/IGetBandwith.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtil.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContext.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/SessionContextOFImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImplTest.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/session/PortFeaturesUtilTest.java [new file with mode: 0644]
samples/sample-consumer/src/main/java/org/opendaylight/openflowplugin/openflow/samples/consumer/SimpleDropFirewallCli.java

index b42597a5cdf6372216039850f9493025f859c2ee..ef87f96dad0079634f344d3e41be8a981f5d5757 100644 (file)
@@ -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 (file)
index 0000000..4162d0c
--- /dev/null
@@ -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 (file)
index 0000000..275819b
--- /dev/null
@@ -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 (file)
index 0000000..8b7fcc9
--- /dev/null
@@ -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 (file)
index 0000000..209515f
--- /dev/null
@@ -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<Short, IGetBandwith> 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;
+    }
+        
+}
index f9a858ed722b0b3bd73be889bf718e8f2f6a1263..e939ea0cb91978a85f01cdff02ec90c4f7108916 100644 (file)
@@ -83,6 +83,12 @@ public interface SessionContext {
      * @return The Map of OFPhysicalPort
      */
     public Map<Long, Port> getPhysicalPorts();
+    
+    /**
+     * Returns a map containing all bandwidths for all OFPorts of this switch.
+     * @return The Map of bandwidths for all OFPorts
+     */
+    public Map<Long, Boolean> getPortsBandwidth();
 
     /**
      * Returns a Set containing all port IDs of this switch.
@@ -124,9 +130,6 @@ public interface SessionContext {
      */
     public List<Port> getEnabledPorts();
 
-    public void processPortStatusMsg(PortStatus arg0);
-
-
     // TODO:: add listeners here, manager will set them and conductor use them
 
     /**
index f53ca2676f0599fca4392812f267b2454945f8f2..ee7189cbe193f55f48aa0b752902cc81e7f94178 100644 (file)
@@ -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<Long, Port> getPhysicalPorts() {
         return this.physicalPorts;
     }
+    
+    @Override
+    public Map<Long, Boolean> getPortsBandwidth() {
+        return this.portBandwidth;
+    }
 
     @Override
     public Set<Long> 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);
-    }
 }
index 03b30abaa9b2d36211241c14ca656ed3e2e064bf..525c29acc0f258c8b89e67da022aef08a588302d 100644 (file)
@@ -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)}
+     * <br><br> 
+     * Tests for getting features from port status message by port version 
+     * <ul>
+     * <li>features are malformed - one of them is null</li>
+     * <li>mismatch between port version and port features</li>
+     * <li>mismatch between port version and port features</li>
+     * <li>non-existing port version</li>
+     * <li>port version OF 1.0</li>
+     * <li>port version OF 1.3</li>
+     * </ul>
+     * 
+     */
+    @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);
+    }
 }
index da49bdd431da744a09ed5eb27d14dc115f4ef397..fe5c625549b5d0e9167a480501fd3415de560332 100644 (file)
@@ -282,9 +282,9 @@ class MockSessionContext implements SessionContext {
     }
 
     @Override
-    public void processPortStatusMsg(PortStatus arg0) {
+    public Map<Long, Boolean> 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 (file)
index 0000000..fcb412a
--- /dev/null
@@ -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()));
+    }
+
+}
index e997988c5a9c5e8a07e4f1ee14f53a58b3e50cbf..1dab8ac682ddab06e65e9afd9c60ae954f342b4d 100644 (file)
@@ -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<Action> 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());