Bump MRI upstreams
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / TcpSrcCodec.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 package org.opendaylight.openflowjava.nx.codec.match;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfTcpSrc;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.TcpSrcCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.TcpSrcCaseValueBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.tcp.src.grouping.TcpSrcValuesBuilder;
26
27 /**
28  * Codec for the TcpSrc message..
29  *
30  * @author Aswin Suryanarayanan.
31  */
32 public class TcpSrcCodec extends AbstractMatchCodec {
33
34     private static final int VALUE_LENGTH = 2;
35     private static final int NXM_FIELD_CODE = 9;
36     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfTcpSrc> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
37             EncodeConstants.OF_VERSION_1_3, Nxm0Class.class, NxmOfTcpSrc.class);
38     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
39             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
40
41     @Override
42     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
43         serializeHeader(input, outBuffer);
44         TcpSrcCaseValue tcpSrcCase = (TcpSrcCaseValue) input.getMatchEntryValue();
45         outBuffer.writeShort(tcpSrcCase.getTcpSrcValues().getPort().getValue().toJava());
46         outBuffer.writeShort(tcpSrcCase.getTcpSrcValues().getMask().toJava());
47     }
48
49     @Override
50     public MatchEntry deserialize(final ByteBuf message) {
51         return deserializeHeaderToBuilder(message)
52                 .setHasMask(true)
53                 .setMatchEntryValue(new TcpSrcCaseValueBuilder()
54                     .setTcpSrcValues(new TcpSrcValuesBuilder()
55                         .setPort(new PortNumber(readUint16(message)))
56                         .setMask(readUint16(message))
57                         .build())
58                     .build())
59                 .build();
60     }
61
62     @Override
63     public int getNxmFieldCode() {
64         return NXM_FIELD_CODE;
65     }
66
67     @Override
68     public int getOxmClassCode() {
69         return OxmMatchConstants.NXM_0_CLASS;
70     }
71
72     @Override
73     public int getValueLength() {
74         return VALUE_LENGTH;
75     }
76
77     @Override
78     public Class<? extends MatchField> getNxmField() {
79         return NxmOfTcpSrc.class;
80     }
81
82     @Override
83     public Class<? extends OxmClassBase> getOxmClass() {
84         return Nxm0Class.class;
85     }
86 }