BUG-1994: IP ToS bits match field for OF 1.0
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / util / ActionUtil.java
1 /**
2  * Copyright IBM Corporation, 2013.  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
11 /**
12  * OF-action related utilities
13  */
14 public final class ActionUtil {
15
16     /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.) */
17     public static final int ENC_FIELD_BIT_SIZE = 2;
18
19     private ActionUtil() {
20         throw new AssertionError("ActionUtil is not expected to be instantiated.");
21     }
22
23     /**
24      * @param tosValue TypeOfService value
25      * @return DSCP value
26      */
27     public static Short tosToDscp(short tosValue) {
28         return (short) (tosValue >>> ActionUtil.ENC_FIELD_BIT_SIZE);
29     }
30     
31     /**
32      * @param dscpValue TypeOfService value
33      * @return TOS value
34      */
35     public static Short dscpToTos(short dscpValue) {
36         return (short) (dscpValue << ActionUtil.ENC_FIELD_BIT_SIZE);
37     }
38
39     
40 }