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%2FSetAsyncInputMessageFactory.java;h=65cb07e33ff880fce4edf468555dfa7102f10424;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=7f5e901d1ae6b411fc3e2e34f630bdc013a47826;hpb=7d9b6038060779d819e17d5add8556dcc097fcea;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java index 7f5e901d..65cb07e3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetAsyncInputMessageFactory.java @@ -1,153 +1,110 @@ -/* 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.Iterator; -import java.util.List; -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.FlowRemovedReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; - -/** - * Translates SetAsync messages - * @author timotej.kubas - * @author michal.polkorab - */ -public class SetAsyncInputMessageFactory implements OFSerializer { - private static final byte MESSAGE_TYPE = 28; - private static final int MESSAGE_LENGTH = 32; - private static SetAsyncInputMessageFactory instance; - - private SetAsyncInputMessageFactory() { - // singleton - } - - /** - * @return singleton factory - */ - public static synchronized SetAsyncInputMessageFactory getInstance() { - if (instance == null) { - instance = new SetAsyncInputMessageFactory(); - } - return instance; - } - - @Override - public void messageToBuffer(short version, ByteBuf out, - SetAsyncInput message) { - ByteBufUtils.writeOFHeader(instance, message, out); - encodePacketInMask(message.getPacketInMask(), out); - encodePortStatusMask(message.getPortStatusMask(), out); - encodeFlowRemovedMask(message.getFlowRemovedMask(), out); - } - - @Override - public int computeLength(SetAsyncInput message) { - return MESSAGE_LENGTH; - } - - @Override - public byte getMessageType() { - return MESSAGE_TYPE; - } - - private static void encodePacketInMask(List packetInMask, ByteBuf outBuffer) { - for (Iterator iterator = packetInMask.iterator(); iterator.hasNext();) { - PacketInReason currentPacketInReason = iterator.next(); - outBuffer.writeInt(packetInReasonToBitmask(currentPacketInReason.getIntValue())); - } - } - - private static void encodePortStatusMask(List portStatusMask, ByteBuf outBuffer) { - for (Iterator iterator = portStatusMask.iterator(); iterator.hasNext();) { - PortReason currentPortReason = iterator.next(); - outBuffer.writeInt(portReasonToBitmask(currentPortReason.getIntValue())); - } - } - - private static void encodeFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { - for (Iterator iterator = flowRemovedMask.iterator(); iterator.hasNext();) { - FlowRemovedReason currentFlowRemovedReason = iterator.next(); - outBuffer.writeInt(flowRemovedReasonToBitmask(currentFlowRemovedReason.getIntValue())); - } - } - - private static int packetInReasonToBitmask(int option) { - Boolean OFPRNOMATCH = false; - Boolean OFPRACTION = false; - Boolean OFPRINVALIDTTL = false; - int packetInReasonBitmask = 0; - - switch(option) { - case 0: OFPRNOMATCH = true; break; - case 1: OFPRACTION = true; break; - case 2: OFPRINVALIDTTL = true; break; - default: break; - } - - Map packetInReasonMap = new HashMap<>(); - packetInReasonMap.put(0, OFPRNOMATCH); - packetInReasonMap.put(1, OFPRACTION); - packetInReasonMap.put(2, OFPRINVALIDTTL); - - packetInReasonBitmask = ByteBufUtils.fillBitMaskFromMap(packetInReasonMap); - - return packetInReasonBitmask; - } - - private static int portReasonToBitmask(int option) { - Boolean OFPPRADD = false; - Boolean OFPPRDELETE = false; - Boolean OFPPRMODIFY = false; - int portReasonBitmask = 0; - - switch(option) { - case 0: OFPPRADD = true; break; - case 1: OFPPRDELETE = true; break; - case 2: OFPPRMODIFY = true; break; - default: break; - } - - Map portReasonMap = new HashMap<>(); - portReasonMap.put(0, OFPPRADD); - portReasonMap.put(1, OFPPRDELETE); - portReasonMap.put(2, OFPPRMODIFY); - - portReasonBitmask = ByteBufUtils.fillBitMaskFromMap(portReasonMap); - - return portReasonBitmask; - } - - private static int flowRemovedReasonToBitmask(int option) { - Boolean OFPRRIDLETIMEOUT = false; - Boolean OFPRRHARDTIMEOUT = false; - Boolean OFPRRDELETE = false; - Boolean OFPRRGROUPDELETE = false; - int flowRemovedReasonBitmask = 0; - - switch(option) { - case 0: OFPRRIDLETIMEOUT = true; break; - case 1: OFPRRHARDTIMEOUT = true; break; - case 2: OFPRRDELETE = true; break; - case 3: OFPRRGROUPDELETE = true; break; - default: break; - } - - Map portReasonMap = new HashMap<>(); - portReasonMap.put(0, OFPRRIDLETIMEOUT); - portReasonMap.put(1, OFPRRHARDTIMEOUT); - portReasonMap.put(2, OFPRRDELETE); - portReasonMap.put(3, OFPRRGROUPDELETE); - - flowRemovedReasonBitmask = ByteBufUtils.fillBitMaskFromMap(portReasonMap); - - return flowRemovedReasonBitmask; - } -} +/* + * 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.List; +import java.util.Map; + +import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer; +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask; + +/** + * Translates SetAsync messages + * @author timotej.kubas + * @author michal.polkorab + */ +public class SetAsyncInputMessageFactory implements OFSerializer { + private static final byte MESSAGE_TYPE = 28; + + @Override + public void serialize(SetAsyncInput message, ByteBuf outBuffer) { + ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); + serializePacketInMask(message.getPacketInMask(), outBuffer); + serializePortStatusMask(message.getPortStatusMask(), outBuffer); + serializerFlowRemovedMask(message.getFlowRemovedMask(), outBuffer); + ByteBufUtils.updateOFHeaderLength(outBuffer); + } + + private static void serializePacketInMask(List packetInMask, ByteBuf outBuffer) { + if (packetInMask != null) { + for (PacketInMask currentPacketMask : packetInMask) { + List mask = currentPacketMask.getMask(); + if (mask != null) { + Map packetInReasonMap = new HashMap<>(); + for (PacketInReason packetInReason : mask) { + if (PacketInReason.OFPRNOMATCH.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRNOMATCH.getIntValue(), true); + } else if (PacketInReason.OFPRACTION.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRACTION.getIntValue(), true); + } else if (PacketInReason.OFPRINVALIDTTL.equals(packetInReason)) { + packetInReasonMap.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(packetInReasonMap)); + } + } + } + } + + private static void serializePortStatusMask(List portStatusMask, ByteBuf outBuffer) { + if (portStatusMask != null) { + for (PortStatusMask currentPortStatusMask : portStatusMask) { + List mask = currentPortStatusMask.getMask(); + if (mask != null) { + Map portStatusReasonMap = new HashMap<>(); + for (PortReason packetInReason : mask) { + if (PortReason.OFPPRADD.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRADD.getIntValue(), true); + } else if (PortReason.OFPPRDELETE.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRDELETE.getIntValue(), true); + } else if (PortReason.OFPPRMODIFY.equals(packetInReason)) { + portStatusReasonMap.put(PortReason.OFPPRMODIFY.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(portStatusReasonMap)); + } + } + } + } + + private static void serializerFlowRemovedMask(List flowRemovedMask, ByteBuf outBuffer) { + if (flowRemovedMask != null) { + for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) { + List mask = currentFlowRemovedMask.getMask(); + if (mask != null) { + Map flowRemovedReasonMap = new HashMap<>(); + for (FlowRemovedReason packetInReason : mask) { + if (FlowRemovedReason.OFPRRIDLETIMEOUT.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRHARDTIMEOUT.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRDELETE.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true); + } else if (FlowRemovedReason.OFPRRGROUPDELETE.equals(packetInReason)) { + flowRemovedReasonMap.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true); + } + } + outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(flowRemovedReasonMap)); + } + } + } + } + +} \ No newline at end of file