2 * Copyright (c) 2013, 2015 IBM Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.util;
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import org.opendaylight.yangtools.yang.common.Uint8;
14 * OF-action related utilities.
16 public final class ActionUtil {
18 /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.). */
19 public static final int ENC_FIELD_BIT_SIZE = 2;
21 private ActionUtil() {
22 throw new AssertionError("ActionUtil is not expected to be instantiated.");
26 * Converts TOS to DSCP value.
28 * @param tosValue TypeOfService value
31 @SuppressFBWarnings("ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT")
32 public static Short tosToDscp(final short tosValue) {
33 return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
36 public static Uint8 tosToDscp(final Uint8 tosValue) {
37 return Uint8.valueOf(tosValue.toJava() >>> ActionUtil.ENC_FIELD_BIT_SIZE);
41 * Converts DSCP to TOS value.
43 * @param dscpValue TypeOfService value
46 public static Short dscpToTos(final short dscpValue) {
47 return (short) (dscpValue << ActionUtil.ENC_FIELD_BIT_SIZE);