diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-03 14:08:10 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-03 14:08:10 -0800 |
commit | 643ee33289bd2cb9e6afbfb09b4ed72d467ba1c2 (patch) | |
tree | c2c376a44a359544fe3d4c45eb0cc0e2ec4a7080 /framework/src/onos/core/api/src/main/java/org | |
parent | 46eeb79b54345bdafb6055b8ee4bad4ce8b01274 (diff) |
This updates ONOS src tree to commit id
03fa5e571cabbd001ddb1598847e1150b11c7333
Change-Id: I13b554026d6f902933e35887d29bd5fdb669c0bd
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org')
44 files changed, 1460 insertions, 148 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterAdminService.java index 5f2b5fff..47944874 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterAdminService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterAdminService.java @@ -30,9 +30,8 @@ public interface ClusterAdminService { * instance. * * @param nodes set of nodes that form the cluster - * @param ipPrefix IP address prefix, e.g. 10.0.1.* */ - void formCluster(Set<ControllerNode> nodes, String ipPrefix); + void formCluster(Set<ControllerNode> nodes); /** * Adds a new controller node to the cluster. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterDefinitionService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterDefinitionService.java deleted file mode 100644 index 1ee78b15..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterDefinitionService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.cluster; - -import java.util.Set; - -/** - * Service for obtaining the static definition of a controller cluster. - */ -public interface ClusterDefinitionService { - - /** - * Returns the local controller node. - * @return local controller node - */ - ControllerNode localNode(); - - /** - * Returns the set of seed nodes that should be used for discovering other members - * of the cluster. - * @return set of seed controller nodes - */ - Set<ControllerNode> seedNodes(); - - /** - * Forms cluster configuration based on the specified set of node - * information. Assumes subsequent restart for the new configuration to - * take hold. - * - * @param nodes set of nodes that form the cluster - * @param ipPrefix IP address prefix, e.g. 10.0.1.* - */ - void formCluster(Set<ControllerNode> nodes, String ipPrefix); -}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java new file mode 100644 index 00000000..e1eacfee --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java @@ -0,0 +1,185 @@ +/* + * 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.cluster; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Set; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Verify.verifyNotNull; +import static com.google.common.base.Verify.verify; + +import com.google.common.base.MoreObjects; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * Cluster metadata. + * <p> + * Metadata specifies the attributes that define a ONOS cluster and comprises the collection + * of {@link org.onosproject.cluster.ControllerNode nodes} and the collection of data + * {@link org.onosproject.cluster.Partition partitions}. + */ +public final class ClusterMetadata { + + private String name; + private Set<ControllerNode> nodes; + private Set<Partition> partitions; + + /** + * Returns a new cluster metadata builder. + * @return The cluster metadata builder. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Returns the name of the cluster. + * + * @return cluster name + */ + public String getName() { + return this.name; + } + + /** + * Returns the collection of {@link org.onosproject.cluster.ControllerNode nodes} that make up the cluster. + * @return cluster nodes + */ + public Collection<ControllerNode> getNodes() { + return this.nodes; + } + + /** + * Returns the collection of data {@link org.onosproject.cluster.Partition partitions} that make up the cluster. + * @return collection of partitions. + */ + public Collection<Partition> getPartitions() { + return this.partitions; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(ClusterMetadata.class) + .add("name", name) + .add("nodes", nodes) + .add("partitions", partitions) + .toString(); + } + + @Override + public int hashCode() { + return Arrays.deepHashCode(new Object[] {name, nodes, partitions}); + } + + /* + * Provide a deep quality check of the meta data (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object object) { + + if (!ClusterMetadata.class.isInstance(object)) { + return false; + } + ClusterMetadata that = (ClusterMetadata) object; + + if (!this.name.equals(that.name) || this.nodes.size() != that.nodes.size() + || this.partitions.size() != that.partitions.size()) { + return false; + } + + return Sets.symmetricDifference(this.nodes, that.nodes).isEmpty() + && Sets.symmetricDifference(this.partitions, that.partitions).isEmpty(); + } + + /** + * Builder for a {@link ClusterMetadata} instance. + */ + public static class Builder { + + private final ClusterMetadata metadata; + + public Builder() { + metadata = new ClusterMetadata(); + } + + /** + * Sets the cluster name, returning the cluster metadata builder for method chaining. + * @param name cluster name + * @return this cluster metadata builder + */ + public Builder withName(String name) { + metadata.name = checkNotNull(name); + return this; + } + + /** + * Sets the collection of cluster nodes, returning the cluster metadata builder for method chaining. + * @param controllerNodes collection of cluster nodes + * @return this cluster metadata builder + */ + public Builder withControllerNodes(Collection<ControllerNode> controllerNodes) { + metadata.nodes = ImmutableSet.copyOf(checkNotNull(controllerNodes)); + return this; + } + + /** + * Sets the collection of data partitions, returning the cluster metadata builder for method chaining. + * @param partitions collection of partitions + * @return this cluster metadata builder + */ + public Builder withPartitions(Collection<Partition> partitions) { + metadata.partitions = ImmutableSet.copyOf(checkNotNull(partitions)); + return this; + } + + /** + * Builds the cluster metadata. + * @return cluster metadata + * @throws com.google.common.base.VerifyException VerifyException if the metadata is misconfigured + */ + public ClusterMetadata build() { + verifyMetadata(); + return metadata; + } + + /** + * Validates the constructed metadata for semantic correctness. + * @throws VerifyException if the metadata is misconfigured. + */ + private void verifyMetadata() { + verifyNotNull(metadata.getName(), "Cluster name must be specified"); + verifyNotNull(metadata.getNodes(), "Cluster nodes must be specified"); + verifyNotNull(metadata.getPartitions(), "Cluster partitions must be specified"); + verify(!metadata.getNodes().isEmpty(), "Cluster nodes must not be empty"); + verify(!metadata.getPartitions().isEmpty(), "Cluster nodes must not be empty"); + + // verify that partitions are constituted from valid cluster nodes. + boolean validPartitions = Collections2.transform(metadata.getNodes(), ControllerNode::id) + .containsAll(metadata.getPartitions() + .stream() + .flatMap(r -> r.getMembers().stream()) + .collect(Collectors.toSet())); + verify(validPartitions, "Partition locations must be valid cluster nodes"); + } + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEvent.java new file mode 100644 index 00000000..a0f461c4 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEvent.java @@ -0,0 +1,56 @@ +/* + * 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.cluster; + +import org.onosproject.event.AbstractEvent; + +/** + * Describes a cluster metadata event. + */ +public class ClusterMetadataEvent extends AbstractEvent<ClusterMetadataEvent.Type, ClusterMetadata> { + + /** + * Type of cluster metadata events. + */ + public enum Type { + /** + * Signifies that the cluster metadata has changed. + */ + METADATA_CHANGED, + } + + /** + * Creates an event of a given type and for the specified metadata and the + * current time. + * + * @param type cluster metadata event type + * @param metadata cluster metadata subject + */ + public ClusterMetadataEvent(Type type, ClusterMetadata metadata) { + super(type, metadata); + } + + /** + * Creates an event of a given type and for the specified metadata and time. + * + * @param type cluster metadata event type + * @param metadata cluster metadata subject + * @param time occurrence time + */ + public ClusterMetadataEvent(Type type, ClusterMetadata metadata, long time) { + super(type, metadata, time); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEventListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEventListener.java new file mode 100644 index 00000000..fdfaeed0 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataEventListener.java @@ -0,0 +1,24 @@ +/* + * 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.cluster; + +import org.onosproject.event.EventListener; + +/** + * Entity capable of receiving cluster metadata related events. + */ +public interface ClusterMetadataEventListener extends EventListener<ClusterMetadataEvent> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java new file mode 100644 index 00000000..25a6df63 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java @@ -0,0 +1,40 @@ +/* + * 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.cluster; + +/** + * Service for obtaining metadata information about the cluster. + */ +public interface ClusterMetadataService { + + /** + * Returns the current cluster metadata. + * @return cluster metadata + */ + ClusterMetadata getClusterMetadata(); + + /** + * Updates the cluster metadata. + * @param metadata new metadata + */ + void setClusterMetadata(ClusterMetadata metadata); + + /** + * Returns the local controller node representing this instance. + * @return local controller node + */ + ControllerNode getLocalNode(); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java new file mode 100644 index 00000000..7e83b5b5 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java @@ -0,0 +1,77 @@ +/* + * 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.cluster; + +import java.util.Collection; + +import org.onosproject.store.Store; +import org.onosproject.store.service.Versioned; + +/** + * Manages persistence of cluster metadata; not intended for direct use. + */ +public interface ClusterMetadataStore extends Store<ClusterMetadataEvent, ClusterMetadataStoreDelegate> { + + /** + * Returns the cluster metadata. + * <p> + * The returned metadata is versioned to aid determining if a metadata instance is more recent than another. + * @return cluster metadata + */ + Versioned<ClusterMetadata> getClusterMetadata(); + + /** + * Updates the cluster metadata. + * @param metadata new metadata value + */ + void setClusterMetadata(ClusterMetadata metadata); + + // TODO: The below methods should move to a separate store interface that is responsible for + // tracking cluster partition operational state. + + /** + * Sets a controller node as an active member of a partition. + * <p> + * Active members are those replicas that are up to speed with the rest of the system and are + * usually capable of participating in the replica state management activities in accordance with + * the data consistency and replication protocol in use. + * @param partitionId partition identifier + * @param nodeId id of controller node + */ + void setActiveReplica(String partitionId, NodeId nodeId); + + /** + * Removes a controller node as an active member for a partition. + * <p> + * Active members are those replicas that are up to speed with the rest of the system and are + * usually capable of participating in the replica state management activities in accordance with + * the data consistency and replication protocol in use. + * @param partitionId partition identifier + * @param nodeId id of controller node + */ + void unsetActiveReplica(String partitionId, NodeId nodeId); + + /** + * Returns the collection of controller nodes that are the active replicas for a partition. + * <p> + * Active members are those replicas that are up to speed with the rest of the system and are + * usually capable of participating in the replica state management activities in accordance with + * the data consistency and replication protocol in use. + * @param partitionId partition identifier + * @return identifiers of controller nodes that are the active replicas + */ + Collection<NodeId> getActiveReplicas(String partitionId); +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStoreDelegate.java new file mode 100644 index 00000000..b56b7a24 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStoreDelegate.java @@ -0,0 +1,24 @@ +/* + * 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.cluster; + +import org.onosproject.store.StoreDelegate; + +/** + * Cluster metadata store delegate abstraction. + */ +public interface ClusterMetadataStoreDelegate extends StoreDelegate<ClusterMetadataEvent> { +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java index 68b490f2..6cfb42c7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java @@ -20,7 +20,7 @@ import java.util.Objects; /** * Controller cluster identity. */ -public class NodeId { +public class NodeId implements Comparable<NodeId> { private final String id; @@ -55,4 +55,9 @@ public class NodeId { return id; } + @Override + public int compareTo(NodeId that) { + return this.id.compareTo(that.id); + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/Partition.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/Partition.java new file mode 100644 index 00000000..1eca4aeb --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/Partition.java @@ -0,0 +1,91 @@ +/* + * 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.cluster; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Set; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * A data partition. + * <p> + * Partition represents a slice of the data space and is made up of a collection + * of {@link org.onosproject.cluster.ControllerNode nodes} + * that all maintain copies of this data. + */ +public class Partition { + + private final String name; + private final Set<NodeId> members; + + private Partition() { + name = null; + members = null; + } + + public Partition(String name, Collection<NodeId> members) { + this.name = checkNotNull(name); + this.members = ImmutableSet.copyOf(checkNotNull(members)); + } + + /** + * Returns the partition name. + * <p> + * Each partition is identified by a unique name. + * @return partition name + */ + public String getName() { + return this.name; + } + + /** + * Returns the collection of controller node identifiers that make up this partition. + * @return collection of controller node identifiers + */ + public Collection<NodeId> getMembers() { + return this.members; + } + + @Override + public int hashCode() { + return Arrays.deepHashCode(new Object[] {name, members}); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (other == null || !Partition.class.isInstance(other)) { + return false; + } + + Partition that = (Partition) other; + + if (!this.name.equals(that.name) || (this.members == null && that.members != null) + || (this.members != null && that.members == null) || this.members.size() != that.members.size()) { + return false; + } + + return Sets.symmetricDifference(this.members, that.members).isEmpty(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java index 7f157e95..e3d6993c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java @@ -36,6 +36,17 @@ public interface BridgeConfig extends HandlerBehaviour { void addBridge(BridgeName bridgeName); /** + * Adds a bridge with given bridge name and dpid, and sets the controller + * of the bridge with given controllers. + * + * @param bridgeName bridge name + * @param dpid dpid + * @param controllers list of controller + * @return true if succeeds, fail otherwise + */ + boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers); + + /** * Remove a bridge. * * @param bridgeName bridge name diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionResolver.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionResolver.java new file mode 100644 index 00000000..54cbc7ac --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionResolver.java @@ -0,0 +1,40 @@ +/* + * 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.behaviour; + +import com.google.common.annotations.Beta; +import org.onosproject.net.driver.HandlerBehaviour; +import org.onosproject.net.flow.instructions.ExtensionInstruction; +import org.onosproject.net.flow.instructions.ExtensionType; + +/** + * Provides access to the extension implemented by this driver. + */ +@Beta +public interface ExtensionResolver extends HandlerBehaviour { + + /** + * Gets an extension instruction instance of the specified type, if supported + * by the driver. + * + * @param type type of extension to get + * @return extension instruction + * @throws UnsupportedOperationException if the extension type is not + * supported by this driver + */ + ExtensionInstruction getExtensionInstruction(ExtensionType type); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java index 7e79a57e..e3b4c198 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/TunnelConfig.java @@ -32,6 +32,15 @@ public interface TunnelConfig extends HandlerBehaviour { void createTunnel(TunnelDescription tunnel); /** + * Creates a tunnel interface on a given bridge of this device. + * + * @param bridgeName bridge name + * @param tunnel tunnel description + * @return true if succeeds, false otherwise + */ + boolean createTunnelInterface(BridgeName bridgeName, TunnelDescription tunnel); + + /** * Removes a tunnel on this device. * * @param tunnel tunnel descriptor diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java index 4416456c..453a7648 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java @@ -15,8 +15,14 @@ */ package org.onosproject.net.flow; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableSet; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; + import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; @@ -27,13 +33,8 @@ import org.onosproject.net.PortNumber; import org.onosproject.net.flow.criteria.Criteria; import org.onosproject.net.flow.criteria.Criterion; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.TreeSet; +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; /** * Default traffic selector implementation. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java index 6174cef6..6beeecc9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java @@ -15,9 +15,11 @@ */ package org.onosproject.net.flow; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Objects; + import org.onlab.packet.EthType; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; @@ -25,16 +27,17 @@ import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; import org.onosproject.core.GroupId; +import org.onosproject.net.DeviceId; import org.onosproject.net.IndexedLambda; import org.onosproject.net.PortNumber; +import org.onosproject.net.flow.instructions.ExtensionInstruction; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instructions; import org.onosproject.net.meter.MeterId; -import java.util.List; -import java.util.Objects; - -import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; /** * Default traffic treatment implementation. @@ -239,9 +242,11 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { case GROUP: case QUEUE: case L0MODIFICATION: + case L1MODIFICATION: case L2MODIFICATION: case L3MODIFICATION: case L4MODIFICATION: + case EXTENSION: current.add(instruction); break; case TABLE: @@ -479,6 +484,12 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { } @Override + public TrafficTreatment.Builder extension(ExtensionInstruction extension, + DeviceId deviceId) { + return add(Instructions.extension(extension, deviceId)); + } + + @Override public TrafficTreatment build() { if (deferred.size() == 0 && immediate.size() == 0 && table == null && !clear) { diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java index c7fe8b85..b14ab99c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java @@ -15,6 +15,8 @@ */ package org.onosproject.net.flow; +import java.util.List; + import org.onlab.packet.EthType; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; @@ -22,13 +24,13 @@ import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; import org.onosproject.core.GroupId; +import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; +import org.onosproject.net.flow.instructions.ExtensionInstruction; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instructions; import org.onosproject.net.meter.MeterId; -import java.util.List; - /** * Abstraction of network traffic treatment. */ @@ -413,6 +415,15 @@ public interface TrafficTreatment { Builder setUdpDst(TpPort port); /** + * Uses an extension treatment. + * + * @param extension extension treatment + * @param deviceId device ID + * @return a treatment builder + */ + Builder extension(ExtensionInstruction extension, DeviceId deviceId); + + /** * Builds an immutable traffic treatment descriptor. * <p> * If the treatment is empty when build() is called, it will add a default diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionInstruction.java new file mode 100644 index 00000000..9f22f888 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionInstruction.java @@ -0,0 +1,71 @@ +/* + * 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.flow.instructions; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract implementation of the set/get property methods of ExtensionInstruction. + */ +public abstract class AbstractExtensionInstruction implements ExtensionInstruction { + + private static final String INVALID_KEY = "Invalid property key: "; + private static final String INVALID_TYPE = "Given type does not match field type: "; + + @Override + public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException { + Class<?> clazz = this.getClass(); + try { + Field field = clazz.getDeclaredField(key); + field.setAccessible(true); + field.set(this, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new ExtensionPropertyException(INVALID_KEY + key); + } + } + + @Override + public <T> T getPropertyValue(String key) throws ExtensionPropertyException { + Class<?> clazz = this.getClass(); + try { + Field field = clazz.getDeclaredField(key); + field.setAccessible(true); + @SuppressWarnings("unchecked") + T result = (T) field.get(this); + return result; + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new ExtensionPropertyException(INVALID_KEY + key); + } catch (ClassCastException e) { + throw new ExtensionPropertyException(INVALID_TYPE + key); + } + } + + @Override + public List<String> getProperties() { + Class<?> clazz = this.getClass(); + + List<String> fields = new ArrayList<>(); + + for (Field field : clazz.getDeclaredFields()) { + fields.add(field.getName()); + } + + return fields; + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionInstruction.java new file mode 100644 index 00000000..89e0cc5e --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionInstruction.java @@ -0,0 +1,78 @@ +/* + * 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.flow.instructions; + +import java.util.List; + +/** + * An extensible instruction type. + */ +public interface ExtensionInstruction { + + /** + * Gets the type of the extension instruction. + * + * @return type + */ + ExtensionType type(); + + /** + * Sets a property on the extension instruction. + * + * @param key property key + * @param value value to set for the given key + * @param <T> class of the value + * @throws ExtensionPropertyException if the given key is not a valid + * property on this extension instruction + */ + <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException; + + /** + * Gets a property value of an extension instruction. + * + * @param key property key + * @param <T> class of the value + * @return value of the property + * @throws ExtensionPropertyException if the given key is not a valid + * property on this extension instruction + */ + <T> T getPropertyValue(String key) throws ExtensionPropertyException; + + /** + * Gets a list of all properties on the extension instruction. + * + * @return list of properties + */ + List<String> getProperties(); + + /** + * Serialize the extension instruction to a byte array. + * + * @return byte array + */ + byte[] serialize(); + + /** + * Deserialize the extension instruction from a byte array. The properties + * of this object will be overwritten with the data in the byte array. + * + * @param data input byte array + */ + void deserialize(byte[] data); + + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Treatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionPropertyException.java index a77079ce..5750d09e 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Treatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionPropertyException.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Open Networking Laboratory + * 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. @@ -13,24 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.net.flow; -import org.onosproject.net.PortNumber; +package org.onosproject.net.flow.instructions; /** - * Abstraction of different kinds of treatment that can be applied to an - * outbound packet. + * Exception indicating there was an error while setting/getting an extension + * instruction property. */ -public interface Treatment { +public class ExtensionPropertyException extends Exception { - // TODO: implement these later: modifications, group - // TODO: elsewhere provide factory methods for some default treatments - - /** - * Returns the port number where the packet should be emitted. - * - * @return output port number - */ - PortNumber output(); + public ExtensionPropertyException(String message) { + super(message); + } + public ExtensionPropertyException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java new file mode 100644 index 00000000..747a85b5 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java @@ -0,0 +1,92 @@ +/* + * 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.flow.instructions; + +import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; + +import java.util.Objects; + +/** + * Type of extension instructions. + */ +@Beta +public final class ExtensionType { + + /** + * A list of well-known named extension instruction type codes. + */ + public enum ExtensionTypes { + // TODO fix type numbers to include experimenter id + NICIRA_SET_TUNNEL_DST(31); + + private ExtensionType type; + + /** + * Creates a new named extension instruction type. + * + * @param type type code + */ + ExtensionTypes(int type) { + this.type = new ExtensionType(type); + } + + /** + * Gets the extension type object for this named type code. + * + * @return extension type object + */ + public ExtensionType type() { + return type; + } + } + + private final int type; + + /** + * Creates an extension type with the given int type code. + * + * @param type type code + */ + public ExtensionType(int type) { + this.type = type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExtensionType) { + final ExtensionType that = (ExtensionType) obj; + return this.type == that.type; + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(ExtensionType.class) + .add("type", type) + .toString(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java index 2f6a1cc1..31ad80c5 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java @@ -92,7 +92,12 @@ public interface Instruction { /** * Signifies that the traffic should be modified in L4 way. */ - L4MODIFICATION + L4MODIFICATION, + + /** + * Signifies that an extension instruction will be used. + */ + EXTENSION } /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java index 8868bf7c..aad407c8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java @@ -22,6 +22,7 @@ import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; import org.onosproject.core.GroupId; +import org.onosproject.net.DeviceId; import org.onosproject.net.IndexedLambda; import org.onosproject.net.Lambda; import org.onosproject.net.OchSignal; @@ -480,6 +481,20 @@ public final class Instructions { } /** + * Creates an extension instruction. + * + * @param extension extension instruction + * @param deviceId device ID + * @return extension instruction + */ + public static ExtensionInstructionWrapper extension(ExtensionInstruction extension, + DeviceId deviceId) { + checkNotNull(extension, "Extension instruction cannot be null"); + checkNotNull(deviceId, "Device ID cannot be null"); + return new ExtensionInstructionWrapper(extension, deviceId); + } + + /** * Drop instruction. */ @Deprecated @@ -820,6 +835,59 @@ public final class Instructions { } } + /** + * Extension instruction. + */ + public static class ExtensionInstructionWrapper implements Instruction { + private final ExtensionInstruction extensionInstruction; + private final DeviceId deviceId; + + ExtensionInstructionWrapper(ExtensionInstruction extension, DeviceId deviceId) { + extensionInstruction = extension; + this.deviceId = deviceId; + } + + public ExtensionInstruction extensionInstruction() { + return extensionInstruction; + } + + public DeviceId deviceId() { + return deviceId; + } + + @Override + public Type type() { + return Type.EXTENSION; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("extension", extensionInstruction) + .add("deviceId", deviceId) + .toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), extensionInstruction, deviceId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExtensionInstructionWrapper) { + ExtensionInstructionWrapper that = (ExtensionInstructionWrapper) obj; + return Objects.equals(extensionInstruction, that.extensionInstruction) + && Objects.equals(deviceId, that.deviceId); + + } + return false; + } + } + } 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 index 7b5924fb..06305bf7 100644 --- 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 @@ -18,6 +18,7 @@ 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 org.onosproject.net.flow.criteria.Criteria; import org.onosproject.net.flow.criteria.Criterion; @@ -46,6 +47,7 @@ public final class DefaultFilteringObjective implements FilteringObjective { private final int id; private final Operation op; private final Optional<ObjectiveContext> context; + private final TrafficTreatment meta; private DefaultFilteringObjective(Builder builder) { this.key = builder.key; @@ -57,6 +59,7 @@ public final class DefaultFilteringObjective implements FilteringObjective { this.conditions = builder.conditions; this.op = builder.op; this.context = Optional.ofNullable(builder.context); + this.meta = builder.meta; this.id = Objects.hash(type, key, conditions, permanent, timeout, appId, priority); @@ -83,6 +86,12 @@ public final class DefaultFilteringObjective implements FilteringObjective { } @Override + public TrafficTreatment meta() { + return meta; + } + + + @Override public int priority() { return priority; } @@ -135,6 +144,7 @@ public final class DefaultFilteringObjective implements FilteringObjective { private List<Criterion> conditions; private Operation op; private ObjectiveContext context; + private TrafficTreatment meta; @Override public Builder withKey(Criterion key) { @@ -186,6 +196,12 @@ public final class DefaultFilteringObjective implements FilteringObjective { } @Override + public Builder setMeta(TrafficTreatment treatment) { + this.meta = treatment; + return this; + } + + @Override public FilteringObjective add() { conditions = listBuilder.build(); op = Operation.ADD; 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 index 58304571..29257c61 100644 --- 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 @@ -17,49 +17,54 @@ package org.onosproject.net.flowobjective; import com.google.common.annotations.Beta; import org.onosproject.core.ApplicationId; +import org.onosproject.net.flow.TrafficTreatment; 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. + * is made up of a key (typically a PortCriterion) mapped to a set of criteria. + * Using this information, a pipeline aware driver will decide how this objective + * should be mapped to the device specific pipeline-tables in order to satisfy the + * filtering condition. For example, consider the following PERMIT filtering + * objective: + * <p> + * portX -> {MAC1, VLAN1} + * <p> + * The driver could decide to pass packets to the MAC table or VLAN or PORT + * tables to ensure that only those packets arriving with the correct dst MAC + * and VLAN ids from Port X are allowed into the pipeline. + * <p> + * Filtering objectives of type PERMIT allow packets that match the key:criteria + * to enter the pipeline. As a result, the implication is that packets that don't + * match are automatically denied (dropped). + * <p> + * Filtering objectives of type DENY, are used to deny packets that would + * otherwise be permitted and forwarded through the pipeline (ie. those packets + * that make it through the PERMIT filters). */ @Beta public interface FilteringObjective extends Objective { enum Type { /** - * Enables the filtering condition. + * Permits packets that match the filtering condition to be processed + * by the rest of the pipeline. Automatically denies packets that don't + * match the criteria. */ PERMIT, /** - * Disables the filtering condition. + * Denies packets that make it through the permit filters. */ DENY } /** - * Obtain the key for this filter. + * Obtain the key for this filter. The filter may or may not require a key. * - * @return a criterion + * @return a criterion, which could be null if no key was provided. */ Criterion key(); @@ -78,6 +83,16 @@ public interface FilteringObjective extends Objective { Collection<Criterion> conditions(); /** + * Auxiliary optional information provided to the device-driver.Typically + * conveys information about changes (treatments) to packets that are + * permitted into the pipeline by the PERMIT filtering condition. + * + * @return a treatment on the packets that make it through the PERMIT filters. + * Value may be null if no meta information is provided. + */ + TrafficTreatment meta(); + + /** * Builder of Filtering objective entities. */ interface Builder extends Objective.Builder { @@ -113,11 +128,20 @@ public interface FilteringObjective extends Objective { Builder deny(); /** + * Set meta information about this filtering condition set. + * + * @param treatment traffic treatment to use + * @return a filtering builder + */ + Builder setMeta(TrafficTreatment treatment); + + /** * Assigns an application id. * * @param appId an application id * @return a filtering builder */ + @Override Builder fromApp(ApplicationId appId); /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java index 6efd3e79..9d942ee4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroupBucket.java @@ -139,6 +139,20 @@ public final class DefaultGroupBucket implements GroupBucket, StoredGroupBucketE watchGroup); } + /** + * Creates all group bucket. + * + * @param treatment traffic treatment associated with group bucket + * @return all group bucket object + */ + public static GroupBucket createAllGroupBucket(TrafficTreatment treatment) { + return new DefaultGroupBucket(GroupDescription.Type.ALL, + treatment, + (short) -1, + null, + null); + } + @Override public GroupDescription.Type type() { return this.type; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java index bd4219ad..c1467241 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java @@ -17,11 +17,15 @@ package org.onosproject.net.intent; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; + import org.onosproject.core.ApplicationId; import org.onosproject.net.HostId; +import org.onosproject.net.Link; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; +import org.onosproject.net.intent.constraint.LinkTypeConstraint; import java.util.List; @@ -33,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull; @Beta public final class HostToHostIntent extends ConnectivityIntent { + static final LinkTypeConstraint NOT_OPTICAL = new LinkTypeConstraint(false, Link.Type.OPTICAL); + private final HostId one; private final HostId two; @@ -115,6 +121,15 @@ public final class HostToHostIntent extends ConnectivityIntent { */ public HostToHostIntent build() { + List<Constraint> theConstraints = constraints; + // If not-OPTICAL constraint hasn't been specified, add them + if (!constraints.contains(NOT_OPTICAL)) { + theConstraints = ImmutableList.<Constraint>builder() + .add(NOT_OPTICAL) + .addAll(constraints) + .build(); + } + return new HostToHostIntent( appId, key, @@ -122,7 +137,7 @@ public final class HostToHostIntent extends ConnectivityIntent { two, selector, treatment, - constraints, + theConstraints, priority ); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/Key.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/Key.java index 18baafc8..0344acbf 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/Key.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/Key.java @@ -28,7 +28,7 @@ import java.util.Objects; */ // TODO maybe pull this up to utils @Beta -public abstract class Key { +public abstract class Key implements Comparable<Key> { //TODO consider making this a HashCode object (worry about performance) private final long hash; @@ -117,6 +117,12 @@ public abstract class Key { Objects.equals(this.appId, other.appId) && Objects.equals(this.key, other.key); } + + @Override + public int compareTo(Key o) { + StringKey sk = (StringKey) o; + return this.key.compareTo(sk.key); + } } private static final class LongKey extends Key { @@ -157,6 +163,13 @@ public abstract class Key { this.key == other.key && Objects.equals(this.appId, other.appId); } + + @Override + public int compareTo(Key o) { + Long myKey = key; + Long otherKey = ((LongKey) o).key; + return myKey.compareTo(otherKey); + } } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java index 43b8e4b1..20ccb55d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java @@ -16,6 +16,8 @@ package org.onosproject.net.intent.constraint; import com.google.common.annotations.Beta; + +import org.onlab.util.DataRateUnit; import org.onosproject.net.Link; import org.onosproject.net.resource.link.BandwidthResource; import org.onosproject.net.resource.link.BandwidthResourceRequest; @@ -32,7 +34,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * Constraint that evaluates links based on available bandwidths. */ @Beta -public class BandwidthConstraint extends BooleanConstraint { +public final class BandwidthConstraint extends BooleanConstraint { private final BandwidthResource bandwidth; @@ -45,6 +47,17 @@ public class BandwidthConstraint extends BooleanConstraint { this.bandwidth = checkNotNull(bandwidth, "Bandwidth cannot be null"); } + /** + * Creates a new bandwidth constraint. + * + * @param v required amount of bandwidth + * @param unit {@link DataRateUnit} of {@code v} + * @return {@link BandwidthConstraint} instance with given bandwidth requirement + */ + public static BandwidthConstraint of(double v, DataRateUnit unit) { + return new BandwidthConstraint(BandwidthResource.of(v, unit)); + } + // Constructor for serialization private BandwidthConstraint() { this.bandwidth = null; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java index 82d84743..ad684c8c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java @@ -153,6 +153,14 @@ public interface ResourceService { Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer); /** + * Returns resource paths that point available child resources under the specified resource path. + * + * @param parent parent resource path + * @return available resource paths under the specified resource path + */ + Collection<ResourcePath> getAvailableResources(ResourcePath parent); + + /** * Returns the availability of the specified resource. * * @param resource resource to check the availability diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java index 5a034b4d..2cab9d4b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java @@ -92,6 +92,14 @@ public interface ResourceStore { Collection<ResourcePath> getResources(ResourceConsumer consumer); /** + * Returns a collection of the child resources of the specified parent. + * + * @param parent parent of the resource to be returned + * @return a collection of the child resources of the specified resource + */ + Collection<ResourcePath> getChildResources(ResourcePath parent); + + /** * Returns a collection of the resources which are children of the specified parent and * whose type is the specified class. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java index fe21e042..0bfb3795 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java @@ -16,7 +16,7 @@ package org.onosproject.net.resource.link; import org.onlab.util.Bandwidth; - +import org.onlab.util.DataRateUnit; import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -43,6 +43,17 @@ public final class BandwidthResource implements LinkResource { } /** + * Creates a new bandwidth resource. + * + * @param v amount of bandwidth to request + * @param unit {@link DataRateUnit} of {@code v} + * @return {@link BandwidthResource} instance with given bandwidth + */ + public static BandwidthResource of(double v, DataRateUnit unit) { + return new BandwidthResource(Bandwidth.of(v, unit)); + } + + /** * Returns bandwidth as a double value. * * @return bandwidth as a double value diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java index 5153aebf..f8e143a4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java @@ -16,48 +16,47 @@ package org.onosproject.net.resource.link; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.Objects; +import java.util.stream.Collectors; +import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableMap; import org.onlab.util.Bandwidth; import org.onosproject.net.Link; import org.onosproject.net.intent.Constraint; import org.onosproject.net.intent.IntentId; -import com.google.common.collect.ImmutableSet; - import org.onosproject.net.intent.constraint.BandwidthConstraint; import org.onosproject.net.intent.constraint.LambdaConstraint; import org.onosproject.net.resource.ResourceRequest; import org.onosproject.net.resource.ResourceType; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Implementation of {@link LinkResourceRequest}. */ public final class DefaultLinkResourceRequest implements LinkResourceRequest { private final IntentId intentId; - private final Collection<Link> links; - private final Set<ResourceRequest> resources; + protected final Map<Link, Set<ResourceRequest>> requests; /** - * Creates a new link resource request with the given ID, links, and - * resource requests. + * Creates a new link resource request with the specified Intent ID, + * and resource requests over links. * - * @param intentId intent ID related to this request - * @param links a set of links for the request - * @param resources a set of resources to be requested + * @param intentId intent ID associated with this request + * @param requests resource requests over links */ - private DefaultLinkResourceRequest(IntentId intentId, - Collection<Link> links, - Set<ResourceRequest> resources) { - this.intentId = intentId; - this.links = ImmutableSet.copyOf(links); - this.resources = ImmutableSet.copyOf(resources); + private DefaultLinkResourceRequest(IntentId intentId, Map<Link, Set<ResourceRequest>> requests) { + this.intentId = checkNotNull(intentId); + this.requests = checkNotNull(ImmutableMap.copyOf(requests)); } - @Override public ResourceType type() { return null; @@ -70,12 +69,19 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { @Override public Collection<Link> links() { - return links; + return requests.keySet(); } @Override public Set<ResourceRequest> resources() { - return resources; + return requests.values().stream() + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + } + + @Override + public Set<ResourceRequest> resources(Link link) { + return requests.get(link); } /** @@ -95,8 +101,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { */ public static final class Builder implements LinkResourceRequest.Builder { private IntentId intentId; - private Collection<Link> links; - private Set<ResourceRequest> resources; + private Map<Link, Set<ResourceRequest>> requests; /** * Creates a new link resource request. @@ -106,18 +111,33 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { */ private Builder(IntentId intentId, Collection<Link> links) { this.intentId = intentId; - this.links = links; - this.resources = new HashSet<>(); + this.requests = new HashMap<>(); + for (Link link : links) { + requests.put(link, new HashSet<>()); + } } /** * Adds lambda request. * * @return self + * @deprecated in Emu Release */ + @Deprecated @Override public Builder addLambdaRequest() { - resources.add(new LambdaResourceRequest()); + for (Link link : requests.keySet()) { + requests.get(link).add(new LambdaResourceRequest()); + } + return this; + } + + @Beta + @Override + public LinkResourceRequest.Builder addLambdaRequest(LambdaResource lambda) { + for (Link link : requests.keySet()) { + requests.get(link).add(new LambdaResourceRequest(lambda)); + } return this; } @@ -125,10 +145,36 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { * Adds Mpls request. * * @return self + * @deprecated in Emu Release */ + @Deprecated @Override public Builder addMplsRequest() { - resources.add(new MplsLabelResourceRequest()); + for (Link link : requests.keySet()) { + requests.get(link).add(new MplsLabelResourceRequest()); + } + return this; + } + + @Beta + @Override + public Builder addMplsRequest(MplsLabel label) { + for (Link link : requests.keySet()) { + requests.get(link).add(new MplsLabelResourceRequest(label)); + } + return this; + } + + @Beta + @Override + public LinkResourceRequest.Builder addMplsRequest(Map<Link, MplsLabel> labels) { + for (Link link : labels.keySet()) { + if (!requests.containsKey(link)) { + requests.put(link, new HashSet<>()); + } + requests.get(link).add(new MplsLabelResourceRequest(labels.get(link))); + } + return this; } @@ -140,7 +186,9 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { */ @Override public Builder addBandwidthRequest(double bandwidth) { - resources.add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth)))); + for (Link link : requests.keySet()) { + requests.get(link).add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth)))); + } return this; } @@ -162,13 +210,13 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { */ @Override public LinkResourceRequest build() { - return new DefaultLinkResourceRequest(intentId, links, resources); + return new DefaultLinkResourceRequest(intentId, requests); } } @Override public int hashCode() { - return Objects.hash(intentId, links); + return Objects.hash(intentId, links()); } @Override @@ -181,6 +229,6 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { } final DefaultLinkResourceRequest other = (DefaultLinkResourceRequest) obj; return Objects.equals(this.intentId, other.intentId) - && Objects.equals(this.links, other.links); + && Objects.equals(this.links(), other.links()); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java index b0391f5a..d264d5e5 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java @@ -15,15 +15,50 @@ */ package org.onosproject.net.resource.link; +import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import org.onosproject.net.resource.ResourceRequest; import org.onosproject.net.resource.ResourceType; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Representation of a request for lambda resource. */ public class LambdaResourceRequest implements ResourceRequest { + private final LambdaResource lambda; + + /** + * Constructs a request specifying the given lambda. + * + * @param lambda lambda to be requested + */ + @Beta + public LambdaResourceRequest(LambdaResource lambda) { + this.lambda = checkNotNull(lambda); + } + + /** + * Constructs a request asking an arbitrary available lambda. + * + * @deprecated in Emu Release + */ + @Deprecated + public LambdaResourceRequest() { + this.lambda = null; + } + + /** + * Returns the lambda this request expects. + * + * @return the lambda this request expects + */ + @Beta + public LambdaResource lambda() { + return lambda; + } + @Override public ResourceType type() { return ResourceType.LAMBDA; @@ -32,6 +67,7 @@ public class LambdaResourceRequest implements ResourceRequest { @Override public String toString() { return MoreObjects.toStringHelper(this) + .add("lambda", lambda) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java index 8023a92e..37622e79 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java @@ -16,8 +16,10 @@ package org.onosproject.net.resource.link; import java.util.Collection; +import java.util.Map; import java.util.Set; +import com.google.common.annotations.Beta; import org.onosproject.net.Link; import org.onosproject.net.intent.Constraint; import org.onosproject.net.intent.IntentId; @@ -50,22 +52,62 @@ public interface LinkResourceRequest extends ResourceRequest { Set<ResourceRequest> resources(); /** + * Returns the set of resource request against the specified link. + * + * @param link link whose associated resource request is to be returned + * @return set of resource request against the specified link + */ + @Beta + Set<ResourceRequest> resources(Link link); + + /** * Builder of link resource request. */ interface Builder { - /** + /** * Adds lambda request. * * @return self + * @deprecated in Emu Release */ + @Deprecated Builder addLambdaRequest(); /** - * Adds MPLS request. - * - * @return self - */ - Builder addMplsRequest(); + * Adds lambda request. + * + * @param lambda lambda to be requested + * @return self + */ + @Beta + Builder addLambdaRequest(LambdaResource lambda); + + /** + * Adds MPLS request. + * + * @return self + * @deprecated in Emu Release + */ + @Deprecated + Builder addMplsRequest(); + + /** + * Adds MPLS request. + * + * @param label MPLS label to be requested + * @return self + */ + @Beta + Builder addMplsRequest(MplsLabel label); + + /** + * Adds MPLS request against the specified links. + * + * @param labels MPLS labels to be requested against links + * @return self + */ + @Beta + Builder addMplsRequest(Map<Link, MplsLabel> labels); /** * Adds bandwidth request with bandwidth value. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceService.java index 6dc04dfc..71ea7e1a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceService.java @@ -22,7 +22,10 @@ import org.onosproject.net.resource.ResourceRequest; /** * Service for providing link resource allocation. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceService extends ListenerService<LinkResourceEvent, LinkResourceListener> { @@ -31,14 +34,18 @@ public interface LinkResourceService * * @param req resources to be allocated * @return allocated resources + * @deprecated in Emu Release */ + @Deprecated LinkResourceAllocations requestResources(LinkResourceRequest req); /** * Releases resources. * * @param allocations resources to be released + * @deprecated in Emu Release */ + @Deprecated void releaseResources(LinkResourceAllocations allocations); /** @@ -47,7 +54,9 @@ public interface LinkResourceService * @param req updated resource request * @param oldAllocations old resource allocations * @return new resource allocations + * @deprecated in Emu Release */ + @Deprecated LinkResourceAllocations updateResources(LinkResourceRequest req, LinkResourceAllocations oldAllocations); @@ -55,7 +64,9 @@ public interface LinkResourceService * Returns all allocated resources. * * @return allocated resources + * @deprecated in Emu Release */ + @Deprecated Iterable<LinkResourceAllocations> getAllocations(); /** @@ -63,7 +74,9 @@ public interface LinkResourceService * * @param link a target link * @return allocated resources + * @deprecated in Emu Release */ + @Deprecated Iterable<LinkResourceAllocations> getAllocations(Link link); /** @@ -71,7 +84,9 @@ public interface LinkResourceService * * @param intentId the target Intent's id * @return allocated resources for Intent + * @deprecated in Emu Release */ + @Deprecated LinkResourceAllocations getAllocations(IntentId intentId); /** @@ -79,7 +94,9 @@ public interface LinkResourceService * * @param link a target link * @return available resources for the target link + * @deprecated in Emu Release */ + @Deprecated Iterable<ResourceRequest> getAvailableResources(Link link); /** @@ -88,7 +105,9 @@ public interface LinkResourceService * @param link a target link * @param allocations allocations to be included as available * @return available resources for the target link + * @deprecated in Emu Release */ + @Deprecated Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java index 0a03f450..01a048b7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java @@ -15,15 +15,50 @@ */ package org.onosproject.net.resource.link; +import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import org.onosproject.net.resource.ResourceRequest; import org.onosproject.net.resource.ResourceType; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Representation of a request for lambda resource. */ public class MplsLabelResourceRequest implements ResourceRequest { + private final MplsLabel mplsLabel; + + /** + * Constructs a request specifying the given MPLS label. + * + * @param mplsLabel MPLS label to be requested + */ + @Beta + public MplsLabelResourceRequest(MplsLabel mplsLabel) { + this.mplsLabel = checkNotNull(mplsLabel); + } + + /** + * Constructs a request asking an arbitrary available MPLS label. + * + * @deprecated in Emu Release + */ + @Deprecated + public MplsLabelResourceRequest() { + this.mplsLabel = null; + } + + /** + * Returns the MPLS label this request expects. + * + * @return the MPLS label this request expects + */ + @Beta + public MplsLabel mplsLabel() { + return mplsLabel; + } + @Override public ResourceType type() { return ResourceType.MPLS_LABEL; @@ -32,6 +67,7 @@ public class MplsLabelResourceRequest implements ResourceRequest { @Override public String toString() { return MoreObjects.toStringHelper(this) + .add("mplsLabel", mplsLabel) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistenceService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistenceService.java new file mode 100644 index 00000000..09065dec --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistenceService.java @@ -0,0 +1,40 @@ +/* + * 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.persistence; + +/** + * Service that allows for the creation of local disk backed map for instance specific values that persist across + * restarts. Empty maps and sets are deleted on shutdown. + */ +public interface PersistenceService { + /** + * A builder for the creation of local persistent maps backed by disk. + * + * @param <K> the type of keys in this map + * @param <V> the type of values in this map + * @return a persistent map builder + */ + <K, V> PersistentMapBuilder<K, V> persistentMapBuilder(); + + /** + * A builder for the creation of local persistent sets backed by disk. + * + * @param <E> the type of the elements + * @return a persistent set builder + */ + <E> PersistentSetBuilder<E> persistentSetBuilder(); +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentMapBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentMapBuilder.java new file mode 100644 index 00000000..c3c855e1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentMapBuilder.java @@ -0,0 +1,49 @@ +/* + * 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.persistence; + + +import org.onosproject.store.service.Serializer; + +import java.util.Map; + +/** + * The interface for a persistent map builder for use with mapDB. + */ +public interface PersistentMapBuilder<K, V> { + + /** + * Sets the name of this map. + * @param name the string name of this map + * @return a persistent map builder with the name option now set + */ + PersistentMapBuilder<K, V> withName(String name); + + /** + * Sets the key serializer to be used to serialize this map, this is a required parameter. + * @param serializer the serializer to be used for keys + * @return a persistent map builder with the key serializer set + */ + PersistentMapBuilder<K, V> withSerializer(Serializer serializer); + + /** + * Validates the map settings and then builds this map in the database. Throws an exception if invalid settings + * are found. + * @return The map that was created + */ + Map<K, V> build(); +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentSetBuilder.java b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentSetBuilder.java new file mode 100644 index 00000000..851872cf --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/PersistentSetBuilder.java @@ -0,0 +1,48 @@ +/* + * 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.persistence; + +import org.onosproject.store.service.Serializer; + +import java.util.Set; + +/** + * The default interface for the persistent set builder for use with mapDB. + */ +public interface PersistentSetBuilder<E> { + + /** + * Sets the name of this set. + * @param name the string name of this set + * @return a persistent set builder with the name option now set + */ + PersistentSetBuilder<E> withName(String name); + + /** + * Sets the serializer to be used to serialize this set, this is a required parameter. + * @param serializer the serializer to be used + * @return a persistent set builder with the serializer set + */ + PersistentSetBuilder<E> withSerializer(Serializer serializer); + + /** + * Validates the set settings and then builds this map in the database. Throws an exception if invalid settings + * are found. + * @return The set that was created + */ + Set<E> build(); +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/package-info.java new file mode 100644 index 00000000..6e11a5e1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/persistence/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * Persistence service and builders. + */ +package org.onosproject.persistence; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java index 94942e20..ef972536 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/TransactionContext.java @@ -56,9 +56,9 @@ public interface TransactionContext { * Commits a transaction that was previously started thereby making its changes permanent * and externally visible. * - * @throws TransactionException if transaction fails to commit + * @return true if this transaction succeeded, otherwise false. */ - void commit(); + boolean commit(); /** * Aborts any changes made in this transaction context and discarding all locally cached updates. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiTopoOverlay.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiTopoOverlay.java index e0d7d239..88796de7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiTopoOverlay.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiTopoOverlay.java @@ -16,6 +16,8 @@ package org.onosproject.ui; +import org.onosproject.net.DeviceId; +import org.onosproject.net.HostId; import org.onosproject.ui.topo.PropertyPanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,8 +107,9 @@ public class UiTopoOverlay { * This default implementation does nothing. * * @param pp property panel model of summary data + * @param deviceId device id */ - public void modifyDeviceDetails(PropertyPanel pp) { + public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) { } /** @@ -115,7 +118,8 @@ public class UiTopoOverlay { * This default implementation does nothing. * * @param pp property panel model of summary data + * @param hostId host id */ - public void modifyHostDetails(PropertyPanel pp) { + public void modifyHostDetails(PropertyPanel pp, HostId hostId) { } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java index 0e1c248b..f7947a75 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/table/cell/AppIdFormatter.java @@ -27,6 +27,7 @@ public final class AppIdFormatter extends AbstractCellFormatter { // non-instantiable private AppIdFormatter() { } + // NOTE: do not change this format; we parse it on the client side. @Override protected String nonNullFormat(Object value) { ApplicationId appId = (ApplicationId) value; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java index 7b517111..4edb6712 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/NodeBadge.java @@ -40,7 +40,7 @@ public final class NodeBadge { return "{" + code + "}"; } - /** Returns the status code in string form. */ + /* Returns the status code in string form. */ public String code() { return code; } |