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/DefaultForwardingObjective.java | |
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/DefaultForwardingObjective.java')
-rw-r--r-- | framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultForwardingObjective.java | 241 |
1 files changed, 241 insertions, 0 deletions
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); + } + } +} |