Merge "Remove Itemlifecycle"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / messages / AsyncConfigMessageDeserializer.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.messages;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.AsyncConfigMessageBuilder;
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.async.config.service.rev170619.async.config.FlowRemovedMaskBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.async.config.PacketInMaskBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.async.config.service.rev170619.async.config.PortStatusMaskBuilder;
22
23 public class AsyncConfigMessageDeserializer implements OFDeserializer<AsyncConfigMessage> {
24     @Override
25     public AsyncConfigMessage deserialize(ByteBuf message) {
26         return new AsyncConfigMessageBuilder()
27                 .setVersion((short) EncodeConstants.OF13_VERSION_ID)
28                 .setXid(message.readUnsignedInt())
29                 .setPacketInMask(new PacketInMaskBuilder()
30                         .setMasterMask(deserializePacketInMask(message))
31                         .setSlaveMask(deserializePacketInMask(message))
32                         .build())
33                 .setPortStatusMask(new PortStatusMaskBuilder()
34                         .setMasterMask(deserializePortStatusMask(message))
35                         .setSlaveMask(deserializePortStatusMask(message))
36                         .build())
37                 .setFlowRemovedMask(new FlowRemovedMaskBuilder()
38                         .setMasterMask(deserializeFlowRemovedMask(message))
39                         .setSlaveMask(deserializeFlowRemovedMask(message))
40                         .build())
41                 .build();
42     }
43
44     private static PacketInMask deserializePacketInMask(final ByteBuf byteBuf) {
45         final long mask = byteBuf.readUnsignedInt();
46         final boolean isNoMatch = (mask & (1)) != 0;
47         final boolean isAction = (mask & (1 << 1)) != 0;
48         final boolean isInvalidTtl = (mask & (1 << 2)) != 0;
49         return new PacketInMask(isAction, isInvalidTtl, isNoMatch);
50     }
51
52     private static PortStatusMask deserializePortStatusMask(final ByteBuf byteBuf) {
53         final long mask = byteBuf.readUnsignedInt();
54         final boolean isAdd = (mask & (1)) != 0;
55         final boolean isDelete = (mask & (1 << 1)) != 0;
56         final boolean isModify = (mask & (1 << 2)) != 0;
57         return new PortStatusMask(isAdd, isDelete, isModify);
58     }
59
60     private static FlowRemovedMask deserializeFlowRemovedMask(final ByteBuf byteBuf) {
61         final long mask = byteBuf.readUnsignedInt();
62         final boolean isIdleTimeout = (mask & (1)) != 0;
63         final boolean isHardTimeout = (mask & (1 << 1)) != 0;
64         final boolean isDelete = (mask & (1 << 2)) != 0;
65         final boolean isGroupDelete = (mask & (1 << 3)) != 0;
66         return new FlowRemovedMask(isDelete, isGroupDelete, isHardTimeout, isIdleTimeout);
67     }
68 }