Merge "Turn extension/pom.xml into an aggregator"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / util / ActionUtil.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.openflow.md.util;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import org.opendaylight.yangtools.yang.common.Uint8;
12
13 /**
14  * OF-action related utilities.
15  */
16 public final class ActionUtil {
17
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;
20
21     private ActionUtil() {
22         throw new AssertionError("ActionUtil is not expected to be instantiated.");
23     }
24
25     /**
26      * Converts TOS to DSCP value.
27      *
28      * @param tosValue TypeOfService value
29      * @return DSCP value
30      */
31     @SuppressFBWarnings("ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT")
32     public static Short tosToDscp(final short tosValue) {
33         return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
34     }
35
36     public static Uint8 tosToDscp(final Uint8 tosValue) {
37         return Uint8.valueOf(tosValue.toJava() >>> ActionUtil.ENC_FIELD_BIT_SIZE);
38     }
39
40     /**
41      * Converts DSCP to TOS value.
42      *
43      * @param dscpValue TypeOfService value
44      * @return TOS value
45      */
46     public static Short dscpToTos(final short dscpValue) {
47         return (short) (dscpValue << ActionUtil.ENC_FIELD_BIT_SIZE);
48     }
49 }