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.deserialization.factories;
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
12 import com.google.common.collect.ImmutableSet;
13 import io.netty.buffer.ByteBuf;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
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;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInputBuilder;
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.FlowRemovedMaskBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
32 * Translates SetAsyncInput messages.
34 * @author giuseppex.petralia@intel.com
36 public class SetAsyncInputMessageFactory implements OFDeserializer<SetAsyncInput> {
37 private static final byte SEPARATE_ROLES = 2;
40 public SetAsyncInput deserialize(ByteBuf rawMessage) {
41 return new SetAsyncInputBuilder()
42 .setVersion(EncodeConstants.OF_VERSION_1_3)
43 .setXid(readUint32(rawMessage))
44 .setPacketInMask(decodePacketInMask(rawMessage))
45 .setPortStatusMask(decodePortStatusMask(rawMessage))
46 .setFlowRemovedMask(decodeFlowRemovedMask(rawMessage))
50 private static List<PacketInMask> decodePacketInMask(ByteBuf input) {
51 List<PacketInMask> inMasks = new ArrayList<>(SEPARATE_ROLES);
52 PacketInMaskBuilder maskBuilder;
53 for (int i = 0; i < SEPARATE_ROLES; i++) {
54 maskBuilder = new PacketInMaskBuilder();
55 maskBuilder.setMask(decodePacketInReasons(input.readUnsignedInt()));
56 inMasks.add(maskBuilder.build());
61 private static Set<PacketInReason> decodePacketInReasons(long input) {
62 final var builder = ImmutableSet.<PacketInReason>builder();
63 if ((input & 1 << 0) != 0) {
64 builder.add(PacketInReason.OFPRNOMATCH);
66 if ((input & 1 << 1) != 0) {
67 builder.add(PacketInReason.OFPRACTION);
69 if ((input & 1 << 2) != 0) {
70 builder.add(PacketInReason.OFPRINVALIDTTL);
72 return builder.build();
75 private static List<PortStatusMask> decodePortStatusMask(ByteBuf input) {
76 List<PortStatusMask> inMasks = new ArrayList<>(SEPARATE_ROLES);
77 PortStatusMaskBuilder maskBuilder;
78 for (int i = 0; i < SEPARATE_ROLES; i++) {
79 maskBuilder = new PortStatusMaskBuilder();
80 maskBuilder.setMask(decodePortReasons(input.readUnsignedInt()));
81 inMasks.add(maskBuilder.build());
86 private static Set<PortReason> decodePortReasons(long input) {
87 final var builder = ImmutableSet.<PortReason>builder();
88 if ((input & 1 << 0) != 0) {
89 builder.add(PortReason.OFPPRADD);
91 if ((input & 1 << 1) != 0) {
92 builder.add(PortReason.OFPPRDELETE);
94 if ((input & 1 << 2) != 0) {
95 builder.add(PortReason.OFPPRMODIFY);
97 return builder.build();
100 private static List<FlowRemovedMask> decodeFlowRemovedMask(ByteBuf input) {
101 List<FlowRemovedMask> inMasks = new ArrayList<>(SEPARATE_ROLES);
102 FlowRemovedMaskBuilder maskBuilder;
103 for (int i = 0; i < SEPARATE_ROLES; i++) {
104 maskBuilder = new FlowRemovedMaskBuilder();
105 maskBuilder.setMask(decodeFlowRemovedReasons(input.readUnsignedInt()));
106 inMasks.add(maskBuilder.build());
111 private static Set<FlowRemovedReason> decodeFlowRemovedReasons(long input) {
112 final var builder = ImmutableSet.<FlowRemovedReason>builder();
113 if ((input & 1 << 0) != 0) {
114 builder.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
116 if ((input & 1 << 1) != 0) {
117 builder.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
119 if ((input & 1 << 2) != 0) {
120 builder.add(FlowRemovedReason.OFPRRDELETE);
122 if ((input & 1 << 3) != 0) {
123 builder.add(FlowRemovedReason.OFPRRGROUPDELETE);
125 return builder.build();