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.HashMap;
13 import java.util.List;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.FlowRemovedMask;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
27 * Translates SetAsync messages.
29 * @author timotej.kubas
30 * @author michal.polkorab
32 public class SetAsyncInputMessageFactory implements OFSerializer<SetAsyncInput> {
33 private static final byte MESSAGE_TYPE = 28;
36 public void serialize(SetAsyncInput message, ByteBuf outBuffer) {
37 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
38 serializePacketInMask(message.getPacketInMask(), outBuffer);
39 serializePortStatusMask(message.getPortStatusMask(), outBuffer);
40 serializerFlowRemovedMask(message.getFlowRemovedMask(), outBuffer);
41 ByteBufUtils.updateOFHeaderLength(outBuffer);
44 private static void serializePacketInMask(List<PacketInMask> packetInMask, ByteBuf outBuffer) {
45 if (packetInMask != null) {
46 for (PacketInMask currentPacketMask : packetInMask) {
47 List<PacketInReason> mask = currentPacketMask.getMask();
49 Map<Integer, Boolean> packetInReasonMap = new HashMap<>();
50 for (PacketInReason packetInReason : mask) {
51 if (PacketInReason.OFPRNOMATCH.equals(packetInReason)) {
52 packetInReasonMap.put(PacketInReason.OFPRNOMATCH.getIntValue(), true);
53 } else if (PacketInReason.OFPRACTION.equals(packetInReason)) {
54 packetInReasonMap.put(PacketInReason.OFPRACTION.getIntValue(), true);
55 } else if (PacketInReason.OFPRINVALIDTTL.equals(packetInReason)) {
56 packetInReasonMap.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true);
59 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(packetInReasonMap));
65 private static void serializePortStatusMask(List<PortStatusMask> portStatusMask, ByteBuf outBuffer) {
66 if (portStatusMask != null) {
67 for (PortStatusMask currentPortStatusMask : portStatusMask) {
68 List<PortReason> mask = currentPortStatusMask.getMask();
70 Map<Integer, Boolean> portStatusReasonMap = new HashMap<>();
71 for (PortReason packetInReason : mask) {
72 if (PortReason.OFPPRADD.equals(packetInReason)) {
73 portStatusReasonMap.put(PortReason.OFPPRADD.getIntValue(), true);
74 } else if (PortReason.OFPPRDELETE.equals(packetInReason)) {
75 portStatusReasonMap.put(PortReason.OFPPRDELETE.getIntValue(), true);
76 } else if (PortReason.OFPPRMODIFY.equals(packetInReason)) {
77 portStatusReasonMap.put(PortReason.OFPPRMODIFY.getIntValue(), true);
80 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(portStatusReasonMap));
86 private static void serializerFlowRemovedMask(List<FlowRemovedMask> flowRemovedMask, ByteBuf outBuffer) {
87 if (flowRemovedMask != null) {
88 for (FlowRemovedMask currentFlowRemovedMask : flowRemovedMask) {
89 List<FlowRemovedReason> mask = currentFlowRemovedMask.getMask();
91 Map<Integer, Boolean> flowRemovedReasonMap = new HashMap<>();
92 for (FlowRemovedReason packetInReason : mask) {
93 if (FlowRemovedReason.OFPRRIDLETIMEOUT.equals(packetInReason)) {
94 flowRemovedReasonMap.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true);
95 } else if (FlowRemovedReason.OFPRRHARDTIMEOUT.equals(packetInReason)) {
96 flowRemovedReasonMap.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true);
97 } else if (FlowRemovedReason.OFPRRDELETE.equals(packetInReason)) {
98 flowRemovedReasonMap.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true);
99 } else if (FlowRemovedReason.OFPRRGROUPDELETE.equals(packetInReason)) {
100 flowRemovedReasonMap.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true);
103 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(flowRemovedReasonMap));