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.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutputBuilder;
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.FlowRemovedMaskBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMask;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PacketInMaskBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMask;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.async.body.grouping.PortStatusMaskBuilder;
30 * Translates GetAsyncReply messages
31 * @author timotej.kubas
32 * @author michal.polkorab
34 public class GetAsyncReplyMessageFactory implements OFDeserializer<GetAsyncOutput> {
36 private static GetAsyncReplyMessageFactory instance;
37 private static final byte SEPARATE_ROLES = 2;
39 private GetAsyncReplyMessageFactory() {
44 * @return singleton factory
46 public static synchronized GetAsyncReplyMessageFactory getInstance() {
47 if (instance == null) {
48 instance = new GetAsyncReplyMessageFactory();
54 public GetAsyncOutput bufferToMessage(ByteBuf rawMessage, short version) {
55 GetAsyncOutputBuilder builder = new GetAsyncOutputBuilder();
56 builder.setVersion(version);
57 builder.setXid(rawMessage.readUnsignedInt());
58 builder.setPacketInMask(decodePacketInMask(rawMessage));
59 builder.setPortStatusMask(decodePortStatusMask(rawMessage));
60 builder.setFlowRemovedMask(decodeFlowRemovedMask(rawMessage));
61 return builder.build();
64 private static List<PacketInMask> decodePacketInMask(ByteBuf input) {
65 List<PacketInMask> inMasks = new ArrayList<>();
66 PacketInMaskBuilder maskBuilder;
67 for (int i = 0; i < SEPARATE_ROLES; i++) {
68 maskBuilder = new PacketInMaskBuilder();
69 maskBuilder.setMask(decodePacketInReasons(input.readUnsignedInt()));
70 inMasks.add(maskBuilder.build());
75 private static List<PortStatusMask> decodePortStatusMask(ByteBuf input) {
76 List<PortStatusMask> inMasks = new ArrayList<>();
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 List<FlowRemovedMask> decodeFlowRemovedMask(ByteBuf input) {
87 List<FlowRemovedMask> inMasks = new ArrayList<>();
88 FlowRemovedMaskBuilder maskBuilder;
89 for (int i = 0; i < SEPARATE_ROLES; i++) {
90 maskBuilder = new FlowRemovedMaskBuilder();
91 maskBuilder.setMask(decodeFlowRemovedReasons(input.readUnsignedInt()));
92 inMasks.add(maskBuilder.build());
97 private static List<PacketInReason> decodePacketInReasons(long input) {
98 List<PacketInReason> reasons = new ArrayList<>();
99 if ((input & (1 << 0)) != 0) {
100 reasons.add(PacketInReason.OFPRNOMATCH);
102 if ((input & (1 << 1)) != 0) {
103 reasons.add(PacketInReason.OFPRACTION);
105 if ((input & (1 << 2)) != 0) {
106 reasons.add(PacketInReason.OFPRINVALIDTTL);
111 private static List<PortReason> decodePortReasons(long input) {
112 List<PortReason> reasons = new ArrayList<>();
113 if ((input & (1 << 0)) != 0) {
114 reasons.add(PortReason.OFPPRADD);
116 if ((input & (1 << 1)) != 0) {
117 reasons.add(PortReason.OFPPRDELETE);
119 if ((input & (1 << 2)) != 0) {
120 reasons.add(PortReason.OFPPRMODIFY);
125 private static List<FlowRemovedReason> decodeFlowRemovedReasons(long input) {
126 List<FlowRemovedReason> reasons = new ArrayList<>();
127 if ((input & (1 << 0)) != 0) {
128 reasons.add(FlowRemovedReason.OFPRRIDLETIMEOUT);
130 if ((input & (1 << 1)) != 0) {
131 reasons.add(FlowRemovedReason.OFPRRHARDTIMEOUT);
133 if ((input & (1 << 2)) != 0) {
134 reasons.add(FlowRemovedReason.OFPRRDELETE);
136 if ((input & (1 << 3)) != 0) {
137 reasons.add(FlowRemovedReason.OFPRRGROUPDELETE);