diff options
Diffstat (limited to 'framework/src/onos/core/api/src/main')
81 files changed, 1067 insertions, 122 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java index 2561280b..e8ff9ec4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java @@ -86,4 +86,11 @@ public interface ApplicationDescription { * @return application features */ List<String> features(); + + /** + * Returns list of required application names. + * + * @return list of application names + */ + List<String> requiredApps(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java index 73dcc86c..1e543b85 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java @@ -67,4 +67,11 @@ public interface ApplicationService */ Set<Permission> getPermissions(ApplicationId appId); + /** + * Registers application pre-deactivation processing hook. + * + * @param appId application identifier + * @param hook pre-deactivation hook + */ + void registerDeactivateHook(ApplicationId appId, Runnable hook); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java index b3cdc43e..0a1f0727 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java @@ -76,7 +76,7 @@ public interface ApplicationStore extends Store<ApplicationEvent, ApplicationSto void remove(ApplicationId appId); /** - * Mark the application as actived. + * Mark the application as active. * * @param appId application identifier */ diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java index 710d0f9c..569183a7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java @@ -41,6 +41,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { private final Set<Permission> permissions; private final Optional<URI> featuresRepo; private final List<String> features; + private final List<String> requiredApps; /** * Creates a new application descriptor using the supplied data. @@ -53,11 +54,13 @@ public class DefaultApplicationDescription implements ApplicationDescription { * @param permissions requested permissions * @param featuresRepo optional features repo URI * @param features application features + * @param requiredApps list of required application names */ public DefaultApplicationDescription(String name, Version version, String description, String origin, ApplicationRole role, Set<Permission> permissions, - URI featuresRepo, List<String> features) { + URI featuresRepo, List<String> features, + List<String> requiredApps) { this.name = checkNotNull(name, "Name cannot be null"); this.version = checkNotNull(version, "Version cannot be null"); this.description = checkNotNull(description, "Description cannot be null"); @@ -66,6 +69,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { this.permissions = checkNotNull(permissions, "Permissions cannot be null"); this.featuresRepo = Optional.ofNullable(featuresRepo); this.features = checkNotNull(features, "Features cannot be null"); + this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); checkArgument(!features.isEmpty(), "There must be at least one feature"); } @@ -110,6 +114,11 @@ public class DefaultApplicationDescription implements ApplicationDescription { } @Override + public List<String> requiredApps() { + return requiredApps; + } + + @Override public String toString() { return toStringHelper(this) .add("name", name) @@ -120,6 +129,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { .add("permissions", permissions) .add("featuresRepo", featuresRepo) .add("features", features) + .add("requiredApps", requiredApps) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java index 36cd22b5..f1b602e8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java @@ -245,7 +245,7 @@ public final class ConfigProperty { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java index 5f3e0e19..3787daa5 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java @@ -20,6 +20,7 @@ import org.onlab.packet.IpAddress; import java.util.Objects; import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; /** * Default implementation of a controller instance descriptor. @@ -57,7 +58,7 @@ public class DefaultControllerNode implements ControllerNode { * @param tcpPort TCP port */ public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) { - this.id = id; + this.id = checkNotNull(id); this.ip = ip; this.tcpPort = tcpPort; } @@ -79,7 +80,7 @@ public class DefaultControllerNode implements ControllerNode { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override 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 6cfb42c7..e5ab9dc8 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 @@ -35,7 +35,7 @@ public class NodeId implements Comparable<NodeId> { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java index fca53843..ea2eab9b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java @@ -84,4 +84,11 @@ public interface Application { * @return application features */ List<String> features(); + + /** + * Returns list of required application names. + * + * @return list of application names + */ + List<String> requiredApps(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java index 303ad395..0825a6d1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java @@ -50,6 +50,7 @@ public interface CoreService { /** * Returns an existing application id from a given id. + * * @param id the short value of the id * @return an application id */ @@ -57,6 +58,7 @@ public interface CoreService { /** * Returns an existing application id from a given id. + * * @param name the name portion of the ID to look up * @return an application id */ @@ -67,10 +69,21 @@ public interface CoreService { * to follow the reverse DNS convention, e.g. * {@code org.flying.circus.app} * - * @param identifier string identifier + * @param name string identifier + * @return the application id + */ + ApplicationId registerApplication(String name); + + /** + * Registers a new application by its name, which is expected + * to follow the reverse DNS convention, e.g. + * {@code org.flying.circus.app}, along with its pre-deactivation hook. + * + * @param name string identifier + * @param preDeactivate pre-deactivation hook * @return the application id */ - ApplicationId registerApplication(String identifier); + ApplicationId registerApplication(String name, Runnable preDeactivate); /** * Returns an id generator for a given topic. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java index d8062ddf..c3515638 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java @@ -40,6 +40,7 @@ public class DefaultApplication implements Application { private final Set<Permission> permissions; private final Optional<URI> featuresRepo; private final List<String> features; + private final List<String> requiredApps; /** * Creates a new application descriptor using the supplied data. @@ -52,11 +53,13 @@ public class DefaultApplication implements Application { * @param permissions requested permissions * @param featuresRepo optional features repo URI * @param features application features + * @param requiredApps list of required application names */ public DefaultApplication(ApplicationId appId, Version version, String description, String origin, ApplicationRole role, Set<Permission> permissions, - Optional<URI> featuresRepo, List<String> features) { + Optional<URI> featuresRepo, List<String> features, + List<String> requiredApps) { this.appId = checkNotNull(appId, "ID cannot be null"); this.version = checkNotNull(version, "Version cannot be null"); this.description = checkNotNull(description, "Description cannot be null"); @@ -65,6 +68,7 @@ public class DefaultApplication implements Application { this.permissions = checkNotNull(permissions, "Permissions cannot be null"); this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null"); this.features = checkNotNull(features, "Features cannot be null"); + this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); checkArgument(!features.isEmpty(), "There must be at least one feature"); } @@ -109,9 +113,14 @@ public class DefaultApplication implements Application { } @Override + public List<String> requiredApps() { + return requiredApps; + } + + @Override public int hashCode() { return Objects.hash(appId, version, description, origin, role, permissions, - featuresRepo, features); + featuresRepo, features, requiredApps); } @Override @@ -130,7 +139,8 @@ public class DefaultApplication implements Application { Objects.equals(this.role, other.role) && Objects.equals(this.permissions, other.permissions) && Objects.equals(this.featuresRepo, other.featuresRepo) && - Objects.equals(this.features, other.features); + Objects.equals(this.features, other.features) && + Objects.equals(this.requiredApps, other.requiredApps); } @Override @@ -144,6 +154,7 @@ public class DefaultApplication implements Application { .add("permissions", permissions) .add("featuresRepo", featuresRepo) .add("features", features) + .add("requiredApps", requiredApps) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java index c7b5b2da..aedfb0d3 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java @@ -58,7 +58,7 @@ public class DefaultApplicationId implements ApplicationId { @Override public int hashCode() { - return Objects.hash(id); + return Short.hashCode(id); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java index 9fa8d2b6..243e5216 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java @@ -42,7 +42,7 @@ public class DefaultGroupId implements GroupId { @Override public int hashCode() { - return Objects.hash(id); + return id; } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java index a5377016..06e9e206 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java @@ -127,7 +127,7 @@ public final class Version { @Override public int hashCode() { - return Objects.hash(format); + return format.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java index d81b83cc..34042dad 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java @@ -16,6 +16,7 @@ package org.onosproject.net; import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.base.Objects; /** * Base implementation of an annotated model description. @@ -46,4 +47,18 @@ public abstract class AbstractDescription implements Annotated { return annotations; } + @Override + public int hashCode() { + return Objects.hashCode(annotations); + } + + @Override + public boolean equals(Object object) { + if (object instanceof AbstractDescription) { + AbstractDescription that = (AbstractDescription) object; + return Objects.equal(this.annotations, that.annotations); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java index 2877701e..557fa5c1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java @@ -98,7 +98,8 @@ public class DefaultHost extends AbstractElement implements Host { return Objects.equals(this.id, other.id) && Objects.equals(this.mac, other.mac) && Objects.equals(this.vlan, other.vlan) && - Objects.equals(this.location, other.location); + Objects.equals(this.location, other.location) && + Objects.equals(this.ipAddresses(), other.ipAddresses()); } return false; } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java index a4789cac..2da2463a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java @@ -88,7 +88,7 @@ public class DefaultPath extends DefaultLink implements Path { @Override public int hashCode() { - return Objects.hash(links); + return links.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java index 5331342e..e2c1214f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java @@ -75,7 +75,7 @@ public final class DeviceId extends ElementId { @Override public int hashCode() { - return Objects.hash(str); + return str.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java index 03e6dba9..8c9b1349 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java @@ -15,6 +15,16 @@ */ package org.onosproject.net; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import com.google.common.primitives.UnsignedLongs; /** @@ -26,8 +36,7 @@ public final class PortNumber { // TODO: revisit the max and the logical port value assignments - private static final long MAX_NUMBER = (2L * Integer.MAX_VALUE) + 1; - + static final long MAX_NUMBER = (2L * Integer.MAX_VALUE) + 1; static final long IN_PORT_NUMBER = -8L; static final long TABLE_NUMBER = -7L; @@ -37,6 +46,39 @@ public final class PortNumber { static final long LOCAL_NUMBER = -2L; static final long CONTROLLER_NUMBER = -3L; + /** + * Logical PortNumbers. + */ + public static enum Logical { + IN_PORT(IN_PORT_NUMBER), + TABLE(TABLE_NUMBER), + NORMAL(NORMAL_NUMBER), + FLOOD(FLOOD_NUMBER), + ALL(ALL_NUMBER), + LOCAL(LOCAL_NUMBER), + CONTROLLER(CONTROLLER_NUMBER); + + private final long number; + private final PortNumber instance; + + public long number() { + return number; + } + + /** + * PortNumber instance for the logical port. + * @return {@link PortNumber} + */ + public PortNumber instance() { + return instance; + } + + Logical(long number) { + this.number = number; + this.instance = new PortNumber(number); + } + } + public static final PortNumber IN_PORT = new PortNumber(IN_PORT_NUMBER); public static final PortNumber TABLE = new PortNumber(TABLE_NUMBER); public static final PortNumber NORMAL = new PortNumber(NORMAL_NUMBER); @@ -45,6 +87,15 @@ public final class PortNumber { public static final PortNumber LOCAL = new PortNumber(LOCAL_NUMBER); public static final PortNumber CONTROLLER = new PortNumber(CONTROLLER_NUMBER); + // lazily populated Logical port number to PortNumber + static final Supplier<Map<Long, Logical>> LOGICAL = Suppliers.memoize(() -> { + Builder<Long, Logical> builder = ImmutableMap.<Long, Logical>builder(); + for (Logical lp : Logical.values()) { + builder.put(lp.number(), lp); + } + return builder.build(); + }); + private final long number; private final String name; private final boolean hasName; @@ -136,30 +187,68 @@ public final class PortNumber { } private String decodeLogicalPort() { - if (number == CONTROLLER_NUMBER) { - return "CONTROLLER"; - } else if (number == LOCAL_NUMBER) { - return "LOCAL"; - } else if (number == ALL_NUMBER) { - return "ALL"; - } else if (number == FLOOD_NUMBER) { - return "FLOOD"; - } else if (number == NORMAL_NUMBER) { - return "NORMAL"; - } else if (number == TABLE_NUMBER) { - return "TABLE"; - } else if (number == IN_PORT_NUMBER) { - return "IN_PORT"; + Logical logical = LOGICAL.get().get(number); + if (logical != null) { + // enum name + return logical.toString(); + } + return String.format("UNKNOWN(%s)", UnsignedLongs.toString(number)); + } + + + /** + * Regular expression to match String representation of named PortNumber. + * + * Format: "[name](num:unsigned decimal string)" + */ + private static final Pattern NAMED = Pattern.compile("^\\[(?<name>.*)\\]\\((?<num>\\d+)\\)$"); + + private static boolean isAsciiDecimal(char c) { + return '0' <= c && c <= '9'; + } + + /** + * Returns PortNumber instance from String representation. + * + * @param s String representation equivalent to {@link PortNumber#toString()} + * @return {@link PortNumber} instance + * @throws IllegalArgumentException if given String was malformed + */ + public static PortNumber fromString(String s) { + checkNotNull(s); + checkArgument(!s.isEmpty(), "cannot be empty"); + + if (isAsciiDecimal(s.charAt(0))) { + // unsigned decimal string + return portNumber(s); + } else if (s.startsWith("[")) { + // named PortNumber + Matcher matcher = NAMED.matcher(s); + checkArgument(matcher.matches(), "Invalid named PortNumber %s", s); + + String name = matcher.group("name"); + String num = matcher.group("num"); + return portNumber(UnsignedLongs.parseUnsignedLong(num), name); + } + + // Logical + if (s.startsWith("UNKNOWN(") && s.endsWith(")")) { + return portNumber(s.substring("UNKNOWN(".length(), s.length() - 1)); + } else { + return Logical.valueOf(s).instance; } - return "UNKNOWN"; } @Override public String toString() { - if (!isLogical()) { - return name; - } else { + if (isLogical()) { return decodeLogicalPort(); + } else if (hasName()) { + // named port + return String.format("[%s](%d)", name, number); + } else { + // unsigned decimal string + return name; } } 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 e3d6993c..cf7bed6d 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,15 @@ public interface BridgeConfig extends HandlerBehaviour { void addBridge(BridgeName bridgeName); /** + * Adds a bridge with given bridge name, dpid and exPortName. + * + * @param bridgeName bridge name + * @param dpid dpid + * @param exPortName external port name + */ + void addBridge(BridgeName bridgeName, String dpid, String exPortName); + + /** * Adds a bridge with given bridge name and dpid, and sets the controller * of the bridge with given controllers. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java index 3f782954..a15217c6 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java @@ -52,7 +52,7 @@ public final class BridgeName { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java index 5cdc0c12..3757d327 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java @@ -20,10 +20,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterators; import com.google.common.collect.Lists; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.function.Function; import static com.google.common.base.Preconditions.checkNotNull; @@ -51,6 +56,21 @@ public abstract class Config<S> { protected ConfigApplyDelegate delegate; /** + * Indicator of whether a configuration JSON field is required. + */ + public enum FieldPresence { + /** + * Signifies that config field is an optional one. + */ + OPTIONAL, + + /** + * Signifies that config field is mandatory. + */ + MANDATORY + } + + /** * Initializes the configuration behaviour with necessary context. * * @param subject configuration subject @@ -71,6 +91,29 @@ public abstract class Config<S> { } /** + * Indicates whether or not the backing JSON node contains valid data. + * <p> + * Default implementation returns true. + * Subclasses are expected to override this with their own validation. + * </p> + * + * @return true if the data is valid; false otherwise + */ + public boolean isValid() { + // TODO: figure out what assertions could be made in the base class + // NOTE: The thought is to have none, but instead to provide a set + // of predicates to allow configs to test validity of present fields, + // e.g.: + // isString(path) + // isBoolean(path) + // isNumber(path, [min, max]) + // isDecimal(path, [min, max]) + // isMacAddress(path) + // isIpAddress(path) + return true; + } + + /** * Returns the specific subject to which this configuration pertains. * * @return configuration subject @@ -309,4 +352,104 @@ public abstract class Config<S> { return this; } + /** + * Indicates whether only the specified fields are present in the backing JSON. + * + * @param allowedFields allowed field names + * @return true if all allowedFields are present; false otherwise + */ + protected boolean hasOnlyFields(String... allowedFields) { + Set<String> fields = ImmutableSet.copyOf(allowedFields); + return !Iterators.any(object.fieldNames(), f -> !fields.contains(f)); + } + + /** + * Indicates whether the specified field holds a valid MAC address. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid MAC + */ + protected boolean isMacAddress(String field, FieldPresence presence) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + MacAddress.valueOf(node.asText()) != null); + } + + /** + * Indicates whether the specified field holds a valid IP address. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid IP + */ + protected boolean isIpAddress(String field, FieldPresence presence) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + IpAddress.valueOf(node.asText()) != null); + } + + /** + * Indicates whether the specified field holds a valid string value. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param pattern optional regex pattern + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid MAC + */ + protected boolean isString(String field, FieldPresence presence, String... pattern) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + (pattern.length > 0 && node.asText().matches(pattern[0]) || pattern.length < 1)); + } + + /** + * Indicates whether the specified field holds a valid number. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param minMax optional min/max values + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid + */ + protected boolean isNumber(String field, FieldPresence presence, long... minMax) { + JsonNode node = object.path(field); + return isValid(node, presence, (node.isLong() || node.isInt()) && + (minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) && + (minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2)); + } + + /** + * Indicates whether the specified field holds a valid decimal number. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param minMax optional min/max values + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid + */ + protected boolean isDecimal(String field, FieldPresence presence, double... minMax) { + JsonNode node = object.path(field); + return isValid(node, presence, (node.isDouble() || node.isFloat()) && + (minMax.length > 0 && minMax[0] <= node.asDouble() || minMax.length < 1) && + (minMax.length > 1 && minMax[1] > node.asDouble() || minMax.length < 2)); + } + + /** + * Indicates whether the node is present and of correct value or not + * mandatory and absent. + * + * @param node JSON node + * @param presence specifies if field is optional or mandatory + * @param correctValue true if the value is correct + * @return true if the field is as expected + */ + private boolean isValid(JsonNode node, FieldPresence presence, boolean correctValue) { + boolean isMandatory = presence == FieldPresence.MANDATORY; + return isMandatory && correctValue || !isMandatory && !node.isNull() || correctValue; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java index 8eb69a45..f1b22c41 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java @@ -119,7 +119,7 @@ public interface NetworkConfigService /** * Applies configuration for the specified subject and configuration - * class using the raw JSON object. If configuration already exists, it + * class using the raw JSON node. If configuration already exists, it * will be updated. * * @param subject configuration subject @@ -128,6 +128,8 @@ public interface NetworkConfigService * @param <S> type of subject * @param <C> type of configuration * @return configuration or null if one is not available + * @throws IllegalArgumentException if the supplied JSON node contains + * invalid data */ <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java index 9dd66e8d..9be4b120 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java @@ -113,6 +113,8 @@ public interface NetworkConfigStore extends Store<NetworkConfigEvent, NetworkCon * @param <S> type of subject * @param <C> type of configuration * @return configuration object + * @throws IllegalArgumentException if the supplied JSON node contains + * invalid data */ <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java index 3a8c8c1f..9074792c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java @@ -24,6 +24,7 @@ import java.net.URI; import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import static org.onosproject.net.Device.Type; +import com.google.common.base.Objects; /** * Default implementation of immutable device description entity. @@ -71,7 +72,7 @@ public class DefaultDeviceDescription extends AbstractDescription */ public DefaultDeviceDescription(DeviceDescription base, SparseAnnotations... annotations) { - this(base.deviceURI(), base.type(), base.manufacturer(), + this(base.deviceUri(), base.type(), base.manufacturer(), base.hwVersion(), base.swVersion(), base.serialNumber(), base.chassisId(), annotations); } @@ -83,13 +84,13 @@ public class DefaultDeviceDescription extends AbstractDescription * @param annotations Annotations to use. */ public DefaultDeviceDescription(DeviceDescription base, Type type, SparseAnnotations... annotations) { - this(base.deviceURI(), type, base.manufacturer(), + this(base.deviceUri(), type, base.manufacturer(), base.hwVersion(), base.swVersion(), base.serialNumber(), base.chassisId(), annotations); } @Override - public URI deviceURI() { + public URI deviceUri() { return uri; } @@ -132,6 +133,30 @@ public class DefaultDeviceDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), uri, type, manufacturer, + hwVersion, swVersion, serialNumber, chassisId); + } + + @Override + public boolean equals(Object object) { + if (object instanceof DefaultDeviceDescription) { + if (!super.equals(object)) { + return false; + } + DefaultDeviceDescription that = (DefaultDeviceDescription) object; + return Objects.equal(this.uri, that.uri) + && Objects.equal(this.type, that.type) + && Objects.equal(this.manufacturer, that.manufacturer) + && Objects.equal(this.hwVersion, that.hwVersion) + && Objects.equal(this.swVersion, that.swVersion) + && Objects.equal(this.serialNumber, that.serialNumber) + && Objects.equal(this.chassisId, that.chassisId); + } + return false; + } + // default constructor for serialization private DefaultDeviceDescription() { this.uri = null; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java index 572d201c..d62e932c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java @@ -21,6 +21,7 @@ import org.onosproject.net.PortNumber; import org.onosproject.net.SparseAnnotations; import static org.onosproject.net.Port.Type; +import com.google.common.base.Objects; /** * Default implementation of immutable port description. @@ -117,4 +118,25 @@ public class DefaultPortDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), number, isEnabled, type, + portSpeed); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultPortDescription that = (DefaultPortDescription) object; + return Objects.equal(this.number, that.number) + && Objects.equal(this.isEnabled, that.isEnabled) + && Objects.equal(this.type, that.type) + && Objects.equal(this.portSpeed, that.portSpeed); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java index 64b84b5a..f206b080 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java @@ -33,7 +33,7 @@ public interface DeviceDescription extends Description { * * @return provider specific URI for the device */ - URI deviceURI(); + URI deviceUri(); /** * Returns the type of the infrastructure device. 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 453a7648..a842d600 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 @@ -23,6 +23,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; +import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; @@ -353,6 +354,26 @@ public final class DefaultTrafficSelector implements TrafficSelector { } @Override + public Builder matchArpTpa(Ip4Address addr) { + return add(Criteria.matchArpTpa(addr)); + } + + @Override + public Builder matchArpSpa(Ip4Address addr) { + return add(Criteria.matchArpSpa(addr)); + } + + @Override + public Builder matchArpTha(MacAddress addr) { + return add(Criteria.matchArpTha(addr)); + } + + @Override + public Builder matchArpSha(MacAddress addr) { + return add(Criteria.matchArpSha(addr)); + } + + @Override public TrafficSelector build() { return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values())); } 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 6beeecc9..4615a82b 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 @@ -388,7 +388,12 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { @Override public Builder setQueue(long queueId) { - return add(Instructions.setQueue(queueId)); + return add(Instructions.setQueue(queueId, null)); + } + + @Override + public Builder setQueue(long queueId, PortNumber port) { + return add(Instructions.setQueue(queueId, port)); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java index 1286ffc1..9fe88d5a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java @@ -17,6 +17,7 @@ package org.onosproject.net.flow; import java.util.Set; +import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; @@ -386,6 +387,38 @@ public interface TrafficSelector { Builder matchIPv6ExthdrFlags(short exthdrFlags); /** + * Matches a arp IPv4 destination address. + * + * @param addr a arp IPv4 destination address + * @return a selection builder + */ + Builder matchArpTpa(Ip4Address addr); + + /** + * Matches a arp IPv4 source address. + * + * @param addr a arp IPv4 source address + * @return a selection builder + */ + Builder matchArpSpa(Ip4Address addr); + + /** + * Matches a arp_eth_dst address. + * + * @param addr a arp_eth_dst address + * @return a selection builder + */ + Builder matchArpTha(MacAddress addr); + + /** + * Matches a arp_eth_src address. + * + * @param addr a arp_eth_src address + * @return a selection builder + */ + Builder matchArpSha(MacAddress addr); + + /** * Builds an immutable traffic selector. * * @return traffic selector 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 b14ab99c..f1a676ab 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 @@ -271,6 +271,15 @@ public interface TrafficTreatment { Builder setQueue(long queueId); /** + * Sets the Queue ID for a specific port. + * + * @param queueId a queue ID + * @param port a port number + * @return a treatment builder + */ + Builder setQueue(long queueId, PortNumber port); + + /** * Sets a meter to be used by this flow. * * @param meterId a meter id diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java new file mode 100644 index 00000000..71269dd1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java @@ -0,0 +1,83 @@ +/* + * 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.criteria; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +import org.onlab.packet.MacAddress; + +/** + * Implementation of arp_eth_src address or arp_eth_dst address criterion. + */ +public final class ArpHaCriterion implements Criterion { + private final MacAddress mac; + private final Type type; + + /** + * Constructor. + * + * @param mac the MAC Address to match. + * @param type the match type. Should be one of the following: + * Type.ARP_SHA, Type.ARP_THA + */ + ArpHaCriterion(MacAddress mac, Type type) { + checkNotNull(mac, "mac cannot be null"); + checkNotNull(type, "type cannot be null"); + this.mac = mac; + this.type = type; + } + + @Override + public Type type() { + return this.type; + } + + /** + * Gets the MAC Address to match. + * + * @return the MAC Address to match + */ + public MacAddress mac() { + return this.mac; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("mac", mac).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), mac); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ArpHaCriterion) { + ArpHaCriterion that = (ArpHaCriterion) obj; + return Objects.equals(mac, that.mac) && + Objects.equals(type, that.type); + } + return false; + } +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java index 778d50a5..554b8e74 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java @@ -510,15 +510,45 @@ public final class Criteria { } /** - * Creates a match on IPv4 source field using the specified value. + * Creates a match on IPv4 destination field using the specified value. * - * @param ip ipv4 source value + * @param ip ipv4 destination value * @return match criterion */ public static Criterion matchArpTpa(Ip4Address ip) { return new ArpPaCriterion(ip, Type.ARP_TPA); } + /** + * Creates a match on IPv4 source field using the specified value. + * + * @param ip ipv4 source value + * @return match criterion + */ + public static Criterion matchArpSpa(Ip4Address ip) { + return new ArpPaCriterion(ip, Type.ARP_SPA); + } + + /** + * Creates a match on MAC destination field using the specified value. + * + * @param mac MAC destination value + * @return match criterion + */ + public static Criterion matchArpTha(MacAddress mac) { + return new ArpHaCriterion(mac, Type.ARP_THA); + } + + /** + * Creates a match on MAC source field using the specified value. + * + * @param mac MAC source value + * @return match criterion + */ + public static Criterion matchArpSha(MacAddress mac) { + return new ArpHaCriterion(mac, Type.ARP_SHA); + } + public static Criterion dummy() { return new DummyCriterion(); } 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 index 747a85b5..3e1cb75c 100644 --- 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 @@ -32,7 +32,8 @@ public final class ExtensionType { */ public enum ExtensionTypes { // TODO fix type numbers to include experimenter id - NICIRA_SET_TUNNEL_DST(31); + NICIRA_SET_TUNNEL_DST(31), + NICIRA_RESUBMIT(32); private ExtensionType type; 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 aad407c8..126e722e 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 @@ -15,6 +15,7 @@ */ package org.onosproject.net.flow.instructions; +import com.google.common.base.MoreObjects; import org.onlab.packet.EthType; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; @@ -99,11 +100,12 @@ public final class Instructions { * Creates a set-queue instruction. * * @param queueId Queue Id + * @param port Port number * @return set-queue instruction */ - public static SetQueueInstruction setQueue(final long queueId) { + public static SetQueueInstruction setQueue(final long queueId, final PortNumber port) { checkNotNull(queueId, "queue ID cannot be null"); - return new SetQueueInstruction(queueId); + return new SetQueueInstruction(queueId, port); } public static MeterInstruction meterTraffic(final MeterId meterId) { @@ -514,7 +516,7 @@ public final class Instructions { @Override public int hashCode() { - return Objects.hash(type().ordinal()); + return type().ordinal(); } @Override @@ -548,7 +550,7 @@ public final class Instructions { @Override public int hashCode() { - return Objects.hash(type().ordinal()); + return type().ordinal(); } @Override @@ -628,7 +630,8 @@ public final class Instructions { @Override public String toString() { return toStringHelper(type().toString()) - .add("group ID", groupId.id()).toString(); + .addValue("group ID=0x" + Integer.toHexString(groupId.id())) + .toString(); } @Override @@ -655,15 +658,26 @@ public final class Instructions { */ public static final class SetQueueInstruction implements Instruction { private final long queueId; + private final PortNumber port; private SetQueueInstruction(long queueId) { this.queueId = queueId; + this.port = null; + } + + private SetQueueInstruction(long queueId, PortNumber port) { + this.queueId = queueId; + this.port = port; } public long queueId() { return queueId; } + public PortNumber port() { + return port; + } + @Override public Type type() { return Type.QUEUE; @@ -671,13 +685,18 @@ public final class Instructions { @Override public String toString() { - return toStringHelper(type().toString()) - .add("queueId", queueId).toString(); + MoreObjects.ToStringHelper toStringHelper = toStringHelper(type().toString()); + toStringHelper.add("queueId", queueId); + + if (port() != null) { + toStringHelper.add("port", port); + } + return toStringHelper.toString(); } @Override public int hashCode() { - return Objects.hash(type().ordinal(), queueId); + return Objects.hash(type().ordinal(), queueId, port); } @Override @@ -687,7 +706,7 @@ public final class Instructions { } if (obj instanceof SetQueueInstruction) { SetQueueInstruction that = (SetQueueInstruction) obj; - return Objects.equals(queueId, that.queueId); + return Objects.equals(queueId, that.queueId) && Objects.equals(port, that.port); } return false; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java index a6e5903c..4af3d168 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java @@ -114,7 +114,7 @@ public abstract class L0ModificationInstruction implements Instruction { @Override public int hashCode() { - return Objects.hash(lambda); + return lambda.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java index c6847d1c..b72dd7bc 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java @@ -62,7 +62,7 @@ public abstract class L1ModificationInstruction implements Instruction { @Override public int hashCode() { - return Objects.hash(oduSignalId); + return oduSignalId.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java index 546a4513..97f8aedf 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java @@ -186,7 +186,7 @@ public class DefaultGroup extends DefaultGroupDescription */ @Override public int hashCode() { - return super.hashCode() + Objects.hash(id); + return Objects.hash(super.hashCode(), id); } /* diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java index 1f05197a..307a6078 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java @@ -28,6 +28,7 @@ import org.onlab.packet.VlanId; import com.google.common.collect.ImmutableSet; import static com.google.common.base.MoreObjects.toStringHelper; +import com.google.common.base.Objects; /** * Default implementation of an immutable host description. @@ -119,4 +120,24 @@ public class DefaultHostDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), mac, vlan, location, ip); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultHostDescription that = (DefaultHostDescription) object; + return Objects.equal(this.mac, that.mac) + && Objects.equal(this.vlan, that.vlan) + && Objects.equal(this.location, that.location) + && Objects.equal(this.ip, that.ip); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java index 98329df0..92824cf8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java @@ -15,9 +15,12 @@ */ package org.onosproject.net.host; +import org.joda.time.LocalDateTime; import org.onosproject.event.AbstractEvent; import org.onosproject.net.Host; +import static com.google.common.base.MoreObjects.toStringHelper; + /** * Describes end-station host event. */ @@ -48,6 +51,8 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { HOST_MOVED } + private Host prevSubject; + /** * Creates an event of a given type and for the specified host and the * current time. @@ -70,4 +75,39 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { super(type, host, time); } + /** + * Creates an event with previous subject. + * + * The previous subject is ignored if the type is not moved or updated + * + * @param type host event type + * @param host event host subject + * @param prevSubject previous host subject + */ + public HostEvent(Type type, Host host, Host prevSubject) { + super(type, host); + if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED) { + this.prevSubject = prevSubject; + } + } + + /** + * Gets the previous subject in this host event. + * + * @return the previous subject, or null if previous subject is not + * specified. + */ + public Host prevSubject() { + return this.prevSubject; + } + + @Override + public String toString() { + return toStringHelper(this) + .add("time", new LocalDateTime(time())) + .add("type", type()) + .add("subject", subject()) + .add("prevSubject", prevSubject()) + .toString(); + } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java index caa5fbb9..4548c44d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java @@ -42,6 +42,7 @@ public final class MplsPathIntent extends PathIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -51,11 +52,11 @@ public final class MplsPathIntent extends PathIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException {@code path} is null */ - private MplsPathIntent(ApplicationId appId, TrafficSelector selector, + private MplsPathIntent(ApplicationId appId, Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, Optional<MplsLabel> egressLabel, List<Constraint> constraints, int priority) { - super(appId, selector, treatment, path, constraints, + super(appId, key, selector, treatment, path, constraints, priority); this.ingressLabel = checkNotNull(ingressLabel); @@ -149,6 +150,7 @@ public final class MplsPathIntent extends PathIntent { return new MplsPathIntent( appId, + key, selector, treatment, path, diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java index 0c831fd5..9bf137a1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java @@ -42,6 +42,7 @@ public class PathIntent extends ConnectivityIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -50,12 +51,13 @@ public class PathIntent extends ConnectivityIntent { * @throws NullPointerException {@code path} is null */ protected PathIntent(ApplicationId appId, + Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, List<Constraint> constraints, int priority) { - super(appId, null, resources(path.links()), selector, treatment, constraints, + super(appId, key, resources(path.links()), selector, treatment, constraints, priority); PathIntent.validate(path.links()); this.path = path; @@ -138,6 +140,7 @@ public class PathIntent extends ConnectivityIntent { return new PathIntent( appId, + key, selector, treatment, path, @@ -184,6 +187,7 @@ public class PathIntent extends ConnectivityIntent { public String toString() { return MoreObjects.toStringHelper(getClass()) .add("id", id()) + .add("key", key()) .add("appId", appId()) .add("priority", priority()) .add("resources", resources()) 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 20ccb55d..444feee4 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 @@ -87,7 +87,7 @@ public final class BandwidthConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java index 9dd813b2..7811a004 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java @@ -69,7 +69,7 @@ public class LambdaConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(lambda); + return Objects.hashCode(lambda); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java index 54eb4ea5..aecef879 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java @@ -67,7 +67,7 @@ public class LatencyConstraint implements Constraint { @Override public int hashCode() { - return Objects.hash(latency); + return latency.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java index cb1e6b2b..ca4f3fd3 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java @@ -66,7 +66,7 @@ public class ObstacleConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(obstacles); + return obstacles.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java index 1acf6dfe..4839feec 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java @@ -91,7 +91,7 @@ public class WaypointConstraint implements Constraint { @Override public int hashCode() { - return Objects.hash(waypoints); + return waypoints.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java index 891eb65d..cba17640 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java @@ -20,6 +20,7 @@ import org.onosproject.net.AbstractDescription; import org.onosproject.net.ConnectPoint; import org.onosproject.net.Link; import org.onosproject.net.SparseAnnotations; +import com.google.common.base.Objects; /** * Default implementation of immutable link description entity. @@ -70,4 +71,23 @@ public class DefaultLinkDescription extends AbstractDescription .add("type", type()).toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), src, dst, type); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultLinkDescription that = (DefaultLinkDescription) object; + return Objects.equal(this.src, that.src) + && Objects.equal(this.dst, that.dst) + && Objects.equal(this.type, that.type); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java index e94ee452..cdcd4072 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java @@ -26,7 +26,7 @@ import java.util.List; @Beta public interface ResourceAdminService { /** - * Register resources as the children of the parent resource path. + * Registers resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are registered * @param children resources to be registered as the children of the parent @@ -39,7 +39,7 @@ public interface ResourceAdminService { } /** - * Register resources as the children of the parent resource path. + * Registers resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are registered * @param children resources to be registered as the children of the parent @@ -50,7 +50,7 @@ public interface ResourceAdminService { <T> boolean registerResources(ResourcePath parent, List<T> children); /** - * Unregister resources as the children of the parent resource path. + * Unregisters resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are unregistered * @param children resources to be unregistered as the children of the parent @@ -63,7 +63,7 @@ public interface ResourceAdminService { } /** - * Unregister resources as the children of the parent resource path. + * Unregisters resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are unregistered * @param children resources to be unregistered as the children of the parent diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java new file mode 100644 index 00000000..98abf301 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java @@ -0,0 +1,54 @@ +/* + * 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.newresource; + +import com.google.common.annotations.Beta; +import org.onosproject.event.AbstractEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Describes an event related to a resource. + */ +@Beta +public final class ResourceEvent extends AbstractEvent<ResourceEvent.Type, ResourcePath> { + + /** + * Type of resource events. + */ + @Beta + public enum Type { + /** + * Signifies that a new resource has been detected. + */ + RESOURCE_ADDED, + + /** + * Signifies that a resource has been removed. + */ + RESOURCE_REMOVED + } + + /** + * Create a resource event. + * + * @param type type of resource event + * @param subject subject of resource event + */ + public ResourceEvent(Type type, ResourcePath subject) { + super(checkNotNull(type), checkNotNull(subject)); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java new file mode 100644 index 00000000..3f871900 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java @@ -0,0 +1,26 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.net.newresource; + +import com.google.common.annotations.Beta; +import org.onosproject.event.EventListener; + +/** + * Entity capable of receiving resource related events. + */ +@Beta +public interface ResourceListener extends EventListener<ResourceEvent> { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java index 3aa29f6b..d87682a9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java @@ -19,12 +19,14 @@ import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; -import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Optional; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; /** * An object that is used to locate a resource in a network. @@ -32,32 +34,45 @@ import static com.google.common.base.Preconditions.checkNotNull; * of elementary resources that are not globally identifiable. A ResourcePath can be a globally * unique resource identifier. * + * Two types of resource are considered. One is discrete type and the other is continuous type. + * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and + * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose + * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. + * A double value is associated with a continuous type value. + * * Users of this class must keep the semantics of resources regarding the hierarchical structure. * For example, resource path, Link:1/VLAN ID:100, is valid, but resource path, VLAN ID:100/Link:1 * is not valid because a link is not a sub-component of a VLAN ID. */ @Beta -public final class ResourcePath { +public abstract class ResourcePath { - private final List<Object> resources; + private final Discrete parent; + private final Object last; - public static final ResourcePath ROOT = new ResourcePath(ImmutableList.of()); + public static final Discrete ROOT = new Discrete(); - public static ResourcePath child(ResourcePath parent, Object child) { - ImmutableList<Object> components = ImmutableList.builder() - .addAll(parent.components()) - .add(child) - .build(); - return new ResourcePath(components); + /** + * Creates an resource path which represents a discrete-type resource from the specified components. + * + * @param components components of the path. The order represents hierarchical structure of the resource. + */ + public static ResourcePath discrete(Object... components) { + if (components.length == 0) { + return ROOT; + } else { + return new Discrete(ImmutableList.copyOf(components)); + } } /** - * Creates an resource path from the specified components. + * Creates an resource path which represents a continuous-type resource from the specified components. * + * @param value amount of the resource * @param components components of the path. The order represents hierarchical structure of the resource. */ - public ResourcePath(Object... components) { - this(Arrays.asList(components)); + public static ResourcePath continuous(double value, Object... components) { + return new Continuous(ImmutableList.copyOf(components), value); } /** @@ -65,15 +80,37 @@ public final class ResourcePath { * * @param components components of the path. The order represents hierarchical structure of the resource. */ - public ResourcePath(List<Object> components) { + ResourcePath(List<Object> components) { checkNotNull(components); + checkArgument(!components.isEmpty()); + + LinkedList<Object> children = new LinkedList<>(components); + this.last = children.pollLast(); + if (children.isEmpty()) { + this.parent = ROOT; + } else { + this.parent = new Discrete(children); + } + } - this.resources = ImmutableList.copyOf(components); + /** + * Creates an resource path from the specified parent and child. + * + * @param parent the parent of this resource + * @param last a child of the parent + */ + ResourcePath(Discrete parent, Object last) { + checkNotNull(parent); + checkNotNull(last); + + this.parent = parent; + this.last = last; } // for serialization private ResourcePath() { - this.resources = null; + this.parent = null; + this.last = null; } /** @@ -82,7 +119,15 @@ public final class ResourcePath { * @return the components of this resource path */ public List<Object> components() { - return resources; + LinkedList<Object> components = new LinkedList<>(); + + ResourcePath current = this; + while (current.parent().isPresent()) { + components.addFirst(current.last); + current = current.parent; + } + + return components; } /** @@ -92,21 +137,20 @@ public final class ResourcePath { * @return the parent resource path of this instance. * If there is no parent, empty instance will be returned. */ - public Optional<ResourcePath> parent() { - if (!isRoot()) { - return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1))); - } + public Optional<Discrete> parent() { + return Optional.ofNullable(parent); + } + + public ResourcePath child(Object child) { + checkState(this instanceof Discrete); - return Optional.empty(); + return new Discrete((Discrete) this, child); } - /** - * Returns true if the path represents root. - * - * @return true if the path represents root, false otherwise. - */ - public boolean isRoot() { - return resources.size() == 0; + public ResourcePath child(Object child, double value) { + checkState(this instanceof Discrete); + + return new Continuous((Discrete) this, child, value); } /** @@ -115,14 +159,13 @@ public final class ResourcePath { * @return the last component of this instance. * The return value is equal to the last object of {@code components()}. */ - public Object lastComponent() { - int last = resources.size() - 1; - return resources.get(last); + public Object last() { + return last; } @Override public int hashCode() { - return resources.hashCode(); + return Objects.hash(this.parent, this.last); } @Override @@ -134,13 +177,68 @@ public final class ResourcePath { return false; } final ResourcePath that = (ResourcePath) obj; - return Objects.equals(this.resources, that.resources); + return Objects.equals(this.parent, that.parent) + && Objects.equals(this.last, that.last); } @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("resources", resources) + .add("parent", parent) + .add("last", last) .toString(); } + + /** + * Represents a resource path which specifies a resource which can be measured + * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource. + * <p> + * Note: This class is exposed to the public, but intended to be used in the resource API + * implementation only. It is not for resource API user. + * </p> + */ + public static final class Discrete extends ResourcePath { + private Discrete() { + super(); + } + + private Discrete(List<Object> components) { + super(components); + } + + private Discrete(Discrete parent, Object last) { + super(parent, last); + } + } + + /** + * Represents a resource path which specifies a resource which can be measured + * as continuous value. Bandwidth of a link is an example of the resource. + * <p> + * Note: This class is exposed to the public, but intended to be used in the resource API + * implementation only. It is not for resource API user. + */ + public static final class Continuous extends ResourcePath { + // Note: value is not taken into account for equality + private final double value; + + private Continuous(List<Object> components, double value) { + super(components); + this.value = value; + } + + public Continuous(Discrete parent, Object last, double value) { + super(parent, last); + this.value = value; + } + + /** + * Returns the value of the resource amount. + * + * @return the value of the resource amount + */ + public double value() { + return value; + } + } } 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 ad684c8c..966de500 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 @@ -17,6 +17,7 @@ package org.onosproject.net.newresource; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; +import org.onosproject.event.ListenerService; import java.util.Arrays; import java.util.Collection; @@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability. */ @Beta -public interface ResourceService { +public interface ResourceService extends ListenerService<ResourceEvent, ResourceListener> { /** * Allocates the specified resource to the specified user. * 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 2cab9d4b..7c67430e 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 @@ -16,6 +16,7 @@ package org.onosproject.net.newresource; import com.google.common.annotations.Beta; +import org.onosproject.store.Store; import java.util.Collection; import java.util.List; @@ -25,7 +26,7 @@ import java.util.Optional; * Service for storing resource and consumer information. */ @Beta -public interface ResourceStore { +public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegate> { /** * Registers the resources in transactional way. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java new file mode 100644 index 00000000..a0b9bb25 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.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.net.newresource; + +import org.onosproject.store.StoreDelegate; + +/** + * Resource store delegate abstraction. + */ +public interface ResourceStoreDelegate extends StoreDelegate<ResourceEvent> { +} 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 0bfb3795..d3bd2d7b 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 @@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of bandwidth resource in bps. + * + * @deprecated in Emu Release */ +@Deprecated public final class BandwidthResource implements LinkResource { private final Bandwidth bandwidth; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java index 74f6e102..5f36d5f8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java @@ -23,7 +23,10 @@ import java.util.Objects; /** * Representation of allocated bandwidth resource. + * + * @deprecated in Emu Release */ +@Deprecated public class BandwidthResourceAllocation implements ResourceAllocation { private final BandwidthResource bandwidth; @@ -53,7 +56,7 @@ public class BandwidthResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java index e07309cb..ff26e81e 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java @@ -23,7 +23,10 @@ import org.onosproject.net.resource.ResourceType; /** * Representation of a request for bandwidth resource. + * + * @deprecated in Emu Release */ +@Deprecated public class BandwidthResourceRequest implements ResourceRequest { private final BandwidthResource bandwidth; @@ -53,7 +56,7 @@ public class BandwidthResourceRequest implements ResourceRequest { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java index 379bf71e..2fa4fa6b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java @@ -36,7 +36,10 @@ import java.util.Set; /** * Implementation of {@link LinkResourceAllocations}. + * + * @deprecated in Emu Release */ +@Deprecated public class DefaultLinkResourceAllocations implements LinkResourceAllocations { private final LinkResourceRequest request; // TODO: probably should be using LinkKey instead 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 f8e143a4..b57465f2 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 @@ -39,7 +39,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Implementation of {@link LinkResourceRequest}. + * + * @deprecated in Emu Release */ +@Deprecated public final class DefaultLinkResourceRequest implements LinkResourceRequest { private final IntentId intentId; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java index 3733e467..06582497 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java @@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class LambdaResource implements LinkResource { private final IndexedLambda lambda; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java index 545f025f..930a6b27 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java @@ -23,7 +23,10 @@ import java.util.Objects; /** * Representation of allocated lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class LambdaResourceAllocation implements ResourceAllocation { private final LambdaResource lambda; @@ -53,7 +56,7 @@ public class LambdaResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(lambda); + return Objects.hashCode(lambda); } @Override 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 d264d5e5..24d3d78d 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 @@ -24,7 +24,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of a request for lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class LambdaResourceRequest implements ResourceRequest { private final LambdaResource lambda; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java index ec06611e..b06f16bf 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java @@ -17,6 +17,9 @@ package org.onosproject.net.resource.link; /** * Abstraction of link resource. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResource { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java index 7828867c..d0211e26 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java @@ -25,7 +25,10 @@ import org.onosproject.net.resource.ResourceRequest; /** * Representation of allocated link resources. + * + * @deprecated */ +@Deprecated public interface LinkResourceAllocations extends ResourceAllocation { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java index 3edb386a..a3702923 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java @@ -23,7 +23,10 @@ import com.google.common.collect.ImmutableList; /** * Describes an event related to a Link Resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class LinkResourceEvent extends AbstractEvent<LinkResourceEvent.Type, Collection<LinkResourceAllocations>> { diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java index 599dd4fb..bbb02e2f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java @@ -19,6 +19,9 @@ import org.onosproject.event.EventListener; /** * Entity for receiving link resource events. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceListener extends EventListener<LinkResourceEvent> { } 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 37622e79..9774e8e7 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 @@ -27,7 +27,10 @@ import org.onosproject.net.resource.ResourceRequest; /** * Representation of a request for link resource. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceRequest extends ResourceRequest { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java index e6674dbd..e8a295c2 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java @@ -23,7 +23,10 @@ import org.onosproject.net.resource.ResourceAllocation; /** * Manages link resources. + * + * @deprecated in Emu Release. */ +@Deprecated public interface LinkResourceStore { /** * Returns free resources for given link. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java index 6c051d6a..dbfb3b04 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java @@ -19,6 +19,9 @@ import org.onosproject.store.StoreDelegate; /** * Link resource store delegate abstraction. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceStoreDelegate extends StoreDelegate<LinkResourceEvent> { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java index dc005227..46450427 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java @@ -19,7 +19,10 @@ import java.util.Set; /** * Abstraction of a resources of a link. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResources { /** @@ -31,7 +34,10 @@ public interface LinkResources { /** * Builder of {@link LinkResources}. + * + * @deprecated in Emu Release */ + @Deprecated interface Builder { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java index 89c87760..5138d02c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java @@ -20,7 +20,10 @@ import java.util.Objects; /** * Representation of MPLS label resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class MplsLabel implements LinkResource { private final org.onlab.packet.MplsLabel mplsLabel; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java index 10911539..7441bee9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java @@ -24,7 +24,10 @@ import java.util.Objects; /** * Representation of allocated MPLS label resource. + * + * @deprecated in Emu Release */ +@Deprecated public class MplsLabelResourceAllocation implements ResourceAllocation { private final MplsLabel mplsLabel; @@ -54,7 +57,7 @@ public class MplsLabelResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(mplsLabel); + return Objects.hashCode(mplsLabel); } @Override 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 01a048b7..5b9c4a0a 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 @@ -24,7 +24,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of a request for lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class MplsLabelResourceRequest implements ResourceRequest { private final MplsLabel mplsLabel; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java index b10e4ba4..f374d778 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java @@ -17,5 +17,11 @@ /** * Services for reserving links and their capacity as network resources, * e.g. bandwidth, lambdas. + * <p> + * Note: Classes under the package will be remove. + * Developers should not use the classes. + * This package is marked as deprecated in Emu Release. + * </p> */ +@Deprecated package org.onosproject.net.resource.link; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java index e676fc87..a05dfda1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java @@ -16,5 +16,9 @@ /** * Abstractions for reserving network resources. + * <p> + * Note: Classes under the package will be removed. + * Developers should not use the classes. + * </p> */ package org.onosproject.net.resource; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java index 676f0068..1e6780fa 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java @@ -53,7 +53,7 @@ public final class ClusterId { @Override public int hashCode() { - return Objects.hash(id); + return id; } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java index dacb5fd8..99d700e1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java @@ -20,6 +20,7 @@ import org.onosproject.net.Link; import java.util.Objects; import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; /** * Implementation of the topology edge backed by a link. @@ -40,7 +41,7 @@ public class DefaultTopologyEdge implements TopologyEdge { public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) { this.src = src; this.dst = dst; - this.link = link; + this.link = checkNotNull(link); } @Override @@ -60,7 +61,7 @@ public class DefaultTopologyEdge implements TopologyEdge { @Override public int hashCode() { - return Objects.hash(link); + return link.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java index 07a09cbd..4782bc95 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java @@ -42,7 +42,7 @@ public class DefaultTopologyVertex implements TopologyVertex { @Override public int hashCode() { - return Objects.hash(deviceId); + return deviceId.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java index 0cc7b453..4be7ede7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java @@ -52,7 +52,7 @@ public class WallClockTimestamp implements Timestamp { } @Override public int hashCode() { - return Objects.hash(unixTimestamp); + return Long.hashCode(unixTimestamp); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java index 2b8b7fa2..c8671159 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java @@ -138,7 +138,7 @@ public class UiView { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java index a165be33..c75eccf9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java @@ -18,7 +18,7 @@ package org.onosproject.ui.topo; import com.google.common.collect.Sets; -import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -28,7 +28,7 @@ import java.util.Set; */ public class PropertyPanel { - private static final DecimalFormat DF0 = new DecimalFormat("#,###"); + private static final NumberFormat NF = NumberFormat.getInstance(); private String title; private String typeId; @@ -49,6 +49,24 @@ public class PropertyPanel { } /** + * Returns a number formatter to use for formatting integer and long + * property values. + * <p> + * This default implementation uses a formatter for the default + * locale. For example: + * <pre> + * Locale.ENGLISH : 1000 -> "1,000" + * Locale.FRENCH : 1000 -> "1 000" + * Locale.GERMAN : 1000 -> "1.000" + * </pre> + * + * @return the number formatter + */ + protected NumberFormat formatter() { + return NF; + } + + /** * Adds an ID field to the panel data, to be included in * the returned JSON data to the client. * @@ -80,7 +98,7 @@ public class PropertyPanel { * @return self, for chaining */ public PropertyPanel addProp(String key, int value) { - properties.add(new Prop(key, DF0.format(value))); + properties.add(new Prop(key, formatter().format(value))); return this; } @@ -92,7 +110,7 @@ public class PropertyPanel { * @return self, for chaining */ public PropertyPanel addProp(String key, long value) { - properties.add(new Prop(key, DF0.format(value))); + properties.add(new Prop(key, formatter().format(value))); return this; } |