Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / IcmpTypeCodec.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. 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.readUint8;
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.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.openflowjava.nx.match.rev140421.NxmOfIcmpType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.IcmpTypeCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.aug.nx.match.IcmpTypeCaseValueBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.icmp.type.grouping.IcmpTypeValuesBuilder;
25
26 /**
27  * Codec for the Icmp type message.
28  *
29  * @author Josh Hershberg (jhershbe@redhat.com)
30  */
31 public class IcmpTypeCodec extends AbstractMatchCodec {
32     private static final int VALUE_LENGTH = 1;
33     private static final int NXM_FIELD_CODE = 13;
34     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfIcmpType> SERIALIZER_KEY =
35             new MatchEntrySerializerKey<>(EncodeConstants.OF_VERSION_1_3, Nxm0Class.VALUE, NxmOfIcmpType.VALUE);
36     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
37             EncodeConstants.OF_VERSION_1_3, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
38
39     @Override
40     public MatchEntry deserialize(final ByteBuf message) {
41         return deserializeHeaderToBuilder(message)
42                 .setMatchEntryValue(new IcmpTypeCaseValueBuilder()
43                     .setIcmpTypeValues(new IcmpTypeValuesBuilder().setValue(readUint8(message)).build())
44                     .build())
45                 .setHasMask(false)
46                 .build();
47     }
48
49     @Override
50     public void serialize(final MatchEntry input, final ByteBuf outBuffer) {
51         serializeHeader(input, outBuffer);
52         IcmpTypeCaseValue icmpTypeValue = (IcmpTypeCaseValue) input.getMatchEntryValue();
53         outBuffer.writeByte(icmpTypeValue.getIcmpTypeValues().getValue().toJava());
54     }
55
56     @Override
57     public int getNxmFieldCode() {
58         return NXM_FIELD_CODE;
59     }
60
61     @Override
62     public int getOxmClassCode() {
63         return OxmMatchConstants.NXM_0_CLASS;
64     }
65
66     @Override
67     public int getValueLength() {
68         return VALUE_LENGTH;
69     }
70
71     @Override
72     public MatchField getNxmField() {
73         return NxmOfIcmpType.VALUE;
74     }
75
76     @Override
77     public OxmClassBase getOxmClass() {
78         return Nxm0Class.VALUE;
79     }
80 }