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