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%2FOF10FeaturesReplyMessageFactory.java;h=469f920edfa50555233182dd0fa0d65f6ef9f78b;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=7c6dc262a265e53466724d7d9eace891f7ff7432;hpb=58d3805deba3b135427167cdd5bea1024a4e3c91;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java index 7c6dc262..469f920e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10FeaturesReplyMessageFactory.java @@ -1,159 +1,105 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.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.ActionTypeV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder; - -/** - * Translates FeaturesReply messages (OpenFlow v1.0) - * @author michal.polkorab - */ -public class OF10FeaturesReplyMessageFactory implements OFDeserializer { - - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3; - - private static OF10FeaturesReplyMessageFactory instance; - - private OF10FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new OF10FeaturesReplyMessageFactory(); - } - return instance; - } - - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); - builder.setVersion(version); - builder.setXid(rawMessage.readUnsignedInt()); - byte[] datapathId = new byte[Long.SIZE/Byte.SIZE]; - rawMessage.readBytes(datapathId); - builder.setDatapathId(new BigInteger(datapathId)); - builder.setBuffers(rawMessage.readUnsignedInt()); - builder.setTables(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); - builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt())); - builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt())); - List ports = new ArrayList<>(); - while (rawMessage.readableBytes() > 0) { - ports.add(deserializePort(rawMessage)); - } - builder.setPhyPort(ports); - return builder.build(); - } - - private static CapabilitiesV10 createCapabilitiesV10(long input) { - final Boolean FLOW_STATS = (input & (1 << 0)) != 0; - final Boolean TABLE_STATS = (input & (1 << 1)) != 0; - final Boolean PORT_STATS = (input & (1 << 2)) != 0; - final Boolean STP = (input & (1 << 3)) != 0; - final Boolean RESERVED = (input & (1 << 4)) != 0; - final Boolean IP_REASM = (input & (1 << 5)) != 0; - final Boolean QUEUE_STATS = (input & (1 << 6)) != 0; - final Boolean ARP_MATCH_IP = (input & (1 << 7)) != 0; - return new CapabilitiesV10(ARP_MATCH_IP, FLOW_STATS, IP_REASM, - PORT_STATS, QUEUE_STATS, RESERVED, STP, TABLE_STATS); - } - - private static ActionTypeV10 createActionsV10(long input) { - final Boolean OUTPUT = (input & (1 << 0)) != 0; - final Boolean SET_VLAN_VID = (input & (1 << 1)) != 0; - final Boolean SET_VLAN_PCP = (input & (1 << 2)) != 0; - final Boolean STRIP_VLAN = (input & (1 << 3)) != 0; - final Boolean SET_DL_SRC = (input & (1 << 4)) != 0; - final Boolean SET_DL_DST = (input & (1 << 5)) != 0; - final Boolean SET_NW_SRC = (input & (1 << 6)) != 0; - final Boolean SET_NW_DST = (input & (1 << 7)) != 0; - final Boolean SET_NW_TOS = (input & (1 << 8)) != 0; - final Boolean SET_TP_SRC = (input & (1 << 9)) != 0; - final Boolean SET_TP_DST = (input & (1 << 10)) != 0; - final Boolean ENQUEUE = (input & (1 << 11)) != 0; - final Boolean VENDOR = (input & (1 << 12)) != 0; - return new ActionTypeV10(ENQUEUE, OUTPUT, SET_DL_DST, SET_DL_SRC, - SET_NW_DST, SET_NW_SRC, SET_NW_TOS, SET_TP_DST, SET_TP_SRC, - SET_VLAN_PCP, SET_VLAN_VID, STRIP_VLAN, VENDOR); - } - - private static PhyPort deserializePort(ByteBuf rawMessage) { - PhyPortBuilder builder = new PhyPortBuilder(); - builder.setPortNo((long) rawMessage.readUnsignedShort()); - byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; - rawMessage.readBytes(address); - builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); - builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); - builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt())); - builder.setStateV10(createPortState(rawMessage.readUnsignedInt())); - builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt())); - return builder.build(); - } - - - - private static PortStateV10 createPortState(long input){ - final Boolean _linkDown = ((input) & (1<<0)) != 0; - final Boolean _blocked = ((input) & (1<<1)) != 0; - final Boolean _live = ((input) & (1<<2)) != 0; - final Boolean _stpListen = ((input) & (0<<8)) != 0; - final Boolean _stpLearn = ((input) & (1<<8)) != 0; - final Boolean _stpForward = ((input) & (1<<9)) != 0; // equals 2 << 8 - final Boolean _stpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8 - final Boolean _stpMask = ((input) & (1<<10)) != 0; // equals 4 << 8 - return new PortStateV10(_blocked, _linkDown, _live, _stpBlock, _stpForward, _stpLearn, _stpListen, _stpMask); - } - - private static PortConfigV10 createPortConfig(long input){ - final Boolean _portDown = ((input) & (1<<0)) != 0; - final Boolean _noStp = ((input) & (1<<1)) != 0; - final Boolean _noRecv = ((input) & (1<<2)) != 0; - final Boolean _noRecvStp = ((input) & (1<<3)) != 0; - final Boolean _noFlood = ((input) & (1<<4)) != 0; - final Boolean _noFwd = ((input) & (1<<5)) != 0; - final Boolean _noPacketIn = ((input) & (1<<6)) != 0; - return new PortConfigV10(_noFlood, _noFwd, _noPacketIn, _noRecv, _noRecvStp, _noStp, _portDown); - } - - private static PortFeaturesV10 createPortFeatures(long input){ - final Boolean _10mbHd = ((input) & (1<<0)) != 0; - final Boolean _10mbFd = ((input) & (1<<1)) != 0; - final Boolean _100mbHd = ((input) & (1<<2)) != 0; - final Boolean _100mbFd = ((input) & (1<<3)) != 0; - final Boolean _1gbHd = ((input) & (1<<4)) != 0; - final Boolean _1gbFd = ((input) & (1<<5)) != 0; - final Boolean _10gbFd = ((input) & (1<<6)) != 0; - final Boolean _copper = ((input) & (1<<7)) != 0; - final Boolean _fiber = ((input) & (1<<8)) != 0; - final Boolean _autoneg = ((input) & (1<<9)) != 0; - final Boolean _pause = ((input) & (1<<10)) != 0; - final Boolean _pauseAsym = ((input) & (1<<11)) != 0; - return new PortFeaturesV10(_100mbFd, _100mbHd, _10gbFd, _10mbFd, _10mbHd, - _1gbFd, _1gbHd, _autoneg, _copper, _fiber, _pause, _pauseAsym); - } - -} +/* + * 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 java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowjava.protocol.impl.util.OpenflowUtils; +import org.opendaylight.openflowjava.util.ByteBufUtils; +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.ActionTypeV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder; + +/** + * Translates FeaturesReply messages (OpenFlow v1.0) + * @author michal.polkorab + */ +public class OF10FeaturesReplyMessageFactory implements OFDeserializer { + + private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3; + + @Override + public GetFeaturesOutput deserialize(ByteBuf rawMessage) { + GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); + builder.setVersion((short) EncodeConstants.OF10_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + rawMessage.readBytes(datapathId); + builder.setDatapathId(new BigInteger(1, datapathId)); + builder.setBuffers(rawMessage.readUnsignedInt()); + builder.setTables(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); + builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt())); + builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt())); + List ports = new ArrayList<>(); + while (rawMessage.readableBytes() > 0) { + ports.add(deserializePort(rawMessage)); + } + builder.setPhyPort(ports); + return builder.build(); + } + + private static CapabilitiesV10 createCapabilitiesV10(long input) { + final Boolean flowStats = (input & (1 << 0)) != 0; + final Boolean tableStats = (input & (1 << 1)) != 0; + final Boolean portStats = (input & (1 << 2)) != 0; + final Boolean stp = (input & (1 << 3)) != 0; + final Boolean reserved = (input & (1 << 4)) != 0; + final Boolean ipReasm = (input & (1 << 5)) != 0; + final Boolean queueStats = (input & (1 << 6)) != 0; + final Boolean arpMatchIp = (input & (1 << 7)) != 0; + return new CapabilitiesV10(arpMatchIp, flowStats, ipReasm, + portStats, queueStats, reserved, stp, tableStats); + } + + private static ActionTypeV10 createActionsV10(long input) { + final Boolean output = (input & (1 << 0)) != 0; + final Boolean setVLANvid = (input & (1 << 1)) != 0; + final Boolean setVLANpcp = (input & (1 << 2)) != 0; + final Boolean stripVLAN = (input & (1 << 3)) != 0; + final Boolean setDLsrc = (input & (1 << 4)) != 0; + final Boolean setDLdst = (input & (1 << 5)) != 0; + final Boolean setNWsrc = (input & (1 << 6)) != 0; + final Boolean setNWdst = (input & (1 << 7)) != 0; + final Boolean setNWtos = (input & (1 << 8)) != 0; + final Boolean setTPsrc = (input & (1 << 9)) != 0; + final Boolean setTPdst = (input & (1 << 10)) != 0; + final Boolean enqueue = (input & (1 << 11)) != 0; + final Boolean vendor = (input & (1 << 12)) != 0; + return new ActionTypeV10(enqueue, output, setDLdst, setDLsrc, + setNWdst, setNWsrc, setNWtos, setTPdst, setTPsrc, + setVLANpcp, setVLANvid, stripVLAN, vendor); + } + + private static PhyPort deserializePort(ByteBuf rawMessage) { + PhyPortBuilder builder = new PhyPortBuilder(); + builder.setPortNo((long) rawMessage.readUnsignedShort()); + byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; + rawMessage.readBytes(address); + builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address))); + builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH)); + builder.setConfigV10(OpenflowUtils.createPortConfig(rawMessage.readUnsignedInt())); + builder.setStateV10(OpenflowUtils.createPortState(rawMessage.readUnsignedInt())); + builder.setCurrentFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt())); + builder.setAdvertisedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt())); + builder.setSupportedFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt())); + builder.setPeerFeaturesV10(OpenflowUtils.createPortFeatures(rawMessage.readUnsignedInt())); + return builder.build(); + } +} \ No newline at end of file