use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId in project openflowplugin by opendaylight.
the class FlowCapableNodeLookups method wrapMetersToMap.
@Nonnull
public static Map<MeterId, Meter> wrapMetersToMap(@Nullable final List<Meter> meters) {
final Map<MeterId, Meter> meterMap;
if (meters == null) {
meterMap = Collections.emptyMap();
} else {
LOG.trace("meters found: {}", meters.size());
meterMap = new HashMap<>();
for (Meter meter : meters) {
meterMap.put(meter.getMeterId(), meter);
}
}
return meterMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId in project openflowplugin by opendaylight.
the class ReconcileUtil method resolveMeterDiffs.
/**
* Resolves meter differences.
*
* @param nodeId target node
* @param meterOperationalMap meters present on device
* @param metersConfigured meters configured for device
* @param gatherUpdates check content of pending item if present on device (and create update task eventually)
* @return synchronization box
*/
public static ItemSyncBox<Meter> resolveMeterDiffs(final NodeId nodeId, final Map<MeterId, Meter> meterOperationalMap, final List<Meter> metersConfigured, final boolean gatherUpdates) {
LOG.trace("resolving meters for {}", nodeId.getValue());
final ItemSyncBox<Meter> syncBox = new ItemSyncBox<>();
for (Meter meter : metersConfigured) {
final Meter existingMeter = meterOperationalMap.get(meter.getMeterId());
if (existingMeter == null) {
syncBox.getItemsToPush().add(meter);
} else {
// compare content and eventually update
if (gatherUpdates && !meter.equals(existingMeter)) {
syncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingMeter, meter));
}
}
}
return syncBox;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId in project openflowplugin by opendaylight.
the class MeterModInputMessageFactory method deserialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public MeterModInput deserialize(ByteBuf rawMessage) {
Objects.requireNonNull(registry);
MeterModInputBuilder builder = new MeterModInputBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
builder.setCommand(MeterModCommand.forValue(rawMessage.readUnsignedShort()));
builder.setFlags(createMeterFlags(rawMessage.readUnsignedShort()));
builder.setMeterId(new MeterId(rawMessage.readUnsignedInt()));
List<Bands> bandsList = new ArrayList<>();
while (rawMessage.readableBytes() > 0) {
BandsBuilder bandsBuilder = new BandsBuilder();
int bandStartIndex = rawMessage.readerIndex();
int bandType = rawMessage.readUnsignedShort();
switch(bandType) {
case 1:
final MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
bandDropBuilder.setType(MeterBandType.forValue(bandType));
rawMessage.readUnsignedShort();
bandDropBuilder.setRate(rawMessage.readUnsignedInt());
bandDropBuilder.setBurstSize(rawMessage.readUnsignedInt());
rawMessage.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build());
bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
break;
case 2:
final MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
rawMessage.readUnsignedShort();
bandDscpRemarkBuilder.setRate(rawMessage.readUnsignedInt());
bandDscpRemarkBuilder.setBurstSize(rawMessage.readUnsignedInt());
bandDscpRemarkBuilder.setPrecLevel(rawMessage.readUnsignedByte());
rawMessage.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
break;
case 0xFFFF:
long expId = rawMessage.getUnsignedInt(rawMessage.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
rawMessage.readerIndex(bandStartIndex);
OFDeserializer<MeterBandExperimenterCase> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId));
bandsBuilder.setMeterBand(deserializer.deserialize(rawMessage));
break;
default:
break;
}
bandsList.add(bandsBuilder.build());
}
builder.setBands(bandsList);
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId in project openflowplugin by opendaylight.
the class MeterDirectStatisticsServiceTest method testBuildRequestBody.
@Override
public void testBuildRequestBody() throws Exception {
final GetMeterStatisticsInput input = mock(GetMeterStatisticsInput.class);
when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
when(input.getMeterId()).thenReturn(new MeterId(METER_NO));
final MultipartRequestMeterStats body = (MultipartRequestMeterStats) ((MultipartRequest) service.buildRequest(new Xid(42L), input)).getMultipartRequestBody();
assertEquals(METER_NO, body.getMeterId().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testMultipartReplyMeterBodyMulti.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyMeterBodyMulti() {
ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 " + // meterId_0
"00 00 00 09 " + // len_0
"00 58 " + // pad_0
"00 00 00 00 00 00 " + // flowCount_0
"00 00 00 07 " + // packetInCount_0
"FF 01 01 01 01 01 01 01 " + // byteInCount_0
"FF 01 01 01 01 01 01 01 " + // durationSec_0
"00 00 00 05 " + // durationNsec_0
"00 00 00 05 " + // packetBandCount_01
"FF 01 01 01 01 01 01 01 " + // byteBandCount_01
"FF 01 01 01 01 01 01 01 " + // packetBandCount_02
"FF 02 02 02 02 02 02 02 " + // byteBandCount_02
"FF 02 02 02 02 02 02 02 " + // packetBandCount_03
"FF 03 03 03 03 03 03 03 " + // byteBandCount_03
"FF 03 03 03 03 03 03 03 " + // meterId_1
"00 00 00 08 " + // len_1
"00 58 " + // pad_1
"00 00 00 00 00 00 " + // flowCount_1
"00 00 00 07 " + // packetInCount_1
"FF 01 01 01 01 01 01 01 " + // byteInCount_1
"FF 01 01 01 01 01 01 01 " + // durationSec_1
"00 00 00 05 " + // durationNsec_1
"00 00 00 05 " + // packetBandCount_11
"FF 01 01 01 01 01 01 01 " + // byteBandCount_11
"FF 01 01 01 01 01 01 01 " + // packetBandCount_12
"FF 02 02 02 02 02 02 02 " + // byteBandCount_12
"FF 02 02 02 02 02 02 02 " + // packetBandCount_13
"FF 03 03 03 03 03 03 03 " + // byteBandCount_13
"FF 03 03 03 03 03 03 03");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
MultipartReplyMeter message = messageCase.getMultipartReplyMeter();
Assert.assertEquals("Wrong meterId", 9, message.getMeterStats().get(0).getMeterId().getValue().intValue());
Assert.assertEquals("Wrong flowCount", 7, message.getMeterStats().get(0).getFlowCount().intValue());
Assert.assertEquals("Wrong packetInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getPacketInCount());
Assert.assertEquals("Wrong byteInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getByteInCount());
Assert.assertEquals("Wrong durationSec", 5, message.getMeterStats().get(0).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 5, message.getMeterStats().get(0).getDurationNsec().intValue());
Assert.assertEquals("Wrong packetBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
Assert.assertEquals("Wrong packetBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
Assert.assertEquals("Wrong packetBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
Assert.assertEquals("Wrong meterId", 8, message.getMeterStats().get(1).getMeterId().getValue().intValue());
Assert.assertEquals("Wrong flowCount", 7, message.getMeterStats().get(1).getFlowCount().intValue());
Assert.assertEquals("Wrong packetInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getPacketInCount());
Assert.assertEquals("Wrong byteInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getByteInCount());
Assert.assertEquals("Wrong durationSec", 5, message.getMeterStats().get(1).getDurationSec().intValue());
Assert.assertEquals("Wrong durationNsec", 5, message.getMeterStats().get(1).getDurationNsec().intValue());
Assert.assertEquals("Wrong packetBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount());
Assert.assertEquals("Wrong packetBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount());
Assert.assertEquals("Wrong packetBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount());
Assert.assertEquals("Wrong byteBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount());
}
Aggregations