alshabib
Committed by Gerrit Code Review

added treatment support and conversion to an instruction

moved to meter api to onos-api

Change-Id: I0504f06fdc503953fa7696224d97edda43596d6e
Showing 35 changed files with 177 additions and 65 deletions
......@@ -28,6 +28,7 @@ import org.onosproject.net.IndexedLambda;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.meter.MeterId;
import java.util.Collections;
import java.util.List;
......@@ -50,6 +51,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
private static final DefaultTrafficTreatment EMPTY
= new DefaultTrafficTreatment(Collections.emptyList());
private final Instructions.MeterInstruction meter;
/**
* Creates a new traffic treatment from the specified list of instructions.
......@@ -63,6 +65,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
this.hasClear = false;
this.table = null;
this.meta = null;
this.meter = null;
}
/**
......@@ -77,7 +80,8 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
List<Instruction> immediate,
Instructions.TableTypeTransition table,
boolean clear,
Instructions.MetadataInstruction meta) {
Instructions.MetadataInstruction meta,
Instructions.MeterInstruction meter) {
this.immediate = ImmutableList.copyOf(checkNotNull(immediate));
this.deferred = ImmutableList.copyOf(checkNotNull(deferred));
this.all = new ImmutableList.Builder<Instruction>()
......@@ -87,6 +91,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
this.table = table;
this.meta = meta;
this.hasClear = clear;
this.meter = meter;
}
@Override
......@@ -119,6 +124,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
return meta;
}
@Override
public Instructions.MeterInstruction metered() {
return meter;
}
/**
* Returns a new traffic treatment builder.
*
......@@ -193,12 +203,16 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
Instructions.MetadataInstruction meta;
Instructions.MeterInstruction meter;
List<Instruction> deferred = Lists.newLinkedList();
List<Instruction> immediate = Lists.newLinkedList();
List<Instruction> current = immediate;
// Creates a new builder
private Builder() {
}
......@@ -233,6 +247,8 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
case METADATA:
meta = (Instructions.MetadataInstruction) instruction;
break;
case METER:
meter = (Instructions.MeterInstruction) instruction;
default:
throw new IllegalArgumentException("Unknown instruction type: " +
instruction.type());
......@@ -343,6 +359,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@Override
public TrafficTreatment.Builder meter(MeterId meterId) {
return add(Instructions.meterTraffic(meterId));
}
@Override
public Builder popVlan() {
return add(Instructions.popVlan());
}
......@@ -420,7 +441,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
// && table == null && !clear) {
// drop();
//}
return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta);
return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta, meter);
}
}
......
......@@ -24,6 +24,7 @@ import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.meter.MeterId;
import java.util.List;
......@@ -75,6 +76,13 @@ public interface TrafficTreatment {
Instructions.MetadataInstruction writeMetadata();
/**
* Returns the meter instruction if there is one.
*
* @return a meter instruction that may be null
*/
Instructions.MeterInstruction metered();
/**
* Builder of traffic treatment entities.
*/
interface Builder {
......@@ -243,6 +251,13 @@ public interface TrafficTreatment {
*/
Builder group(GroupId groupId);
/**
* Sets a meter to be used by this flow.
*
* @param meterId a meter id
* @return a treatment builder
*/
Builder meter(MeterId meterId);
/**
* Sets the next table type to transition to.
......
......@@ -40,6 +40,11 @@ public interface Instruction {
GROUP,
/**
* Signifies that traffic should be metered according to a meter.
*/
METER,
/**
* Signifies that the traffic should be modified in L0 way.
*/
L0MODIFICATION,
......
......@@ -34,6 +34,7 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6Fl
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
import org.onosproject.net.meter.MeterId;
import java.util.Objects;
......@@ -81,6 +82,11 @@ public final class Instructions {
return new GroupInstruction(groupId);
}
public static MeterInstruction meterTraffic(final MeterId meterId) {
checkNotNull(meterId, "meter id cannot be null");
return new MeterInstruction(meterId);
}
/**
* Creates a l0 modification.
*
......@@ -528,6 +534,50 @@ public final class Instructions {
}
/**
* A meter instruction.
*/
public static final class MeterInstruction implements Instruction {
private final MeterId meterId;
private MeterInstruction(MeterId meterId) {
this.meterId = meterId;
}
public MeterId meterId() {
return meterId;
}
@Override
public Type type() {
return Type.METER;
}
@Override
public String toString() {
return toStringHelper(type().toString())
.add("meter ID", meterId.id()).toString();
}
@Override
public int hashCode() {
return Objects.hash(type().ordinal(), meterId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MeterInstruction) {
MeterInstruction that = (MeterInstruction) obj;
return Objects.equals(meterId, that.meterId);
}
return false;
}
}
/**
* Transition instruction.
*/
public static class TableTypeTransition implements Instruction {
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* Represents a band used within a meter.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* Represents a stored band.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import static com.google.common.base.Preconditions.checkArgument;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* A context permitting the application to be notified when the
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* Represents a stored meter.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.event.AbstractEvent;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* Enum used to represent a meter failure condition.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import static com.google.common.base.Preconditions.checkArgument;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.event.EventListener;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import com.google.common.base.MoreObjects;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import com.google.common.collect.ImmutableList;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.Provider;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.net.provider.ProviderRegistry;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.ProviderService;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.event.ListenerService;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
/**
* Represents the state of the meter as seen by the store.
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.store.Store;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import org.onosproject.store.StoreDelegate;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.incubator.net.meter;
package org.onosproject.net.meter;
import java.util.Optional;
......
......@@ -17,4 +17,4 @@
/**
* Flow meter model and related services.
*/
package org.onosproject.incubator.net.meter;
\ No newline at end of file
package org.onosproject.net.meter;
\ No newline at end of file
......
......@@ -124,6 +124,11 @@ public class IntentTestsMocks {
public MetadataInstruction writeMetadata() {
return null;
}
@Override
public Instructions.MeterInstruction metered() {
return null;
}
}
/**
......
......@@ -610,6 +610,11 @@ public class FlowRuleManagerTest {
return null;
}
@Override
public Instructions.MeterInstruction metered() {
return null;
}
}
public class TestApplicationId extends DefaultApplicationId {
......
......@@ -160,6 +160,7 @@ import org.onosproject.net.intent.constraint.ObstacleConstraint;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.net.intent.constraint.WaypointConstraint;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.meter.MeterId;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.packet.DefaultOutboundPacket;
......@@ -271,6 +272,8 @@ public final class KryoNamespaces {
.register(MISC)
.nextId(KryoNamespace.INITIAL_ID + 30 + 10)
.register(
Instructions.MeterInstruction.class,
MeterId.class,
Version.class,
ControllerNode.State.class,
ApplicationState.class,
......
......@@ -22,21 +22,21 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.TriConsumer;
import org.onosproject.incubator.net.meter.DefaultMeter;
import org.onosproject.incubator.net.meter.Meter;
import org.onosproject.incubator.net.meter.MeterEvent;
import org.onosproject.incubator.net.meter.MeterFailReason;
import org.onosproject.incubator.net.meter.MeterId;
import org.onosproject.incubator.net.meter.MeterListener;
import org.onosproject.incubator.net.meter.MeterOperation;
import org.onosproject.incubator.net.meter.MeterProvider;
import org.onosproject.incubator.net.meter.MeterProviderRegistry;
import org.onosproject.incubator.net.meter.MeterProviderService;
import org.onosproject.incubator.net.meter.MeterService;
import org.onosproject.incubator.net.meter.MeterState;
import org.onosproject.incubator.net.meter.MeterStore;
import org.onosproject.incubator.net.meter.MeterStoreDelegate;
import org.onosproject.incubator.net.meter.MeterStoreResult;
import org.onosproject.net.meter.DefaultMeter;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterEvent;
import org.onosproject.net.meter.MeterFailReason;
import org.onosproject.net.meter.MeterId;
import org.onosproject.net.meter.MeterListener;
import org.onosproject.net.meter.MeterOperation;
import org.onosproject.net.meter.MeterProvider;
import org.onosproject.net.meter.MeterProviderRegistry;
import org.onosproject.net.meter.MeterProviderService;
import org.onosproject.net.meter.MeterService;
import org.onosproject.net.meter.MeterState;
import org.onosproject.net.meter.MeterStore;
import org.onosproject.net.meter.MeterStoreDelegate;
import org.onosproject.net.meter.MeterStoreResult;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
......
......@@ -23,16 +23,16 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
import org.onosproject.incubator.net.meter.DefaultMeter;
import org.onosproject.incubator.net.meter.Meter;
import org.onosproject.incubator.net.meter.MeterEvent;
import org.onosproject.incubator.net.meter.MeterFailReason;
import org.onosproject.incubator.net.meter.MeterId;
import org.onosproject.incubator.net.meter.MeterOperation;
import org.onosproject.incubator.net.meter.MeterState;
import org.onosproject.incubator.net.meter.MeterStore;
import org.onosproject.incubator.net.meter.MeterStoreDelegate;
import org.onosproject.incubator.net.meter.MeterStoreResult;
import org.onosproject.net.meter.DefaultMeter;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterEvent;
import org.onosproject.net.meter.MeterFailReason;
import org.onosproject.net.meter.MeterId;
import org.onosproject.net.meter.MeterOperation;
import org.onosproject.net.meter.MeterState;
import org.onosproject.net.meter.MeterStore;
import org.onosproject.net.meter.MeterStoreDelegate;
import org.onosproject.net.meter.MeterStoreResult;
import org.onosproject.mastership.MastershipService;
import org.onosproject.store.AbstractStore;
import org.onosproject.store.serializers.KryoNamespaces;
......
......@@ -16,8 +16,8 @@
package org.onosproject.incubator.store.meter.impl;
import org.onosproject.cluster.NodeId;
import org.onosproject.incubator.net.meter.Meter;
import org.onosproject.incubator.net.meter.MeterFailReason;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterFailReason;
import java.util.Optional;
......
......@@ -161,6 +161,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
if (treatment.writeMetadata() != null) {
instructions.add(buildMetadata(treatment.writeMetadata()));
}
if (treatment.metered() != null) {
instructions.add(buildMeter(treatment.metered()));
}
long cookie = flowRule().id().value();
......@@ -263,6 +266,11 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
return instruction;
}
private OFInstruction buildMeter(Instructions.MeterInstruction metered) {
return factory().instructions().meter(metered.meterId().id());
}
private OFAction buildL0Modification(Instruction i) {
L0ModificationInstruction l0m = (L0ModificationInstruction) i;
switch (l0m.subtype()) {
......
......@@ -15,9 +15,9 @@
*/
package org.onosproject.provider.of.meter.impl;
import org.onosproject.incubator.net.meter.Band;
import org.onosproject.incubator.net.meter.Meter;
import org.onosproject.incubator.net.meter.MeterId;
import org.onosproject.net.meter.Band;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterId;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFMeterFlags;
import org.projectfloodlight.openflow.protocol.OFMeterMod;
......
......@@ -28,17 +28,17 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.meter.Band;
import org.onosproject.incubator.net.meter.DefaultBand;
import org.onosproject.incubator.net.meter.DefaultMeter;
import org.onosproject.incubator.net.meter.Meter;
import org.onosproject.incubator.net.meter.MeterFailReason;
import org.onosproject.incubator.net.meter.MeterOperation;
import org.onosproject.incubator.net.meter.MeterOperations;
import org.onosproject.incubator.net.meter.MeterProvider;
import org.onosproject.incubator.net.meter.MeterProviderRegistry;
import org.onosproject.incubator.net.meter.MeterProviderService;
import org.onosproject.incubator.net.meter.MeterState;
import org.onosproject.net.meter.Band;
import org.onosproject.net.meter.DefaultBand;
import org.onosproject.net.meter.DefaultMeter;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterFailReason;
import org.onosproject.net.meter.MeterOperation;
import org.onosproject.net.meter.MeterOperations;
import org.onosproject.net.meter.MeterProvider;
import org.onosproject.net.meter.MeterProviderRegistry;
import org.onosproject.net.meter.MeterProviderService;
import org.onosproject.net.meter.MeterState;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
......