Search in sources :

Example 6 with MeterBandHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader in project openflowplugin by opendaylight.

the class MeterConvertorTest method testMeterModCommandConvertorwithNoFlags.

@Test
public void testMeterModCommandConvertorwithNoFlags() {
    long burstSize = 10L;
    long dropRate = 20L;
    // / DROP Band
    MeterBandTypesBuilder meterBandTypesB = new MeterBandTypesBuilder();
    MeterBandType bandFlag = new MeterBandType(true, false, false);
    // _ofpmbtDrop
    meterBandTypesB.setFlags(bandFlag);
    DropBuilder drop = new DropBuilder();
    drop.setDropBurstSize(burstSize);
    drop.setDropRate(dropRate);
    Drop drp = drop.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder.setBandType(drp);
    meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesB.build());
    final MeterBandHeader meterBH = meterBandHeaderBuilder.build();
    // DSCP Mark
    final long dscpRemarkBurstSize = 11L;
    final long dscpRemarkRate = 21L;
    final short dscpPercLevel = 1;
    MeterBandTypesBuilder meterBandTypesB1 = new MeterBandTypesBuilder();
    MeterBandType bandFlag1 = new MeterBandType(false, true, false);
    meterBandTypesB1.setFlags(bandFlag1);
    DscpRemarkBuilder dscp = new DscpRemarkBuilder();
    dscp.setDscpRemarkBurstSize(dscpRemarkBurstSize);
    dscp.setDscpRemarkRate(dscpRemarkRate);
    dscp.setPrecLevel(dscpPercLevel);
    DscpRemark dscpRemark = dscp.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder1 = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder1.setBandType(dscpRemark);
    meterBandHeaderBuilder1.setMeterBandTypes(meterBandTypesB1.build());
    final MeterBandHeader meterBH1 = meterBandHeaderBuilder1.build();
    // Experimental
    final long expBurstSize = 12L;
    final long expRate = 22L;
    final long expExperimenter = 23L;
    MeterBandTypesBuilder meterBandTypesB2 = new MeterBandTypesBuilder();
    MeterBandType bandFlag2 = new MeterBandType(false, false, true);
    meterBandTypesB2.setFlags(bandFlag2);
    ExperimenterBuilder exp = new ExperimenterBuilder();
    exp.setExperimenterBurstSize(expBurstSize);
    exp.setExperimenterRate(expRate);
    exp.setExperimenter(expExperimenter);
    Experimenter experimenter = exp.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder2 = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder2.setBandType(experimenter);
    meterBandHeaderBuilder2.setMeterBandTypes(meterBandTypesB2.build());
    MeterBandHeader meterBH2 = meterBandHeaderBuilder2.build();
    List<MeterBandHeader> meterBandList = new ArrayList<>();
    meterBandList.add(0, meterBH);
    meterBandList.add(1, meterBH1);
    meterBandList.add(2, meterBH2);
    // Constructing List of Bands
    MeterBandHeadersBuilder meterBandHeadersBuilder = new MeterBandHeadersBuilder();
    meterBandHeadersBuilder.setMeterBandHeader(meterBandList);
    MeterBandHeaders meterBandHeaders = meterBandHeadersBuilder.build();
    AddMeterInputBuilder addMeterFromSAL = new AddMeterInputBuilder();
    // MeterBands
    addMeterFromSAL.setMeterBandHeaders(meterBandHeaders);
    // NodeKey key = new NodeKey(new NodeId("24"));
    // InstanceIdentifier<Node> path =
    // InstanceIdentifier.builder().node(Nodes.class).node(Node.class,
    // key).build();
    addMeterFromSAL.setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(10L));
    AddMeterInput meterInputCommand = addMeterFromSAL.build();
    MeterModInputBuilder outMeterModInput = convert(meterInputCommand, new VersionConvertorData((short) 0X4));
    assertEquals(MeterModCommand.OFPMCADD, outMeterModInput.getCommand());
    assertFalse(outMeterModInput.getFlags().isOFPMFBURST());
    assertTrue(outMeterModInput.getFlags().isOFPMFPKTPS());
    assertEquals(Long.valueOf(10L), outMeterModInput.getMeterId().getValue());
    // BandInformation starts here:
    List<Bands> bands = outMeterModInput.getBands();
    for (Bands currentBand : bands) {
        MeterBand meterBand = currentBand.getMeterBand();
        if (meterBand instanceof MeterBandDropCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDROP, ((MeterBandDropCase) meterBand).getMeterBandDrop().getType());
            assertEquals(burstSize, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getBurstSize());
            assertEquals(dropRate, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getRate());
        }
        if (meterBand instanceof MeterBandDscpRemarkCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDSCPREMARK, ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getType());
            assertEquals(dscpRemarkBurstSize, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getBurstSize());
            assertEquals(dscpRemarkRate, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getRate());
            assertEquals(dscpPercLevel, (short) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getPrecLevel());
        }
        if (meterBand instanceof MeterBandExperimenterCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTEXPERIMENTER, ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getType());
            assertEquals(expBurstSize, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getBurstSize());
            assertEquals(expRate, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getRate());
            ExperimenterIdMeterBand expBand = ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getAugmentation(ExperimenterIdMeterBand.class);
            assertEquals(expExperimenter, (long) expBand.getExperimenter().getValue());
        }
    }
}
Also used : MeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand) ExperimenterIdMeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder) ArrayList(java.util.ArrayList) MeterBandDscpRemarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) DropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder) MeterBandHeaders(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) MeterBandDropCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) ExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.ExperimenterBuilder) ExperimenterIdMeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand) AddMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder) Test(org.junit.Test)

