1 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
4 * This class is used for converting the data from SAL layer to OF Library Layer for Meter Mod Command.
8 import java.util.ArrayList;
9 import java.util.Iterator;
10 import java.util.List;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags.Flags;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeaders;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterModCommand;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder;
30 //import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder;
33 public final class MeterConvertor {
35 private static List<Bands> bands;
36 private static MeterModInputBuilder meterModInputBuilder;
37 private static MeterFlags flags;
38 private MeterConvertor(){
42 //Get all the data for the meter from the Yang/SAL-Layer
44 * @param Yang Data source
45 * @return MeterModInput required by OF Library
47 public static MeterModInput toMeterModInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter source ) {
49 meterModInputBuilder = new MeterModInputBuilder();
52 if(source instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)
53 meterModInputBuilder.setCommand(MeterModCommand.OFPMCADD);
54 if(source instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput)
55 meterModInputBuilder.setCommand(MeterModCommand.OFPMCDELETE);
56 if(source instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput)
57 meterModInputBuilder.setCommand(MeterModCommand.OFPMCMODIFY);
59 meterModInputBuilder.setMeterId(new MeterId(source.getMeterId().getValue()));
61 getFlagsFromSAL(source.getFlags());
62 meterModInputBuilder.setFlags(flags);
63 getBandsFromSAL(source.getMeterBandHeaders());
64 meterModInputBuilder.setBands(bands);
65 return meterModInputBuilder.build();
70 private static void getBandsFromSAL(MeterBandHeaders meterBandHeaders) {
72 Iterator <MeterBandHeader> bandHeadersIterator = meterBandHeaders.getMeterBandHeader().iterator();
73 MeterBandHeader meterBandHeader;
75 BandsBuilder bandsB = null;
76 //MeterBandHeaderBuilder meterBandHeaderBuilder = null ;
77 bands = new ArrayList<Bands>();
78 while(bandHeadersIterator.hasNext())
80 meterBandHeader = bandHeadersIterator.next();
81 MeterBand meterBandItem = null;
82 //The band types :drop,DSCP_Remark or experimenter.
83 //meterBandHeaderBuilder = new MeterBandHeaderBuilder();
86 if(meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDrop()){
88 MeterBandDropBuilder meterBandDropBuilder = new MeterBandDropBuilder();
89 meterBandDropBuilder.setType(MeterBandType.OFPMBTDROP);
91 Drop drop = (Drop)meterBandHeader.getBandType();
93 meterBandDropBuilder.setBurstSize(drop.getRate());
94 meterBandDropBuilder.setRate(drop.getBurstSize());
95 meterBandItem= meterBandDropBuilder.build();
98 else if(meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtDscpRemark())
100 MeterBandDscpRemarkBuilder meterBandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
101 meterBandDscpRemarkBuilder.setType(MeterBandType.OFPMBTDSCPREMARK);
103 DscpRemark dscpRemark = (DscpRemark)meterBandHeader.getBandType();
105 meterBandDscpRemarkBuilder.setBurstSize(dscpRemark.getBurstSize());
106 meterBandDscpRemarkBuilder.setRate(dscpRemark.getRate());
107 meterBandDscpRemarkBuilder.setPrecLevel(dscpRemark.getPercLevel());
108 meterBandItem = meterBandDscpRemarkBuilder.build();
111 else if(meterBandHeader.getMeterBandTypes().getFlags().isOfpmbtExperimenter())
113 MeterBandExperimenterBuilder meterBandExperimenterBuilder = new MeterBandExperimenterBuilder();
114 meterBandExperimenterBuilder.setType(MeterBandType.OFPMBTEXPERIMENTER);
115 Experimenter experimenter = (Experimenter)meterBandHeader.getBandType();
116 meterBandExperimenterBuilder.setBurstSize(experimenter.getBurstSize());
117 meterBandExperimenterBuilder.setRate(experimenter.getRate());
118 meterBandExperimenterBuilder.setExperimenter(experimenter.getExperimenter());
119 meterBandItem = meterBandExperimenterBuilder.build();
123 bandsB = new BandsBuilder();
124 bandsB.setMeterBand(meterBandItem).build();
126 bands.add(bandsB.build()); //Bands list
133 //get it from plugin(SAL) layer
134 private static void getFlagsFromSAL(Flags flags2) {
135 boolean meterBurst_SAL = false;
136 boolean meterKbps_SAL = false;
137 boolean meterPktps_SAL = false;
138 boolean meterStats_SAL = false;
141 if(flags2.isMeterBurst()) meterBurst_SAL = true;
142 if(flags2.isMeterKbps()) meterKbps_SAL = true;
143 if(flags2.isMeterPktps()) meterPktps_SAL = true;
144 if(flags2.isMeterStats()) meterStats_SAL = true;
146 flags = new MeterFlags(meterBurst_SAL,meterKbps_SAL,meterPktps_SAL,meterStats_SAL);