Merge "Bug 8535: Fix IPv6 OXMHeader Mask issue"
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / Ipv6DstCodec.java
1 /*
2  * Copyright (c) 2017 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.openflow.oxm.rev150225.MatchField;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfIpDst;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.ip.dst.grouping.IpDstValuesBuilder;
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
25 /**
26  * @author Sridhar Gaddam (sgaddam@redhat.com)
27  */
28 public class Ipv6DstCodec extends AbstractMatchCodec {
29
30     private static final int VALUE_LENGTH = 16;
31     private static final int NXM_FIELD_CODE = 20;
32     public static final MatchEntrySerializerKey<Nxm1Class, NxmOfIpDst> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
33             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmOfIpDst.class);
34     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
35             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
36
37
38     @Override
39     public MatchEntry deserialize(ByteBuf message) {
40         MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message);
41         IpDstCaseValueBuilder caseBuilder = new IpDstCaseValueBuilder();
42         caseBuilder.setIpDstValues(new IpDstValuesBuilder().setValue(message.readUnsignedInt()).build());
43         matchEntriesBuilder.setMatchEntryValue(caseBuilder.build());
44         return matchEntriesBuilder.build();
45     }
46
47     @Override
48     public void serialize(MatchEntry input, ByteBuf outBuffer) {
49         serializeHeader(input, outBuffer);
50         IpDstCaseValue ipDstCase = ((IpDstCaseValue) input.getMatchEntryValue());
51         outBuffer.writeInt(ipDstCase.getIpDstValues().getValue().intValue());
52     }
53
54     @Override
55     public int getNxmFieldCode() {
56         return NXM_FIELD_CODE;
57     }
58
59     @Override
60     public int getOxmClassCode() {
61         return OxmMatchConstants.NXM_1_CLASS;
62     }
63
64     @Override
65     public int getValueLength() {
66         return VALUE_LENGTH;
67     }
68
69     @Override
70     public Class<? extends MatchField> getNxmField() {
71         return NxmOfIpDst.class;
72     }
73
74     @Override
75     public Class<? extends OxmClassBase> getOxmClass() {
76         return Nxm1Class.class;
77     }
78
79 }