Example 7 with MeterBandHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader in project openflowplugin by opendaylight.

the class MeterConvertorTest method testMeterModCommandConvertorwithAllParameters.

@Test
public void testMeterModCommandConvertorwithAllParameters() {
    long burstSize = 10L;
    long dropRate = 20L;
    // / DROP Band
    MeterBandTypesBuilder meterBandTypesB = new MeterBandTypesBuilder();
    MeterBandType bandFlag = new MeterBandType(true, false, false);
    // _ofpmbtDrop
    meterBandTypesB.setFlags(bandFlag);
    DropBuilder drop = new DropBuilder();
    drop.setDropBurstSize(burstSize);
    drop.setDropRate(dropRate);
    Drop drp = drop.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder.setBandType(drp);
    meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesB.build());
    final MeterBandHeader meterBH = meterBandHeaderBuilder.build();
    // DSCP Mark
    final long dscpRemarkBurstSize = 11L;
    final long dscpRemarkRate = 21L;
    final short dscpPercLevel = 1;
    MeterBandTypesBuilder meterBandTypesB1 = new MeterBandTypesBuilder();
    MeterBandType bandFlag1 = new MeterBandType(false, true, false);
    meterBandTypesB1.setFlags(bandFlag1);
    DscpRemarkBuilder dscp = new DscpRemarkBuilder();
    dscp.setDscpRemarkBurstSize(dscpRemarkBurstSize);
    dscp.setDscpRemarkRate(dscpRemarkRate);
    dscp.setPrecLevel(dscpPercLevel);
    DscpRemark dscpRemark = dscp.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder1 = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder1.setBandType(dscpRemark);
    meterBandHeaderBuilder1.setMeterBandTypes(meterBandTypesB1.build());
    final MeterBandHeader meterBH1 = meterBandHeaderBuilder1.build();
    // Experimental
    final long expBurstSize = 12L;
    final long expRate = 22L;
    final long expExperimenter = 23L;
    MeterBandTypesBuilder meterBandTypesB2 = new MeterBandTypesBuilder();
    MeterBandType bandFlag2 = new MeterBandType(false, false, true);
    meterBandTypesB2.setFlags(bandFlag2);
    ExperimenterBuilder exp = new ExperimenterBuilder();
    exp.setExperimenterBurstSize(expBurstSize);
    exp.setExperimenterRate(expRate);
    exp.setExperimenter(expExperimenter);
    Experimenter experimenter = exp.build();
    MeterBandHeaderBuilder meterBandHeaderBuilder2 = new MeterBandHeaderBuilder();
    meterBandHeaderBuilder2.setBandType(experimenter);
    meterBandHeaderBuilder2.setMeterBandTypes(meterBandTypesB2.build());
    MeterBandHeader meterBH2 = meterBandHeaderBuilder2.build();
    List<MeterBandHeader> meterBandList = new ArrayList<>();
    meterBandList.add(0, meterBH);
    meterBandList.add(1, meterBH1);
    meterBandList.add(2, meterBH2);
    // Constructing List of Bands
    MeterBandHeadersBuilder meterBandHeadersBuilder = new MeterBandHeadersBuilder();
    meterBandHeadersBuilder.setMeterBandHeader(meterBandList);
    MeterBandHeaders meterBandHeaders = meterBandHeadersBuilder.build();
    AddMeterInputBuilder addMeterFromSAL = new AddMeterInputBuilder();
    // MeterBands
    addMeterFromSAL.setMeterBandHeaders(meterBandHeaders);
    // NodeKey key = new NodeKey(new NodeId("24"));
    // InstanceIdentifier<Node> path =
    // InstanceIdentifier.builder().node(Nodes.class).node(Node.class,
    // key).build();
    addMeterFromSAL.setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(10L));
    MeterFlags flagV = new MeterFlags(true, true, true, true);
    addMeterFromSAL.setFlags(flagV);
    AddMeterInput meterInputCommand = addMeterFromSAL.build();
    MeterModInputBuilder outMeterModInput = convert(meterInputCommand, new VersionConvertorData((short) 0X4));
    assertEquals(MeterModCommand.OFPMCADD, outMeterModInput.getCommand());
    assertTrue(outMeterModInput.getFlags().isOFPMFBURST());
    assertEquals(Long.valueOf(10L), outMeterModInput.getMeterId().getValue());
    // BandInformation starts here:
    List<Bands> bands = outMeterModInput.getBands();
    for (Bands currentBand : bands) {
        MeterBand meterBand = currentBand.getMeterBand();
        if (meterBand instanceof MeterBandDropCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDROP, ((MeterBandDropCase) meterBand).getMeterBandDrop().getType());
            assertEquals(burstSize, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getBurstSize());
            assertEquals(dropRate, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getRate());
        }
        if (meterBand instanceof MeterBandDscpRemarkCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDSCPREMARK, ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getType());
            assertEquals(dscpRemarkBurstSize, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getBurstSize());
            assertEquals(dscpRemarkRate, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getRate());
            assertEquals(dscpPercLevel, (short) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getPrecLevel());
        }
        if (meterBand instanceof MeterBandExperimenterCase) {
            assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTEXPERIMENTER, ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getType());
            assertEquals(expBurstSize, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getBurstSize());
            assertEquals(expRate, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getRate());
            ExperimenterIdMeterBand expBand = ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getAugmentation(ExperimenterIdMeterBand.class);
            assertEquals(expExperimenter, (long) expBand.getExperimenter().getValue());
        }
    }
}
Also used : MeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand) ExperimenterIdMeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder) ArrayList(java.util.ArrayList) MeterBandDscpRemarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) DropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder) MeterBandHeaders(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) MeterBandDropCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) ExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.ExperimenterBuilder) ExperimenterIdMeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand) AddMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder) Test(org.junit.Test)

