X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Ffactories%2FOF10PortModInputMessageFactory.java;h=7f452bb2df3037781da2366a567618d2d6b83bfe;hb=4a87ddbf7738a0dbfd65949c1f006991972d5f8a;hp=ef53543cdc9d6b0c3f6d464a3ce6ec2334482355;hpb=55670826f95d73afa4292f8cf729778e38d07aeb;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java index ef53543c..7f452bb2 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10PortModInputMessageFactory.java @@ -1,100 +1,72 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.serialization.factories; - -import io.netty.buffer.ByteBuf; - -import java.util.HashMap; -import java.util.Map; - -import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -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.protocol.rev130731.PortModInput; - -/** - * Translates PortMod messages - * @author michal.polkorab - */ -public class OF10PortModInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 15; - private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4; - private static final int MESSAGE_LENGTH = 32; - - private static OF10PortModInputMessageFactory instance; - - private OF10PortModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10PortModInputMessageFactory getInstance() { - if (instance == null) { - instance = new OF10PortModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, PortModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeShort(message.getPortNo().getValue().intValue()); - out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); - out.writeInt(createPortConfigBitmask(message.getConfigV10())); - out.writeInt(createPortConfigBitmask(message.getMaskV10())); - out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10())); - ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, out); - } - - @Override - public int computeLength(PortModInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - - /** - * @param config - * @return port config bitmask - */ - private static int createPortConfigBitmask(PortConfigV10 config) { - int configBitmask = 0; - Map portConfigMap = new HashMap<>(); - portConfigMap.put(0, config.isPortDown()); - portConfigMap.put(1, config.isNoStp()); - portConfigMap.put(2, config.isNoRecv()); - portConfigMap.put(3, config.isNoRecvStp()); - portConfigMap.put(4, config.isNoFlood()); - portConfigMap.put(5, config.isNoFwd()); - portConfigMap.put(6, config.isNoPacketIn()); - - configBitmask = ByteBufUtils.fillBitMaskFromMap(portConfigMap); - return configBitmask; - } - - private static int createPortFeaturesBitmask(PortFeaturesV10 feature) { - int configBitmask = 0; - Map portFeaturesMap = new HashMap<>(); - portFeaturesMap.put(0, feature.is_10mbHd()); - portFeaturesMap.put(1, feature.is_10mbFd()); - portFeaturesMap.put(2, feature.is_100mbHd()); - portFeaturesMap.put(3, feature.is_100mbFd()); - portFeaturesMap.put(4, feature.is_1gbHd()); - portFeaturesMap.put(5, feature.is_1gbFd()); - portFeaturesMap.put(6, feature.is_10gbFd()); - portFeaturesMap.put(7, feature.isCopper()); - portFeaturesMap.put(8, feature.isFiber()); - portFeaturesMap.put(9, feature.isAutoneg()); - portFeaturesMap.put(10, feature.isPause()); - portFeaturesMap.put(11, feature.isPauseAsym()); - configBitmask = ByteBufUtils.fillBitMaskFromMap(portFeaturesMap); - return configBitmask; - } -} +/* + * 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.serialization.factories; + +import io.netty.buffer.ByteBuf; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; +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.protocol.rev130731.PortModInput; + +/** + * Translates PortMod messages + * @author michal.polkorab + */ +public class OF10PortModInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 15; + private static final byte PADDING_IN_PORT_MOD_MESSAGE = 4; + + @Override + public void serialize(final PortModInput message, final ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + outBuffer.writeShort(message.getPortNo().getValue().intValue()); + outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue())); + outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10())); + outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10())); + outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10())); + ByteBufUtils.padBuffer(PADDING_IN_PORT_MOD_MESSAGE, outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); + } + + /** + * @param config + * @return port config bitmask + */ + private static int createPortConfigBitmask(final PortConfigV10 config) { + return ByteBufUtils.fillBitMask(0, + config.isPortDown(), + config.isNoStp(), + config.isNoRecv(), + config.isNoRecvStp(), + config.isNoFlood(), + config.isNoFwd(), + config.isNoPacketIn()); + } + + private static int createPortFeaturesBitmask(final PortFeaturesV10 feature) { + return ByteBufUtils.fillBitMask(0, + feature.is_10mbHd(), + feature.is_10mbFd(), + feature.is_100mbHd(), + feature.is_100mbFd(), + feature.is_1gbHd(), + feature.is_1gbFd(), + feature.is_10gbFd(), + feature.isCopper(), + feature.isFiber(), + feature.isAutoneg(), + feature.isPause(), + feature.isPauseAsym()); + } + +}