alshabib
Committed by Gerrit Code Review

sketching model elements for meter objects.

Change-Id: Ie9e8eb2af634f2f591089445d2258495285dcdd1
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.net.meter;
17 +
18 +/**
19 + * Represents a band used within a meter.
20 + */
21 +public interface Band {
22 +
23 + /**
24 + * Specifies the type of band.
25 + */
26 + enum Type {
27 + /**
28 + * Simple rate limiter which drops packets
29 + * when the rate is exceeded.
30 + */
31 + DROP,
32 +
33 + /**
34 + * defines a simple DiffServ policer that remark
35 + * the drop precedence of the DSCP eld in the
36 + * IP header of the packets that exceed the band
37 + * rate value.
38 + */
39 + REMARK
40 + }
41 +
42 + /**
43 + * The rate at which this meter applies.
44 + *
45 + * @return the integer value of the rate
46 + */
47 + int rate();
48 +
49 + /**
50 + * The burst size at which the meter applies.
51 + *
52 + * @return the integer value of the size
53 + */
54 + int burst();
55 +
56 +
57 +}
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.net.meter;
17 +
18 +import org.onosproject.core.ApplicationId;
19 +
20 +import java.util.Collection;
21 +
22 +/**
23 + * Represents a generalized meter to be deployed on a device.
24 + */
25 +public interface Meter {
26 +
27 + enum Unit {
28 + /**
29 + * Packets per second.
30 + */
31 + PKTS_PER_SEC,
32 +
33 + /**
34 + * Kilo bits per second.
35 + */
36 + KB_PER_SEC
37 + }
38 +
39 + /**
40 + * This meters id.
41 + *
42 + * @return a meter id
43 + */
44 + MeterId id();
45 +
46 + /**
47 + * The id of the application which created this meter.
48 + *
49 + * @return an application id
50 + */
51 + ApplicationId appId();
52 +
53 + /**
54 + * The unit used within this meter.
55 + *
56 + * @return
57 + */
58 + Unit unit();
59 +
60 + /**
61 + * Signals whether this meter applies to bursts only.
62 + *
63 + * @return a boolean
64 + */
65 + boolean isBurst();
66 +
67 + /**
68 + * The collection of bands to apply on the dataplane.
69 + *
70 + * @return a collection of bands.
71 + */
72 + Collection<Band> bands();
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.net.meter;
17 +
18 +/**
19 + * Enum used to represent a meter failure condition.
20 + */
21 +public enum MeterFailReason {
22 + /**
23 + * A meter with the same identifier already exists.
24 + * Essentially a duplicate meter exists.
25 + */
26 + EXISTING_METER,
27 +
28 + /**
29 + * The device does not support any more meters.
30 + */
31 + OUT_OF_METERS,
32 +
33 + /**
34 + * The device does not support any more bands for this meter.
35 + */
36 + OUT_OF_BANDS,
37 +
38 + /**
39 + * The meter that was attempted to be modified is unknown.
40 + */
41 + UNKNOWN
42 +}
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.net.meter;
17 +
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +
20 +/**
21 + * A representation of a meter id.
22 + * Uniquely identifies a meter for a given device.
23 + */
24 +public final class MeterId {
25 +
26 + static final long MAX = 0xFFFF0000;
27 +
28 + private final int id;
29 +
30 + public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
31 + public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
32 + public static final MeterId ALL = new MeterId(0xFFFFFFFF);
33 +
34 + protected MeterId(int id) {
35 + checkArgument(id <= MAX, "id cannot be larger than 0xFFFF0000");
36 + this.id = id;
37 + }
38 +
39 + /**
40 + * The integer representation of the meter id.
41 + *
42 + * @return an integer
43 + */
44 + int id() {
45 + return id;
46 + }
47 +
48 + @Override
49 + public boolean equals(Object o) {
50 + if (this == o) {
51 + return true;
52 + }
53 + if (o == null || getClass() != o.getClass()) {
54 + return false;
55 + }
56 +
57 + MeterId meterId = (MeterId) o;
58 +
59 + return id == meterId.id;
60 +
61 + }
62 +
63 + @Override
64 + public int hashCode() {
65 + return id;
66 + }
67 +
68 + public static MeterId meterId(int id) {
69 + return new MeterId(id);
70 +
71 + }
72 +
73 +}
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.net.meter;
17 +
18 +import com.google.common.base.MoreObjects;
19 +
20 +/**
21 + * Representation of an operation on the meter table.
22 + */
23 +public class MeterOperation {
24 +
25 + /**
26 + * Tyoe of meter operation.
27 + */
28 + public enum Type {
29 + ADD,
30 + REMOVE,
31 + MODIFY
32 + }
33 +
34 + private final Meter meter;
35 + private final Type type;
36 +
37 +
38 + public MeterOperation(Meter meter, Type type) {
39 + this.meter = meter;
40 + this.type = type;
41 + }
42 +
43 + /**
44 + * Returns the type of operation.
45 + *
46 + * @return type
47 + */
48 + public Type type() {
49 + return type;
50 + }
51 +
52 + /**
53 + * Returns the meter.
54 + *
55 + * @return a meter
56 + */
57 + public Meter meter() {
58 + return meter;
59 + }
60 +
61 + @Override
62 + public String toString() {
63 + return MoreObjects.toStringHelper(this)
64 + .add("meter", meter)
65 + .add("type", type)
66 + .toString();
67 + }
68 +}
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.net.meter;
17 +
18 +import com.google.common.collect.ImmutableList;
19 +
20 +import java.util.List;
21 +
22 +import static com.google.common.base.Preconditions.checkNotNull;
23 +
24 +/**
25 + * Immutable collection of meter operation to be used between
26 + * core and provider layers of group subsystem.
27 + *
28 + */
29 +public final class MeterOperations {
30 + private final List<MeterOperation> operations;
31 +
32 + /**
33 + * Creates a immutable list of meter operation.
34 + *
35 + * @param operations list of meter operation
36 + */
37 + public MeterOperations(List<MeterOperation> operations) {
38 + this.operations = ImmutableList.copyOf(checkNotNull(operations));
39 + }
40 +
41 + /**
42 + * Returns immutable list of Meter operation.
43 + *
44 + * @return list of Meter operation
45 + */
46 + public List<MeterOperation> operations() {
47 + return operations;
48 + }
49 +
50 +}
...@@ -15,10 +15,34 @@ ...@@ -15,10 +15,34 @@
15 */ 15 */
16 package org.onosproject.net.meter; 16 package org.onosproject.net.meter;
17 17
18 +import org.onosproject.net.DeviceId;
18 import org.onosproject.net.provider.Provider; 19 import org.onosproject.net.provider.Provider;
19 20
20 /** 21 /**
21 * Abstraction of a Meter provider. 22 * Abstraction of a Meter provider.
22 */ 23 */
23 public interface MeterProvider extends Provider { 24 public interface MeterProvider extends Provider {
25 +
26 + /**
27 + * Performs a batch of meter operation on the specified device with the
28 + * specified parameters.
29 + *
30 + * @param deviceId device identifier on which the batch of group
31 + * operations to be executed
32 + * @param meterOps immutable list of meter operation
33 + */
34 + void performMeterOperation(DeviceId deviceId,
35 + MeterOperations meterOps);
36 +
37 +
38 + /**
39 + * Performs a meter operation on the specified device with the
40 + * specified parameters.
41 + *
42 + * @param deviceId device identifier on which the batch of group
43 + * operations to be executed
44 + * @param meterOp a meter operation
45 + */
46 + void performMeterOperation(DeviceId deviceId,
47 + MeterOperation meterOp);
24 } 48 }
......
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.net.meter;
17 +
18 +
19 +import org.onosproject.net.provider.ProviderRegistry;
20 +
21 +/**
22 + * Abstraction for a meter provider registry.
23 + */
24 +public interface MeterProviderRegistry
25 + extends ProviderRegistry<MeterProvider, MeterProviderService> {
26 +}
27 +
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.net.meter;
17 +
18 +import org.onosproject.net.DeviceId;
19 +import org.onosproject.net.provider.ProviderService;
20 +
21 +import java.util.Collection;
22 +
23 +/**
24 + * Service through which meter providers can inject information
25 + * into the core.
26 + */
27 +public interface MeterProviderService extends ProviderService<MeterProvider> {
28 +
29 + /**
30 + * Notifies the core that a meter operaton failed for a
31 + * specific reason.
32 + * @param deviceId
33 + * @param operation
34 + */
35 + void meterOperationFailed(DeviceId deviceId, MeterOperation operation,
36 + MeterFailReason reason);
37 +
38 + /**
39 + * Pushes the collection of meters observed on the data plane as
40 + * well as their associated statistics.
41 + *
42 + * @param deviceId a device id
43 + * @param meterEntries a collection of meter entries
44 + */
45 + void pushMeterMetrics(DeviceId deviceId,
46 + Collection<Meter> meterEntries);
47 +
48 +
49 +}
...@@ -19,6 +19,9 @@ package org.onosproject.provider.of.meter.impl; ...@@ -19,6 +19,9 @@ package org.onosproject.provider.of.meter.impl;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Reference; 20 import org.apache.felix.scr.annotations.Reference;
21 import org.apache.felix.scr.annotations.ReferenceCardinality; 21 import org.apache.felix.scr.annotations.ReferenceCardinality;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.meter.MeterOperation;
24 +import org.onosproject.net.meter.MeterOperations;
22 import org.onosproject.net.meter.MeterProvider; 25 import org.onosproject.net.meter.MeterProvider;
23 import org.onosproject.net.provider.AbstractProvider; 26 import org.onosproject.net.provider.AbstractProvider;
24 import org.onosproject.net.provider.ProviderId; 27 import org.onosproject.net.provider.ProviderId;
...@@ -45,4 +48,14 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv ...@@ -45,4 +48,14 @@ public class OpenFlowMeterProvider extends AbstractProvider implements MeterProv
45 public OpenFlowMeterProvider() { 48 public OpenFlowMeterProvider() {
46 super(new ProviderId("of", "org.onosproject.provider.meter")); 49 super(new ProviderId("of", "org.onosproject.provider.meter"));
47 } 50 }
51 +
52 + @Override
53 + public void performMeterOperation(DeviceId deviceId, MeterOperations meterOps) {
54 +
55 + }
56 +
57 + @Override
58 + public void performMeterOperation(DeviceId deviceId, MeterOperation meterOp) {
59 +
60 + }
48 } 61 }
......