From 76dc892491948adae5e5e62cf94448967e8d865b Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Sun, 6 Dec 2015 07:15:03 -0800 Subject: Fixes bad POM file with ONOS commit 8c68536972f63069c263635c9d9f4f31d7f3e9a2 Change-Id: I7adb5a2d3738d53dbc41db7577768b0e7ced5450 Signed-off-by: Ashlee Young --- .../java/org/onosproject/net/AnnotationKeys.java | 18 ++- .../net/DefaultOchSignalComparator.java | 37 +++++ .../java/org/onosproject/net/NshContextHeader.java | 83 +++++++++++ .../java/org/onosproject/net/NshServiceIndex.java | 83 +++++++++++ .../java/org/onosproject/net/NshServicePathId.java | 83 +++++++++++ .../src/main/java/org/onosproject/net/OchPort.java | 4 +- .../main/java/org/onosproject/net/OchSignal.java | 8 +- .../main/java/org/onosproject/net/OduCltPort.java | 2 +- .../src/main/java/org/onosproject/net/OmsPort.java | 2 +- .../net/behaviour/ExtensionSelectorResolver.java | 40 +++++ .../net/behaviour/ExtensionTreatmentResolver.java | 4 +- .../org/onosproject/net/behaviour/LambdaQuery.java | 40 +++++ .../net/config/basics/BasicHostConfig.java | 72 ++++++++- .../net/config/basics/BasicLinkConfig.java | 33 ++++- .../onosproject/net/flow/AbstractExtension.java | 74 ++++++++++ .../net/flow/DefaultTrafficSelector.java | 27 ++-- .../net/flow/DefaultTrafficTreatment.java | 15 ++ .../java/org/onosproject/net/flow/Extension.java | 71 +++++++++ .../org/onosproject/net/flow/TrafficSelector.java | 15 +- .../org/onosproject/net/flow/TrafficTreatment.java | 24 +++ .../onosproject/net/flow/criteria/Criteria.java | 28 ++++ .../onosproject/net/flow/criteria/Criterion.java | 3 + .../net/flow/criteria/ExtensionCriterion.java | 92 ++++++++++++ .../net/flow/criteria/ExtensionSelector.java | 32 ++++ .../net/flow/criteria/ExtensionSelectorType.java | 98 +++++++++++++ .../net/flow/criteria/OduSignalIdCriterion.java | 2 +- .../net/flow/criteria/OduSignalTypeCriterion.java | 2 +- .../net/flow/criteria/PbbIsidCriterion.java | 75 ++++++++++ .../instructions/AbstractExtensionTreatment.java | 71 --------- .../net/flow/instructions/ExtensionTreatment.java | 53 +------ .../flow/instructions/ExtensionTreatmentType.java | 17 ++- .../net/flow/instructions/Instructions.java | 36 +++++ .../instructions/L3ModificationInstruction.java | 162 ++++++++++++++++++++- .../flowobjective/DefaultFilteringObjective.java | 2 +- .../net/flowobjective/DefaultNextObjective.java | 2 +- .../net/flowobjective/FilteringObjective.java | 2 +- .../net/flowobjective/NextObjective.java | 2 +- .../org/onosproject/net/intent/IntentUtils.java | 84 +++++++++++ .../net/mcast/MulticastRouteService.java | 4 +- .../onosproject/net/newresource/ResourcePath.java | 74 ++++++++-- .../net/topology/GeoDistanceLinkWeight.java | 72 +++++++++ .../net/topology/HopCountLinkWeight.java | 36 +++++ .../onosproject/net/topology/MetricLinkWeight.java | 36 +++++ .../onosproject/net/topology/PathAdminService.java | 44 ++++++ .../org/onosproject/net/topology/PathService.java | 36 +++-- .../java/org/onosproject/ui/topo/TopoJson.java | 4 + 46 files changed, 1620 insertions(+), 184 deletions(-) create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/NshContextHeader.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServiceIndex.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServicePathId.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionSelectorResolver.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/LambdaQuery.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/AbstractExtension.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Extension.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionCriterion.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelector.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelectorType.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/PbbIsidCriterion.java delete mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/IntentUtils.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/GeoDistanceLinkWeight.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/HopCountLinkWeight.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/MetricLinkWeight.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathAdminService.java (limited to 'framework/src/onos/core/api/src/main/java/org') diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java index 8c5fb790..38b599de 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java @@ -25,7 +25,6 @@ package org.onosproject.net; */ public final class AnnotationKeys { - // Prohibit instantiation private AnnotationKeys() { } @@ -80,6 +79,12 @@ public final class AnnotationKeys { */ public static final String DURABLE = "durable"; + /** + * Annotation key for link metric; used by + * {@link org.onosproject.net.topology.MetricLinkWeight} function. + */ + public static final String METRIC = "metric"; + /** * Annotation key for latency. * @@ -107,13 +112,24 @@ public final class AnnotationKeys { */ public static final String PORT_NAME = "portName"; + /** + * Annotation key for the port mac. + */ + public static final String PORT_MAC = "portMac"; + /** * Annotation key for the router ID. */ public static final String ROUTER_ID = "routerId"; + /** + * Annotation key for the static lambda. + */ public static final String STATIC_LAMBDA = "staticLambda"; + /** + * Annotation key for the static port. + */ public static final String STATIC_PORT = "staticPort"; /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java new file mode 100644 index 00000000..e605dcfd --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultOchSignalComparator.java @@ -0,0 +1,37 @@ +/* + * 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; + +import java.util.Comparator; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Comparator implementation for OchSignal. Assumes identical grid type and channel spacing. + */ +public class DefaultOchSignalComparator implements Comparator { + @Override + public int compare(OchSignal o1, OchSignal o2) { + checkNotNull(o1.gridType()); + checkNotNull(o1.channelSpacing()); + + checkArgument(o1.gridType().equals(o2.gridType())); + checkArgument(o1.channelSpacing().equals(o2.channelSpacing())); + + return o1.spacingMultiplier() * o1.slotGranularity() - o2.spacingMultiplier() * o2.slotGranularity(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshContextHeader.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshContextHeader.java new file mode 100644 index 00000000..745b616f --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshContextHeader.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; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; + +/* + * Representation of NSH context header value + */ +public final class NshContextHeader { + + private final int nshContextHeader; + + /** + * Default constructor. + * + * @param nshContextHeader nsh context header value. + */ + private NshContextHeader(int nshContextHeader) { + this.nshContextHeader = nshContextHeader; + } + + /** + * Returns the NshContextHeader by setting its value. + * + * @param nshContextHeader nsh context header value. + * @return NshContextHeader + */ + public static NshContextHeader of(int nshContextHeader) { + return new NshContextHeader(nshContextHeader); + } + + + /** + * Returns nsh context header value. + * + * @return the nsh context header + */ + public int nshContextHeader() { + return nshContextHeader; + } + + + @Override + public int hashCode() { + return Objects.hash(nshContextHeader); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof NshContextHeader)) { + return false; + } + final NshContextHeader other = (NshContextHeader) obj; + return Objects.equals(this.nshContextHeader, other.nshContextHeader); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("nshContextHeader", nshContextHeader) + .toString(); + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServiceIndex.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServiceIndex.java new file mode 100644 index 00000000..7e0c914c --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServiceIndex.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; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; + +/* + * Representation of NSH Service index + */ +public final class NshServiceIndex { + private static final short MASK = 0xFF; + private final short serviceIndex; + + /** + * Default constructor. + * + * @param serviceIndex nsh service index + */ + private NshServiceIndex(short serviceIndex) { + this.serviceIndex = (short) (serviceIndex & MASK); + } + + /** + * Returns the NshServiceIndex by setting its value. + * + * @param serviceIndex nsh service index + * @return NshServiceIndex + */ + public static NshServiceIndex of(short serviceIndex) { + return new NshServiceIndex(serviceIndex); + } + + + /** + * Returns nsh service index value. + * + * @return the nsh service index + */ + public short serviceIndex() { + return serviceIndex; + } + + + @Override + public int hashCode() { + return Objects.hash(serviceIndex); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof NshServiceIndex)) { + return false; + } + final NshServiceIndex other = (NshServiceIndex) obj; + return Objects.equals(this.serviceIndex, other.serviceIndex); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("serviceIndex", serviceIndex) + .toString(); + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServicePathId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServicePathId.java new file mode 100644 index 00000000..16fbc4e7 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/NshServicePathId.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; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; + +/* + * Representation of NSH Service path Identifier + */ +public final class NshServicePathId { + + private final int servicePathId; + + /** + * Default constructor. + * + * @param servicePathId nsh service path identifier + */ + private NshServicePathId(int servicePathId) { + this.servicePathId = servicePathId; + } + + /** + * Returns the NshServicePathId by setting its value. + * + * @param servicePathId nsh service path identifier + * @return NshServicePathId + */ + public static NshServicePathId of(int servicePathId) { + return new NshServicePathId(servicePathId); + } + + + /** + * Returns nsh context service path identifier. + * + * @return the nsh context service path id + */ + public int servicePathId() { + return servicePathId; + } + + + @Override + public int hashCode() { + return Objects.hash(servicePathId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof NshServicePathId)) { + return false; + } + final NshServicePathId other = (NshServicePathId) obj; + return Objects.equals(this.servicePathId, other.servicePathId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("servicePathId", servicePathId) + .toString(); + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchPort.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchPort.java index eb956f2a..94d4d321 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchPort.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchPort.java @@ -87,7 +87,9 @@ public class OchPort extends DefaultPort { if (this == obj) { return true; } - if (obj instanceof OchPort) { + + // Subclass is considered as a change of identity, hence equals() will return false if class type don't match + if (obj != null && getClass() == obj.getClass()) { final OchPort other = (OchPort) obj; return Objects.equals(this.element().id(), other.element().id()) && Objects.equals(this.number(), other.number()) && diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchSignal.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchSignal.java index 5a5af34a..3adc9086 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchSignal.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OchSignal.java @@ -17,6 +17,7 @@ package org.onosproject.net; import com.google.common.base.MoreObjects; import org.onlab.util.Frequency; +import org.onlab.util.Spectrum; import java.util.Objects; @@ -32,7 +33,6 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class OchSignal implements Lambda { - public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1); public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5); private static final GridType DEFAULT_OCH_GRIDTYPE = GridType.DWDM; private static final ChannelSpacing DEFAULT_CHANNEL_SPACING = ChannelSpacing.CHL_50GHZ; @@ -78,7 +78,7 @@ public class OchSignal implements Lambda { this.gridType = DEFAULT_OCH_GRIDTYPE; this.channelSpacing = DEFAULT_CHANNEL_SPACING; - this.spacingMultiplier = (int) (centerFrequency.subtract(OchSignal.CENTER_FREQUENCY).asHz() / grid.asHz()); + this.spacingMultiplier = (int) (centerFrequency.subtract(Spectrum.CENTER_FREQUENCY).asHz() / grid.asHz()); this.slotGranularity = (int) Math.round((double) grid.asHz() / ChannelSpacing.CHL_12P5GHZ.frequency().asHz()); } @@ -86,7 +86,7 @@ public class OchSignal implements Lambda { this.gridType = DEFAULT_OCH_GRIDTYPE; this.channelSpacing = channelSpacing; this.spacingMultiplier = (int) Math.round((double) centerFrequency. - subtract(OchSignal.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz()); + subtract(Spectrum.CENTER_FREQUENCY).asHz() / channelSpacing().frequency().asHz()); this.slotGranularity = slotGranularity; } @@ -132,7 +132,7 @@ public class OchSignal implements Lambda { * @return frequency in MHz */ public Frequency centralFrequency() { - return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); + return Spectrum.CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); } /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OduCltPort.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OduCltPort.java index e5602f36..f51393a4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OduCltPort.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OduCltPort.java @@ -71,7 +71,7 @@ public class OduCltPort extends DefaultPort { if (this == obj) { return true; } - if (obj instanceof OduCltPort) { + if (obj != null && getClass() == obj.getClass()) { final OduCltPort other = (OduCltPort) obj; return Objects.equals(this.element().id(), other.element().id()) && Objects.equals(this.number(), other.number()) && diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OmsPort.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OmsPort.java index 753834b5..d37fe75d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/OmsPort.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/OmsPort.java @@ -102,7 +102,7 @@ public class OmsPort extends DefaultPort { if (this == obj) { return true; } - if (obj instanceof OmsPort) { + if (obj != null && getClass() == obj.getClass()) { final OmsPort other = (OmsPort) obj; return Objects.equals(this.element().id(), other.element().id()) && Objects.equals(this.number(), other.number()) && diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionSelectorResolver.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionSelectorResolver.java new file mode 100644 index 00000000..d45dd53c --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionSelectorResolver.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.net.behaviour; + +import com.google.common.annotations.Beta; +import org.onosproject.net.driver.HandlerBehaviour; +import org.onosproject.net.flow.criteria.ExtensionSelector; +import org.onosproject.net.flow.criteria.ExtensionSelectorType; + +/** + * Provides access to the extension selectors implemented by this driver. + */ +@Beta +public interface ExtensionSelectorResolver extends HandlerBehaviour { + + /** + * Gets an extension selector instance of the specified type, if supported + * by the driver. + * + * @param type type of extension to get + * @return extension selector + * @throws UnsupportedOperationException if the extension type is not + * supported by this driver + */ + ExtensionSelector getExtensionSelector(ExtensionSelectorType type); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionTreatmentResolver.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionTreatmentResolver.java index 85f0216d..8ca05af3 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionTreatmentResolver.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/ExtensionTreatmentResolver.java @@ -22,13 +22,13 @@ import org.onosproject.net.flow.instructions.ExtensionTreatment; import org.onosproject.net.flow.instructions.ExtensionTreatmentType; /** - * Provides access to the extension implemented by this driver. + * Provides access to the extension treatments implemented by this driver. */ @Beta public interface ExtensionTreatmentResolver extends HandlerBehaviour { /** - * Gets an extension instruction instance of the specified type, if supported + * Gets an extension treatment instance of the specified type, if supported * by the driver. * * @param type type of extension to get diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/LambdaQuery.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/LambdaQuery.java new file mode 100644 index 00000000..e3b1d963 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/LambdaQuery.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.net.behaviour; + +import com.google.common.annotations.Beta; +import org.onosproject.net.OchSignal; +import org.onosproject.net.PortNumber; +import org.onosproject.net.driver.HandlerBehaviour; + +import java.util.SortedSet; + +/** + * A HandlerBehaviour to retrieve available wavelength resources. + */ +@Beta +public interface LambdaQuery extends HandlerBehaviour { + + // Currently returns set of FLEX GridType ochSignal instances + /** + * Returns set of Lambda instances which can be used at the port. + * + * @param port to be checked for the available resources. + * @return Set of OchSignals which can be used at the port. + */ + SortedSet queryLambdas(PortNumber port); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java index 2fe2b2c0..92946312 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicHostConfig.java @@ -15,13 +15,83 @@ */ package org.onosproject.net.config.basics; +import com.fasterxml.jackson.databind.node.ArrayNode; +import org.onlab.packet.IpAddress; +import org.onosproject.net.ConnectPoint; import org.onosproject.net.HostId; +import java.util.HashSet; +import java.util.Set; /** * Basic configuration for network end-station hosts. */ public class BasicHostConfig extends BasicElementConfig { + private static final String IPS = "ips"; + private static final String LOCATION = "location"; - // TODO: determine what aspects of configuration to add for hosts + @Override + public boolean isValid() { + return hasOnlyFields(IPS, LOCATION) && + this.location() != null && + this.ipAddresses() != null; + } + /** + * Gets location of the host. + * + * @return location of the host. Or null if not specified with correct format. + */ + public ConnectPoint location() { + String location = get(LOCATION, null); + + if (location != null) { + try { + return ConnectPoint.deviceConnectPoint(location); + } catch (Exception e) { + return null; + } + } + return null; + } + + /** + * Sets the location of the host. + * + * @param location location of the host. + * @return the config of the host. + */ + public BasicHostConfig setLocation(String location) { + return (BasicHostConfig) setOrClear(LOCATION, location); + } + + /** + * Gets IP addresses of the host. + * + * @return IP addresses of the host. Or null if not specified with correct format. + */ + public Set ipAddresses() { + HashSet ipAddresses = new HashSet<>(); + if (object.has(IPS)) { + ArrayNode ipNodes = (ArrayNode) object.path(IPS); + try { + ipNodes.forEach(ipNode -> { + ipAddresses.add(IpAddress.valueOf(ipNode.asText())); + }); + return ipAddresses; + } catch (Exception e) { + return null; + } + } + return null; + } + + /** + * Sets the IP addresses of the host. + * + * @param ipAddresses IP addresses of the host. + * @return the config of the host. + */ + public BasicHostConfig setIps(Set ipAddresses) { + return (BasicHostConfig) setOrClear(IPS, ipAddresses); + } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java index e962110c..ed807b8f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java @@ -15,22 +15,32 @@ */ package org.onosproject.net.config.basics; +import com.fasterxml.jackson.databind.JsonNode; import org.onosproject.net.Link; import org.onosproject.net.LinkKey; -import com.fasterxml.jackson.databind.JsonNode; import java.time.Duration; +import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL; + /** * Basic configuration for network infrastructure link. */ public class BasicLinkConfig extends AllowedEntityConfig { public static final String TYPE = "type"; + public static final String METRIC = "metric"; public static final String LATENCY = "latency"; public static final String BANDWIDTH = "bandwidth"; public static final String IS_DURABLE = "durable"; + @Override + public boolean isValid() { + return hasOnlyFields(TYPE, METRIC, LATENCY, BANDWIDTH, IS_DURABLE) && + isNumber(METRIC, OPTIONAL) && isNumber(LATENCY, OPTIONAL) && + isNumber(BANDWIDTH, OPTIONAL); + } + /** * Returns the link type. * @@ -50,6 +60,27 @@ public class BasicLinkConfig extends AllowedEntityConfig { return (BasicLinkConfig) setOrClear(TYPE, type); } + /** + * Returns link metric value for use by + * {@link org.onosproject.net.topology.MetricLinkWeight} function. + * + * @return link metric; -1 if not set + */ + public double metric() { + return get(METRIC, -1); + } + + /** + * Sets the link metric for use by + * {@link org.onosproject.net.topology.MetricLinkWeight} function. + * + * @param metric new metric; null to clear + * @return self + */ + public BasicLinkConfig metric(Double metric) { + return (BasicLinkConfig) setOrClear(METRIC, metric); + } + /** * Returns link latency in terms of nanos. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/AbstractExtension.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/AbstractExtension.java new file mode 100644 index 00000000..b48d69ce --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/AbstractExtension.java @@ -0,0 +1,74 @@ +/* + * 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; + +import org.onosproject.net.flow.instructions.ExtensionPropertyException; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract implementation of the set/get property methods of Extension. + */ +public abstract class AbstractExtension implements Extension { + + private static final String INVALID_KEY = "Invalid property key: "; + private static final String INVALID_TYPE = "Given type does not match field type: "; + + @Override + public void setPropertyValue(String key, T value) throws + ExtensionPropertyException { + Class clazz = this.getClass(); + try { + Field field = clazz.getDeclaredField(key); + field.setAccessible(true); + field.set(this, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new ExtensionPropertyException(INVALID_KEY + key); + } + } + + @Override + public T getPropertyValue(String key) throws ExtensionPropertyException { + Class clazz = this.getClass(); + try { + Field field = clazz.getDeclaredField(key); + field.setAccessible(true); + @SuppressWarnings("unchecked") + T result = (T) field.get(this); + return result; + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new ExtensionPropertyException(INVALID_KEY + key); + } catch (ClassCastException e) { + throw new ExtensionPropertyException(INVALID_TYPE + key); + } + } + + @Override + public List getProperties() { + Class clazz = this.getClass(); + + List fields = new ArrayList<>(); + + for (Field field : clazz.getDeclaredFields()) { + fields.add(field.getName()); + } + + return fields; + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java index d3c2449c..0525d8fa 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java @@ -15,14 +15,8 @@ */ package org.onosproject.net.flow; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.TreeSet; - +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; @@ -30,12 +24,19 @@ import org.onlab.packet.MacAddress; import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; +import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; import org.onosproject.net.flow.criteria.Criteria; import org.onosproject.net.flow.criteria.Criterion; +import org.onosproject.net.flow.criteria.ExtensionSelector; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableSet; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; /** * Default traffic selector implementation. @@ -378,6 +379,12 @@ public final class DefaultTrafficSelector implements TrafficSelector { return add(Criteria.matchArpOp(arpOp)); } + @Override + public TrafficSelector.Builder extension(ExtensionSelector extensionSelector, + DeviceId deviceId) { + return add(Criteria.extension(extensionSelector, deviceId)); + } + @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 22bff7dd..40291f57 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 @@ -488,6 +488,21 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { return add(Instructions.modUdpDst(port)); } + @Override + public Builder setArpSpa(IpAddress addr) { + return add(Instructions.modArpSpa(addr)); + } + + @Override + public Builder setArpSha(MacAddress addr) { + return add(Instructions.modArpSha(addr)); + } + + @Override + public Builder setArpOp(short op) { + return add(Instructions.modL3ArpOp(op)); + } + @Override public TrafficTreatment.Builder extension(ExtensionTreatment extension, DeviceId deviceId) { diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Extension.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Extension.java new file mode 100644 index 00000000..1d61542e --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/Extension.java @@ -0,0 +1,71 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.net.flow; + +import org.onosproject.net.flow.instructions.ExtensionPropertyException; + +import java.util.List; + +/** + * An extension to the northbound APIs. + */ +public interface Extension { + + /** + * Sets a property on the extension. + * + * @param key property key + * @param value value to set for the given key + * @param class of the value + * @throws ExtensionPropertyException if the given key is not a valid + * property on this extension + */ + void setPropertyValue(String key, T value) throws ExtensionPropertyException; + + /** + * Gets a property value of an extension. + * + * @param key property key + * @param class of the value + * @return value of the property + * @throws ExtensionPropertyException if the given key is not a valid + * property on this extension + */ + T getPropertyValue(String key) throws ExtensionPropertyException; + + /** + * Gets a list of all properties on the extension. + * + * @return list of properties + */ + List getProperties(); + + /** + * Serialize the extension to a byte array. + * + * @return byte array + */ + byte[] serialize(); + + /** + * Deserialize the extension from a byte array. The properties + * of this object will be overwritten with the data in the byte array. + * + * @param data input byte array + */ + void deserialize(byte[] data); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java index b92281f5..0d055add 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 @@ -15,8 +15,6 @@ */ package org.onosproject.net.flow; -import java.util.Set; - import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; @@ -24,8 +22,12 @@ import org.onlab.packet.MacAddress; import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; +import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; import org.onosproject.net.flow.criteria.Criterion; +import org.onosproject.net.flow.criteria.ExtensionSelector; + +import java.util.Set; /** * Abstraction of a slice of network traffic. @@ -426,6 +428,15 @@ public interface TrafficSelector { */ Builder matchArpOp(int arpOp); + /** + * Uses an extension selector. + * + * @param extensionSelector extension selector + * @param deviceId device ID + * @return a selection builder + */ + Builder extension(ExtensionSelector extensionSelector, DeviceId deviceId); + /** * Builds an immutable 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 06b6ffa0..3e57925d 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 @@ -423,6 +423,30 @@ public interface TrafficTreatment { */ Builder setUdpDst(TpPort port); + /** + * Sets the arp src ip address. + * + * @param addr an ip + * @return a treatment builder + */ + Builder setArpSpa(IpAddress addr); + + /** + * Sets the arp src mac address. + * + * @param addr a macaddress + * @return a treatment builder + */ + Builder setArpSha(MacAddress addr); + + /** + * Sets the arp operation. + * + * @param op the value of arp operation. + * @return a treatment builder. + */ + Builder setArpOp(short op); + /** * Uses an extension treatment. * 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 a28a4ab9..c94b1e02 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 @@ -23,6 +23,7 @@ import org.onlab.packet.MacAddress; import org.onlab.packet.MplsLabel; import org.onlab.packet.TpPort; import org.onlab.packet.VlanId; +import org.onosproject.net.DeviceId; import org.onosproject.net.IndexedLambda; import org.onosproject.net.Lambda; import org.onosproject.net.OchSignal; @@ -579,6 +580,33 @@ public final class Criteria { return new ArpOpCriterion(arpOp, Type.ARP_OP); } + /** + * Creates a match on PBB I-SID field using the specific value. + * + * @param pbbIsid PBB I-SID + * @return match criterion + */ + public static Criterion matchPbbIsid(int pbbIsid) { + return new PbbIsidCriterion(pbbIsid); + } + + /** + * Creates an extension criterion for the specified extension selector. + * + * @param extensionSelector extension selector + * @param deviceId device ID + * @return match criterion + */ + public static Criterion extension(ExtensionSelector extensionSelector, + DeviceId deviceId) { + return new ExtensionCriterion(extensionSelector, deviceId); + } + + /** + * Creates a dummy criterion. + * + * @return match criterion + */ public static Criterion dummy() { return new DummyCriterion(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java index 26665246..17557b9d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criterion.java @@ -177,6 +177,9 @@ public interface Criterion { /** ODU (Optical channel Data Unit) signal type. */ ODU_SIGTYPE, + /** Extension criterion. */ + EXTENSION, + /** An empty criterion. */ DUMMY } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionCriterion.java new file mode 100644 index 00000000..646b4184 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionCriterion.java @@ -0,0 +1,92 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.net.flow.criteria; + +import org.onosproject.net.DeviceId; + +import java.util.Objects; + +import static com.google.common.base.MoreObjects.toStringHelper; + +/** + * Criterion for implementing selector extensions. + */ +public class ExtensionCriterion implements Criterion { + + private final ExtensionSelector extensionSelector; + private final DeviceId deviceId; + + /** + * Constructor. + * + * @param extensionSelector extension selector + */ + public ExtensionCriterion(ExtensionSelector extensionSelector, DeviceId deviceId) { + this.extensionSelector = extensionSelector; + this.deviceId = deviceId; + } + + /** + * Returns the extension selector. + * + * @return extension selector + */ + public ExtensionSelector extensionSelector() { + return extensionSelector; + } + + /** + * Returns the device ID. + * + * @return device ID + */ + public DeviceId deviceId() { + return deviceId; + } + + @Override + public Type type() { + return Type.EXTENSION; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("extensionSelector", extensionSelector.toString()) + .add("deviceId", deviceId) + .toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), extensionSelector, deviceId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExtensionCriterion) { + ExtensionCriterion that = (ExtensionCriterion) obj; + return Objects.equals(extensionSelector, that.extensionSelector) && + Objects.equals(deviceId, that.deviceId) && + Objects.equals(this.type(), that.type()); + } + return false; + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelector.java new file mode 100644 index 00000000..d3cebb37 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelector.java @@ -0,0 +1,32 @@ +/* + * 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 org.onosproject.net.flow.Extension; + +/** + * An extension for the selector API. + */ +public interface ExtensionSelector extends Extension { + + /** + * Gets the type of the extension selector. + * + * @return type + */ + ExtensionSelectorType type(); +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelectorType.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelectorType.java new file mode 100644 index 00000000..fa8f0923 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ExtensionSelectorType.java @@ -0,0 +1,98 @@ +/* + * 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 com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; + +import java.util.Objects; + +/** + * Type of selector extensions. + */ +@Beta +public class ExtensionSelectorType { + + /** + * A list of well-known named extension selector type codes. + * These numbers have no impact on the actual OF type id. + */ + public enum ExtensionSelectorTypes { + NICIRA_MATCH_NSH_SPI(0), + NICIRA_MATCH_NSH_SI(1), + NICIRA_MATCH_NSH_CH1(2), + NICIRA_MATCH_NSH_CH2(3), + NICIRA_MATCH_NSH_CH3(4), + NICIRA_MATCH_NSH_CH4(5); + + + private ExtensionSelectorType type; + + /** + * Creates a new named extension selector type. + * + * @param type type code + */ + ExtensionSelectorTypes(int type) { + this.type = new ExtensionSelectorType(type); + } + + /** + * Gets the extension type object for this named type code. + * + * @return extension type object + */ + public ExtensionSelectorType type() { + return type; + } + } + + private final int type; + + /** + * Creates an extension type with the given int type code. + * + * @param type type code + */ + public ExtensionSelectorType(int type) { + this.type = type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExtensionSelectorType) { + final ExtensionSelectorType that = (ExtensionSelectorType) obj; + return this.type == that.type; + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(ExtensionSelectorType.class) + .add("type", type) + .toString(); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java index cb513397..21018544 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalIdCriterion.java @@ -74,7 +74,7 @@ public final class OduSignalIdCriterion implements Criterion { @Override public String toString() { - return toStringHelper(type().toString()) + return toStringHelper(this) .add("oduSignalId", oduSignalId) .toString(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java index d92880db..f4854339 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/OduSignalTypeCriterion.java @@ -74,7 +74,7 @@ public final class OduSignalTypeCriterion implements Criterion { @Override public String toString() { - return toStringHelper(type().toString()) + return toStringHelper(this) .add("signalType", signalType) .toString(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/PbbIsidCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/PbbIsidCriterion.java new file mode 100644 index 00000000..979aa6bd --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/PbbIsidCriterion.java @@ -0,0 +1,75 @@ +/* + * 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 java.util.Objects; + +import static com.google.common.base.MoreObjects.toStringHelper; + +/** + * Implementation of PBB I-SID criterion (24 bits unsigned integer). + */ +public final class PbbIsidCriterion implements Criterion { + private static final int MASK = 0xfffff; + private final int pbbIsid; // PBB I-SID: 24 bits + + /** + * Constructor. + * + * @param pbbIsid the PBB I-SID to match (24 bits) + */ + PbbIsidCriterion(int pbbIsid) { + this.pbbIsid = pbbIsid & MASK; + } + + @Override + public Criterion.Type type() { + return Criterion.Type.PBB_ISID; + } + + /** + * Gets the PBB I-SID to match. + * + * @return the PBB I-SID to match (24 bits) + */ + public int pbbIsid() { + return this.pbbIsid; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("pbbIsid", Long.toHexString(pbbIsid)).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), pbbIsid); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof PbbIsidCriterion) { + PbbIsidCriterion that = (PbbIsidCriterion) obj; + return Objects.equals(pbbIsid, that.pbbIsid) && + Objects.equals(this.type(), that.type()); + } + return false; + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java deleted file mode 100644 index ac7c771f..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onosproject.net.flow.instructions; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -/** - * Abstract implementation of the set/get property methods of ExtensionInstruction. - */ -public abstract class AbstractExtensionTreatment implements ExtensionTreatment { - - private static final String INVALID_KEY = "Invalid property key: "; - private static final String INVALID_TYPE = "Given type does not match field type: "; - - @Override - public void setPropertyValue(String key, T value) throws ExtensionPropertyException { - Class clazz = this.getClass(); - try { - Field field = clazz.getDeclaredField(key); - field.setAccessible(true); - field.set(this, value); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new ExtensionPropertyException(INVALID_KEY + key); - } - } - - @Override - public T getPropertyValue(String key) throws ExtensionPropertyException { - Class clazz = this.getClass(); - try { - Field field = clazz.getDeclaredField(key); - field.setAccessible(true); - @SuppressWarnings("unchecked") - T result = (T) field.get(this); - return result; - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new ExtensionPropertyException(INVALID_KEY + key); - } catch (ClassCastException e) { - throw new ExtensionPropertyException(INVALID_TYPE + key); - } - } - - @Override - public List getProperties() { - Class clazz = this.getClass(); - - List fields = new ArrayList<>(); - - for (Field field : clazz.getDeclaredFields()) { - fields.add(field.getName()); - } - - return fields; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java index 0e8885ed..3df152e9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java @@ -16,63 +16,18 @@ package org.onosproject.net.flow.instructions; -import java.util.List; +import org.onosproject.net.flow.Extension; /** - * An extensible instruction type. + * An extension for the treatment API. */ -public interface ExtensionTreatment { +public interface ExtensionTreatment extends Extension { /** - * Gets the type of the extension instruction. + * Gets the type of the treatment extension. * * @return type */ ExtensionTreatmentType type(); - /** - * Sets a property on the extension instruction. - * - * @param key property key - * @param value value to set for the given key - * @param class of the value - * @throws ExtensionPropertyException if the given key is not a valid - * property on this extension instruction - */ - void setPropertyValue(String key, T value) throws ExtensionPropertyException; - - /** - * Gets a property value of an extension instruction. - * - * @param key property key - * @param class of the value - * @return value of the property - * @throws ExtensionPropertyException if the given key is not a valid - * property on this extension instruction - */ - T getPropertyValue(String key) throws ExtensionPropertyException; - - /** - * Gets a list of all properties on the extension instruction. - * - * @return list of properties - */ - List getProperties(); - - /** - * Serialize the extension instruction to a byte array. - * - * @return byte array - */ - byte[] serialize(); - - /** - * Deserialize the extension instruction from a byte array. The properties - * of this object will be overwritten with the data in the byte array. - * - * @param data input byte array - */ - void deserialize(byte[] data); - - } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java index 38fbc279..f597a46c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java @@ -22,7 +22,7 @@ import com.google.common.base.MoreObjects; import java.util.Objects; /** - * Type of extension instructions. + * Type of treatment extensions. */ @Beta public final class ExtensionTreatmentType { @@ -32,15 +32,24 @@ public final class ExtensionTreatmentType { * These numbers have no impact on the actual OF type id. */ public enum ExtensionTreatmentTypes { - // TODO fix type numbers to include experimenter id NICIRA_SET_TUNNEL_DST(0), NICIRA_RESUBMIT(1), - NICIRA_SET_NSH_SPI(32); + NICIRA_RESUBMIT_TABLE(14), + NICIRA_SET_NSH_SPI(32), + NICIRA_SET_NSH_SI(33), + NICIRA_SET_NSH_CH1(34), + NICIRA_SET_NSH_CH2(35), + NICIRA_SET_NSH_CH3(36), + NICIRA_SET_NSH_CH4(37), + NICIRA_MOV_ARP_SHA_TO_THA(2), + NICIRA_MOV_ARP_SPA_TO_TPA(3), + NICIRA_MOV_ETH_SRC_TO_DST(4), + NICIRA_MOV_IP_SRC_TO_DST(5); private ExtensionTreatmentType type; /** - * Creates a new named extension instruction type. + * Creates a new named extension treatment type. * * @param type type code */ 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 4643b315..8ed882c8 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 @@ -35,6 +35,9 @@ import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSig import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction; +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction; +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction; import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType; @@ -298,6 +301,39 @@ public final class Instructions { return new ModTtlInstruction(L3SubType.TTL_IN); } + /** + * Creates a L3 ARP IP src modification. + * + * @param addr the ip address to modify to + * @return a L3 modification + */ + public static L3ModificationInstruction modArpSpa(IpAddress addr) { + checkNotNull(addr, "Src l3 ARP IP address cannot be null"); + return new ModArpIPInstruction(L3SubType.ARP_SPA, addr); + } + + /** + * Creates a l3 ARP Ether src modification. + * + * @param addr the mac address to modify to + * @return a l3 modification + */ + public static L3ModificationInstruction modArpSha(MacAddress addr) { + checkNotNull(addr, "Src l3 ARP address cannot be null"); + return new ModArpEthInstruction(L3SubType.ARP_SHA, addr); + } + + /** + * Creates a l3 ARP operation modification. + * + * @param op the ARP operation to modify to + * @return a l3 modification + */ + public static L3ModificationInstruction modL3ArpOp(short op) { + checkNotNull(op, "Arp operation cannot be null"); + return new ModArpOpInstruction(L3SubType.ARP_OP, op); + } + /** * Creates a push MPLS header instruction. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java index 41819504..0efe9a77 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java @@ -20,6 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import java.util.Objects; import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; /** * Abstraction of a single traffic treatment step. @@ -68,7 +69,22 @@ public abstract class L3ModificationInstruction implements Instruction { /** * Copy TTL in. */ - TTL_IN + TTL_IN, + + /** + * ARP IP src modification. + */ + ARP_SPA, + + /** + * ARP Ether src modification. + */ + ARP_SHA, + + /** + * Arp operation modification. + */ + ARP_OP //TODO: remaining types } @@ -132,6 +148,150 @@ public abstract class L3ModificationInstruction implements Instruction { } } + /** + * Represents a L3 ARP IP src/dst modification instruction. + */ + public static final class ModArpIPInstruction extends L3ModificationInstruction { + + private final L3SubType subtype; + private final IpAddress ip; + + ModArpIPInstruction(L3SubType subType, IpAddress addr) { + + this.subtype = subType; + this.ip = addr; + } + + @Override + public L3SubType subtype() { + return this.subtype; + } + + public IpAddress ip() { + return this.ip; + } + + @Override + public String toString() { + return toStringHelper(subtype().toString()) + .add("ip", ip).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type(), subtype(), ip); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ModArpIPInstruction) { + ModArpIPInstruction that = (ModArpIPInstruction) obj; + return Objects.equals(ip, that.ip) && + Objects.equals(this.subtype(), that.subtype()); + } + return false; + } + } + + /** + * Represents a L3 ARP Ether src/dst modification instruction. + */ + public static final class ModArpEthInstruction extends L3ModificationInstruction { + + private final L3SubType subtype; + private final MacAddress mac; + + ModArpEthInstruction(L3SubType subType, MacAddress addr) { + + this.subtype = subType; + this.mac = addr; + } + + @Override + public L3SubType subtype() { + return this.subtype; + } + + public MacAddress mac() { + return this.mac; + } + + @Override + public String toString() { + return toStringHelper(subtype().toString()) + .add("mac", mac).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type(), subtype(), mac); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ModArpEthInstruction) { + ModArpEthInstruction that = (ModArpEthInstruction) obj; + return Objects.equals(mac, that.mac) && + Objects.equals(this.subtype(), that.subtype()); + } + return false; + } + } + + /** + * Represents a L3 ARP operation modification instruction. + */ + public static final class ModArpOpInstruction extends L3ModificationInstruction { + + private final L3SubType subtype; + private final short op; + + ModArpOpInstruction(L3SubType subType, short op) { + + this.subtype = subType; + this.op = op; + } + + @Override + public L3SubType subtype() { + return this.subtype; + } + + public long op() { + return this.op; + } + + @Override + public String toString() { + return toStringHelper(subtype().toString()) + .add("op", op).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type(), subtype(), op); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ModArpOpInstruction) { + ModArpOpInstruction that = (ModArpOpInstruction) obj; + return Objects.equals(op, that.op) && + Objects.equals(this.subtype(), that.subtype()); + } + return false; + } + } + /** * Represents a L3 IPv6 Flow Label (RFC 6437) modification instruction * (20 bits unsigned integer). diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java index 06305bf7..4d9d7225 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultFilteringObjective.java @@ -196,7 +196,7 @@ public final class DefaultFilteringObjective implements FilteringObjective { } @Override - public Builder setMeta(TrafficTreatment treatment) { + public Builder withMeta(TrafficTreatment treatment) { this.meta = treatment; return this; } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java index 4701589f..bd580507 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/DefaultNextObjective.java @@ -181,7 +181,7 @@ public final class DefaultNextObjective implements NextObjective { } @Override - public Builder setMeta(TrafficSelector meta) { + public Builder withMeta(TrafficSelector meta) { this.meta = meta; return this; } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java index 29257c61..8ed793d0 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/FilteringObjective.java @@ -133,7 +133,7 @@ public interface FilteringObjective extends Objective { * @param treatment traffic treatment to use * @return a filtering builder */ - Builder setMeta(TrafficTreatment treatment); + Builder withMeta(TrafficTreatment treatment); /** * Assigns an application id. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java index 08916eb2..36098d71 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flowobjective/NextObjective.java @@ -147,7 +147,7 @@ public interface NextObjective extends Objective { * @param selector match conditions * @return an objective builder */ - Builder setMeta(TrafficSelector selector); + Builder withMeta(TrafficSelector selector); /** * Builds the next objective that will be added. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/IntentUtils.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/IntentUtils.java new file mode 100644 index 00000000..f6e33b6b --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/IntentUtils.java @@ -0,0 +1,84 @@ +/* + * 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.intent; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +/** + * Utilities for dealing with intents. + */ +public final class IntentUtils { + + private static final Logger log = LoggerFactory.getLogger(IntentUtils.class); + + private IntentUtils() { + } + + /** + * Checks if two intents represent the same value. + * + *

({@link Intent#equals(Object)} only checks ID equality)

+ * + *

Both intents must be of the same type.

+ * + * @param one first intent + * @param two second intent + * @return true if the two intents represent the same value, otherwise false + */ + public static boolean equals(Intent one, Intent two) { + if (one.getClass() != two.getClass()) { + return false; + } + + if (!(Objects.equals(one.appId(), two.appId()) && + Objects.equals(one.key(), two.key()))) { + return false; + } + + if (one instanceof SinglePointToMultiPointIntent) { + SinglePointToMultiPointIntent intent1 = (SinglePointToMultiPointIntent) one; + SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two; + + return Objects.equals(intent1.selector(), intent2.selector()) && + Objects.equals(intent1.treatment(), intent2.treatment()) && + Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) && + Objects.equals(intent1.egressPoints(), intent2.egressPoints()); + } else if (one instanceof MultiPointToSinglePointIntent) { + MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one; + MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two; + + return Objects.equals(intent1.selector(), intent2.selector()) && + Objects.equals(intent1.treatment(), intent2.treatment()) && + Objects.equals(intent1.ingressPoints(), intent2.ingressPoints()) && + Objects.equals(intent1.egressPoint(), intent2.egressPoint()); + } else if (one instanceof PointToPointIntent) { + PointToPointIntent intent1 = (PointToPointIntent) one; + PointToPointIntent intent2 = (PointToPointIntent) two; + + return Objects.equals(intent1.selector(), intent2.selector()) && + Objects.equals(intent1.treatment(), intent2.treatment()) && + Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) && + Objects.equals(intent1.egressPoint(), intent2.egressPoint()); + } else { + log.error("Unimplemented intent type"); + return false; + } + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/mcast/MulticastRouteService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/mcast/MulticastRouteService.java index 56e87c55..bf65033a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/mcast/MulticastRouteService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/mcast/MulticastRouteService.java @@ -16,6 +16,7 @@ package org.onosproject.net.mcast; import com.google.common.annotations.Beta; +import org.onosproject.event.ListenerService; import org.onosproject.net.ConnectPoint; import java.util.List; @@ -24,7 +25,8 @@ import java.util.List; * A service interface for maintaining multicast information. */ @Beta -public interface MulticastRouteService { +public interface MulticastRouteService + extends ListenerService { /** * Adds a route to the information base. 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 c0c4e34f..72f8ac01 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 @@ -18,6 +18,8 @@ package org.onosproject.net.newresource; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; +import org.onosproject.net.DeviceId; +import org.onosproject.net.PortNumber; import java.util.LinkedList; import java.util.List; @@ -41,8 +43,8 @@ import static com.google.common.base.Preconditions.checkState; * 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. + * For example, resource path, Device:1/Port:1/VLAN ID:100, is valid, but resource path, + * VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID. */ @Beta public abstract class ResourcePath { @@ -52,29 +54,73 @@ public abstract class ResourcePath { public static final Discrete ROOT = new Discrete(); + public static ResourcePath discrete(DeviceId device) { + return new Discrete(ImmutableList.of(device)); + } + /** * 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. + * @param device device ID which is the first component of the path + * @param components following components of the path. The order represents hierarchical structure of the resource. * @return resource path instance */ - public static ResourcePath discrete(Object... components) { - if (components.length == 0) { - return ROOT; - } else { - return new Discrete(ImmutableList.copyOf(components)); - } + public static ResourcePath discrete(DeviceId device, Object... components) { + return new Discrete(ImmutableList.builder() + .add(device) + .add(components) + .build()); + } + + /** + * Creates an resource path which represents a discrete-type resource from the specified components. + * + * @param device device ID which is the first component of the path + * @param port port number which is the second component of the path + * @param components following components of the path. The order represents hierarchical structure of the resource. + * @return resource path instance + */ + public static ResourcePath discrete(DeviceId device, PortNumber port, Object... components) { + return new Discrete(ImmutableList.builder() + .add(device) + .add(port) + .add(components) + .build()); } /** * 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. + * @param device device ID which is the first component of the path + * @param components following components of the path. The order represents hierarchical structure of the resource. + * @return resource path instance + */ + public static ResourcePath continuous(double value, DeviceId device, Object... components) { + checkArgument(components.length > 0, + "Length of components must be greater thant 0, but " + components.length); + + return new Continuous(ImmutableList.builder() + .add(device) + .add(components) + .build(), value); + } + + /** + * Creates an resource path which represents a continuous-type resource from the specified components. + * + * @param value amount of the resource + * @param device device ID which is the first component of the path. + * @param port port number which is the second component of the path. + * @param components following components of the path. The order represents hierarchical structure of the resource. * @return resource path instance */ - public static ResourcePath continuous(double value, Object... components) { - return new Continuous(ImmutableList.copyOf(components), value); + public static ResourcePath continuous(double value, DeviceId device, PortNumber port, Object... components) { + return new Continuous(ImmutableList.builder() + .add(device) + .add(port) + .add(components) + .build(), value); } /** @@ -82,7 +128,7 @@ public abstract class ResourcePath { * * @param components components of the path. The order represents hierarchical structure of the resource. */ - ResourcePath(List components) { + protected ResourcePath(List components) { checkNotNull(components); checkArgument(!components.isEmpty()); @@ -101,7 +147,7 @@ public abstract class ResourcePath { * @param parent the parent of this resource * @param last a child of the parent */ - ResourcePath(Discrete parent, Object last) { + protected ResourcePath(Discrete parent, Object last) { checkNotNull(parent); checkNotNull(last); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/GeoDistanceLinkWeight.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/GeoDistanceLinkWeight.java new file mode 100644 index 00000000..c966902e --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/GeoDistanceLinkWeight.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014-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.topology; + +import org.onlab.util.GeoLocation; +import org.onosproject.net.AnnotationKeys; +import org.onosproject.net.Annotations; +import org.onosproject.net.Device; +import org.onosproject.net.DeviceId; +import org.onosproject.net.device.DeviceService; + +import static java.lang.Double.MAX_VALUE; + +/** + * Link weight for measuring link cost using the geo distance between link + * vertices as determined by the element longitude/latitude annotation. + */ +public class GeoDistanceLinkWeight implements LinkWeight { + + private static final double MAX_KM = 40_075 / 2.0; + + private final DeviceService deviceService; + + /** + * Creates a new link-weight with access to the specified device service. + * + * @param deviceService device service reference + */ + public GeoDistanceLinkWeight(DeviceService deviceService) { + this.deviceService = deviceService; + } + + @Override + public double weight(TopologyEdge edge) { + GeoLocation src = getLocation(edge.link().src().deviceId()); + GeoLocation dst = getLocation(edge.link().dst().deviceId()); + return src != null && dst != null ? src.kilometersTo(dst) : MAX_KM; + } + + private GeoLocation getLocation(DeviceId deviceId) { + Device d = deviceService.getDevice(deviceId); + Annotations a = d != null ? d.annotations() : null; + double latitude = getDouble(a, AnnotationKeys.LATITUDE); + double longitude = getDouble(a, AnnotationKeys.LONGITUDE); + return latitude == MAX_VALUE || longitude == MAX_VALUE ? null : + new GeoLocation(latitude, longitude); + } + + private double getDouble(Annotations a, String key) { + String value = a != null ? a.value(key) : null; + try { + return value != null ? Double.parseDouble(value) : MAX_VALUE; + } catch (NumberFormatException e) { + return MAX_VALUE; + } + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/HopCountLinkWeight.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/HopCountLinkWeight.java new file mode 100644 index 00000000..c557016b --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/HopCountLinkWeight.java @@ -0,0 +1,36 @@ +package org.onosproject.net.topology; + +import static org.onosproject.net.Link.State.ACTIVE; +import static org.onosproject.net.Link.Type.INDIRECT; + +/** + * Link weight for measuring link cost as hop count with indirect links + * being as expensive as traversing the entire graph to assume the worst. + */ +public class HopCountLinkWeight implements LinkWeight { + private final int indirectLinkCost; + + /** + * Creates a new hop-count weight. + */ + public HopCountLinkWeight() { + this.indirectLinkCost = Short.MAX_VALUE; + } + + /** + * Creates a new hop-count weight with the specified cost of indirect links. + */ + public HopCountLinkWeight(int indirectLinkCost) { + this.indirectLinkCost = indirectLinkCost; + } + + @Override + public double weight(TopologyEdge edge) { + // To force preference to use direct paths first, make indirect + // links as expensive as the linear vertex traversal. + return edge.link().state() == + ACTIVE ? (edge.link().type() == + INDIRECT ? indirectLinkCost : 1) : -1; + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/MetricLinkWeight.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/MetricLinkWeight.java new file mode 100644 index 00000000..8463e087 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/MetricLinkWeight.java @@ -0,0 +1,36 @@ +/* + * Copyright 2014-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.topology; + +import org.onosproject.net.AnnotationKeys; + +/** + * Link weight for measuring link cost using the link metric annotation. + */ +public class MetricLinkWeight implements LinkWeight { + + @Override + public double weight(TopologyEdge edge) { + String v = edge.link().annotations().value(AnnotationKeys.METRIC); + try { + return v != null ? Double.parseDouble(v) : 1; + } catch (NumberFormatException e) { + return 1; + } + } +} + diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathAdminService.java new file mode 100644 index 00000000..9d077e1e --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathAdminService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2014-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.topology; + +import org.onlab.graph.GraphPathSearch; + +/** + * Provides administrative abilities to tailor the path service behaviours. + */ +public interface PathAdminService { + + /** + * Sets the specified link-weight function to be used as a default. + * If null is specified, the builtin default hop-count link-weight will be + * used. + * + * @param linkWeight default link-weight function + */ + void setDefaultLinkWeight(LinkWeight linkWeight); + + /** + * Sets the specified graph path search algorightm to be used as a default. + * If null is specified, the builtin default all-shortest-paths Dijkstra + * algorithm will be used. + * + * @param graphPathSearch default graph path search algorithm + */ + void setDefaultGraphPathSearch(GraphPathSearch graphPathSearch); + +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathService.java index 0bd4d75d..38954079 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/PathService.java @@ -30,8 +30,9 @@ import java.util.Set; public interface PathService { /** - * Returns the set of all shortest paths, precomputed in terms of hop-count, - * between the specified source and destination elements. + * Returns the set of all shortest paths between the specified source and + * destination elements. The path is computed using the default edge-weight + * function, which by default is hop-count. * * @param src source element * @param dst destination element @@ -40,9 +41,9 @@ public interface PathService { Set getPaths(ElementId src, ElementId dst); /** - * Returns the set of all shortest paths, computed using the supplied - * edge-weight entity, between the specified source and destination - * network elements. + * Returns the set of all shortest paths between the specified source and + * destination network elements. The path is computed using the supplied + * edge-weight function. * * @param src source element * @param dst destination element @@ -52,8 +53,9 @@ public interface PathService { Set getPaths(ElementId src, ElementId dst, LinkWeight weight); /** - * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count, - * between the specified source and destination devices. + * Returns the set of all disjoint shortest path pairs between the + * specified source and destination elements. The path is computed using + * the default edge-weight function, which by default is hop-count. * * @param src source device * @param dst destination device @@ -62,8 +64,9 @@ public interface PathService { Set getDisjointPaths(ElementId src, ElementId dst); /** - * Returns the set of all disjoint shortest path pairs, computed using the supplied - * edge-weight entity, between the specified source and destination devices. + * Returns the set of all disjoint shortest path pairs between the + * specified source and destination elements. The path is computed using + * the supplied edge-weight function. * * @param src source device * @param dst destination device @@ -74,8 +77,10 @@ public interface PathService { LinkWeight weight); /** - * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count, - * between the specified source and destination devices. + * Returns the set of all disjoint shortest path pairs between the + * specified source and destination elements and taking into consideration + * the provided risk profile. The path is computed using the default + * edge-weight function, which by default is hop-count. * * @param src source device * @param dst destination device @@ -86,8 +91,10 @@ public interface PathService { Map riskProfile); /** - * Returns the set of all disjoint shortest path pairs, precomputed in terms of hop-count, - * between the specified source and destination devices. + * Returns the set of all disjoint shortest path pairs between the + * specified source and destination elements and taking into consideration + * the provided risk profile. The path is computed using the supplied + * edge-weight function. * * @param src source device * @param dst destination device @@ -96,6 +103,7 @@ public interface PathService { * @return set of all shortest paths between the two devices */ Set getDisjointPaths(ElementId src, ElementId dst, - LinkWeight weight, Map riskProfile); + LinkWeight weight, + Map riskProfile); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java index 4030abdc..efe69f5f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/TopoJson.java @@ -131,6 +131,10 @@ public final class TopoJson { if (hh.subdued()) { n.put(SUBDUE, true); } + NodeBadge badge = hh.badge(); + if (badge != null) { + n.set(BADGE, json(badge)); + } return n; } -- cgit 1.2.3-korg