BUG-4132 add ip src,dst and icmp type match attrs
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / IpDstCodec.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
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.opendaylight.openflowjava.nx.match.rev140421.NxmOfIpDst;
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.oxm.container.match.entry.value.IpDstCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IpDstCaseValueBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.ip.dst.grouping.IpDstValuesBuilder;
25
26 /**
27  * @author Josh Hershberg (jhershbe@redhat.com)
28  */
29 public class IpDstCodec extends AbstractMatchCodec {
30
31     private static final int VALUE_LENGTH = 4;
32     private static final int NXM_FIELD_CODE = 8;
33     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfIpDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
34             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class, NxmOfIpDst.class);
35     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
36             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS, NXM_FIELD_CODE);
37
38
39     @Override
40     public MatchEntry deserialize(ByteBuf message) {
41         MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message);
42         IpDstCaseValueBuilder caseBuilder = new IpDstCaseValueBuilder();
43         caseBuilder.setIpDstValues(new IpDstValuesBuilder().setValue(message.readUnsignedInt()).build());
44         matchEntriesBuilder.setMatchEntryValue(caseBuilder.build());
45         return matchEntriesBuilder.build();
46     }
47
48     @Override
49     public void serialize(MatchEntry input, ByteBuf outBuffer) {
50         serializeHeader(input, outBuffer);
51         IpDstCaseValue ipDstCase = ((IpDstCaseValue) input.getMatchEntryValue());
52         outBuffer.writeInt(ipDstCase.getIpDstValues().getValue().intValue());
53     }
54
55     @Override
56     public int getNxmFieldCode() {
57         return NXM_FIELD_CODE;
58     }
59
60     @Override
61     public int getOxmClassCode() {
62         return OxmMatchConstants.NXM_0_CLASS;
63     }
64
65     @Override
66     public int getValueLength() {
67         return VALUE_LENGTH;
68     }
69
70     @Override
71     public Class<? extends MatchField> getNxmField() {
72         return NxmOfIpDst.class;
73     }
74
75     @Override
76     public Class<? extends OxmClassBase> getOxmClass() {
77         return Nxm0Class.class;
78     }
79
80 }