2 * Copyright (c) 2014 Red Hat, Inc. and others. All rights reserved.
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 package org.opendaylight.openflowjava.nx.codec.match;
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
14 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
15 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ExperimenterClass;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNsi;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsi.grouping.NsiValues;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsi.grouping.NsiValuesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.NxExpMatchEntryValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NsiCaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NsiCaseValueBuilder;
25 import org.opendaylight.yangtools.yang.common.Uint32;
26 import org.opendaylight.yangtools.yang.common.Uint8;
28 public class NsiCodec extends AbstractExperimenterMatchCodec {
30 private static final int VALUE_LENGTH = EncodeConstants.SIZE_OF_BYTE_IN_BYTES;
31 private static final int NXM_FIELD_CODE = 5;
32 public static final MatchEntrySerializerKey<ExperimenterClass, NxmNxNsi> SERIALIZER_KEY =
34 EncodeConstants.OF13_VERSION_ID,
35 NiciraConstants.NX_NSH_VENDOR_ID,
37 public static final MatchEntryDeserializerKey DESERIALIZER_KEY =
38 createDeserializerKey(
39 EncodeConstants.OF13_VERSION_ID,
40 NiciraConstants.NX_NSH_VENDOR_ID,
44 protected void serializeValue(final NxExpMatchEntryValue value, final boolean hasMask, final ByteBuf outBuffer) {
45 NsiCaseValue nsiCaseValue = (NsiCaseValue) value;
46 NsiValues nsiValues = nsiCaseValue.getNsiValues();
47 outBuffer.writeByte(nsiValues.getNsi().toJava());
49 outBuffer.writeByte(nsiValues.getMask().toJava());
54 protected NxExpMatchEntryValue deserializeValue(final ByteBuf message, final boolean hasMask) {
55 Uint8 value = readUint8(message);
56 Uint8 mask = hasMask ? readUint8(message) : null;
57 NsiValues nsiValues = new NsiValuesBuilder().setNsi(value).setMask(mask).build();
58 return new NsiCaseValueBuilder().setNsiValues(nsiValues).build();
62 public int getNxmFieldCode() {
63 return NXM_FIELD_CODE;
67 protected Uint32 getExperimenterId() {
68 return NiciraConstants.NX_NSH_VENDOR_ID;
72 public int getValueLength() {
77 public Class<? extends MatchField> getNxmField() {
78 return NxmNxNsi.class;