diff options
author | Ashlee Young <ashlee@onosfw.com> | 2015-09-09 22:15:21 -0700 |
---|---|---|
committer | Ashlee Young <ashlee@onosfw.com> | 2015-09-09 22:15:21 -0700 |
commit | 13d05bc8458758ee39cb829098241e89616717ee (patch) | |
tree | 22a4d1ce65f15952f07a3df5af4b462b4697cb3a /framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective | |
parent | 6139282e1e93c2322076de4b91b1c85d0bc4a8b3 (diff) |
ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60
Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective')
14 files changed, 1653 insertions, 0 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java new file mode 100644 index 00000000..7b5924fb --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java @@ -0,0 +1,239 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableList; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.criteria.Criteria; +import org.onosproject.net.flow.criteria.Criterion; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Default implementation of a filtering objective. + */ +@Beta +public final class DefaultFilteringObjective implements FilteringObjective { + + + private final Type type; + private final boolean permanent; + private final int timeout; + private final ApplicationId appId; + private final int priority; + private final Criterion key; + private final List<Criterion> conditions; + private final int id; + private final Operation op; + private final Optional<ObjectiveContext> context; + + private DefaultFilteringObjective(Builder builder) { + this.key = builder.key; + this.type = builder.type; + this.permanent = builder.permanent; + this.timeout = builder.timeout; + this.appId = builder.appId; + this.priority = builder.priority; + this.conditions = builder.conditions; + this.op = builder.op; + this.context = Optional.ofNullable(builder.context); + + this.id = Objects.hash(type, key, conditions, permanent, + timeout, appId, priority); + } + + @Override + public Criterion key() { + return key; + } + + @Override + public Type type() { + return this.type; + } + + @Override + public Collection<Criterion> conditions() { + return conditions; + } + + @Override + public int id() { + return id; + } + + @Override + public int priority() { + return priority; + } + + @Override + public ApplicationId appId() { + return appId; + } + + @Override + public int timeout() { + return timeout; + } + + @Override + public boolean permanent() { + return permanent; + } + + @Override + public Operation op() { + return op; + } + + @Override + public Optional<ObjectiveContext> context() { + return context; + } + + /** + * Returns a new builder. + * + * @return new builder + */ + public static Builder builder() { + return new Builder(); + } + + + public static final class Builder implements FilteringObjective.Builder { + private final ImmutableList.Builder<Criterion> listBuilder + = ImmutableList.builder(); + + private Type type; + private boolean permanent = DEFAULT_PERMANENT; + private int timeout = DEFAULT_TIMEOUT; + private ApplicationId appId; + private int priority = DEFAULT_PRIORITY; + private Criterion key = Criteria.dummy(); + private List<Criterion> conditions; + private Operation op; + private ObjectiveContext context; + + @Override + public Builder withKey(Criterion key) { + this.key = key; + return this; + } + + @Override + public Builder addCondition(Criterion criterion) { + listBuilder.add(criterion); + return this; + } + + @Override + public Builder permit() { + this.type = Type.PERMIT; + return this; + } + + @Override + public Builder deny() { + this.type = Type.DENY; + return this; + } + + @Override + public Builder makeTemporary(int timeout) { + this.timeout = timeout; + permanent = false; + return this; + } + + @Override + public Builder makePermanent() { + permanent = true; + return this; + } + + @Override + public Builder fromApp(ApplicationId appId) { + this.appId = appId; + return this; + } + + @Override + public Builder withPriority(int priority) { + this.priority = priority; + return this; + } + + @Override + public FilteringObjective add() { + conditions = listBuilder.build(); + op = Operation.ADD; + checkNotNull(type, "Must have a type."); + checkArgument(!conditions.isEmpty(), "Must have at least one condition."); + checkNotNull(appId, "Must supply an application id"); + + return new DefaultFilteringObjective(this); + + } + + @Override + public FilteringObjective remove() { + conditions = listBuilder.build(); + checkNotNull(type, "Must have a type."); + checkArgument(!conditions.isEmpty(), "Must have at least one condition."); + checkNotNull(appId, "Must supply an application id"); + op = Operation.REMOVE; + + return new DefaultFilteringObjective(this); + + } + + @Override + public FilteringObjective add(ObjectiveContext context) { + conditions = listBuilder.build(); + checkNotNull(type, "Must have a type."); + checkArgument(!conditions.isEmpty(), "Must have at least one condition."); + checkNotNull(appId, "Must supply an application id"); + op = Operation.ADD; + this.context = context; + + return new DefaultFilteringObjective(this); + } + + @Override + public FilteringObjective remove(ObjectiveContext context) { + conditions = listBuilder.build(); + checkNotNull(type, "Must have a type."); + checkArgument(!conditions.isEmpty(), "Must have at least one condition."); + checkNotNull(appId, "Must supply an application id"); + op = Operation.REMOVE; + this.context = context; + + return new DefaultFilteringObjective(this); + } + + + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultForwardingObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultForwardingObjective.java new file mode 100644 index 00000000..0abf5abe --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultForwardingObjective.java @@ -0,0 +1,241 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; + +import java.util.Objects; +import java.util.Optional; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Default implementation of a forwarding objective. + */ +@Beta +public final class DefaultForwardingObjective implements ForwardingObjective { + + private final TrafficSelector selector; + private final Flag flag; + private final boolean permanent; + private final int timeout; + private final ApplicationId appId; + private final int priority; + private final Integer nextId; + private final TrafficTreatment treatment; + private final Operation op; + private final Optional<ObjectiveContext> context; + + private final int id; + + private DefaultForwardingObjective(Builder builder) { + this.selector = builder.selector; + this.flag = builder.flag; + this.permanent = builder.permanent; + this.timeout = builder.timeout; + this.appId = builder.appId; + this.priority = builder.priority; + this.nextId = builder.nextId; + this.treatment = builder.treatment; + this.op = builder.op; + this.context = Optional.ofNullable(builder.context); + + this.id = Objects.hash(selector, flag, permanent, + timeout, appId, priority, nextId, + treatment, op); + } + + + @Override + public TrafficSelector selector() { + return selector; + } + + @Override + public Integer nextId() { + return nextId; + } + + @Override + public TrafficTreatment treatment() { + return treatment; + } + + + @Override + public Flag flag() { + return flag; + } + + @Override + public int id() { + return id; + } + + @Override + public int priority() { + return priority; + } + + @Override + public ApplicationId appId() { + return appId; + } + + @Override + public int timeout() { + return timeout; + } + + @Override + public boolean permanent() { + return permanent; + } + + @Override + public Operation op() { + return op; + } + + @Override + public Optional<ObjectiveContext> context() { + return context; + } + + /** + * Returns a new builder. + * + * @return new builder + */ + public static Builder builder() { + return new Builder(); + } + + public static final class Builder implements ForwardingObjective.Builder { + + private TrafficSelector selector; + private Flag flag; + private boolean permanent = DEFAULT_PERMANENT; + private int timeout = DEFAULT_TIMEOUT; + private int priority = DEFAULT_PRIORITY; + private ApplicationId appId; + private Integer nextId; + private TrafficTreatment treatment; + private Operation op; + private ObjectiveContext context; + + @Override + public Builder withSelector(TrafficSelector selector) { + this.selector = selector; + return this; + } + + @Override + public Builder nextStep(int nextId) { + this.nextId = nextId; + return this; + } + + @Override + public Builder withTreatment(TrafficTreatment treatment) { + this.treatment = treatment; + return this; + } + + @Override + public Builder withFlag(Flag flag) { + this.flag = flag; + return this; + } + + @Override + public Builder makeTemporary(int timeout) { + this.timeout = timeout; + this.permanent = false; + return this; + } + + @Override + public Builder makePermanent() { + this.permanent = true; + return this; + } + + @Override + public Builder fromApp(ApplicationId appId) { + this.appId = appId; + return this; + } + + @Override + public Builder withPriority(int priority) { + this.priority = priority; + return this; + } + + @Override + public ForwardingObjective add() { + checkNotNull(selector, "Must have a selector"); + checkNotNull(flag, "A flag must be set"); + checkArgument(nextId != null || treatment != null, "Must supply at " + + "least a treatment and/or a nextId"); + checkNotNull(appId, "Must supply an application id"); + op = Operation.ADD; + return new DefaultForwardingObjective(this); + } + + @Override + public ForwardingObjective remove() { + checkNotNull(selector, "Must have a selector"); + checkNotNull(flag, "A flag must be set"); + checkArgument(nextId != null || treatment != null, "Must supply at " + + "least a treatment and/or a nextId"); + checkNotNull(appId, "Must supply an application id"); + op = Operation.REMOVE; + return new DefaultForwardingObjective(this); + } + + @Override + public ForwardingObjective add(ObjectiveContext context) { + checkNotNull(selector, "Must have a selector"); + checkNotNull(flag, "A flag must be set"); + checkArgument(nextId != null || treatment != null, "Must supply at " + + "least a treatment and/or a nextId"); + checkNotNull(appId, "Must supply an application id"); + op = Operation.ADD; + this.context = context; + + return new DefaultForwardingObjective(this); + } + + @Override + public ForwardingObjective remove(ObjectiveContext context) { + checkNotNull(selector, "Must have a selector"); + checkNotNull(flag, "A flag must be set"); + checkArgument(nextId != null || treatment != null, "Must supply at " + + "least a treatment and/or a nextId"); + checkNotNull(appId, "Must supply an application id"); + op = Operation.REMOVE; + this.context = context; + + return new DefaultForwardingObjective(this); + } + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java new file mode 100644 index 00000000..20e89295 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java @@ -0,0 +1,222 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableList; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.TrafficTreatment; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Default implementation of a next objective. + */ +@Beta +public final class DefaultNextObjective implements NextObjective { + + private final List<TrafficTreatment> treatments; + private final ApplicationId appId; + private final Type type; + private final Integer id; + private final Operation op; + private final Optional<ObjectiveContext> context; + + private DefaultNextObjective(Builder builder) { + this.treatments = builder.treatments; + this.appId = builder.appId; + this.type = builder.type; + this.id = builder.id; + this.op = builder.op; + this.context = Optional.ofNullable(builder.context); + } + + @Override + public Collection<TrafficTreatment> next() { + return treatments; + } + + @Override + public Type type() { + return type; + } + + @Override + public int id() { + return id; + } + + @Override + public int priority() { + return 0; + } + + @Override + public ApplicationId appId() { + return appId; + } + + @Override + public int timeout() { + return 0; + } + + @Override + public boolean permanent() { + return false; + } + + @Override + public Operation op() { + return op; + } + + @Override + public Optional<ObjectiveContext> context() { + return context; + } + + /** + * Returns a new builder. + * + * @return new builder + */ + public static Builder builder() { + return new Builder(); + } + + public static final class Builder implements NextObjective.Builder { + + private ApplicationId appId; + private Type type; + private Integer id; + private List<TrafficTreatment> treatments; + private Operation op; + private ObjectiveContext context; + + private final ImmutableList.Builder<TrafficTreatment> listBuilder + = ImmutableList.builder(); + + @Override + public Builder withId(int nextId) { + this.id = nextId; + return this; + } + + @Override + public Builder withType(Type type) { + this.type = type; + return this; + } + + @Override + public Builder addTreatment(TrafficTreatment treatment) { + listBuilder.add(treatment); + return this; + } + + /** + * Noop. This method has no effect. + * + * @param timeout a timeout + * @return a next objective builder + */ + @Override + public Builder makeTemporary(int timeout) { + return this; + } + + /** + * Noop. This method has no effect. + * + * @return a next objective builder + */ + @Override + public Builder makePermanent() { + return this; + } + + @Override + public Builder fromApp(ApplicationId appId) { + this.appId = appId; + return this; + } + + /** + * Noop. This method has no effect. + * + * @param priority an integer + * @return a next objective builder + */ + @Override + public Builder withPriority(int priority) { + return this; + } + + @Override + public NextObjective add() { + treatments = listBuilder.build(); + op = Operation.ADD; + checkNotNull(appId, "Must supply an application id"); + checkNotNull(id, "id cannot be null"); + checkNotNull(type, "The type cannot be null"); + checkArgument(!treatments.isEmpty(), "Must have at least one treatment"); + + return new DefaultNextObjective(this); + } + + @Override + public NextObjective remove() { + treatments = listBuilder.build(); + op = Operation.REMOVE; + checkNotNull(appId, "Must supply an application id"); + checkNotNull(id, "id cannot be null"); + checkNotNull(type, "The type cannot be null"); + + return new DefaultNextObjective(this); + } + + @Override + public NextObjective add(ObjectiveContext context) { + treatments = listBuilder.build(); + op = Operation.ADD; + this.context = context; + checkNotNull(appId, "Must supply an application id"); + checkNotNull(id, "id cannot be null"); + checkNotNull(type, "The type cannot be null"); + checkArgument(!treatments.isEmpty(), "Must have at least one treatment"); + + return new DefaultNextObjective(this); + } + + @Override + public NextObjective remove(ObjectiveContext context) { + treatments = listBuilder.build(); + op = Operation.REMOVE; + this.context = context; + checkNotNull(appId, "Must supply an application id"); + checkNotNull(id, "id cannot be null"); + checkNotNull(type, "The type cannot be null"); + + return new DefaultNextObjective(this); + } + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java new file mode 100644 index 00000000..58304571 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java @@ -0,0 +1,158 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.criteria.Criterion; + +import java.util.Collection; + +/** + * Represents a filtering flow objective. Each filtering flow objective + * is made up of a key (criterion) to a set of criteria. Using this information + * a pipeline aware driver will decide how this objective should be mapped + * to the specific device pipeline. For example, consider the following + * filtering objective: + * + * portX -> {MAC1, IP1, MAC2} + * + * The driver could decide to pass L3 packet to the L3 table and L2 packets to + * the L2 table for packets arriving on portX. + * + * Filtering objectives do not only represent what should be permitted into the + * pipeline but can also be used to deny or drop unwanted packets by specifying + * the appropriate type of filtering objective. It is also important to note + * that submitting a filtering objective does not necessarily result in rules + * programmed at the switch, the driver is free to decide when these rules are + * programmed. For example, a filtering rule may only be programmed once a + * corresponding forwarding objective has been received. + */ +@Beta +public interface FilteringObjective extends Objective { + + enum Type { + /** + * Enables the filtering condition. + */ + PERMIT, + + /** + * Disables the filtering condition. + */ + DENY + } + + /** + * Obtain the key for this filter. + * + * @return a criterion + */ + Criterion key(); + + /** + * Obtain this filtering type. + * + * @return the type + */ + Type type(); + + /** + * The set of conditions the filter must provision at the device. + * + * @return a collection of criteria + */ + Collection<Criterion> conditions(); + + /** + * Builder of Filtering objective entities. + */ + interface Builder extends Objective.Builder { + + /** + * Specify the key for the filter. + * + * @param key a criterion + * @return a filter objective builder + */ + Builder withKey(Criterion key); + + /** + * Add a filtering condition. + * + * @param criterion new criterion + * @return a filtering builder + */ + Builder addCondition(Criterion criterion); + + /** + * Permit this filtering condition set. + * + * @return a filtering builder + */ + Builder permit(); + + /** + * Deny this filtering condition set. + * + * @return a filtering builder + */ + Builder deny(); + + /** + * Assigns an application id. + * + * @param appId an application id + * @return a filtering builder + */ + Builder fromApp(ApplicationId appId); + + /** + * Builds the filtering objective that will be added. + * + * @return a filtering objective + */ + FilteringObjective add(); + + /** + * Builds the filtering objective that will be removed. + * + * @return a filtering objective. + */ + FilteringObjective remove(); + + /** + * Builds the filtering objective that will be added. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a filtering objective + */ + FilteringObjective add(ObjectiveContext context); + + /** + * Builds the filtering objective that will be removed. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a filtering objective + */ + FilteringObjective remove(ObjectiveContext context); + + + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java new file mode 100644 index 00000000..d3254151 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveService.java @@ -0,0 +1,65 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.net.DeviceId; + +/** + * Service for programming data plane flow rules in manner independent of + * specific device table pipeline configuration. + */ +@Beta +public interface FlowObjectiveService { + + /** + * Installs the filtering rules onto the specified device. + * + * @param deviceId device identifier + * @param filteringObjective the filtering objective + */ + void filter(DeviceId deviceId, FilteringObjective filteringObjective); + + /** + * Installs the forwarding rules onto the specified device. + * + * @param deviceId device identifier + * @param forwardingObjective the forwarding objective + */ + void forward(DeviceId deviceId, ForwardingObjective forwardingObjective); + + /** + * Installs the next hop elements into the specified device. + * + * @param deviceId device identifier + * @param nextObjective a next objective + */ + void next(DeviceId deviceId, NextObjective nextObjective); + + /** + * Obtains a globally unique next objective. + * + * @return an integer + */ + int allocateNextId(); + + /** + * Installs the filtering rules onto the specified device. + * + * @param policy policy expression + */ + void initPolicy(String policy); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java new file mode 100644 index 00000000..ecf5d733 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStore.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.net.behaviour.NextGroup; +import org.onosproject.store.Store; + +/** + * The flow objective store. + */ +@Beta +public interface FlowObjectiveStore + extends Store<ObjectiveEvent, FlowObjectiveStoreDelegate> { + + /** + * Adds a NextGroup to the store. + * + * @param nextId an integer + * @param group a next group opaque object + */ + void putNextGroup(Integer nextId, NextGroup group); + + /** + * Fetch a next group from the store. + * @param nextId an integer + * @return a next group + */ + NextGroup getNextGroup(Integer nextId); + + /** + * Allocates a next objective id. This id is globally unique + * + * @return an integer + */ + int allocateNextId(); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStoreDelegate.java new file mode 100644 index 00000000..2189af1b --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FlowObjectiveStoreDelegate.java @@ -0,0 +1,26 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.store.StoreDelegate; + +/** + * Flow Objective store delegate abstraction. + */ +@Beta +public interface FlowObjectiveStoreDelegate extends StoreDelegate<ObjectiveEvent> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ForwardingObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ForwardingObjective.java new file mode 100644 index 00000000..9857a710 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ForwardingObjective.java @@ -0,0 +1,158 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; + +/** + * Represents a description of which types of traffic need to + * be forwarded through the device. A forwarding objective may + * result in multiple rules at the device. There are two main types + * of forwarding objectives: + * + * - Versatile + * - Specific + * + * A versatile forwarding objective represents a composite rule that matches + * two or more header fields. The use of versatile usually indicates that this + * rule should be inserted in its entirety into the ACL table. Although, + * drivers for some devices are free to implement this differently. + * + * A specific forwarding objective represents a specific rule matching one or + * more header fields. The installation of this rule may result in several rules + * at the device. For example, one per table type. + */ +@Beta +public interface ForwardingObjective extends Objective { + + /** + * Represents whether this objective is monolithic or + * may be broken down into parts. + */ + enum Flag { + /** + * A decomposable objective. + */ + SPECIFIC, + + /** + * A monolithic objective. + */ + VERSATILE + } + + /** + * Obtain the selector for this objective. + * + * @return a traffic selector + */ + TrafficSelector selector(); + + /** + * Obtain the traffic treatment for this objective. Mutually exclusive with + * 'treatment'. + * + * @return an integer + */ + Integer nextId(); + + /** + * A traffic treatment for this forwarding objective. Mutually exclusive + * with a nextId. + * + * @return a traffic treatment + */ + TrafficTreatment treatment(); + + /** + * Obtain the type of this objective. + * + * @return a flag type + */ + Flag flag(); + + /** + * A forwarding objective builder. + */ + interface Builder extends Objective.Builder { + + /** + * Assigns a selector to the forwarding objective. + * + * @param selector a traffic selector + * @return a forwarding objective builder + */ + Builder withSelector(TrafficSelector selector); + + /** + * Assigns a next step to the forwarding objective. + * + * @param nextId a next objective id. + * @return a forwarding objective builder + */ + Builder nextStep(int nextId); + + /** + * Assigns the treatment for this forwarding objective. + * + * @param treatment a traffic treatment + * @return a forwarding objective + */ + Builder withTreatment(TrafficTreatment treatment); + + /** + * Assigns the flag to the forwarding objective. + * + * @param flag a flag + * @return a forwarding objective builder + */ + Builder withFlag(Flag flag); + + /** + * Builds the forwarding objective that will be added. + * + * @return a forwarding objective + */ + ForwardingObjective add(); + + /** + * Builds the forwarding objective that will be removed. + * + * @return a forwarding objective. + */ + ForwardingObjective remove(); + + /** + * Builds the forwarding objective that will be added. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a forwarding objective + */ + ForwardingObjective add(ObjectiveContext context); + + /** + * Builds the forwarding objective that will be removed. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a forwarding objective + */ + ForwardingObjective remove(ObjectiveContext context); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java new file mode 100644 index 00000000..1350d7a1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java @@ -0,0 +1,167 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.TrafficTreatment; + +import java.util.Collection; + +/** + * Represents a nexthop which will be translated by a driver + * into the appropriate group or actions needed to implement + * the egress function. + * + * A next objective is made up of a collection of traffic treatments + * associated with a type. These types are: + * + * - Hashed + * - Broadcast + * - Failover + * - Simple + * + * These types will indicate to the driver what the intended behaviour is. + * For example, a broadcast next objective with a collection of output + * treatments will indicate to a driver that all output actions are expected + * to be executed simultaneously. The driver is then free to implement this + * as a group or a simple action list. + */ +@Beta +public interface NextObjective extends Objective { + + /** + * Represents the type of next phase to build. + */ + enum Type { + /** + * A hashed packet processing. + */ + HASHED, + + /** + * Broadcast packet process. + */ + BROADCAST, + + /** + * Failover handling. + */ + FAILOVER, + + /** + * Simple processing. Could be a group or a treatment. + */ + SIMPLE + } + + /** + * The collection of treatments that need to be applied to a set of traffic. + * + * @return a collection of traffic treatments + */ + Collection<TrafficTreatment> next(); + + /** + * The type of operation that will be applied to the traffic using the collection + * of treatments. + * + * @return a type + */ + Type type(); + + /** + * A next step builder. + */ + interface Builder extends Objective.Builder { + + /** + * Specifies the id for this next objective. + * + * @param nextId an integer + * @return a next objective builder + */ + Builder withId(int nextId); + + /** + * Sets the type of next step. + * + * @param type a type + * @return a next step builder + */ + Builder withType(Type type); + + /** + * Adds a treatment to this next step. + * + * @param treatment a traffic treatment + * @return a next step builder + */ + Builder addTreatment(TrafficTreatment treatment); + + /** + * Specifies the application which applied the filter. + * + * @param appId an application id + * @return an objective builder + */ + @Override + Builder fromApp(ApplicationId appId); + + /** + * Sets the priority for this objective. + * + * @param priority an integer + * @return an objective builder + */ + @Override + Builder withPriority(int priority); + + /** + * Builds the next objective that will be added. + * + * @return a next objective + */ + NextObjective add(); + + /** + * Builds the next objective that will be removed. + * + * @return a next objective. + */ + NextObjective remove(); + + /** + * Builds the next objective that will be added. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a next objective + */ + NextObjective add(ObjectiveContext context); + + /** + * Builds the next objective that will be removed. + * The context will be used to notify the calling application. + * + * @param context an objective context + * @return a next objective + */ + NextObjective remove(ObjectiveContext context); + + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/Objective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/Objective.java new file mode 100644 index 00000000..090c298c --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/Objective.java @@ -0,0 +1,134 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.core.ApplicationId; + +import java.util.Optional; + +/** + * Base representation of an flow description. + */ +@Beta +public interface Objective { + + static final boolean DEFAULT_PERMANENT = true; + static final int DEFAULT_TIMEOUT = 0; + static final int DEFAULT_PRIORITY = 32768; + + /** + * Type of operation. + */ + enum Operation { + /** + * Adds the objective. + */ + ADD, + + /** + * Removes the objective. + */ + REMOVE + } + + /** + * An identifier for this objective. + * + * @return an integer + */ + int id(); + + /** + * The priority for this objective. + * + * @return an integer + */ + int priority(); + + /** + * The application which applied this objective. + * + * @return an application id + */ + ApplicationId appId(); + + /** + * The timeout for this objective. + * + * @return an integer + */ + int timeout(); + + /** + * Whether this objective is permanent. + * + * @return a boolean + */ + boolean permanent(); + + /** + * The type of operation for this objective. + * + * @return an operation + */ + Operation op(); + + /** + * Obtains an optional context. + * + * @return optional; which will be empty if there is no context. + * Otherwise it will return the context. + */ + Optional<ObjectiveContext> context(); + + /** + * An objective builder. + */ + interface Builder { + /** + * Makes the filtering objective temporary. + * + * @param timeout a timeout + * @return an objective builder + */ + Builder makeTemporary(int timeout); + + /** + * Makes the filtering objective permanent. + * + * @return an objective builder + */ + Builder makePermanent(); + + /** + * Specifies the application which applied the filter. + * + * @param appId an application id + * @return an objective builder + */ + Builder fromApp(ApplicationId appId); + + /** + * Sets the priority for this objective. + * + * @param priority an integer + * @return an objective builder + */ + Builder withPriority(int priority); + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java new file mode 100644 index 00000000..f3d23e4a --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; + +/** + * The context of a objective that will become the subject of + * the notification. + * <p> + * Implementations of this class must be serializable. + * </p> + */ +@Beta +public interface ObjectiveContext { + + /** + * Invoked on successful execution of the flow objective. + * + * @param objective objective to execute + */ + default void onSuccess(Objective objective) { + } + + /** + * Invoked when error is encountered while executing the flow objective. + * + * @param objective objective to execute + * @param error error encountered + */ + default void onError(Objective objective, ObjectiveError error) { + } + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveError.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveError.java new file mode 100644 index 00000000..fd159d7e --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveError.java @@ -0,0 +1,60 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; + +/** + * Represents the set of errors possible when processing an objective. + */ +@Beta +public enum ObjectiveError { + + /** + * The driver processing this objective does not know how to process it. + */ + UNSUPPORTED, + + /** + * The flow installation for this objective failed. + */ + FLOWINSTALLATIONFAILED, + + /** + * THe group installation for this objective failed. + */ + GROUPINSTALLATIONFAILED, + + /** + * The group was reported as installed but is missing. + */ + GROUPMISSING, + + /** + * The device was not available to install objectives to. + */ + DEVICEMISSING, + + /** + * Incorrect Objective parameters passed in by the caller. + */ + BADPARAMS, + + /** + * An unknown error occurred. + */ + UNKNOWN +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveEvent.java new file mode 100644 index 00000000..c6937e31 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveEvent.java @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.flowobjective; + +import com.google.common.annotations.Beta; +import org.onosproject.event.AbstractEvent; + +/** + * Describes a objective event. + */ +@Beta +public class ObjectiveEvent extends AbstractEvent<ObjectiveEvent.Type, Integer> { + + /** + * Type of objective events. + */ + public enum Type { + /** + * Signifies that the objective has been added to the store. + */ + ADD, + + /** + * Signifies that the objective has been removed. + */ + REMOVE + } + + /** + * Creates an event of the given type for the specified objective id. + * + * @param type the type of the event + * @param objective the objective id the event is about + */ + public ObjectiveEvent(Type type, Integer objective) { + super(type, objective); + } + + /** + * Creates an event of the given type for the specified objective id at the given + * time. + * + * @param type the type of the event + * @param objective the objective id the event is about + * @param time the time of the event + */ + public ObjectiveEvent(Type type, Integer objective, long time) { + super(type, objective, time); + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java new file mode 100644 index 00000000..105f7b59 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Abstractions for objective-based flow programming of data plane without + * requiring device pipeline structure awareness. This subsystem is + * experimental and its interfaces will change in the upcoming release. + */ +package org.onosproject.net.flowobjective;
\ No newline at end of file |