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
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.messages;
10 import io.netty.buffer.ByteBuf;
12 import java.util.Optional;
13 import java.util.WeakHashMap;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.FlowRemovedMask;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.PacketInMask;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.PortStatusMask;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
23 public class AsyncConfigMessageSerializer extends AbstractMessageSerializer<AsyncConfigMessage> {
25 public void serialize(final AsyncConfigMessage message, final ByteBuf outBuffer) {
26 final int index = outBuffer.writerIndex();
27 super.serialize(message, outBuffer);
29 Optional.ofNullable(message.getPacketInMask())
31 serializePacketInMask(mask.getMasterMask(), outBuffer);
32 serializePacketInMask(mask.getSlaveMask(), outBuffer);
35 Optional.ofNullable(message.getPortStatusMask())
37 serializePortStatusMask(mask.getMasterMask(), outBuffer);
38 serializePortStatusMask(mask.getSlaveMask(), outBuffer);
41 Optional.ofNullable(message.getFlowRemovedMask())
43 serializeFlowRemovedMask(mask.getMasterMask(), outBuffer);
44 serializeFlowRemovedMask(mask.getSlaveMask(), outBuffer);
47 outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
51 protected byte getMessageType() {
55 private static void serializePacketInMask(final PacketInMask mask, final ByteBuf outBuffer) {
60 final Map<Integer, Boolean> map = new WeakHashMap<>();
62 if (mask.getNOMATCH()) {
63 map.put(PacketInReason.OFPRNOMATCH.getIntValue(), true);
66 if (mask.getACTION()) {
67 map.put(PacketInReason.OFPRACTION.getIntValue(), true);
70 if (mask.getINVALIDTTL()) {
71 map.put(PacketInReason.OFPRINVALIDTTL.getIntValue(), true);
74 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));
77 private static void serializePortStatusMask(final PortStatusMask mask, final ByteBuf outBuffer) {
82 final Map<Integer, Boolean> map = new WeakHashMap<>();
85 map.put(PortReason.OFPPRADD.getIntValue(), true);
88 if (mask.getDELETE()) {
89 map.put(PortReason.OFPPRDELETE.getIntValue(), true);
92 if (mask.getUPDATE()) {
93 map.put(PortReason.OFPPRMODIFY.getIntValue(), true);
96 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));
99 private static void serializeFlowRemovedMask(final FlowRemovedMask mask, final ByteBuf outBuffer) {
104 final Map<Integer, Boolean> map = new WeakHashMap<>();
106 if (mask.getIDLETIMEOUT()) {
107 map.put(FlowRemovedReason.OFPRRIDLETIMEOUT.getIntValue(), true);
110 if (mask.getHARDTIMEOUT()) {
111 map.put(FlowRemovedReason.OFPRRHARDTIMEOUT.getIntValue(), true);
114 if (mask.getDELETE()) {
115 map.put(FlowRemovedReason.OFPRRDELETE.getIntValue(), true);
118 if (mask.getGROUPDELETE()) {
119 map.put(FlowRemovedReason.OFPRRGROUPDELETE.getIntValue(), true);
122 outBuffer.writeInt(ByteBufUtils.fillBitMaskFromMap(map));