2 * Copyright (c) 2014 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.util;
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;
16 * Used for common structures translation / conversion
18 * @author michal.polkorab
20 public abstract class OpenflowUtils {
23 * Creates PortState (OF v1.0) from input
24 * @param input value read from buffer
27 public static PortStateV10 createPortState(long input){
28 final Boolean psLinkDown = ((input) & (1<<0)) != 0;
29 final Boolean psBlocked = ((input) & (1<<1)) != 0;
30 final Boolean psLive = ((input) & (1<<2)) != 0;
31 final Boolean psStpListen = ((input) & (1<<8)) == 0;
32 final Boolean psStpLearn = ((input) & (1<<8)) != 0;
33 final Boolean psStpForward = ((input) & (1<<9)) != 0; // equals 2 << 8
34 final Boolean psStpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8
35 final Boolean psStpMask = ((input) & (1<<10)) != 0; // equals 4 << 8
36 return new PortStateV10(psBlocked, psLinkDown, psLive, psStpBlock, psStpForward, psStpLearn, psStpListen, psStpMask);
40 * Creates PortConfig (OF v1.0) from input
41 * @param input value read from buffer
44 public static PortConfigV10 createPortConfig(long input){
45 final Boolean pcPortDown = ((input) & (1<<0)) != 0;
46 final Boolean pcNoStp = ((input) & (1<<1)) != 0;
47 final Boolean pcNoRecv = ((input) & (1<<2)) != 0;
48 final Boolean pcNoRecvStp = ((input) & (1<<3)) != 0;
49 final Boolean pcNoFlood = ((input) & (1<<4)) != 0;
50 final Boolean pcNoFwd = ((input) & (1<<5)) != 0;
51 final Boolean pcNoPacketIn = ((input) & (1<<6)) != 0;
52 return new PortConfigV10(pcNoFlood, pcNoFwd, pcNoPacketIn, pcNoRecv, pcNoRecvStp, pcNoStp, pcPortDown);
56 * Creates PortFeatures (OF v1.0) from input
57 * @param input value read from buffer
60 public static PortFeaturesV10 createPortFeatures(long input){
61 final Boolean pf10mbHd = ((input) & (1<<0)) != 0;
62 final Boolean pf10mbFd = ((input) & (1<<1)) != 0;
63 final Boolean pf100mbHd = ((input) & (1<<2)) != 0;
64 final Boolean pf100mbFd = ((input) & (1<<3)) != 0;
65 final Boolean pf1gbHd = ((input) & (1<<4)) != 0;
66 final Boolean pf1gbFd = ((input) & (1<<5)) != 0;
67 final Boolean pf10gbFd = ((input) & (1<<6)) != 0;
68 final Boolean pfCopper = ((input) & (1<<7)) != 0;
69 final Boolean pfFiber = ((input) & (1<<8)) != 0;
70 final Boolean pfAutoneg = ((input) & (1<<9)) != 0;
71 final Boolean pfPause = ((input) & (1<<10)) != 0;
72 final Boolean pfPauseAsym = ((input) & (1<<11)) != 0;
73 return new PortFeaturesV10(pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd,
74 pf1gbFd, pf1gbHd, pfAutoneg, pfCopper, pfFiber, pfPause, pfPauseAsym);