Enable AD-SAL application to configure OF 1.3 PUSH_VLAN action. 01/8801/2
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 8 Jul 2014 14:29:39 +0000 (23:29 +0900)
committerEd Warnicke <eaw@cisco.com>
Fri, 5 Sep 2014 00:33:00 +0000 (00:33 +0000)
OF 1.3 PUSH_VLAN action takes only one argument, ethernet type,
and its value must be 0x8100 or 0x88a8.

Change-Id: I4d6bcabb430245594b747e31f9edb2034f39acb6
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java
opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java

index 9b5d0e887541da50e9a802811b84e046f3573b7d..5837e35b3a65b7bb4a7b8fc7c0ae2517cbe07db6 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -272,10 +272,7 @@ public final class MDFlowMapping {
         return new PushVlanActionCaseBuilder()
         .setPushVlanAction(
                 new PushVlanActionBuilder()
-                .setCfi(new VlanCfi(sourceAction.getCfi()))
-                .setPcp(sourceAction.getPcp())
-                .setTag(sourceAction.getTag())
-                .setVlanId(new VlanId(sourceAction.getVlanId()))
+                .setEthernetType(Integer.valueOf(sourceAction.getTag()))
                 .build()
                 ).build();
     }
index 58cfb20650930f82f5768fa9f96bbcd1e287ad14..28dd57c3b7986fecabae2c2fa9749e8d58fbd36e 100644 (file)
@@ -356,23 +356,9 @@ public class ToSalConversionsUtils {
     }
 
     private static PushVlan pushVlanFrom(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction pushVlanAction) {
-        final int tag;
-        final int pcp;
-        final int cfi;
-        final int vlanId;
-
-        if (pushVlanAction.getTag() != null) {
-            tag = pushVlanAction.getTag();
-            if (pushVlanAction.getPcp() != null) {
-                pcp = pushVlanAction.getPcp();
-                if (pushVlanAction.getCfi() != null && pushVlanAction.getCfi().getValue() != null) {
-                    cfi = pushVlanAction.getCfi().getValue();
-                    if (pushVlanAction.getVlanId() != null && pushVlanAction.getVlanId().getValue() != null) {
-                        vlanId = pushVlanAction.getVlanId().getValue();
-                        return new PushVlan(tag, pcp, cfi, vlanId);
-                    }
-                }
-            }
+        Integer tag = pushVlanAction.getTag();
+        if (tag != null) {
+            return new PushVlan(tag.intValue());
         }
         return null;
     }
index 4e5f318d4c479711b137cce98d4b59ad6cda33d9..78e82c32de856c36178445d0638fab34af2880c6 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -10,13 +10,18 @@ package org.opendaylight.controller.sal.compatibility.test;
 import junit.framework.Assert;
 
 import org.junit.Test;
+import org.opendaylight.controller.sal.action.Action;
+import org.opendaylight.controller.sal.action.PushVlan;
 import org.opendaylight.controller.sal.compatibility.MDFlowMapping;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.Node.NodeIDType;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
+import org.opendaylight.controller.sal.utils.EtherTypes;
+
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
 
 /**
  * test for {@link MDFlowMapping}
@@ -36,4 +41,29 @@ public class MDFlowMappingTest {
         Assert.assertEquals("openflow:41:42", observed.getValue());
     }
 
+    /**
+     * Test method for {@link MDFlowMapping#toAction(Action, int)}.
+     */
+    @Test
+    public void testToAction() {
+        // PUSH_VLAN test.
+        EtherTypes[] tags = {EtherTypes.VLANTAGGED, EtherTypes.QINQ};
+        int order = 0;
+        for (EtherTypes tag: tags) {
+            Action action = new PushVlan(tag);
+            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
+                rev131112.action.list.Action mdActionList =
+                MDFlowMapping.toAction(action, order);
+            Assert.assertEquals(order, mdActionList.getOrder().intValue());
+
+            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
+                rev131112.action.Action mdAction = mdActionList.getAction();
+            Assert.assertTrue(mdAction instanceof PushVlanActionCase);
+            PushVlanActionCase pushVlan = (PushVlanActionCase)mdAction;
+            Assert.assertEquals(tag.intValue(),
+                                pushVlan.getPushVlanAction().getEthernetType().
+                                intValue());
+            order++;
+        }
+    }
 }
index e9f56f6a0301798b963fe9fb567c34076a640a44..9f787b7e391010cee640d6b0582c4e0447ded4c2 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Copyright (c) 2013-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
-*/
+ *
+ * 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.controller.sal.compatibility.test;
 
 import static org.junit.Assert.assertEquals;
