Committed by
Gerrit Code Review
fixes for Meter Service
Change-Id: I83d5b8a2e0a955c050f7afe96761d5709d4f9f18
Showing
12 changed files
with
226 additions
and
22 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.cli.net; | ||
| 17 | + | ||
| 18 | +import org.apache.karaf.shell.commands.Argument; | ||
| 19 | +import org.apache.karaf.shell.commands.Command; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.core.CoreService; | ||
| 22 | +import org.onosproject.net.DeviceId; | ||
| 23 | +import org.onosproject.net.meter.Band; | ||
| 24 | +import org.onosproject.net.meter.DefaultBand; | ||
| 25 | +import org.onosproject.net.meter.DefaultMeter; | ||
| 26 | +import org.onosproject.net.meter.Meter; | ||
| 27 | +import org.onosproject.net.meter.MeterId; | ||
| 28 | +import org.onosproject.net.meter.MeterOperation; | ||
| 29 | +import org.onosproject.net.meter.MeterService; | ||
| 30 | + | ||
| 31 | +import java.util.Collections; | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | + * Add a meter. | ||
| 35 | + */ | ||
| 36 | +@Command(scope = "onos", name = "add-meter", | ||
| 37 | + description = "Adds a meter to a device (currently for testing)") | ||
| 38 | +public class AddMeter extends AbstractShellCommand { | ||
| 39 | + | ||
| 40 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
| 41 | + required = true, multiValued = false) | ||
| 42 | + String uri = null; | ||
| 43 | + | ||
| 44 | + private final String appId = "org.onosproject.cli.addMeter"; | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + protected void execute() { | ||
| 48 | + MeterService service = get(MeterService.class); | ||
| 49 | + CoreService coreService = get(CoreService.class); | ||
| 50 | + | ||
| 51 | + DeviceId deviceId = DeviceId.deviceId(uri); | ||
| 52 | + | ||
| 53 | + MeterId meterId = service.allocateMeterId(); | ||
| 54 | + | ||
| 55 | + Band band = DefaultBand.builder() | ||
| 56 | + .ofType(Band.Type.DROP) | ||
| 57 | + .withRate(500) | ||
| 58 | + .build(); | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + Meter meter = DefaultMeter.builder() | ||
| 62 | + .forDevice(deviceId) | ||
| 63 | + .fromApp(coreService.registerApplication(appId)) | ||
| 64 | + .withId(meterId) | ||
| 65 | + .withUnit(Meter.Unit.KB_PER_SEC) | ||
| 66 | + .withBands(Collections.singleton(band)) | ||
| 67 | + .build(); | ||
| 68 | + | ||
| 69 | + MeterOperation op = new MeterOperation(meter, MeterOperation.Type.ADD, null); | ||
| 70 | + | ||
| 71 | + service.addMeter(op); | ||
| 72 | + | ||
| 73 | + } | ||
| 74 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.cli.net; | ||
| 17 | + | ||
| 18 | +import com.google.common.collect.Collections2; | ||
| 19 | +import org.apache.karaf.shell.commands.Argument; | ||
| 20 | +import org.apache.karaf.shell.commands.Command; | ||
| 21 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 22 | +import org.onosproject.net.DeviceId; | ||
| 23 | +import org.onosproject.net.meter.Meter; | ||
| 24 | +import org.onosproject.net.meter.MeterService; | ||
| 25 | + | ||
| 26 | +import java.util.Collection; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Add a meter. | ||
| 30 | + */ | ||
| 31 | +@Command(scope = "onos", name = "meters", | ||
| 32 | + description = "Shows meters") | ||
| 33 | +public class Meters extends AbstractShellCommand { | ||
| 34 | + | ||
| 35 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
| 36 | + required = false, multiValued = false) | ||
| 37 | + String uri = null; | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + protected void execute() { | ||
| 42 | + MeterService service = get(MeterService.class); | ||
| 43 | + | ||
| 44 | + Collection<Meter> meters = service.getAllMeters(); | ||
| 45 | + if (uri != null) { | ||
| 46 | + DeviceId deviceId = DeviceId.deviceId(uri); | ||
| 47 | + Collection<Meter> devMeters = Collections2.filter(meters, | ||
| 48 | + m -> m.deviceId().equals(deviceId)); | ||
| 49 | + printMeters(devMeters); | ||
| 50 | + } else { | ||
| 51 | + printMeters(meters); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + private void printMeters(Collection<Meter> meters) { | ||
| 56 | + meters.forEach(m -> print(" %s", m)); | ||
| 57 | + } | ||
| 58 | +} |
| ... | @@ -113,6 +113,18 @@ | ... | @@ -113,6 +113,18 @@ |
| 113 | </completers> | 113 | </completers> |
| 114 | </command> | 114 | </command> |
| 115 | <command> | 115 | <command> |
| 116 | + <action class="org.onosproject.cli.net.AddMeter"/> | ||
| 117 | + <completers> | ||
| 118 | + <ref component-id="deviceIdCompleter"/> | ||
| 119 | + </completers> | ||
| 120 | + </command> | ||
| 121 | + <command> | ||
| 122 | + <action class="org.onosproject.cli.net.Meters"/> | ||
| 123 | + <completers> | ||
| 124 | + <ref component-id="deviceIdCompleter"/> | ||
| 125 | + </completers> | ||
| 126 | + </command> | ||
| 127 | + <command> | ||
| 116 | <action class="org.onosproject.cli.net.DeviceRoleCommand"/> | 128 | <action class="org.onosproject.cli.net.DeviceRoleCommand"/> |
| 117 | <completers> | 129 | <completers> |
| 118 | <ref component-id="deviceIdCompleter"/> | 130 | <ref component-id="deviceIdCompleter"/> | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.meter; | 16 | package org.onosproject.net.meter; |
| 17 | 17 | ||
| 18 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 18 | import static com.google.common.base.Preconditions.checkArgument; | 19 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | 20 | ||
| 20 | /** | 21 | /** |
| ... | @@ -24,13 +25,14 @@ public final class DefaultBand implements Band, BandEntry { | ... | @@ -24,13 +25,14 @@ public final class DefaultBand implements Band, BandEntry { |
| 24 | 25 | ||
| 25 | private final Type type; | 26 | private final Type type; |
| 26 | private final long rate; | 27 | private final long rate; |
| 27 | - private final long burstSize; | 28 | + //TODO: should be made optional |
| 28 | - private final short prec; | 29 | + private final Long burstSize; |
| 30 | + private final Short prec; | ||
| 29 | private long packets; | 31 | private long packets; |
| 30 | private long bytes; | 32 | private long bytes; |
| 31 | 33 | ||
| 32 | public DefaultBand(Type type, long rate, | 34 | public DefaultBand(Type type, long rate, |
| 33 | - long burstSize, short prec) { | 35 | + Long burstSize, Short prec) { |
| 34 | this.type = type; | 36 | this.type = type; |
| 35 | this.rate = rate; | 37 | this.rate = rate; |
| 36 | this.burstSize = burstSize; | 38 | this.burstSize = burstSize; |
| ... | @@ -77,6 +79,15 @@ public final class DefaultBand implements Band, BandEntry { | ... | @@ -77,6 +79,15 @@ public final class DefaultBand implements Band, BandEntry { |
| 77 | this.bytes = bytes; | 79 | this.bytes = bytes; |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 82 | + @Override | ||
| 83 | + public String toString() { | ||
| 84 | + return toStringHelper(this) | ||
| 85 | + .add("rate", rate) | ||
| 86 | + .add("burst-size", burstSize) | ||
| 87 | + .add("type", type) | ||
| 88 | + .add("drop-precedence", prec).toString(); | ||
| 89 | + } | ||
| 90 | + | ||
| 80 | public static Builder builder() { | 91 | public static Builder builder() { |
| 81 | return new Builder(); | 92 | return new Builder(); |
| 82 | } | 93 | } |
| ... | @@ -84,7 +95,7 @@ public final class DefaultBand implements Band, BandEntry { | ... | @@ -84,7 +95,7 @@ public final class DefaultBand implements Band, BandEntry { |
| 84 | public static final class Builder implements Band.Builder { | 95 | public static final class Builder implements Band.Builder { |
| 85 | 96 | ||
| 86 | private long rate; | 97 | private long rate; |
| 87 | - private long burstSize; | 98 | + private Long burstSize; |
| 88 | private Short prec; | 99 | private Short prec; |
| 89 | private Type type; | 100 | private Type type; |
| 90 | 101 | ||
| ... | @@ -114,7 +125,7 @@ public final class DefaultBand implements Band, BandEntry { | ... | @@ -114,7 +125,7 @@ public final class DefaultBand implements Band, BandEntry { |
| 114 | 125 | ||
| 115 | @Override | 126 | @Override |
| 116 | public DefaultBand build() { | 127 | public DefaultBand build() { |
| 117 | - checkArgument(prec != null && type == Type.REMARK, | 128 | + checkArgument(type != Type.REMARK && prec == null, |
| 118 | "Only REMARK bands can have a precendence."); | 129 | "Only REMARK bands can have a precendence."); |
| 119 | 130 | ||
| 120 | return new DefaultBand(type, rate, burstSize, prec); | 131 | return new DefaultBand(type, rate, burstSize, prec); | ... | ... |
| ... | @@ -15,12 +15,13 @@ | ... | @@ -15,12 +15,13 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.meter; | 16 | package org.onosproject.net.meter; |
| 17 | 17 | ||
| 18 | +import com.google.common.collect.ImmutableSet; | ||
| 18 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 20 | 21 | ||
| 21 | import java.util.Collection; | 22 | import java.util.Collection; |
| 22 | -import java.util.Collections; | ||
| 23 | 23 | ||
| 24 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
| 24 | import static com.google.common.base.Preconditions.checkArgument; | 25 | import static com.google.common.base.Preconditions.checkArgument; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | 27 | ||
| ... | @@ -138,6 +139,18 @@ public final class DefaultMeter implements Meter, MeterEntry { | ... | @@ -138,6 +139,18 @@ public final class DefaultMeter implements Meter, MeterEntry { |
| 138 | this.bytes = bytes; | 139 | this.bytes = bytes; |
| 139 | } | 140 | } |
| 140 | 141 | ||
| 142 | + @Override | ||
| 143 | + public String toString() { | ||
| 144 | + return toStringHelper(this) | ||
| 145 | + .add("device", deviceId) | ||
| 146 | + .add("id", id) | ||
| 147 | + .add("appId", appId.name()) | ||
| 148 | + .add("unit", unit) | ||
| 149 | + .add("isBurst", burst) | ||
| 150 | + .add("state", state) | ||
| 151 | + .add("bands", bands).toString(); | ||
| 152 | + } | ||
| 153 | + | ||
| 141 | public static final class Builder implements Meter.Builder { | 154 | public static final class Builder implements Meter.Builder { |
| 142 | 155 | ||
| 143 | private MeterId id; | 156 | private MeterId id; |
| ... | @@ -155,8 +168,8 @@ public final class DefaultMeter implements Meter, MeterEntry { | ... | @@ -155,8 +168,8 @@ public final class DefaultMeter implements Meter, MeterEntry { |
| 155 | } | 168 | } |
| 156 | 169 | ||
| 157 | @Override | 170 | @Override |
| 158 | - public Meter.Builder withId(long id) { | 171 | + public Meter.Builder withId(MeterId id) { |
| 159 | - this.id = MeterId.meterId(id); | 172 | + this.id = id; |
| 160 | return this; | 173 | return this; |
| 161 | } | 174 | } |
| 162 | 175 | ||
| ... | @@ -180,7 +193,7 @@ public final class DefaultMeter implements Meter, MeterEntry { | ... | @@ -180,7 +193,7 @@ public final class DefaultMeter implements Meter, MeterEntry { |
| 180 | 193 | ||
| 181 | @Override | 194 | @Override |
| 182 | public Meter.Builder withBands(Collection<Band> bands) { | 195 | public Meter.Builder withBands(Collection<Band> bands) { |
| 183 | - this.bands = Collections.unmodifiableCollection(bands); | 196 | + this.bands = ImmutableSet.copyOf(bands); |
| 184 | return this; | 197 | return this; |
| 185 | } | 198 | } |
| 186 | 199 | ... | ... |
| ... | @@ -130,10 +130,10 @@ public interface Meter { | ... | @@ -130,10 +130,10 @@ public interface Meter { |
| 130 | /** | 130 | /** |
| 131 | * Assigns the id to this meter. | 131 | * Assigns the id to this meter. |
| 132 | * | 132 | * |
| 133 | - * @param id a long | 133 | + * @param id a meter id |
| 134 | * @return this | 134 | * @return this |
| 135 | */ | 135 | */ |
| 136 | - Builder withId(long id); | 136 | + Builder withId(MeterId id); |
| 137 | 137 | ||
| 138 | /** | 138 | /** |
| 139 | * Assigns the application that built this meter. | 139 | * Assigns the application that built this meter. | ... | ... |
| ... | @@ -32,7 +32,7 @@ public final class MeterId { | ... | @@ -32,7 +32,7 @@ public final class MeterId { |
| 32 | public static final MeterId ALL = new MeterId(0xFFFFFFFF); | 32 | public static final MeterId ALL = new MeterId(0xFFFFFFFF); |
| 33 | 33 | ||
| 34 | private MeterId(long id) { | 34 | private MeterId(long id) { |
| 35 | - checkArgument(id <= MAX, "id cannot be larger than 0xFFFF0000"); | 35 | + checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000"); |
| 36 | this.id = id; | 36 | this.id = id; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| ... | @@ -65,6 +65,11 @@ public final class MeterId { | ... | @@ -65,6 +65,11 @@ public final class MeterId { |
| 65 | return Long.hashCode(id); | 65 | return Long.hashCode(id); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | + @Override | ||
| 69 | + public String toString() { | ||
| 70 | + return Long.toHexString(this.id); | ||
| 71 | + } | ||
| 72 | + | ||
| 68 | public static MeterId meterId(long id) { | 73 | public static MeterId meterId(long id) { |
| 69 | return new MeterId(id); | 74 | return new MeterId(id); |
| 70 | 75 | ... | ... |
| ... | @@ -17,6 +17,8 @@ package org.onosproject.net.meter; | ... | @@ -17,6 +17,8 @@ package org.onosproject.net.meter; |
| 17 | 17 | ||
| 18 | import org.onosproject.event.ListenerService; | 18 | import org.onosproject.event.ListenerService; |
| 19 | 19 | ||
| 20 | +import java.util.Collection; | ||
| 21 | + | ||
| 20 | /** | 22 | /** |
| 21 | * Service for add/updating and removing meters. Meters are | 23 | * Service for add/updating and removing meters. Meters are |
| 22 | * are assigned to flow to rate limit them and provide a certain | 24 | * are assigned to flow to rate limit them and provide a certain |
| ... | @@ -55,6 +57,13 @@ public interface MeterService | ... | @@ -55,6 +57,13 @@ public interface MeterService |
| 55 | Meter getMeter(MeterId id); | 57 | Meter getMeter(MeterId id); |
| 56 | 58 | ||
| 57 | /** | 59 | /** |
| 60 | + * Fetches all the meters. | ||
| 61 | + * | ||
| 62 | + * @return a collection of meters | ||
| 63 | + */ | ||
| 64 | + Collection<Meter> getAllMeters(); | ||
| 65 | + | ||
| 66 | + /** | ||
| 58 | * Allocate a meter id which must be used to create the meter. | 67 | * Allocate a meter id which must be used to create the meter. |
| 59 | * | 68 | * |
| 60 | * @return a meter id | 69 | * @return a meter id | ... | ... |
| ... | @@ -52,7 +52,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -52,7 +52,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 52 | /** | 52 | /** |
| 53 | * Provides implementation of the meter service APIs. | 53 | * Provides implementation of the meter service APIs. |
| 54 | */ | 54 | */ |
| 55 | -@Component(immediate = true) | 55 | +@Component(immediate = true, enabled = true) |
| 56 | @Service | 56 | @Service |
| 57 | public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, MeterListener, | 57 | public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, MeterListener, |
| 58 | MeterProvider, MeterProviderService> | 58 | MeterProvider, MeterProviderService> |
| ... | @@ -66,7 +66,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M | ... | @@ -66,7 +66,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M |
| 66 | protected StorageService storageService; | 66 | protected StorageService storageService; |
| 67 | 67 | ||
| 68 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 68 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 69 | - MeterStore store; | 69 | + protected MeterStore store; |
| 70 | 70 | ||
| 71 | private AtomicCounter meterIdCounter; | 71 | private AtomicCounter meterIdCounter; |
| 72 | 72 | ||
| ... | @@ -78,6 +78,8 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M | ... | @@ -78,6 +78,8 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M |
| 78 | .withName(meterIdentifier) | 78 | .withName(meterIdentifier) |
| 79 | .build(); | 79 | .build(); |
| 80 | 80 | ||
| 81 | + store.setDelegate(delegate); | ||
| 82 | + | ||
| 81 | onComplete = (op, result, error) -> | 83 | onComplete = (op, result, error) -> |
| 82 | { | 84 | { |
| 83 | op.context().ifPresent(c -> { | 85 | op.context().ifPresent(c -> { |
| ... | @@ -98,6 +100,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M | ... | @@ -98,6 +100,7 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M |
| 98 | 100 | ||
| 99 | @Deactivate | 101 | @Deactivate |
| 100 | public void deactivate() { | 102 | public void deactivate() { |
| 103 | + store.unsetDelegate(delegate); | ||
| 101 | log.info("Stopped"); | 104 | log.info("Stopped"); |
| 102 | } | 105 | } |
| 103 | 106 | ||
| ... | @@ -136,6 +139,11 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M | ... | @@ -136,6 +139,11 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M |
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | @Override | 141 | @Override |
| 142 | + public Collection<Meter> getAllMeters() { | ||
| 143 | + return store.getAllMeters(); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + @Override | ||
| 139 | public MeterId allocateMeterId() { | 147 | public MeterId allocateMeterId() { |
| 140 | // FIXME: This will break one day. | 148 | // FIXME: This will break one day. |
| 141 | return MeterId.meterId((int) meterIdCounter.getAndIncrement()); | 149 | return MeterId.meterId((int) meterIdCounter.getAndIncrement()); | ... | ... |
| ... | @@ -18,11 +18,16 @@ package org.onosproject.incubator.store.meter.impl; | ... | @@ -18,11 +18,16 @@ package org.onosproject.incubator.store.meter.impl; |
| 18 | import com.google.common.collect.Collections2; | 18 | import com.google.common.collect.Collections2; |
| 19 | import com.google.common.collect.Maps; | 19 | import com.google.common.collect.Maps; |
| 20 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | +import org.apache.felix.scr.annotations.Component; | ||
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | +import org.apache.felix.scr.annotations.Service; | ||
| 24 | import org.onosproject.cluster.ClusterService; | 26 | import org.onosproject.cluster.ClusterService; |
| 25 | import org.onosproject.cluster.NodeId; | 27 | import org.onosproject.cluster.NodeId; |
| 28 | +import org.onosproject.mastership.MastershipService; | ||
| 29 | +import org.onosproject.net.meter.Band; | ||
| 30 | +import org.onosproject.net.meter.DefaultBand; | ||
| 26 | import org.onosproject.net.meter.DefaultMeter; | 31 | import org.onosproject.net.meter.DefaultMeter; |
| 27 | import org.onosproject.net.meter.Meter; | 32 | import org.onosproject.net.meter.Meter; |
| 28 | import org.onosproject.net.meter.MeterEvent; | 33 | import org.onosproject.net.meter.MeterEvent; |
| ... | @@ -33,7 +38,6 @@ import org.onosproject.net.meter.MeterState; | ... | @@ -33,7 +38,6 @@ import org.onosproject.net.meter.MeterState; |
| 33 | import org.onosproject.net.meter.MeterStore; | 38 | import org.onosproject.net.meter.MeterStore; |
| 34 | import org.onosproject.net.meter.MeterStoreDelegate; | 39 | import org.onosproject.net.meter.MeterStoreDelegate; |
| 35 | import org.onosproject.net.meter.MeterStoreResult; | 40 | import org.onosproject.net.meter.MeterStoreResult; |
| 36 | -import org.onosproject.mastership.MastershipService; | ||
| 37 | import org.onosproject.store.AbstractStore; | 41 | import org.onosproject.store.AbstractStore; |
| 38 | import org.onosproject.store.serializers.KryoNamespaces; | 42 | import org.onosproject.store.serializers.KryoNamespaces; |
| 39 | import org.onosproject.store.service.ConsistentMap; | 43 | import org.onosproject.store.service.ConsistentMap; |
| ... | @@ -56,6 +60,8 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -56,6 +60,8 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 56 | * A distributed meter store implementation. Meters are stored consistently | 60 | * A distributed meter store implementation. Meters are stored consistently |
| 57 | * across the cluster. | 61 | * across the cluster. |
| 58 | */ | 62 | */ |
| 63 | +@Component(immediate = true) | ||
| 64 | +@Service | ||
| 59 | public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreDelegate> | 65 | public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreDelegate> |
| 60 | implements MeterStore { | 66 | implements MeterStore { |
| 61 | 67 | ||
| ... | @@ -89,8 +95,14 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD | ... | @@ -89,8 +95,14 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD |
| 89 | meters = storageService.<MeterId, MeterData>consistentMapBuilder() | 95 | meters = storageService.<MeterId, MeterData>consistentMapBuilder() |
| 90 | .withName(METERSTORE) | 96 | .withName(METERSTORE) |
| 91 | .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), | 97 | .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), |
| 92 | - MeterData.class)) | 98 | + MeterData.class, |
| 93 | - .build(); | 99 | + DefaultMeter.class, |
| 100 | + DefaultBand.class, | ||
| 101 | + Band.Type.class, | ||
| 102 | + MeterState.class, | ||
| 103 | + Meter.Unit.class, | ||
| 104 | + MeterFailReason.class, | ||
| 105 | + MeterId.class)).build(); | ||
| 94 | 106 | ||
| 95 | meters.addListener(mapListener); | 107 | meters.addListener(mapListener); |
| 96 | 108 | ||
| ... | @@ -205,13 +217,13 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD | ... | @@ -205,13 +217,13 @@ public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreD |
| 205 | } else if (data.reason().isPresent() && local.equals(data.origin())) { | 217 | } else if (data.reason().isPresent() && local.equals(data.origin())) { |
| 206 | MeterStoreResult msr = MeterStoreResult.fail(data.reason().get()); | 218 | MeterStoreResult msr = MeterStoreResult.fail(data.reason().get()); |
| 207 | //TODO: No future -> no friend | 219 | //TODO: No future -> no friend |
| 208 | - futures.get(data.meter().id()).complete(msr); | 220 | + futures.remove(data.meter().id()).complete(msr); |
| 209 | } | 221 | } |
| 210 | break; | 222 | break; |
| 211 | case ADDED: | 223 | case ADDED: |
| 212 | case REMOVED: | 224 | case REMOVED: |
| 213 | if (local.equals(data.origin())) { | 225 | if (local.equals(data.origin())) { |
| 214 | - futures.get(data.meter().id()).complete(MeterStoreResult.success()); | 226 | + futures.remove(data.meter().id()).complete(MeterStoreResult.success()); |
| 215 | } | 227 | } |
| 216 | break; | 228 | break; |
| 217 | default: | 229 | default: | ... | ... |
| ... | @@ -116,7 +116,8 @@ public final class MeterModBuilder { | ... | @@ -116,7 +116,8 @@ public final class MeterModBuilder { |
| 116 | default: | 116 | default: |
| 117 | log.warn("Unknown unit type {}", unit); | 117 | log.warn("Unknown unit type {}", unit); |
| 118 | } | 118 | } |
| 119 | - builder.setBands(buildBands()); | 119 | + //FIXME: THIS WILL CHANGE IN OF1.4 to setBands. |
| 120 | + builder.setMeters(buildBands()); | ||
| 120 | builder.setFlags(flags) | 121 | builder.setFlags(flags) |
| 121 | .setMeterId(id) | 122 | .setMeterId(id) |
| 122 | .setXid(xid); | 123 | .setXid(xid); | ... | ... |
| ... | @@ -33,6 +33,7 @@ import org.onosproject.net.meter.DefaultBand; | ... | @@ -33,6 +33,7 @@ import org.onosproject.net.meter.DefaultBand; |
| 33 | import org.onosproject.net.meter.DefaultMeter; | 33 | import org.onosproject.net.meter.DefaultMeter; |
| 34 | import org.onosproject.net.meter.Meter; | 34 | import org.onosproject.net.meter.Meter; |
| 35 | import org.onosproject.net.meter.MeterFailReason; | 35 | import org.onosproject.net.meter.MeterFailReason; |
| 36 | +import org.onosproject.net.meter.MeterId; | ||
| 36 | import org.onosproject.net.meter.MeterOperation; | 37 | import org.onosproject.net.meter.MeterOperation; |
| 37 | import org.onosproject.net.meter.MeterOperations; | 38 | import org.onosproject.net.meter.MeterOperations; |
| 38 | import org.onosproject.net.meter.MeterProvider; | 39 | import org.onosproject.net.meter.MeterProvider; |
| ... | @@ -74,7 +75,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -74,7 +75,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 74 | /** | 75 | /** |
| 75 | * Provider which uses an OpenFlow controller to handle meters. | 76 | * Provider which uses an OpenFlow controller to handle meters. |
| 76 | */ | 77 | */ |
| 77 | -@Component(immediate = true, enabled = false) | 78 | +@Component(immediate = true, enabled = true) |
| 78 | public class OpenFlowMeterProvider extends AbstractProvider implements MeterProvider { | 79 | public class OpenFlowMeterProvider extends AbstractProvider implements MeterProvider { |
| 79 | 80 | ||
| 80 | 81 | ||
| ... | @@ -245,7 +246,7 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv | ... | @@ -245,7 +246,7 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv |
| 245 | DefaultMeter.Builder builder = DefaultMeter.builder(); | 246 | DefaultMeter.Builder builder = DefaultMeter.builder(); |
| 246 | Collection<Band> bands = buildBands(stat.getBandStats()); | 247 | Collection<Band> bands = buildBands(stat.getBandStats()); |
| 247 | builder.forDevice(deviceId) | 248 | builder.forDevice(deviceId) |
| 248 | - .withId(stat.getMeterId()) | 249 | + .withId(MeterId.meterId(stat.getMeterId())) |
| 249 | //FIXME: need to encode appId in meter id, but that makes | 250 | //FIXME: need to encode appId in meter id, but that makes |
| 250 | // things a little annoying for debugging | 251 | // things a little annoying for debugging |
| 251 | .fromApp(coreService.getAppId("org.onosproject.core")) | 252 | .fromApp(coreService.getAppId("org.onosproject.core")) | ... | ... |
-
Please register or login to post a comment