Merge "Replace odl-dlux-core with odl-dluxapps-topology"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / match / TunnelIdEntryDeserializer.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.match;
10
11 import java.math.BigInteger;
12 import java.util.Objects;
13
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
17
18 import io.netty.buffer.ByteBuf;
19
20 public class TunnelIdEntryDeserializer extends AbstractMatchEntryDeserializer {
21
22     @Override
23     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
24         final boolean hasMask = processHeader(message);
25
26         final byte[] tunnelId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
27         message.readBytes(tunnelId);
28         final TunnelBuilder tunnelBuilder = new TunnelBuilder()
29             .setTunnelId(new BigInteger(1, tunnelId));
30
31         if (hasMask) {
32             final byte[] tunnelMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
33             message.readBytes(tunnelMask);
34             tunnelBuilder.setTunnelMask(new BigInteger(1, tunnelMask));
35         }
36
37         if (Objects.isNull(builder.getTunnel())) {
38             builder.setTunnel(tunnelBuilder.build());
39         } else {
40             throwErrorOnMalformed(builder, "tunnel");
41         }
42     }
43
44 }