2 * Copyright (c) 2015 NetIDE Consortium 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
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import java.util.Collection;
12 import java.util.List;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
20 import org.opendaylight.yangtools.yang.binding.Enumeration;
23 * Translates GetAsyncOutput messages.
25 * @author giuseppex.petralia@intel.com
27 public class GetAsyncReplyMessageFactory implements OFSerializer<GetAsyncOutput> {
28 private static final byte MESSAGE_TYPE = 27;
31 public void serialize(final GetAsyncOutput message, final ByteBuf outBuffer) {
32 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
33 serializePacketInMask(message.getPacketInMask(), outBuffer);
34 serializePortStatusMask(message.getPortStatusMask(), outBuffer);
35 serializeFlowRemovedMask(message.getFlowRemovedMask(), outBuffer);
36 ByteBufUtils.updateOFHeaderLength(outBuffer);
39 private static void serializePacketInMask(final List<PacketInMask> packetInMask, final ByteBuf outBuffer) {
40 if (packetInMask != null) {
41 for (PacketInMask currentPacketMask : packetInMask) {
42 serializeReasons(currentPacketMask.getMask(), outBuffer);
47 private static void serializePortStatusMask(final List<PortStatusMask> portStatusMask, final ByteBuf outBuffer) {
48 if (portStatusMask != null) {
49 for (PortStatusMask currentPortStatusMask : portStatusMask) {
50 serializeReasons(currentPortStatusMask.getMask(), outBuffer);
55 private static void serializeFlowRemovedMask(final List<FlowRemovedMask> flowRemovedMask, final ByteBuf outBuffer) {
56 if (flowRemovedMask != null) {
57 for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) {
58 serializeReasons(currentFlowRemovedMask.getMask(), outBuffer);
63 private static void serializeReasons(final Collection<? extends Enumeration> reasons, final ByteBuf outBuffer) {
64 if (reasons != null) {
66 for (Enumeration reason : reasons) {
67 bitmap |= 1 << reason.getIntValue();
69 outBuffer.writeInt(bitmap);