Example 8 with MeterBandHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader in project openflowplugin by opendaylight.

the class OpenflowpluginMeterTestCommandProvider method createTestMeter.

private MeterBuilder createTestMeter() {
    // Sample data , committing to DataStore
    long id = 12;
    MeterKey key = new MeterKey(new MeterId(id));
    MeterBuilder meter = new MeterBuilder();
    meter.setContainerName("abcd");
    meter.setKey(key);
    meter.setMeterId(new MeterId(9L));
    meter.setMeterName(originalMeterName);
    meter.setFlags(new MeterFlags(true, false, false, false));
    MeterBandHeaderBuilder bandHeader = new MeterBandHeaderBuilder();
    bandHeader.setBandRate((long) 234);
    bandHeader.setBandBurstSize((long) 444);
    DscpRemarkBuilder dscpRemark = new DscpRemarkBuilder();
    dscpRemark.setDscpRemarkBurstSize((long) 5);
    dscpRemark.setPrecLevel((short) 1);
    dscpRemark.setDscpRemarkRate((long) 12);
    bandHeader.setBandType(dscpRemark.build());
    MeterBandTypesBuilder bandTypes = new MeterBandTypesBuilder();
    MeterBandType bandType = new MeterBandType(false, true, false);
    bandTypes.setFlags(bandType);
    bandHeader.setMeterBandTypes(bandTypes.build());
    bandHeader.setBandId(new BandId(0L));
    List<MeterBandHeader> bandHdr = new ArrayList<>();
    bandHdr.add(bandHeader.build());
    MeterBandHeadersBuilder bandHeaders = new MeterBandHeadersBuilder();
    bandHeaders.setMeterBandHeader(bandHdr);
    meter.setMeterBandHeaders(bandHeaders.build());
    testMeter = meter.build();
    return meter;
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) ArrayList(java.util.ArrayList) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) BandId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId)

