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%2FOF10FlowModInputMessageFactory.java;h=7fe217a6a5e725bd3f55074eed4358a1671808d5;hb=c478b5dffd54fc748945a4d98a22fe1b2143daf9;hp=7821cd4979ad354993b1c37f63fd822c8a1da9a4;hpb=09a089ee658f6fc1627b5eafdbb29249e7c7ffb9;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java index 7821cd49..7fe217a6 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/OF10FlowModInputMessageFactory.java @@ -1,75 +1,82 @@ -/* 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.OF10ActionsSerializer; -import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; - -/** - * Translates FlowMod messages - * @author michal.polkorab - */ -public class OF10FlowModInputMessageFactory implements OFSerializer { - - private static final byte MESSAGE_TYPE = 14; - private static final int MESSAGE_LENGTH = 72; - - private static OF10FlowModInputMessageFactory instance; - - private OF10FlowModInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized OF10FlowModInputMessageFactory getInstance() { - if(instance == null) { - instance = new OF10FlowModInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10()); - out.writeLong(message.getCookie().longValue()); - out.writeShort(message.getCommand().getIntValue()); - out.writeShort(message.getIdleTimeout().intValue()); - out.writeShort(message.getHardTimeout().intValue()); - out.writeShort(message.getPriority()); - out.writeInt(message.getBufferId().intValue()); - out.writeShort(message.getOutPort().getValue().intValue()); - out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); - OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList()); - } - - @Override - public int computeLength(FlowModInput message) { - return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList()); - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) { - int flowModFlagBitmask = 0; - Map flowModFlagsMap = new HashMap<>(); - flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); - flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); - flowModFlagsMap.put(2, flags.isOFPFFEMERG()); - 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.OF10ActionsSerializer; +import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput; + +/** + * Translates FlowMod messages + * @author michal.polkorab + */ +public class OF10FlowModInputMessageFactory implements OFSerializer { + + private static final byte MESSAGE_TYPE = 14; + private static final int MESSAGE_LENGTH = 72; + + private static OF10FlowModInputMessageFactory instance; + + private OF10FlowModInputMessageFactory() { + // singleton + } + + /** + * @return singleton factory + */ + public static synchronized OF10FlowModInputMessageFactory getInstance() { + if(instance == null) { + instance = new OF10FlowModInputMessageFactory(); + } + return instance; + } + + @Override + public void messageToBuffer(short version, ByteBuf out, FlowModInput message) { + ByteBufUtils.writeOFHeader(instance, message, out); + OF10MatchSerializer.encodeMatchV10(out, message.getMatchV10()); + out.writeLong(message.getCookie().longValue()); + out.writeShort(message.getCommand().getIntValue()); + out.writeShort(message.getIdleTimeout().intValue()); + out.writeShort(message.getHardTimeout().intValue()); + out.writeShort(message.getPriority()); + out.writeInt(message.getBufferId().intValue()); + out.writeShort(message.getOutPort().getValue().intValue()); + out.writeShort(createFlowModFlagsBitmask(message.getFlagsV10())); + OF10ActionsSerializer.encodeActionsV10(out, message.getAction()); + } + + @Override + public int computeLength(FlowModInput message) { + return MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getAction()); + } + + @Override + public byte getMessageType() { + return MESSAGE_TYPE; + } + + private static int createFlowModFlagsBitmask(FlowModFlagsV10 flags) { + int flowModFlagBitmask = 0; + Map flowModFlagsMap = new HashMap<>(); + flowModFlagsMap.put(0, flags.isOFPFFSENDFLOWREM()); + flowModFlagsMap.put(1, flags.isOFPFFCHECKOVERLAP()); + flowModFlagsMap.put(2, flags.isOFPFFEMERG()); + flowModFlagBitmask = ByteBufUtils.fillBitMaskFromMap(flowModFlagsMap); + return flowModFlagBitmask; + } +}