From: Shigeru Yasuda Date: Tue, 8 Jul 2014 14:29:39 +0000 (+0900) Subject: Enable AD-SAL application to configure OF 1.3 PUSH_VLAN action. X-Git-Tag: release/helium~130^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=e38e37d94000a573ccfec627f490d1847ae6304d Enable AD-SAL application to configure OF 1.3 PUSH_VLAN action. 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 --- diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java index 9b5d0e8875..5837e35b3a 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.java @@ -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(); } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java index 58cfb20650..28dd57c3b7 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java @@ -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; } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java index 4e5f318d4c..78e82c32de 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/MDFlowMappingTest.java @@ -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++; + } + } } diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java index e9f56f6a03..9f787b7e39 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java @@ -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)); diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java index 7601a7d9cf..60b77394c1 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java @@ -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()); } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java index edb30ae031..a1b50edd51 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/PushVlan.java @@ -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); } diff --git a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java index 3fe9a18b3f..14f0d83ff6 100644 --- a/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java +++ b/opendaylight/sal/api/src/test/java/org/opendaylight/controller/sal/action/ActionTest.java @@ -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