@@ -272,14 +272,8 @@ public class TestFromSalConversionsUtils {
             if (cl.isInstance(innerAction)) {
                 numOfFoundActions++;
                 if (innerAction instanceof PushVlanActionCase) {
-                    assertEquals("Wrong value of cfi in PushVlanAction.", (Integer) 1, ((PushVlanActionCase) innerAction).getPushVlanAction()
-                            .getCfi().getValue());
-                    assertEquals("Wrong value of pcp in PushVlanAction.", (Integer) 7,
-                            ((PushVlanActionCase) innerAction).getPushVlanAction().getPcp());
                     assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100,
-                            ((PushVlanActionCase) innerAction).getPushVlanAction().getTag());
-                    assertEquals("Wrong value of vlad ID in PushVlanAction.", (Integer) 4095,
-                            ((PushVlanActionCase) innerAction).getPushVlanAction().getVlanId().getValue());
+                            ((PushVlanActionCase) innerAction).getPushVlanAction().getEthernetType());
                 } else if (innerAction instanceof SetDlDstActionCase) {
                     assertEquals("Wrong MAC destination address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
                             ((SetDlDstActionCase) innerAction).getSetDlDstAction().getAddress().getValue());
@@ -420,7 +414,7 @@ public class TestFromSalConversionsUtils {
         salActions.add(new Loopback());
         // salActions.add(new Output //TODO: mapping is missing
         salActions.add(new PopVlan());
-        salActions.add(new PushVlan(0x8100, 7, 1, 4095));
+        salActions.add(new PushVlan(0x8100));
         salActions.add(new SetDlDst(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
         salActions.add(new SetDlSrc(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
         salActions.add(new SetDlType(513));
index 7601a7d9cf67ba543d50d8e49b3fb0d6bbe1ae82..60b77394c1f15e8055d93afa259862dccd33c5a3 100644 (file)
@@ -330,9 +330,6 @@ public class TestToSalConversionsUtils {
             // be defined
         } else if (action instanceof PushVlan) {
             assertEquals("Wrong value for action PushVlan for tag.", 0x8100, ((PushVlan) action).getTag());
-            assertEquals("Wrong value for action PushVlan for pcp.", 7, ((PushVlan) action).getPcp());
-            assertEquals("Wrong value for action PushVlan for cfi.", 1, ((PushVlan) action).getCfi());
-            assertEquals("Wrong value for action PushVlan for vlanID.", 4095, ((PushVlan) action).getVlanId());
         } else if (action instanceof SetDlDst) {
             //assertEquals("Wrong value for action SetDlDst for MAC address.", "3C:A9:F4:00:E0:C8", new String(
             //        ((SetDlDst) action).getDlAddress()));
@@ -575,9 +572,6 @@ public class TestToSalConversionsUtils {
 
     private void prepareActionPushVlan(PushVlanActionCaseBuilder wrapper) {
         PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder();
-        pushVlanActionBuilder.setPcp(7); // 3 bits
-        pushVlanActionBuilder.setCfi(new VlanCfi(1)); // 1 bit
-        pushVlanActionBuilder.setVlanId(new VlanId(4095));
         pushVlanActionBuilder.setTag(0x8100); // 12 bit
         wrapper.setPushVlanAction(pushVlanActionBuilder.build());
     }
index edb30ae031ac25f344b447aa83a6344c3f0965c6..a1b50edd5116fcc8a451d86ae2dff61d5f2b643e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013-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,
@@ -59,6 +59,32 @@ public class PushVlan extends Action {
         runChecks();
     }
 
+    /**
+     * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
+     *
+     * @param tag  An {@link EtherTypes} instance.
+     */
+    public PushVlan(EtherTypes tag) {
+        this(tag.intValue());
+    }
+
+    /**
+     * Construct a new action instance which represents OF 1.3 PUSH_VLAN.
+     *
+     * @param tag  An ethernet type of a new VLAN tag.
+     */
+    public PushVlan(int tag) {
+        type = ActionType.PUSH_VLAN;
+        this.tag = tag;
+
+        if (tag != EtherTypes.VLANTAGGED.intValue() &&
+            tag != EtherTypes.QINQ.intValue()) {
+            // pass a value which will tell fail and tell something about the
+            // original wrong value
+            checkValue(ActionType.SET_DL_TYPE, 0xBAD << 16 | tag);
+        }
+    }
+
     private int createTci() {
         return (pcp & 0x7) << 13 | (cfi & 0x1) << 12 | (vlanId & 0xfff);
     }
index 3fe9a18b3fa545cbdcf279092c272c43a34d4cc1..14f0d83ff670d7343b1b67e59796cdec44223cf9 100644 (file)
@@ -87,6 +87,24 @@ public class ActionTest {
 
         action = new PushVlan(EtherTypes.QINQ, 0x4, -1, 2000);
         Assert.assertFalse(action.isValid());
+
+        // OF 1.3 PUSH_VLAN test.
+        for (EtherTypes tag: EtherTypes.values()) {
+            int t = tag.intValue();
+            boolean valid =
+                (tag == EtherTypes.VLANTAGGED || tag == EtherTypes.QINQ);
+            PushVlan pv = new PushVlan(tag);
+            Assert.assertEquals(valid, pv.isValid());
+            if (valid) {
+                Assert.assertEquals(t, pv.getTag());
+            }
+
+            pv = new PushVlan(t);
+            Assert.assertEquals(valid, pv.isValid());
+            if (valid) {
+                Assert.assertEquals(t, pv.getTag());
+            }
+        }
     }
 
     @Test