Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[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 package org.opendaylight.openflowplugin.impl.protocol.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import java.math.BigInteger;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
14
15 public class TunnelIdEntryDeserializer extends AbstractMatchEntryDeserializer {
16     @Override
17     public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
18         final boolean hasMask = processHeader(message);
19
20         final byte[] tunnelId = new byte[Long.BYTES];
21         message.readBytes(tunnelId);
22         final TunnelBuilder tunnelBuilder = new TunnelBuilder()
23             .setTunnelId(new BigInteger(1, tunnelId));
24
25         if (hasMask) {
26             final byte[] tunnelMask = new byte[Long.BYTES];
27             message.readBytes(tunnelMask);
28             tunnelBuilder.setTunnelMask(new BigInteger(1, tunnelMask));
29         }
30
31         if (builder.getTunnel() == null) {
32             builder.setTunnel(tunnelBuilder.build());
33         } else {
34             throwErrorOnMalformed(builder, "tunnel");
35         }
36     }
37 }