Bug 2756 - Instruction model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / OpenflowUtils.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.util;
10
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
14
15 /**
16  * Used for common structures translation / conversion
17  *
18  * @author michal.polkorab
19  */
20 public abstract class OpenflowUtils {
21
22     private OpenflowUtils() {
23         //not called
24     }
25     
26     /**
27      * Creates PortState (OF v1.0) from input
28      * @param input value read from buffer
29      * @return port state
30      */
31     public static PortStateV10 createPortState(long input){
32         final Boolean psLinkDown = ((input) & (1<<0)) != 0;
33         final Boolean psBlocked = ((input) & (1<<1)) != 0;
34         final Boolean psLive = ((input) & (1<<2)) != 0;
35         final Boolean psStpListen = ((input) & (1<<8)) == 0;
36         final Boolean psStpLearn = ((input) & (1<<8)) != 0;
37         final Boolean psStpForward = ((input) & (1<<9)) != 0; // equals 2 << 8
38         final Boolean psStpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8
39         final Boolean psStpMask = ((input) & (1<<10)) != 0; // equals 4 << 8
40         return new PortStateV10(psBlocked, psLinkDown, psLive, psStpBlock, psStpForward, psStpLearn, psStpListen, psStpMask);
41     }
42
43     /**
44      * Creates PortConfig (OF v1.0) from input
45      * @param input value read from buffer
46      * @return port state
47      */
48     public static PortConfigV10 createPortConfig(long input){
49         final Boolean pcPortDown = ((input) & (1<<0)) != 0;
50         final Boolean pcNoStp = ((input) & (1<<1)) != 0;
51         final Boolean pcNoRecv = ((input) & (1<<2)) != 0;
52         final Boolean pcNoRecvStp = ((input) & (1<<3)) != 0;
53         final Boolean pcNoFlood = ((input) & (1<<4)) != 0;
54         final Boolean pcNoFwd  = ((input) & (1<<5)) != 0;
55         final Boolean pcNoPacketIn = ((input) & (1<<6)) != 0;
56         return new PortConfigV10(pcNoFlood, pcNoFwd, pcNoPacketIn, pcNoRecv, pcNoRecvStp, pcNoStp, pcPortDown);
57     }
58
59     /**
60      * Creates PortFeatures (OF v1.0) from input
61      * @param input value read from buffer
62      * @return port state
63      */
64     public static PortFeaturesV10 createPortFeatures(long input){
65         final Boolean pf10mbHd = ((input) & (1<<0)) != 0;
66         final Boolean pf10mbFd = ((input) & (1<<1)) != 0;
67         final Boolean pf100mbHd = ((input) & (1<<2)) != 0;
68         final Boolean pf100mbFd = ((input) & (1<<3)) != 0;
69         final Boolean pf1gbHd = ((input) & (1<<4)) != 0;
70         final Boolean pf1gbFd = ((input) & (1<<5)) != 0;
71         final Boolean pf10gbFd = ((input) & (1<<6)) != 0;
72         final Boolean pfCopper = ((input) & (1<<7)) != 0;
73         final Boolean pfFiber = ((input) & (1<<8)) != 0;
74         final Boolean pfAutoneg = ((input) & (1<<9)) != 0;
75         final Boolean pfPause = ((input) & (1<<10)) != 0;
76         final Boolean pfPauseAsym = ((input) & (1<<11)) != 0;
77         return new PortFeaturesV10(pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd,
78                 pf1gbFd, pf1gbHd, pfAutoneg, pfCopper, pfFiber, pfPause, pfPauseAsym);
79     }
80 }