2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import java.util.Collection;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
21 import org.opendaylight.yangtools.yang.binding.Enumeration;
24 * Translates SetAsync messages.
26 * @author timotej.kubas
27 * @author michal.polkorab
29 public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput> {
30 private static final byte MESSAGE_TYPE = 28;
33 public void serialize(final SetAsyncInput message, final ByteBuf outBuffer) {
34 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
35 serializePacketInMask(message.getPacketInMask(), outBuffer);
36 serializePortStatusMask(message.getPortStatusMask(), outBuffer);
37 serializerFlowRemovedMask(message.getFlowRemovedMask(), outBuffer);
38 ByteBufUtils.updateOFHeaderLength(outBuffer);
41 private static void serializePacketInMask(final List<PacketInMask> packetInMask, final ByteBuf outBuffer) {
42 if (packetInMask != null) {
43 for (PacketInMask currentPacketMask : packetInMask) {
44 serializeReasons(currentPacketMask.getMask(), outBuffer);
49 private static void serializePortStatusMask(final List<PortStatusMask> portStatusMask, final ByteBuf outBuffer) {
50 if (portStatusMask != null) {
51 for (PortStatusMask currentPortStatusMask : portStatusMask) {
52 serializeReasons(currentPortStatusMask.getMask(), outBuffer);
57 private static void serializerFlowRemovedMask(final List<FlowRemovedMask> flowRemovedMask,
58 final ByteBuf outBuffer) {
59 if (flowRemovedMask != null) {
60 for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) {
61 serializeReasons(currentFlowRemovedMask.getMask(), outBuffer);
66 private static void serializeReasons(final Collection<? extends Enumeration> reasons, final ByteBuf outBuffer) {
67 if (reasons != null) {
69 for (Enumeration reason : reasons) {
70 bitmap |= 1 << reason.getIntValue();
72 outBuffer.writeInt(bitmap);