Merge "Fix onSwitchIdleEvent echo request-reply xid"
[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 io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfIcmpType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IcmpTypeCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.icmp.type.grouping.IcmpTypeValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IcmpTypeCaseValueBuilder;
24
25 /**
26  * @author Josh Hershberg (jhershbe@redhat.com)
27  */
28 public class IcmpTypeCodec extends AbstractMatchCodec {
29     private static final int VALUE_LENGTH = 1;
30     private static final int NXM_FIELD_CODE = 13;
31     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfIcmpType> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
32             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfIcmpType.class);
33     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
34             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
35
36     @Override
37     public MatchEntry deserialize(ByteBuf message) {
38         MatchEntryBuilder matchEntriesBuilder = deserializeHeaderToBuilder(message);
39         IcmpTypeCaseValueBuilder icmpTypeCaseValueBuilder = new IcmpTypeCaseValueBuilder();
40         icmpTypeCaseValueBuilder.setIcmpTypeValues(new IcmpTypeValuesBuilder().setValue(message.readUnsignedByte()).build());
41         matchEntriesBuilder.setMatchEntryValue(icmpTypeCaseValueBuilder.build());
42         matchEntriesBuilder.setHasMask(false);
43         return matchEntriesBuilder.build();
44     }
45
46     @Override
47     public void serialize(MatchEntry input, ByteBuf outBuffer) {
48         serializeHeader(input, outBuffer);
49         IcmpTypeCaseValue icmpTypeValue = ((IcmpTypeCaseValue) input.getMatchEntryValue());
50         outBuffer.writeByte(icmpTypeValue.getIcmpTypeValues().getValue());
51     }
52
53     @Override
54     public int getNxmFieldCode() {
55         return NXM_FIELD_CODE;
56     }
57
58     @Override
59     public int getOxmClassCode() {
60         return OxmMatchConstants.NXM_0_CLASS;
61     }
62
63     @Override
64     public int getValueLength() {
65         return VALUE_LENGTH;
66     }
67
68     @Override
69     public Class<? extends MatchField> getNxmField() {
70         return NxmOfIcmpType.class;
71     }
72
73     @Override
74     public Class<? extends OxmClassBase> getOxmClass() {
75         return Nxm0Class.class;
76     }
77 }