Refactor AbstractOxmMatchEntryDeserializer
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / match / OxmTunnelIdDeserializer.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TunnelId;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCaseBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelIdBuilder;
15
16 /**
17  * Translates OxmTunnelId messages.
18  *
19  * @author michal.polkorab
20  */
21 public class OxmTunnelIdDeserializer extends AbstractOxmMatchEntryDeserializer {
22     public OxmTunnelIdDeserializer() {
23         super(TunnelId.class);
24     }
25
26     @Override
27     protected void deserialize(final ByteBuf input, final MatchEntryBuilder builder) {
28         final byte[] metadataBytes = new byte[Long.BYTES];
29         input.readBytes(metadataBytes);
30         final TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder()
31                 .setTunnelId(metadataBytes);
32         if (builder.isHasMask()) {
33             tunnelIdBuilder.setMask(OxmDeserializerHelper.convertMask(input, Long.BYTES));
34         }
35         builder.setMatchEntryValue(new TunnelIdCaseBuilder().setTunnelId(tunnelIdBuilder.build()).build());
36     }
37 }