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%2FFlowModInputMessageFactory.java;h=cb2a5f74bef6e412485feb95d34d44d3262b9420;hb=0d942e8fb70b2c21f97eea3ed8904336ab5c54a4;hp=511f1622a31d7e490de7916b88533c95d1923c57;hpb=e51cdb2f4034dc3429721a9f5693cb8eddc2194a;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java index 511f1622..cb2a5f74 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/FlowModInputMessageFactory.java @@ -1,85 +1,92 @@ -/* 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.openflowjava.protocol.impl.util.InstructionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; - -/** - * Translates FlowMod messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class FlowModInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 14; - private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; - private static final int MESSAGE_LENGTH = 48; - private static FlowModInputMessageFactory instance; - - private FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - out.writeLong(message.getCookie().longValue()); - out.writeLong(message.getCookieMask().longValue()); - out.writeByte(message.getTableId().getValue().byteValue()); - out.writeByte(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeInt(message.getOutPort().getValue().intValue()); - out.writeInt(message.getOutGroup().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlags())); - ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out); - MatchSerializer.encodeMatch(message.getMatch(), out); - InstructionsSerializer.encodeInstructions(message.getInstructions(), out); - } - - @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch()) - + InstructionsSerializer.computeInstructionsLength(message.getInstructions()); - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static int createFlowModFlagsBitmask(FlowModFlags flags) { - int flowModFlagBitmask = 0; - Map flowModFlagsMap = new HashMap<>(); - flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); - flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); - flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS()); - flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS()); - flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS()); - - flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); - return flowModFlagBitmask; - } - - -} +/* + * 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 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.openflowjava.protocol.impl.util.InstructionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; + +/** + * Translates FlowMod messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class FlowModInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 14; + private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2; + private static final int MESSAGE_LENGTH = 48; + private static FlowModInputMessageFactory instance; + + private FlowModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized FlowModInputMessageFactory getInstance() { + if(instance == null) { + instance = new FlowModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + out.writeLong(message.getCookie().longValue()); + out.writeLong(message.getCookieMask().longValue()); + out.writeByte(message.getTableId().getValue().byteValue()); + out.writeByte(message.getCommand().getIntValue()); + out.writeShort(message.getIdleTimeout().intValue()); + out.writeShort(message.getHardTimeout().intValue()); + out.writeShort(message.getPriority()); + out.writeInt(message.getBufferId().intValue()); + out.writeInt(message.getOutPort().getValue().intValue()); + out.writeInt(message.getOutGroup().intValue()); + out.writeShort(createFlowModFlagsBitmask(message.getFlags())); + ByteBufUtils.padBuffer(PADDING_IN_FLOW_MOD_MESSAGE, out); + MatchSerializer.encodeMatch(message.getMatch(), out); + InstructionsSerializer.encodeInstructions(message.getInstructions(), out); + } + + @Override + public int computeLength(FlowModInput message) { + return MESSAGE_LENGTH + MatchSerializer.computeMatchLength(message.getMatch()) + + InstructionsSerializer.computeInstructionsLength(message.getInstructions()); + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createFlowModFlagsBitmask(FlowModFlags flags) { + int flowModFlagBitmask = 0; + Map flowModFlagsMap = new HashMap<>(); + flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); + flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); + flowModFlagsMap.put(2, flags.isOFPFFRESETCOUNTS()); + flowModFlagsMap.put(3, flags.isOFPFFNOPKTCOUNTS()); + flowModFlagsMap.put(4, flags.isOFPFFNOBYTCOUNTS()); + + flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); + return flowModFlagBitmask; + } + + +}