2 * Copyright (c) 2015 Hewlett-Packard Enterprise and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.nx.codec.match;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfTcpDst;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.dst.grouping.TcpDstValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
28 * Codec for the TcpDst message.
30 * @author Aswin Suryanarayanan.
32 public class TcpDstCodec extends AbstractMatchCodec {
34 private static final int VALUE_LENGTH = 2;
35 private static final int NXM_FIELD_CODE = 10;
36 public static final MatchEntrySerializerKey<Nxm0Class, NxmOfTcpDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
37 EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfTcpDst.class);
38 public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
39 EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
42 public void serialize(MatchEntry input, ByteBuf outBuffer) {
43 serializeHeader(input, outBuffer);
44 TcpDstCaseValue tcpDstCase = (TcpDstCaseValue) input.getMatchEntryValue();
45 outBuffer.writeShort(tcpDstCase.getTcpDstValues().getPort().getValue());
46 outBuffer.writeShort(tcpDstCase.getTcpDstValues().getMask());
50 public MatchEntry deserialize(ByteBuf message) {
51 MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
52 matchEntryBuilder.setHasMask(true);
53 int portNo = message.readUnsignedShort();
54 int mask = message.readUnsignedShort();
55 TcpDstCaseValueBuilder caseBuilder = new TcpDstCaseValueBuilder();
56 TcpDstValuesBuilder tcpDstValuesBuilder = new TcpDstValuesBuilder();
57 tcpDstValuesBuilder.setPort(new PortNumber(portNo));
58 tcpDstValuesBuilder.setMask(mask);
59 caseBuilder.setTcpDstValues(tcpDstValuesBuilder.build());
60 matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
61 return matchEntryBuilder.build();
65 public int getNxmFieldCode() {
66 return NXM_FIELD_CODE;
70 public int getOxmClassCode() {
71 return OxmMatchConstants.NXM_0_CLASS;
75 public int getValueLength() {
80 public Class<? extends MatchField> getNxmField() {
81 return NxmOfTcpDst.class;
85 public Class<? extends OxmClassBase> getOxmClass() {
86 return Nxm0Class.class;