Bump mdsal to 5.0.2
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / CtZoneCodec.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
9 package org.opendaylight.openflowjava.nx.codec.match;
10
11 import io.netty.buffer.ByteBuf;
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.openflow.oxm.rev150225.MatchField;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
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.NxmNxCtZone;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.zone.grouping.CtZoneValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
25
26 /**
27  * Codec for CtZone.
28  *
29  * @author Aswin Suryanarayanan.
30  */
31 public class CtZoneCodec extends AbstractMatchCodec {
32
33     private static final int VALUE_LENGTH = 2;
34     private static final int NXM_FIELD_CODE = 106;
35     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxCtZone> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
36             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxCtZone.class);
37     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
38             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
39
40     @Override
41     public void serialize(MatchEntry input, ByteBuf outBuffer) {
42         serializeHeader(input, outBuffer);
43         CtZoneCaseValue ctZoneCase = (CtZoneCaseValue) input.getMatchEntryValue();
44         outBuffer.writeShort(ctZoneCase.getCtZoneValues().getCtZone().toJava());
45     }
46
47     @Override
48     public MatchEntry deserialize(ByteBuf message) {
49         MatchEntryBuilder matchEntryBuilder = deserializeHeaderToBuilder(message);
50         CtZoneCaseValueBuilder caseBuilder = new CtZoneCaseValueBuilder();
51         CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder();
52         ctZoneValuesBuilder.setCtZone(message.readUnsignedShort());
53         caseBuilder.setCtZoneValues(ctZoneValuesBuilder.build());
54         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
55         return matchEntryBuilder.build();
56     }
57
58     @Override
59     public int getNxmFieldCode() {
60         return NXM_FIELD_CODE;
61     }
62
63     @Override
64     public int getOxmClassCode() {
65         return OxmMatchConstants.NXM_1_CLASS;
66     }
67
68     @Override
69     public int getValueLength() {
70         return VALUE_LENGTH;
71     }
72
73     @Override
74     public Class<? extends MatchField> getNxmField() {
75         return NxmNxCtZone.class;
76     }
77
78     @Override
79     public Class<? extends OxmClassBase> getOxmClass() {
80         return Nxm1Class.class;
81     }
82
83 }