Example 9 with MeterBandHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader in project openflowplugin by opendaylight.

the class MeterMessageSerializer method serializeBands.

private void serializeBands(final MeterBandHeaders meterBandHeaders, final ByteBuf outBuffer) {
    if (Objects.nonNull(meterBandHeaders) && Objects.nonNull(meterBandHeaders.getMeterBandHeader())) {
        meterBandHeaders.getMeterBandHeader().forEach(meterBandHeader -> Optional.ofNullable(meterBandHeader.getMeterBandTypes()).flatMap(m -> Optional.ofNullable(m.getFlags())).ifPresent(flags -> Optional.ofNullable(meterBandHeader.getBandType()).ifPresent(type -> {
            if (flags.isOfpmbtDrop()) {
                final Drop band = Drop.class.cast(type);
                outBuffer.writeShort(MeterBandType.OFPMBTDROP.getIntValue());
                outBuffer.writeShort(LENGTH_OF_METER_BANDS);
                outBuffer.writeInt(band.getDropRate().intValue());
                outBuffer.writeInt(band.getDropBurstSize().intValue());
                outBuffer.writeZero(PADDING_IN_METER_BAND_DROP);
            } else if (flags.isOfpmbtDscpRemark()) {
                final DscpRemark band = DscpRemark.class.cast(type);
                outBuffer.writeShort(MeterBandType.OFPMBTDSCPREMARK.getIntValue());
                outBuffer.writeShort(LENGTH_OF_METER_BANDS);
                outBuffer.writeInt(band.getDscpRemarkRate().intValue());
                outBuffer.writeInt(band.getDscpRemarkBurstSize().intValue());
                outBuffer.writeByte(band.getPrecLevel());
                outBuffer.writeZero(PADDING_IN_METER_BAND_DSCP_REMARK);
            } else if (flags.isOfpmbtExperimenter()) {
                final Experimenter band = Experimenter.class.cast(type);
                // TODO: finish experimenter serialization
                final ExperimenterIdSerializerKey<Experimenter> key = new ExperimenterIdSerializerKey<>(EncodeConstants.OF13_VERSION_ID, band.getExperimenter(), (Class<Experimenter>) type.getImplementedInterface());
                try {
                    final OFSerializer<Experimenter> serializer = registry.getSerializer(key);
                    serializer.serialize(band, outBuffer);
                } catch (final IllegalStateException e) {
                    LOG.warn("Serializer for key: {} wasn't found, exception {}", key, e);
                }
            }
        })));
    }
}
Also used : SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) OFSerializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer) Logger(org.slf4j.Logger) ExperimenterIdSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey) MeterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterBandHeaders(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders) LoggerFactory(org.slf4j.LoggerFactory) MoreObjects(com.google.common.base.MoreObjects) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) Objects(java.util.Objects) ByteBuf(io.netty.buffer.ByteBuf) EncodeConstants(org.opendaylight.openflowjava.protocol.api.util.EncodeConstants) Optional(java.util.Optional) ByteBufUtils(org.opendaylight.openflowjava.util.ByteBufUtils) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) ExperimenterIdSerializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop)

Example 10 with MeterBandHeader

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader in project openflowplugin by opendaylight.

the class MeterConvertor method getBandsFromSAL.

