NXM_NX_NSP openflow extended match support.
[ovsdb.git] / of-extension / nx-ofjava / src / main / java / org / opendaylight / ovs / nx / ofjava / codec / match / NspCodec.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc.
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  * Authors : Madhu Venugopal
9  */
10
11 package org.opendaylight.ovs.nx.ofjava.codec.match;
12 import io.netty.buffer.ByteBuf;
13
14 import org.opendaylight.openflowjava.nx.codec.match.AbstractMatchCodec;
15 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MatchField;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm1Class;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmClassBase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.match.rev140421.NxmNxNsp;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.match.rev140421.OfjAugNxMatch;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.match.rev140421.OfjAugNxMatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.ovs.nx.match.rev140421.ofj.nxm.nx.match.nsp.grouping.NspValuesBuilder;
28
29 public class NspCodec extends AbstractMatchCodec {
30
31     private static final int VALUE_LENGTH = 4;
32     private static final int NXM_FIELD_CODE = 37;
33     public static final MatchEntrySerializerKey<Nxm1Class, NxmNxNsp> SERIALIZER_KEY = new MatchEntrySerializerKey<>(
34             EncodeConstants.OF13_VERSION_ID, Nxm1Class.class, NxmNxNsp.class);
35     public static final MatchEntryDeserializerKey DESERIALIZER_KEY = new MatchEntryDeserializerKey(
36             EncodeConstants.OF13_VERSION_ID, OxmMatchConstants.NXM_1_CLASS, NXM_FIELD_CODE);
37
38     @Override
39     public void serialize(MatchEntries input, ByteBuf outBuffer) {
40         serializeHeader(input, outBuffer);
41         Long nsp = input.getAugmentation(OfjAugNxMatch.class).getNspValues().getNsp();
42         outBuffer.writeInt(nsp.intValue());
43     }
44
45     @Override
46     public MatchEntries deserialize(ByteBuf message) {
47         MatchEntriesBuilder matchEntriesBuilder = deserializeHeader(message);
48         OfjAugNxMatchBuilder augNxMatchBuilder = new OfjAugNxMatchBuilder();
49         augNxMatchBuilder.setNspValues(new NspValuesBuilder().setNsp(message.readUnsignedInt()).build());
50         matchEntriesBuilder.addAugmentation(OfjAugNxMatch.class, augNxMatchBuilder.build());
51         return matchEntriesBuilder.build();
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 NxmNxNsp.class;
72     }
73
74     @Override
75     public Class<? extends OxmClassBase> getOxmClass() {
76         return Nxm1Class.class;
77     }
78 }