Bug 6633 : NXM_OF_IN_PORT support in openflowplugin
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / match / InPortCodec.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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 org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
11 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfInPort;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.in.port.type.grouping.NxmOfInPortValuesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.OfInPortCaseValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.OfInPortCaseValueBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import io.netty.buffer.ByteBuf;
27
28 public class InPortCodec extends AbstractMatchCodec {
29
30     private static final int VALUE_LENGTH = 2;
31     private static final int NXM_FIELD_CODE = 0;
32
33     public static final MatchEntrySerializerKey<Nxm0Class, NxmOfInPort> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
34             EncodeConstants.OF13_VERSION_ID, Nxm0Class.class,
35             NxmOfInPort.class);
36
37     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
38             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_0_CLASS,
39             NXM_FIELD_CODE);
40
41     @Override
42     public void serialize(MatchEntry input, ByteBuf outBuffer) {
43         serializeHeader(input, outBuffer);
44         OfInPortCaseValue value = (OfInPortCaseValue) input.getMatchEntryValue();
45         outBuffer.writeInt(value.getNxmOfInPortValues().getValue());
46     }
47
48     @Override
49     public MatchEntry deserialize(ByteBuf message) {
50         MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
51         OfInPortCaseValueBuilder caseBuilder = new OfInPortCaseValueBuilder();
52         NxmOfInPortValuesBuilder valuesBuilder = new NxmOfInPortValuesBuilder();
53         valuesBuilder.setValue(message.readInt()).build();
54         caseBuilder.setNxmOfInPortValues(valuesBuilder.build());
55         matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
56         return matchEntryBuilder.build();
57     }
58
59     @Override
60     public int getNxmFieldCode() {
61         return NXM_FIELD_CODE;
62     }
63
64     @Override
65     public int getOxmClassCode() {
66         return OxmMatchConstants.NXM_0_CLASS;
67     }
68
69     @Override
70     public int getValueLength() {
71         return VALUE_LENGTH;
72     }
73
74     @Override
75     public Class<? extends MatchField> getNxmField() {
76         return NxmOfInPort.class;
77     }
78
79     @Override
80     public Class<? extends OxmClassBase> getOxmClass() {
81         return Nxm0Class.class;
82     }
83
84 }