X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FPortStatusMessageFactory.java;h=fe3d7ac7bf4103a77ba722c247f262e745416897;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=79183330362bf6d7cc5794aa9e87d8ceec998b03;hpb=f7b135c5a0fab2841b445a567b27271081722984;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java index 79183330..fe3d7ac7 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java @@ -1,50 +1,95 @@ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class PortStatusMessageFactory implements OFDeserializer { - - private static PortStatusMessageFactory instance; - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 7; - - private PortStatusMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static PortStatusMessageFactory getInstance(){ - if(instance == null){ - - instance = new PortStatusMessageFactory(); - } - - return instance; - } - - @Override - public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) { - PortStatusMessageBuilder psmb = new PortStatusMessageBuilder(); - psmb.setVersion(version); - psmb.setXid(rawMessage.readUnsignedInt()); - -// TODO enum portReason -// psmb.setReason(PortReason.values()[rawMessage.readInt()]); - rawMessage.skipBytes(1); //instead of portReason enum - - rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); - return psmb.build(); - } - - - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder; + +/** + * Translates PortStatus messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class PortStatusMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_PORT_STATUS_HEADER = 7; + private static final byte PADDING_IN_OFP_PORT_HEADER_1 = 4; + private static final byte PADDING_IN_OFP_PORT_HEADER_2 = 2; + + @Override + public PortStatusMessage deserialize(ByteBuf rawMessage) { + PortStatusMessageBuilder builder = new PortStatusMessageBuilder(); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + builder.setReason(PortReason.forValue(rawMessage.readUnsignedByte())); + rawMessage.skipBytes(PADDING_IN_PORT_STATUS_HEADER); + builder.setPortNo(rawMessage.readUnsignedInt()); + rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_1); + byte[] hwAddress = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(hwAddress); + builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(hwAddress))); + rawMessage.skipBytes(PADDING_IN_OFP_PORT_HEADER_2); + builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); + builder.setConfig(createPortConfig(rawMessage.readUnsignedInt())); + builder.setState(createPortState(rawMessage.readUnsignedInt())); + builder.setCurrentFeatures(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setAdvertisedFeatures(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setSupportedFeatures(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setPeerFeatures(createPortFeatures(rawMessage.readUnsignedInt())); + builder.setCurrSpeed(rawMessage.readUnsignedInt()); + builder.setMaxSpeed(rawMessage.readUnsignedInt()); + return builder.build(); + } + + private static PortFeatures createPortFeatures(long input){ + final Boolean pf10mbHd = ((input) & (1<<0)) != 0; + final Boolean pf10mbFd = ((input) & (1<<1)) != 0; + final Boolean pf100mbHd = ((input) & (1<<2)) != 0; + final Boolean pf100mbFd = ((input) & (1<<3)) != 0; + final Boolean pf1gbHd = ((input) & (1<<4)) != 0; + final Boolean pf1gbFd = ((input) & (1<<5)) != 0; + final Boolean pf10gbFd = ((input) & (1<<6)) != 0; + final Boolean pf40gbFd = ((input) & (1<<7)) != 0; + final Boolean pf100gbFd = ((input) & (1<<8)) != 0; + final Boolean pf1tbFd = ((input) & (1<<9)) != 0; + final Boolean pfOther = ((input) & (1<<10)) != 0; + final Boolean pfCopper = ((input) & (1<<11)) != 0; + final Boolean pfFiber = ((input) & (1<<12)) != 0; + final Boolean pfAutoneg = ((input) & (1<<13)) != 0; + final Boolean pfPause = ((input) & (1<<14)) != 0; + final Boolean pfPauseAsym = ((input) & (1<<15)) != 0; + return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd, + pf1gbHd, pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym); + } + + private static PortState createPortState(long input){ + final Boolean psLinkDown = ((input) & (1<<0)) != 0; + final Boolean psBblocked = ((input) & (1<<1)) != 0; + final Boolean psLive = ((input) & (1<<2)) != 0; + return new PortState(psBblocked, psLinkDown, psLive); + } + + private static PortConfig createPortConfig(long input){ + final Boolean pcPortDown = ((input) & (1<<0)) != 0; + final Boolean pcNoRecv = ((input) & (1<<2)) != 0; + final Boolean pcNoFwd = ((input) & (1<<5)) != 0; + final Boolean pcNoPacketIn = ((input) & (1<<6)) != 0; + return new PortConfig(pcNoFwd, pcNoPacketIn, pcNoRecv, pcPortDown); + } +}