2 * Copyright (c) 2017 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.openflowplugin.impl.protocol.serialization.messages;
11 import io.netty.buffer.ByteBuf;
13 import java.util.Objects;
14 import java.util.Optional;
15 import java.util.WeakHashMap;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.FlowRemovedMask;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.PacketInMask;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.PortStatusMask;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
25 public class AsyncConfigMessageSerializer extends AbstractMessageSerializer<AsyncConfigMessage> {
27 public void serialize(AsyncConfigMessage message, ByteBuf outBuffer) {
28 final int index = outBuffer.writerIndex();
29 super.serialize(message, outBuffer);
31 Optional.ofNullable(message.getPacketInMask())
33 serializePacketInMask(mask.getMasterMask(), outBuffer);
34 serializePacketInMask(mask.getSlaveMask(), outBuffer);
37 Optional.ofNullable(message.getPortStatusMask())
39 serializePortStatusMask(mask.getMasterMask(), outBuffer);
40 serializePortStatusMask(mask.getSlaveMask(), outBuffer);
43 Optional.ofNullable(message.getFlowRemovedMask())
45 serializeFlowRemovedMask(mask.getMasterMask(), outBuffer);
46 serializeFlowRemovedMask(mask.getSlaveMask(), outBuffer);
49 outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
53 protected byte getMessageType() {
57 private static void serializePacketInMask(final PacketInMask mask, final ByteBuf outBuffer) {
58 if (Objects.isNull(mask)) {
62 final Map<Integer, Boolean> map = new WeakHashMap<>();
64 if (mask.isNOMATCH()) {
65 map.put(PacketInReason.OFPRNOMATCH.getIntValue(), true);
68 if (mask.isACTION()) {
69 map.put(PacketInReason.OFPRACTION.getIntValue(), true);
72 if (mask.isINVALIDTTL()) {
73 map.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true);
76 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));
79 private static void serializePortStatusMask(final PortStatusMask mask, final ByteBuf outBuffer) {
80 if (Objects.isNull(mask)) {
84 final Map<Integer, Boolean> map = new WeakHashMap<>();
87 map.put(PortReason.OFPPRADD.getIntValue(), true);
90 if (mask.isDELETE()) {
91 map.put(PortReason.OFPPRDELETE.getIntValue(), true);
94 if (mask.isUPDATE()) {
95 map.put(PortReason.OFPPRMODIFY.getIntValue(), true);
98 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));
101 private static void serializeFlowRemovedMask(final FlowRemovedMask mask, final ByteBuf outBuffer) {
102 if (Objects.isNull(mask)) {
106 final Map<Integer, Boolean> map = new WeakHashMap<>();
108 if (mask.isIDLETIMEOUT()) {
109 map.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true);
112 if (mask.isHARDTIMEOUT()) {
113 map.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true);
116 if (mask.isDELETE()) {
117 map.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true);
120 if (mask.isGROUPDELETE()) {
121 map.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true);
124 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));