private static void getBandsFromSAL(MeterBandHeaders meterBandHeaders, List<Bands> bands) {
    for (MeterBandHeader meterBandHeader : meterBandHeaders.getMeterBandHeader()) {
        // The band types :drop,DSCP_Remark or experimenter.
        if (null != meterBandHeader.getMeterBandTypes() && null != meterBandHeader.getMeterBandTypes().getFlags()) {
            if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDrop()) {
                if (meterBandHeader.getBandType() != null) {
                    MeterBandDropBuilder meterBandDropBuilder = new MeterBandDropBuilder();
                    meterBandDropBuilder.setType(MeterBandType.OFPMBTDROP);
                    Drop drop = (Drop) meterBandHeader.getBandType();
                    meterBandDropBuilder.setBurstSize(drop.getDropBurstSize());
                    meterBandDropBuilder.setRate(drop.getDropRate());
                    MeterBandDropCaseBuilder dropCaseBuilder = new MeterBandDropCaseBuilder();
                    dropCaseBuilder.setMeterBandDrop(meterBandDropBuilder.build());
                    MeterBand meterBandItem = dropCaseBuilder.build();
                    BandsBuilder bandsB = new BandsBuilder();
                    bandsB.setMeterBand(meterBandItem);
                    // Bands list
                    bands.add(bandsB.build());
                } else {
                    logBandTypeMissing(MeterBandType.OFPMBTDROP);
                }
            } else if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDscpRemark()) {
                if (meterBandHeader.getBandType() != null) {
                    MeterBandDscpRemarkBuilder meterBandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
                    meterBandDscpRemarkBuilder.setType(MeterBandType.OFPMBTDSCPREMARK);
                    DscpRemark dscpRemark = (DscpRemark) meterBandHeader.getBandType();
                    meterBandDscpRemarkBuilder.setBurstSize(dscpRemark.getDscpRemarkBurstSize());
                    meterBandDscpRemarkBuilder.setRate(dscpRemark.getDscpRemarkRate());
                    meterBandDscpRemarkBuilder.setPrecLevel(dscpRemark.getPrecLevel());
                    MeterBandDscpRemarkCaseBuilder dscpCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
                    dscpCaseBuilder.setMeterBandDscpRemark(meterBandDscpRemarkBuilder.build());
                    MeterBand meterBandItem = dscpCaseBuilder.build();
                    BandsBuilder bandsB = new BandsBuilder();
                    bandsB.setMeterBand(meterBandItem);
                    // Bands list
                    bands.add(bandsB.build());
                } else {
                    logBandTypeMissing(MeterBandType.OFPMBTDSCPREMARK);
                }
            } else if (meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtExperimenter()) {
                if (meterBandHeader.getBandType() != null) {
                    MeterBandExperimenterBuilder meterBandExperimenterBuilder = new MeterBandExperimenterBuilder();
                    meterBandExperimenterBuilder.setType(MeterBandType.OFPMBTEXPERIMENTER);
                    Experimenter experimenter = (Experimenter) meterBandHeader.getBandType();
                    meterBandExperimenterBuilder.setBurstSize(experimenter.getExperimenterBurstSize());
                    meterBandExperimenterBuilder.setRate(experimenter.getExperimenterRate());
                    ExperimenterIdMeterBandBuilder expBuilder = new ExperimenterIdMeterBandBuilder();
                    expBuilder.setExperimenter(new ExperimenterId(experimenter.getExperimenter()));
                    meterBandExperimenterBuilder.addAugmentation(ExperimenterIdMeterBand.class, expBuilder.build());
                    // TODO - implement / finish experimenter meter band translation
                    MeterBandExperimenterCaseBuilder experimenterCaseBuilder = new MeterBandExperimenterCaseBuilder();
                    experimenterCaseBuilder.setMeterBandExperimenter(meterBandExperimenterBuilder.build());
                    MeterBand meterBandItem = experimenterCaseBuilder.build();
                    BandsBuilder bandsB = new BandsBuilder();
                    bandsB.setMeterBand(meterBandItem);
                    // Bands list
                    bands.add(bandsB.build());
                } else {
                    logBandTypeMissing(MeterBandType.OFPMBTEXPERIMENTER);
                }
            }
        } else {
            LOG.error("Invalid meter band data found.");
        }
    }
}
Also used : MeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand) ExperimenterIdMeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand) DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) MeterBandDropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder) MeterBandExperimenterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCaseBuilder) ExperimenterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) MeterBandDscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder) MeterBandExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenterBuilder) MeterBandDropCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder) ExperimenterIdMeterBandBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBandBuilder) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) BandsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder)

Aggregations

MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)10 ArrayList (java.util.ArrayList)8 MeterBandType (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType)8 DscpRemarkBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder)8 MeterBandHeadersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder)8 MeterBandHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder)8 MeterBandTypesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder)8 MeterFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags)6 DscpRemark (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark)6 Experimenter (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter)6 Drop (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop)5 DropBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder)5 Test (org.junit.Test)4 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)4 ExperimenterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.ExperimenterBuilder)4 MeterBandHeaders (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders)4 ExperimenterIdMeterBand (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdMeterBand)4 MeterBand (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand)4 MeterBandDropCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase)4 MeterBandDscpRemarkCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase)4