Bug 6050 - TcpSrcCodec is not maskable
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / TcpDstCodec.java
1 /*
2  * Copyright (c) 2015 Hewlett-Packard Enterprise 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.openflowjava.nx.codec.match;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
19
20 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
21 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfTcpDst;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.dst.grouping.TcpDstValuesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TcpDstCaseValueBuilder;
28
29 /**
30  * @author Aswin Suryanarayanan.
31  */
32
33 public class TcpDstCodec extends AbstractMatchCodec {
34
35     private static final int VALUE_LENGTH = 4;
36     private static final int NXM_FIELD_CODE = 10;
37     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfTcpDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
38             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfTcpDst.class);
39     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
40             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
41
42     @Override
43     public void serialize(MatchEntry input, ByteBuf outBuffer) {
44         serializeHeader(input, outBuffer);
45         TcpDstCaseValue tcpDstCase = ((TcpDstCaseValue) input.getMatchEntryValue());
46         outBuffer.writeShort(tcpDstCase.getTcpDstValues().getPort().getValue());
47     }
48
49     @Override
50     public MatchEntry deserialize(ByteBuf message) {
51         MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
52         int portNo = message.readUnsignedShort();
53         TcpDstCaseValueBuilder caseBuilder = new TcpDstCaseValueBuilder();
54         TcpDstValuesBuilder tcpDstValuesBuilder = new TcpDstValuesBuilder();
55         tcpDstValuesBuilder.setPort(new PortNumber(portNo));
56         caseBuilder.setTcpDstValues(tcpDstValuesBuilder.build());
57         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
58         return matchEntryBuilder.build();
59     }
60
61     @Override
62     public int getNxmFieldCode() {
63         return NXM_FIELD_CODE;
64     }
65
66     @Override
67     public int getOxmClassCode() {
68         return OxmMatchConstants.NXM_0_CLASS;
69     }
70
71     @Override
72     public int getValueLength() {
73         return VALUE_LENGTH;
74     }
75
76     @Override
77     public Class<? extends MatchField> getNxmField() { return NxmOfTcpDst.class; }
78
79     @Override
80     public Class<? extends OxmClassBase> getOxmClass() {
81         return Nxm0Class.class;
82     }
83
84 }