package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
import com.google.common.collect.Ordering;
+
import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
*/
public final class ActionConvertor {
private static final Logger logger = LoggerFactory.getLogger(ActionConvertor.class);
-
+
private ActionConvertor() {
// NOOP
}
actionBuilder
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
List<MatchEntries> matchEntriesList = new ArrayList<>();
- matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(setnwtosaction.getTos().shortValue())));
+ matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(
+ ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue())
+ )));
oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
return actionBuilder.build();
--- /dev/null
+/**
+ * Copyright IBM Corporation, 2013. 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.util;
+
+
+/**
+ * OF-action related utilities
+ */
+public final class ActionUtil {
+
+ /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.) */
+ public static final int ENC_FIELD_BIT_SIZE = 2;
+
+ private ActionUtil() {
+ throw new AssertionError("ActionUtil is not expected to be instantiated.");
+ }
+
+ /**
+ * @param tosValue TypeOfService value
+ * @return DSCP value
+ */
+ public static Short tosToDscp(short tosValue) {
+ return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
+ }
+
+
+}
--- /dev/null
+/**
+ * Copyright (c) 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
+ */
+package org.opendaylight.openflowplugin.openflow.md.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+/**
+ * test of {@link ActionUtil}
+ */
+public class ActionUtilTest {
+
+ /**
+ * Test method for {@link org.opendaylight.openflowplugin.openflow.md.util.ActionUtil#tosToDscp(short)}.
+ */
+ @Test
+ public void testTosToDscp() {
+ Assert.assertEquals(0, ActionUtil.tosToDscp((short) 1).intValue());
+ Assert.assertEquals(1, ActionUtil.tosToDscp((short) 4).intValue());
+ Assert.assertEquals(63, ActionUtil.tosToDscp((short) 252).intValue());
+ }
+
+}