-/**
+/*
* Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
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();
}
}
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;
}
-/**
+/*
* Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
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}
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++;
+ }
+ }
}
/*
* 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;
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());
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));
// 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()));
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());
}
/*
- * 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,
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);
}
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