--- /dev/null
+/*
+ * Copyright (c) 2016 ZTE, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowjava.protocol.api.keys;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+/**
+ * Created by hyy on 2016/9/8.
+ */
+public class ExperimenterIdMeterSubTypeSerializerKey<T extends DataContainer> extends ExperimenterIdSerializerKey<T> {
+
+ private Class<? extends ExperimenterMeterBandSubType> meterSubType;
+
+ /**
+ * @param msgVersion protocol wire version
+ * @param experimenterId experimenter / vendor ID
+ * @param objectClass class of object to be serialized
+ * @param meterSubType vendor defined subtype
+ */
+ public ExperimenterIdMeterSubTypeSerializerKey(short msgVersion, long experimenterId,
+ Class<T> objectClass, Class<? extends ExperimenterMeterBandSubType> meterSubType) {
+ super(msgVersion, experimenterId, objectClass);
+ this.meterSubType = meterSubType;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((meterSubType == null) ? 0 : meterSubType.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ExperimenterIdMeterSubTypeSerializerKey other = (ExperimenterIdMeterSubTypeSerializerKey) obj;
+ if (meterSubType == null) {
+ if (other.meterSubType != null) {
+ return false;
+ }
+ } else if (!meterSubType.equals(other.meterSubType)) {
+ return false;
+ }
+ return true;
+ }
+
+}
leaf experimenter {
type oft:experimenter-id;
}
+ leaf sub-type {
+ type identityref {
+ base oft:experimenter-meter-band-sub-type;
+ }
+ }
}
}
description "Base identity for action types";
}
+ identity experimenter-meter-band-sub-type {
+ description "The base identity for vendor's meter bands.";
+ }
+
typedef metadata {
type binary;
}
package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
import io.netty.buffer.ByteBuf;
-
-import java.util.List;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterBandCommons;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemark;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
/**
* Translates MeterMod messages
public class MeterModInputMessageFactory implements OFSerializer<MeterModInput>,
SerializerRegistryInjector {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(MeterModInputMessageFactory.class);
private static final byte MESSAGE_TYPE = 29;
private static final short LENGTH_OF_METER_BANDS = 16;
private static final short PADDING_IN_METER_BAND_DROP = 4;
} else if (meterBand instanceof MeterBandExperimenterCase) {
MeterBandExperimenterCase experimenterBandCase = (MeterBandExperimenterCase) meterBand;
MeterBandExperimenter experimenterBand = experimenterBandCase.getMeterBandExperimenter();
- long expId = experimenterBand.getAugmentation(ExperimenterIdMeterBand.class)
- .getExperimenter().getValue();
- OFSerializer<MeterBandExperimenterCase> serializer = registry.getSerializer(
- ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
- EncodeConstants.OF13_VERSION_ID, expId));
- serializer.serialize(experimenterBandCase, outBuffer);
+ ExperimenterIdMeterBand expIdMeterBand = experimenterBand.getAugmentation(ExperimenterIdMeterBand.class);
+ if (expIdMeterBand != null) {
+ long expId = expIdMeterBand.getExperimenter().getValue();
+ Class<? extends ExperimenterMeterBandSubType> meterBandSubType = expIdMeterBand.getSubType();
+ try {
+ OFSerializer<MeterBandExperimenterCase> serializer = registry.getSerializer(
+ ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
+ EncodeConstants.OF13_VERSION_ID, expId, meterBandSubType));
+ serializer.serialize(experimenterBandCase, outBuffer);
+ } catch (final IllegalStateException e) {
+ LOG.warn("Serializer for key: {} wasn't found, exception {}", ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
+ EncodeConstants.OF13_VERSION_ID, expId, meterBandSubType), e);
+ }
+ }
}
}
}
package org.opendaylight.openflowjava.util;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
*/
public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
short msgVersion, long experimenterId) {
- return new ExperimenterIdSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class);
+ return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, null);
+ }
+
+ public static ExperimenterIdSerializerKey<MeterBandExperimenterCase> createMeterBandSerializerKey(
+ short msgVersion, long experimenterId, Class<? extends ExperimenterMeterBandSubType> meterSubType) {
+ return new ExperimenterIdMeterSubTypeSerializerKey<>(msgVersion, experimenterId, MeterBandExperimenterCase.class, meterSubType);
}
}
\ No newline at end of file
import org.junit.Assert;
import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
43L, MeterBandExperimenterCase.class);
Assert.assertEquals("Wrong key created", comparationKey, createdKey);
}
+
+ @Test
+ public void testCreateMeterBandSubTypeSerializerKey() throws Exception {
+ ExperimenterIdSerializerKey<?> createdKey;
+ ExperimenterIdSerializerKey<?> comparationKey1;
+ ExperimenterIdSerializerKey<?> comparationKey2;
+ ExperimenterIdSerializerKey<?> comparationKey3;
+ ExperimenterIdSerializerKey<?> comparationKey4;
+ ExperimenterIdSerializerKey<?> comparationKey5;
+
+ createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(
+ EncodeConstants.OF10_VERSION_ID, 43L, ExperimenterMeterBandSubType.class);
+ comparationKey1 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF13_VERSION_ID,
+ 43L, MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.class);
+ comparationKey2 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
+ 42L, MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.class);
+ comparationKey3 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
+ 43L, null, ExperimenterMeterBandSubType.class);
+ comparationKey4 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
+ 43L, MeterBandExperimenterCase.class, null);
+ comparationKey5 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
+ 43L, MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.class);
+ Assert.assertNotEquals("Wrong key created", comparationKey1, createdKey);
+ Assert.assertNotEquals("Wrong key created", comparationKey2, createdKey);
+ Assert.assertNotEquals("Wrong key created", comparationKey3, createdKey);
+ Assert.assertNotEquals("Wrong key created", comparationKey4, createdKey);
+ Assert.assertEquals("Wrong key created", comparationKey5, createdKey);
+ }
}
\ No newline at end of file