Merge "Added Conntrack Support in Nicira Extenstion."
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / CtStateCodec.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
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
18 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
19 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxCtState;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.ct.state.grouping.CtStateValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtStateCaseValueBuilder;
26
27 /**
28  * @author Aswin Suryanarayanan.
29  */
30
31 public class CtStateCodec extends AbstractMatchCodec {
32
33     private static final int VALUE_LENGTH = 8;
34     private static final int NXM_FIELD_CODE = 105;
35     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxCtState> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
36             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxCtState.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         CtStateCaseValue ctStateCase = ((CtStateCaseValue) input.getMatchEntryValue());
44         outBuffer.writeInt(ctStateCase.getCtStateValues().getCtState().intValue());
45         outBuffer.writeInt(ctStateCase.getCtStateValues().getMask().intValue());
46     }
47
48     @Override
49     public MatchEntry deserialize(ByteBuf message) {
50         MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
51         CtStateCaseValueBuilder caseBuilder = new CtStateCaseValueBuilder();
52         CtStateValuesBuilder ctStateValuesBuilder = new CtStateValuesBuilder();
53         ctStateValuesBuilder.setCtState(message.readUnsignedInt());
54         ctStateValuesBuilder.setMask(message.readUnsignedInt());
55         caseBuilder.setCtStateValues(ctStateValuesBuilder.build());
56         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
57         matchEntryBuilder.setHasMask(true);
58         return matchEntryBuilder.build();
59     }
60
61     @Override
62     public int getNxmFieldCode() {
63         return NXM_FIELD_CODE;
64     }
65
66     @Override
67     public int getOxmClassCode() {
68         return OxmMatchConstants.NXM_1_CLASS;
69     }
70
71     @Override
72     public int getValueLength() {
73         return VALUE_LENGTH;
74     }
75
76     @Override
77     public Class<? extends MatchField> getNxmField() {
78         return NxmNxCtState.class;
79     }
80
81     @Override
82     public Class<? extends OxmClassBase> getOxmClass() {
83         return Nxm1Class.class;
84     }
85
86 }