2 * Copyright (C) 2014 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal
11 package org.opendaylight.ovs.nx.ofjava.codec.match;
12 import io.netty.buffer.ByteBuf;
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;
29 public class NspCodec extends AbstractMatchCodec {
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);
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());
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();
55 public int getNxmFieldCode() {
56 return NXM_FIELD_CODE;
60 public int getOxmClassCode() {
61 return OxmMatchConstants.NXM_1_CLASS;
65 public int getValueLength() {
70 public Class<? extends MatchField> getNxmField() {
71 return NxmNxNsp.class;
75 public Class<? extends OxmClassBase> getOxmClass() {
76 return Nxm1Class.class;