Committed by
Gerrit Code Review
moving meter service to incubator and initial implementation of
meter manager. Change-Id: I6ef0d9476b58d00b37f7ef156ac7bdacca20185b
Showing
20 changed files
with
796 additions
and
21 deletions
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Represents a band used within a meter. | 19 | * Represents a band used within a meter. |
... | @@ -69,5 +69,51 @@ public interface Band { | ... | @@ -69,5 +69,51 @@ public interface Band { |
69 | */ | 69 | */ |
70 | Type type(); | 70 | Type type(); |
71 | 71 | ||
72 | + interface Builder { | ||
73 | + | ||
74 | + /** | ||
75 | + * Assigns a rate to this band. The units for this rate | ||
76 | + * are defined in the encapsulating meter. | ||
77 | + * | ||
78 | + * @param rate a long value | ||
79 | + * @return this | ||
80 | + */ | ||
81 | + Builder withRate(long rate); | ||
82 | + | ||
83 | + /** | ||
84 | + * Assigns a burst size to this band. Only meaningful if | ||
85 | + * the encapsulating meter is of burst type. | ||
86 | + * | ||
87 | + * @param burstSize a long value. | ||
88 | + * @return this | ||
89 | + */ | ||
90 | + Builder burstSize(long burstSize); | ||
91 | + | ||
92 | + /** | ||
93 | + * Assigns the drop precedence for this band. Only meaningful if | ||
94 | + * the band is of REMARK type. | ||
95 | + * | ||
96 | + * @param prec a short value | ||
97 | + * @return this | ||
98 | + */ | ||
99 | + Builder dropPrecedence(short prec); | ||
100 | + | ||
101 | + /** | ||
102 | + * Assigns the @See Type of this band. | ||
103 | + * | ||
104 | + * @param type a band type | ||
105 | + * @return this | ||
106 | + */ | ||
107 | + Builder ofType(Type type); | ||
108 | + | ||
109 | + /** | ||
110 | + * Builds the band. | ||
111 | + * | ||
112 | + * @return a band | ||
113 | + */ | ||
114 | + Band build(); | ||
115 | + | ||
116 | + } | ||
117 | + | ||
72 | 118 | ||
73 | } | 119 | } | ... | ... |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
19 | + | ||
20 | +/** | ||
21 | + * A default implementation for a Band. | ||
22 | + */ | ||
23 | +public final class DefaultBand implements Band { | ||
24 | + | ||
25 | + private final Type type; | ||
26 | + private final long rate; | ||
27 | + private final long burstSize; | ||
28 | + private final short prec; | ||
29 | + | ||
30 | + public DefaultBand(Type type, long rate, | ||
31 | + long burstSize, short prec) { | ||
32 | + this.type = type; | ||
33 | + this.rate = rate; | ||
34 | + this.burstSize = burstSize; | ||
35 | + this.prec = prec; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public long rate() { | ||
40 | + return rate; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public long burst() { | ||
45 | + return burstSize; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public short dropPrecedence() { | ||
50 | + return prec; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public Type type() { | ||
55 | + return type; | ||
56 | + } | ||
57 | + | ||
58 | + public static Builder builder() { | ||
59 | + return new Builder(); | ||
60 | + } | ||
61 | + | ||
62 | + public static final class Builder implements Band.Builder { | ||
63 | + | ||
64 | + private long rate; | ||
65 | + private long burstSize; | ||
66 | + private Short prec; | ||
67 | + private Type type; | ||
68 | + | ||
69 | + @Override | ||
70 | + public Band.Builder withRate(long rate) { | ||
71 | + this.rate = rate; | ||
72 | + return this; | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public Band.Builder burstSize(long burstSize) { | ||
77 | + this.burstSize = burstSize; | ||
78 | + return this; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public Band.Builder dropPrecedence(short prec) { | ||
83 | + this.prec = prec; | ||
84 | + return this; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public Band.Builder ofType(Type type) { | ||
89 | + this.type = type; | ||
90 | + return this; | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public Band build() { | ||
95 | + checkArgument(prec != null && type == Type.REMARK, | ||
96 | + "Only REMARK bands can have a precendence."); | ||
97 | + | ||
98 | + return new DefaultBand(type, rate, burstSize, prec); | ||
99 | + } | ||
100 | + | ||
101 | + | ||
102 | + } | ||
103 | +} |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import org.onosproject.core.ApplicationId; | ||
19 | +import org.onosproject.net.DeviceId; | ||
20 | + | ||
21 | +import java.util.Collection; | ||
22 | +import java.util.Collections; | ||
23 | +import java.util.Optional; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkArgument; | ||
26 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
27 | + | ||
28 | +/** | ||
29 | + * A default implementation of a meter. | ||
30 | + */ | ||
31 | +public final class DefaultMeter implements Meter { | ||
32 | + | ||
33 | + | ||
34 | + private final MeterId id; | ||
35 | + private final ApplicationId appId; | ||
36 | + private final Unit unit; | ||
37 | + private final boolean burst; | ||
38 | + private final Collection<Band> bands; | ||
39 | + private final DeviceId deviceId; | ||
40 | + private final Optional<MeterContext> context; | ||
41 | + | ||
42 | + private DefaultMeter(DeviceId deviceId, MeterId id, ApplicationId appId, | ||
43 | + Unit unit, boolean burst, | ||
44 | + Collection<Band> bands, Optional<MeterContext> context) { | ||
45 | + this.deviceId = deviceId; | ||
46 | + this.id = id; | ||
47 | + this.appId = appId; | ||
48 | + this.unit = unit; | ||
49 | + this.burst = burst; | ||
50 | + this.bands = bands; | ||
51 | + this.context = context; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public DeviceId deviceId() { | ||
56 | + return deviceId; | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public MeterId id() { | ||
61 | + return id; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public ApplicationId appId() { | ||
66 | + return appId; | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public Unit unit() { | ||
71 | + return unit; | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public boolean isBurst() { | ||
76 | + return burst; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public Collection<Band> bands() { | ||
81 | + return bands; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public Optional<MeterContext> context() { | ||
86 | + return null; | ||
87 | + } | ||
88 | + | ||
89 | + public static Builder builder() { | ||
90 | + return new Builder(); | ||
91 | + } | ||
92 | + | ||
93 | + public static final class Builder implements Meter.Builder { | ||
94 | + | ||
95 | + private MeterId id; | ||
96 | + private ApplicationId appId; | ||
97 | + private Unit unit = Unit.KB_PER_SEC; | ||
98 | + private boolean burst = false; | ||
99 | + private Collection<Band> bands; | ||
100 | + private DeviceId deviceId; | ||
101 | + private Optional<MeterContext> context; | ||
102 | + | ||
103 | + | ||
104 | + @Override | ||
105 | + public Meter.Builder forDevice(DeviceId deviceId) { | ||
106 | + this.deviceId = deviceId; | ||
107 | + return this; | ||
108 | + } | ||
109 | + | ||
110 | + @Override | ||
111 | + public Meter.Builder withId(int id) { | ||
112 | + this.id = MeterId.meterId(id); | ||
113 | + return this; | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public Meter.Builder fromApp(ApplicationId appId) { | ||
118 | + this.appId = appId; | ||
119 | + return this; | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public Meter.Builder withUnit(Unit unit) { | ||
124 | + this.unit = unit; | ||
125 | + return this; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public Meter.Builder burst() { | ||
130 | + this.burst = true; | ||
131 | + return this; | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public Meter.Builder withBands(Collection<Band> bands) { | ||
136 | + this.bands = Collections.unmodifiableCollection(bands); | ||
137 | + return this; | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public Meter.Builder withContext(MeterContext context) { | ||
142 | + this.context = Optional.<MeterContext>ofNullable(context); | ||
143 | + return this; | ||
144 | + } | ||
145 | + | ||
146 | + @Override | ||
147 | + public Meter build() { | ||
148 | + checkNotNull(deviceId, "Must specify a device"); | ||
149 | + checkNotNull(bands, "Must have bands."); | ||
150 | + checkArgument(bands.size() > 0, "Must have at least one band."); | ||
151 | + checkNotNull(appId, "Must have an application id"); | ||
152 | + checkNotNull(id, "Must specify a meter id"); | ||
153 | + return new DefaultMeter(deviceId, id, appId, unit, burst, bands, context); | ||
154 | + } | ||
155 | + | ||
156 | + | ||
157 | + } | ||
158 | +} |
... | @@ -13,11 +13,13 @@ | ... | @@ -13,11 +13,13 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import org.onosproject.core.ApplicationId; | 18 | import org.onosproject.core.ApplicationId; |
19 | +import org.onosproject.net.DeviceId; | ||
19 | 20 | ||
20 | import java.util.Collection; | 21 | import java.util.Collection; |
22 | +import java.util.Optional; | ||
21 | 23 | ||
22 | /** | 24 | /** |
23 | * Represents a generalized meter to be deployed on a device. | 25 | * Represents a generalized meter to be deployed on a device. |
... | @@ -37,6 +39,13 @@ public interface Meter { | ... | @@ -37,6 +39,13 @@ public interface Meter { |
37 | } | 39 | } |
38 | 40 | ||
39 | /** | 41 | /** |
42 | + * The target device for this meter. | ||
43 | + * | ||
44 | + * @return a device id | ||
45 | + */ | ||
46 | + DeviceId deviceId(); | ||
47 | + | ||
48 | + /** | ||
40 | * This meters id. | 49 | * This meters id. |
41 | * | 50 | * |
42 | * @return a meter id | 51 | * @return a meter id |
... | @@ -71,4 +80,76 @@ public interface Meter { | ... | @@ -71,4 +80,76 @@ public interface Meter { |
71 | */ | 80 | */ |
72 | Collection<Band> bands(); | 81 | Collection<Band> bands(); |
73 | 82 | ||
83 | + /** | ||
84 | + * Obtains an optional context. | ||
85 | + * | ||
86 | + * @return optional; which will be empty if there is no context. | ||
87 | + * Otherwise it will return the context. | ||
88 | + */ | ||
89 | + Optional<MeterContext> context(); | ||
90 | + | ||
91 | + /** | ||
92 | + * A meter builder. | ||
93 | + */ | ||
94 | + interface Builder { | ||
95 | + | ||
96 | + /** | ||
97 | + * Assigns the target device for this meter. | ||
98 | + * | ||
99 | + * @param deviceId a device id | ||
100 | + * @return this | ||
101 | + */ | ||
102 | + Builder forDevice(DeviceId deviceId); | ||
103 | + | ||
104 | + /** | ||
105 | + * Assigns the id to this meter. | ||
106 | + * | ||
107 | + * @param id an integer | ||
108 | + * @return this | ||
109 | + */ | ||
110 | + Builder withId(int id); | ||
111 | + | ||
112 | + /** | ||
113 | + * Assigns the application that built this meter. | ||
114 | + * | ||
115 | + * @param appId an application id | ||
116 | + * @return this | ||
117 | + */ | ||
118 | + Builder fromApp(ApplicationId appId); | ||
119 | + | ||
120 | + /** | ||
121 | + * Assigns the @See Unit to use for this meter. | ||
122 | + * Defaults to kb/s | ||
123 | + * | ||
124 | + * @param unit a unit | ||
125 | + * @return this | ||
126 | + */ | ||
127 | + Builder withUnit(Unit unit); | ||
128 | + | ||
129 | + /** | ||
130 | + * Sets this meter as applicable to burst traffic only. | ||
131 | + * Defaults to false. | ||
132 | + * | ||
133 | + * @return this | ||
134 | + */ | ||
135 | + Builder burst(); | ||
136 | + | ||
137 | + /** | ||
138 | + * Assigns bands to this meter. There must be at least one band. | ||
139 | + * | ||
140 | + * @param bands a collection of bands | ||
141 | + * @return this | ||
142 | + */ | ||
143 | + Builder withBands(Collection<Band> bands); | ||
144 | + | ||
145 | + Builder withContext(MeterContext context); | ||
146 | + | ||
147 | + /** | ||
148 | + * Builds the meter based on the specified parameters. | ||
149 | + * | ||
150 | + * @return a meter | ||
151 | + */ | ||
152 | + Meter build(); | ||
153 | + } | ||
154 | + | ||
74 | } | 155 | } | ... | ... |
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.incubator.net.meter; | ||
17 | + | ||
18 | +/** | ||
19 | + * Created by ash on 01/08/15. | ||
20 | + */ | ||
21 | +public interface MeterContext { | ||
22 | + | ||
23 | + /** | ||
24 | + * Invoked on successful installation of the meter. | ||
25 | + * | ||
26 | + * @param op a meter operation | ||
27 | + */ | ||
28 | + default void onSuccess(MeterOperation op) { | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Invoked when error is encountered while installing a meter. | ||
33 | + * | ||
34 | + * @param op a meter operation | ||
35 | + * @param reason the reason why it failed | ||
36 | + */ | ||
37 | + default void onError(MeterOperation op, MeterFailReason reason) { | ||
38 | + } | ||
39 | +} |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import org.onosproject.event.AbstractEvent; | ||
19 | + | ||
20 | +/** | ||
21 | + * Entity that represents Meter events. | ||
22 | + */ | ||
23 | +public class MeterEvent extends AbstractEvent<MeterEvent.Type, Meter> { | ||
24 | + | ||
25 | + | ||
26 | + enum Type { | ||
27 | + | ||
28 | + /** | ||
29 | + * Signals that a new meter has been added. | ||
30 | + */ | ||
31 | + METER_ADDED, | ||
32 | + | ||
33 | + /** | ||
34 | + * Signals that a meter has been removed. | ||
35 | + */ | ||
36 | + METER_REMOVED, | ||
37 | + | ||
38 | + /** | ||
39 | + * Signals that a meter has been added. | ||
40 | + */ | ||
41 | + METER_UPDATED, | ||
42 | + | ||
43 | + /** | ||
44 | + * Signals that a meter addition failed. | ||
45 | + */ | ||
46 | + METER_ADD_FAILED, | ||
47 | + | ||
48 | + /** | ||
49 | + * Signals that a meter removal failed. | ||
50 | + */ | ||
51 | + METER_REMOVE_FAILED, | ||
52 | + | ||
53 | + /** | ||
54 | + * Signals that a meter update failed. | ||
55 | + */ | ||
56 | + METER_UPDATE_FAILED | ||
57 | + } | ||
58 | + | ||
59 | + | ||
60 | + /** | ||
61 | + * Creates an event of a given type and for the specified meter and the | ||
62 | + * current time. | ||
63 | + * | ||
64 | + * @param type meter event type | ||
65 | + * @param meter event subject | ||
66 | + */ | ||
67 | + public MeterEvent(Type type, Meter meter) { | ||
68 | + super(type, meter); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Creates an event of a given type and for the specified meter and time. | ||
73 | + * | ||
74 | + * @param type meter event type | ||
75 | + * @param meter event subject | ||
76 | + * @param time occurrence time | ||
77 | + */ | ||
78 | + public MeterEvent(Type type, Meter meter, long time) { | ||
79 | + super(type, meter, time); | ||
80 | + } | ||
81 | + | ||
82 | +} |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Enum used to represent a meter failure condition. | 19 | * Enum used to represent a meter failure condition. | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkArgument; | 18 | import static com.google.common.base.Preconditions.checkArgument; |
19 | 19 | ||
... | @@ -31,7 +31,7 @@ public final class MeterId { | ... | @@ -31,7 +31,7 @@ public final class MeterId { |
31 | public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE); | 31 | public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE); |
32 | public static final MeterId ALL = new MeterId(0xFFFFFFFF); | 32 | public static final MeterId ALL = new MeterId(0xFFFFFFFF); |
33 | 33 | ||
34 | - protected MeterId(int id) { | 34 | + private MeterId(int 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 | } | ... | ... |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import org.onosproject.event.EventListener; | ||
19 | + | ||
20 | +/** | ||
21 | + * Entity capable of receiving Meter related events. | ||
22 | + */ | ||
23 | +public interface MeterListener extends EventListener<MeterEvent> { | ||
24 | +} |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | 19 | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | 19 | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import org.onosproject.net.DeviceId; | 18 | import org.onosproject.net.DeviceId; |
19 | import org.onosproject.net.provider.Provider; | 19 | import org.onosproject.net.provider.Provider; | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | 18 | ||
19 | import org.onosproject.net.provider.ProviderRegistry; | 19 | import org.onosproject.net.provider.ProviderRegistry; | ... | ... |
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.net.meter; | 16 | +package org.onosproject.incubator.net.meter; |
17 | 17 | ||
18 | import org.onosproject.net.DeviceId; | 18 | import org.onosproject.net.DeviceId; |
19 | import org.onosproject.net.provider.ProviderService; | 19 | import org.onosproject.net.provider.ProviderService; | ... | ... |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import org.onosproject.event.ListenerService; | ||
19 | + | ||
20 | +/** | ||
21 | + * Service for add/updating and removing meters. Meters are | ||
22 | + * are assigned to flow to rate limit them and provide a certain | ||
23 | + * quality of service. | ||
24 | + */ | ||
25 | +public interface MeterService | ||
26 | + extends ListenerService<MeterEvent, MeterListener> { | ||
27 | + | ||
28 | + /** | ||
29 | + * Adds a meter to the system and performs it installation. | ||
30 | + * | ||
31 | + * @param meter a meter. | ||
32 | + */ | ||
33 | + void addMeter(Meter meter); | ||
34 | + | ||
35 | + /** | ||
36 | + * Updates a meter by adding statistic information to the meter. | ||
37 | + * | ||
38 | + * @param meter an updated meter | ||
39 | + */ | ||
40 | + void updateMeter(Meter meter); | ||
41 | + | ||
42 | + /** | ||
43 | + * Remove a meter from the system and the dataplane. | ||
44 | + * | ||
45 | + * @param meter a meter to remove | ||
46 | + */ | ||
47 | + void removeMeter(Meter meter); | ||
48 | + | ||
49 | + /** | ||
50 | + * Remove a meter from the system and the dataplane by meter id. | ||
51 | + * | ||
52 | + * @param id a meter id | ||
53 | + */ | ||
54 | + void removeMeter(MeterId id); | ||
55 | + | ||
56 | + /** | ||
57 | + * Fetch the meter by the meter id. | ||
58 | + * | ||
59 | + * @param id a meter id | ||
60 | + * @return a meter | ||
61 | + */ | ||
62 | + Meter getMeter(MeterId id); | ||
63 | + | ||
64 | + /** | ||
65 | + * Allocate a meter id which must be used to create the meter. | ||
66 | + * | ||
67 | + * @return a meter id | ||
68 | + */ | ||
69 | + MeterId allocateMeterId(); | ||
70 | +} |
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.incubator.net.meter; | ||
17 | + | ||
18 | +import org.onosproject.store.StoreDelegate; | ||
19 | + | ||
20 | +/** | ||
21 | + * Meter store delegate abstraction. | ||
22 | + */ | ||
23 | +public interface MeterStoreDelegate extends StoreDelegate<MeterEvent> { | ||
24 | +} |
... | @@ -17,4 +17,4 @@ | ... | @@ -17,4 +17,4 @@ |
17 | /** | 17 | /** |
18 | * Flow meter model and related services. | 18 | * Flow meter model and related services. |
19 | */ | 19 | */ |
20 | -package org.onosproject.net.meter; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
20 | +package org.onosproject.incubator.net.meter; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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.incubator.net.meter.impl; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.apache.felix.scr.annotations.Service; | ||
24 | +import org.onosproject.incubator.net.meter.Meter; | ||
25 | +import org.onosproject.incubator.net.meter.MeterEvent; | ||
26 | +import org.onosproject.incubator.net.meter.MeterFailReason; | ||
27 | +import org.onosproject.incubator.net.meter.MeterId; | ||
28 | +import org.onosproject.incubator.net.meter.MeterListener; | ||
29 | +import org.onosproject.incubator.net.meter.MeterOperation; | ||
30 | +import org.onosproject.incubator.net.meter.MeterProvider; | ||
31 | +import org.onosproject.incubator.net.meter.MeterProviderRegistry; | ||
32 | +import org.onosproject.incubator.net.meter.MeterProviderService; | ||
33 | +import org.onosproject.incubator.net.meter.MeterService; | ||
34 | +import org.onosproject.incubator.net.meter.MeterStoreDelegate; | ||
35 | +import org.onosproject.net.DeviceId; | ||
36 | +import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ||
37 | +import org.onosproject.net.provider.AbstractProviderService; | ||
38 | +import org.onosproject.store.service.AtomicCounter; | ||
39 | +import org.onosproject.store.service.StorageService; | ||
40 | +import org.slf4j.Logger; | ||
41 | + | ||
42 | +import java.util.Collection; | ||
43 | + | ||
44 | +import static org.slf4j.LoggerFactory.getLogger; | ||
45 | + | ||
46 | + | ||
47 | +/** | ||
48 | + * Provides implementation of the meter service APIs. | ||
49 | + */ | ||
50 | +@Component(immediate = true) | ||
51 | +@Service | ||
52 | +public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, MeterListener, | ||
53 | + MeterProvider, MeterProviderService> | ||
54 | + implements MeterService, MeterProviderRegistry { | ||
55 | + | ||
56 | + private final String meterIdentifier = "meter-id-counter"; | ||
57 | + private final Logger log = getLogger(getClass()); | ||
58 | + private final MeterStoreDelegate delegate = new InternalMeterStoreDelegate(); | ||
59 | + | ||
60 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
61 | + protected StorageService storageService; | ||
62 | + | ||
63 | + private AtomicCounter meterIdCounter; | ||
64 | + | ||
65 | + @Activate | ||
66 | + public void activate() { | ||
67 | + meterIdCounter = storageService.atomicCounterBuilder() | ||
68 | + .withName(meterIdentifier) | ||
69 | + .build(); | ||
70 | + log.info("Started"); | ||
71 | + } | ||
72 | + | ||
73 | + @Deactivate | ||
74 | + public void deactivate() { | ||
75 | + log.info("Stopped"); | ||
76 | + } | ||
77 | + | ||
78 | + @Override | ||
79 | + protected MeterProviderService createProviderService(MeterProvider provider) { | ||
80 | + return new InternalMeterProviderService(provider); | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
84 | + public void addMeter(Meter meter) { | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public void updateMeter(Meter meter) { | ||
90 | + | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public void removeMeter(Meter meter) { | ||
95 | + | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public void removeMeter(MeterId id) { | ||
100 | + | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public Meter getMeter(MeterId id) { | ||
105 | + return null; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public MeterId allocateMeterId() { | ||
110 | + // FIXME: This will break one day. | ||
111 | + return MeterId.meterId((int) meterIdCounter.getAndIncrement()); | ||
112 | + } | ||
113 | + | ||
114 | + private class InternalMeterProviderService | ||
115 | + extends AbstractProviderService<MeterProvider> | ||
116 | + implements MeterProviderService { | ||
117 | + | ||
118 | + /** | ||
119 | + * Creates a provider service on behalf of the specified provider. | ||
120 | + * | ||
121 | + * @param provider provider to which this service is being issued | ||
122 | + */ | ||
123 | + protected InternalMeterProviderService(MeterProvider provider) { | ||
124 | + super(provider); | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public void meterOperationFailed(MeterOperation operation, MeterFailReason reason) { | ||
129 | + | ||
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public void pushMeterMetrics(DeviceId deviceId, Collection<Meter> meterEntries) { | ||
134 | + | ||
135 | + } | ||
136 | + } | ||
137 | + | ||
138 | + private class InternalMeterStoreDelegate implements MeterStoreDelegate { | ||
139 | + | ||
140 | + @Override | ||
141 | + public void notify(MeterEvent event) { | ||
142 | + | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | +} |
... | @@ -15,9 +15,9 @@ | ... | @@ -15,9 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.provider.of.meter.impl; | 16 | package org.onosproject.provider.of.meter.impl; |
17 | 17 | ||
18 | -import org.onosproject.net.meter.Band; | 18 | +import org.onosproject.incubator.net.meter.Band; |
19 | -import org.onosproject.net.meter.Meter; | 19 | +import org.onosproject.incubator.net.meter.Meter; |
20 | -import org.onosproject.net.meter.MeterId; | 20 | +import org.onosproject.incubator.net.meter.MeterId; |
21 | import org.projectfloodlight.openflow.protocol.OFFactory; | 21 | import org.projectfloodlight.openflow.protocol.OFFactory; |
22 | import org.projectfloodlight.openflow.protocol.OFMeterFlags; | 22 | import org.projectfloodlight.openflow.protocol.OFMeterFlags; |
23 | import org.projectfloodlight.openflow.protocol.OFMeterMod; | 23 | import org.projectfloodlight.openflow.protocol.OFMeterMod; | ... | ... |
... | @@ -16,9 +16,11 @@ | ... | @@ -16,9 +16,11 @@ |
16 | 16 | ||
17 | package org.onosproject.provider.of.meter.impl; | 17 | package org.onosproject.provider.of.meter.impl; |
18 | 18 | ||
19 | + | ||
19 | import com.google.common.cache.Cache; | 20 | import com.google.common.cache.Cache; |
20 | import com.google.common.cache.CacheBuilder; | 21 | import com.google.common.cache.CacheBuilder; |
21 | import com.google.common.cache.RemovalCause; | 22 | import com.google.common.cache.RemovalCause; |
23 | + | ||
22 | import com.google.common.cache.RemovalNotification; | 24 | import com.google.common.cache.RemovalNotification; |
23 | import com.google.common.collect.Maps; | 25 | import com.google.common.collect.Maps; |
24 | import org.apache.felix.scr.annotations.Activate; | 26 | import org.apache.felix.scr.annotations.Activate; |
... | @@ -27,13 +29,13 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -27,13 +29,13 @@ import org.apache.felix.scr.annotations.Deactivate; |
27 | import org.apache.felix.scr.annotations.Reference; | 29 | import org.apache.felix.scr.annotations.Reference; |
28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
29 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
30 | -import org.onosproject.net.meter.Meter; | 32 | +import org.onosproject.incubator.net.meter.Meter; |
31 | -import org.onosproject.net.meter.MeterFailReason; | 33 | +import org.onosproject.incubator.net.meter.MeterFailReason; |
32 | -import org.onosproject.net.meter.MeterOperation; | 34 | +import org.onosproject.incubator.net.meter.MeterOperation; |
33 | -import org.onosproject.net.meter.MeterOperations; | 35 | +import org.onosproject.incubator.net.meter.MeterOperations; |
34 | -import org.onosproject.net.meter.MeterProvider; | 36 | +import org.onosproject.incubator.net.meter.MeterProvider; |
35 | -import org.onosproject.net.meter.MeterProviderRegistry; | 37 | +import org.onosproject.incubator.net.meter.MeterProviderRegistry; |
36 | -import org.onosproject.net.meter.MeterProviderService; | 38 | +import org.onosproject.incubator.net.meter.MeterProviderService; |
37 | import org.onosproject.net.provider.AbstractProvider; | 39 | import org.onosproject.net.provider.AbstractProvider; |
38 | import org.onosproject.net.provider.ProviderId; | 40 | import org.onosproject.net.provider.ProviderId; |
39 | import org.onosproject.openflow.controller.Dpid; | 41 | import org.onosproject.openflow.controller.Dpid; | ... | ... |
-
Please register or login to post a comment