1 package org.opendaylight.openflowjava.nx.codec.match;
3 import io.netty.buffer.ByteBuf;
4 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
5 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
6 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
7 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TunnelId;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TunnelIdCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tunnel.id._case.TunnelIdBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxTunId;
19 import java.math.BigInteger;
21 public class TunIdCodec extends AbstractMatchCodec {
23 private static final int VALUE_LENGTH = 8;
24 private static final int NXM_FIELD_CODE = 16;
25 public static final MatchEntrySerializerKey<Nxm1Class, NxmNxTunId> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
26 EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxTunId.class);
27 public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
28 EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
31 public void serialize(MatchEntry input, ByteBuf outBuffer) {
32 serializeHeader(input, outBuffer);
33 TunnelIdCase value = ((TunnelIdCase) input.getMatchEntryValue());
34 outBuffer.writeBytes(value.getTunnelId().getTunnelId());
35 byte[] mask = value.getTunnelId().getTunnelId();
37 outBuffer.writeBytes(mask);
42 public MatchEntry deserialize(ByteBuf message) {
43 MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message);
44 TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder();
45 TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder();
46 tunnelIdBuilder.setTunnelId(BigInteger.valueOf(message.readLong()).toByteArray());
47 tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build());
48 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
49 matchEntriesBuilder.setOxmMatchField(TunnelId.class);
50 matchEntriesBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build());
51 return matchEntriesBuilder.build();
55 public int getNxmFieldCode() {
56 return NXM_FIELD_CODE;
60 public int getOxmClassCode() {
61 return OxmMatchConstants.NXM_1_CLASS;
65 public int getValueLength() {
70 public Class<? extends MatchField> getNxmField() {
71 return NxmNxTunId.class;
75 public Class<? extends OxmClassBase> getOxmClass() {
76 return Nxm1Class.class;