Yuta HIGUCHI
Committed by Gerrit Code Review

[ONOS-4513] Move optical Intent compilers out to optical-model (3/3)

- core/net is now optical clean
- reverting part of Change-Id: Ib8ddac6e93327ade9d42984d8eba66be7047d051
 which lead to loss of package import information, causing OSGi issue

Change-Id: Ie6b16abd3ecc872f0920d29c7577a10c44091af6
Showing 24 changed files with 167 additions and 72 deletions
......@@ -46,6 +46,11 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
......@@ -64,5 +69,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import com.google.common.base.Strings;
......@@ -57,11 +57,9 @@ import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.optical.OchPort;
import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.intent.IntentSetMultimap;
import org.onosproject.net.intent.impl.ResourceHelper;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.Resource;
import org.onosproject.net.resource.ResourceService;
......@@ -193,7 +191,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
// If ports are not available, compilation fails
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
throw new IntentCompilationException("Ports for the intent are not available. Intent: " + intent);
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource);
......@@ -237,7 +235,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
Pair<OchPort, OchPort> ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType());
if (ochPorts == null) {
throw new IntentCompilationException("Unable to find suitable OCH ports for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find suitable OCH ports for intent " + intent);
}
ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number());
......@@ -257,14 +255,14 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
} else {
List<Resource> slots = availableSlotResources(srcCP, dstCP, intent.getSignalType());
if (slots.isEmpty()) {
throw new IntentCompilationException("Unable to find Tributary Slots for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find Tributary Slots for intent " + intent);
}
required = ImmutableList.<Resource>builder().addAll(resources).addAll(slots).build();
}
}
if (resourceService.allocate(intent.id(), required).isEmpty()) {
throw new IntentCompilationException("Unable to allocate resources for intent " + intent
throw new OpticalIntentCompilationException("Unable to allocate resources for intent " + intent
+ ": resources=" + required);
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
......@@ -41,7 +41,6 @@ import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalPathIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.optical.OchPort;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.Resource;
......@@ -49,6 +48,7 @@ import org.onosproject.net.resource.ResourceService;
import org.onosproject.net.resource.Resources;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEdge;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -121,7 +121,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
// If ports are not available, compilation fails
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
throw new IntentCompilationException("Ports for the intent are not available. Intent: " + intent);
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
List<Resource> resources = new ArrayList<>();
......@@ -132,7 +132,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
Set<Path> paths = getOpticalPaths(intent);
if (paths.isEmpty()) {
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
// Static or dynamic lambda allocation
......@@ -178,7 +178,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
OchSignal ochSignal = OchSignal.toFixedGrid(found.get().getValue(), ChannelSpacing.CHL_50GHZ);
return ImmutableList.of(createIntent(intent, found.get().getKey(), ochSignal));
} else {
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
}
......@@ -204,7 +204,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), resources);
if (allocations.isEmpty()) {
log.info("Resource allocation for {} failed (resource request: {})", intent, resources);
throw new IntentCompilationException("Unable to allocate resources: " + resources);
throw new OpticalIntentCompilationException("Unable to allocate resources: " + resources);
}
}
......@@ -300,31 +300,35 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
// Route in WDM topology
Topology topology = topologyService.currentTopology();
LinkWeight weight = edge -> {
// Disregard inactive or non-optical links
if (edge.link().state() == Link.State.INACTIVE) {
return -1;
}
if (edge.link().type() != Link.Type.OPTICAL) {
return -1;
}
// Adhere to static port mappings
DeviceId srcDeviceId = edge.link().src().deviceId();
if (srcDeviceId.equals(intent.getSrc().deviceId())) {
ConnectPoint srcStaticPort = staticPort(intent.getSrc());
if (srcStaticPort != null) {
return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
LinkWeight weight = new LinkWeight() {
@Override
public double weight(TopologyEdge edge) {
// Disregard inactive or non-optical links
if (edge.link().state() == Link.State.INACTIVE) {
return -1;
}
}
DeviceId dstDeviceId = edge.link().dst().deviceId();
if (dstDeviceId.equals(intent.getDst().deviceId())) {
ConnectPoint dstStaticPort = staticPort(intent.getDst());
if (dstStaticPort != null) {
return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
if (edge.link().type() != Link.Type.OPTICAL) {
return -1;
}
// Adhere to static port mappings
DeviceId srcDeviceId = edge.link().src().deviceId();
if (srcDeviceId.equals(intent.getSrc().deviceId())) {
ConnectPoint srcStaticPort = staticPort(intent.getSrc());
if (srcStaticPort != null) {
return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
}
}
DeviceId dstDeviceId = edge.link().dst().deviceId();
if (dstDeviceId.equals(intent.getDst().deviceId())) {
ConnectPoint dstStaticPort = staticPort(intent.getDst());
if (dstStaticPort != null) {
return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
}
}
}
return 1;
return 1;
}
};
ConnectPoint start = intent.getSrc();
......
/*
* Copyright 2016-present 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.optical.intent.impl.compiler;
import org.onosproject.net.intent.IntentCompilationException;
/**
* An exception thrown when an optical intent compilation fails.
*/
public class OpticalIntentCompilationException extends IntentCompilationException {
private static final long serialVersionUID = 2538096696847181373L;
public OpticalIntentCompilationException() {
super();
}
public OpticalIntentCompilationException(String message) {
super(message);
}
public OpticalIntentCompilationException(String message, Throwable cause) {
super(message, cause);
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import org.apache.felix.scr.annotations.Activate;
......@@ -47,7 +47,6 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.optical.OtuPort;
import org.onosproject.net.resource.Resource;
......@@ -138,7 +137,7 @@ public class OpticalOduIntentCompiler implements IntentCompiler<OpticalOduIntent
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
// If ports are not available, compilation fails
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
throw new IntentCompilationException("Ports for the intent are not available. Intent: " + intent);
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
List<Resource> intentResources = new ArrayList<>();
intentResources.add(srcPortResource);
......@@ -148,7 +147,7 @@ public class OpticalOduIntentCompiler implements IntentCompiler<OpticalOduIntent
Set<Path> paths = getOpticalPaths(intent);
if (paths.isEmpty()) {
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
// Use first path that can be successfully reserved
......@@ -180,7 +179,7 @@ public class OpticalOduIntentCompiler implements IntentCompiler<OpticalOduIntent
rules, ImmutableSet.copyOf(path.links())));
}
throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
/**
......@@ -219,7 +218,7 @@ public class OpticalOduIntentCompiler implements IntentCompiler<OpticalOduIntent
List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), resources);
if (allocations.isEmpty()) {
log.info("Resource allocation for {} failed (resource request: {})", intent, resources);
throw new IntentCompilationException("Unable to allocate resources: " + resources);
throw new OpticalIntentCompilationException("Unable to allocate resources: " + resources);
}
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
package org.onosproject.net.optical.intent.impl.compiler;
import com.google.common.annotations.Beta;
import org.onosproject.net.intent.IntentId;
......@@ -24,6 +24,7 @@ import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
// TODO consider moving this to api bundle.
/**
* Helper class for ResourceService related processes.
*/
......
/*
* Copyright 2016-present 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.
*/
/**
* Implementations of optical intent compilers.
*/
package org.onosproject.net.optical.intent.impl.compiler;
\ No newline at end of file
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import org.easymock.EasyMock;
import org.junit.After;
......@@ -63,6 +63,7 @@ import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.optical.impl.DefaultOchPort;
import org.onosproject.net.optical.impl.DefaultOduCltPort;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.MockResourceService;
import org.onosproject.net.intent.IntentSetMultimap;
import org.onosproject.net.behaviour.TributarySlotQuery;
import org.onosproject.net.device.DeviceServiceAdapter;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import org.junit.After;
import org.junit.Before;
......@@ -61,6 +61,7 @@ import org.onosproject.net.optical.OtuPort;
import org.onosproject.net.optical.impl.DefaultOduCltPort;
import org.onosproject.net.optical.impl.DefaultOtuPort;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.MockResourceService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyServiceAdapter;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.optical.intent.impl.compiler;
import org.junit.After;
import org.junit.Before;
......
/*
* Copyright 2014-present 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;
/**
* An exception thrown when a intent compilation fails.
*/
public class IntentCompilationException extends IntentException {
private static final long serialVersionUID = 2439094479018639853L;
public IntentCompilationException() {
super();
}
public IntentCompilationException(String message) {
super(message);
}
public IntentCompilationException(String message, Throwable cause) {
super(message, cause);
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl.compiler;
package org.onosproject.net.resource;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
......@@ -22,16 +22,6 @@ import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onlab.util.Tools;
import org.onosproject.net.TributarySlot;
import org.onosproject.net.resource.ContinuousResourceId;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceId;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.net.resource.ResourceId;
import org.onosproject.net.resource.ResourceListener;
import org.onosproject.net.resource.Resource;
import org.onosproject.net.resource.ResourceService;
import org.onosproject.net.resource.Resources;
import java.util.Collection;
import java.util.HashMap;
......@@ -43,7 +33,7 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
class MockResourceService implements ResourceService {
public class MockResourceService implements ResourceService {
private final Map<Resource, ResourceConsumer> assignment = new HashMap<>();
......
......@@ -4,8 +4,6 @@ COMPILE_DEPS = [
'//utils/rest:onlab-rest',
'//incubator/net:onos-incubator-net',
'//incubator/store:onos-incubator-store',
# TODO Remove after decoupling optical
'//apps/optical-model:onos-apps-optical-model',
]
TEST_DEPS = [
......
......@@ -104,14 +104,6 @@
<artifactId>onos-incubator-api</artifactId>
</dependency>
<!-- TODO Remove after decoupling optical -->
<!-- - OpticalCompilers x4 -->
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-optical-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
......
......@@ -19,7 +19,10 @@ import org.onosproject.net.intent.IntentException;
/**
* An exception thrown when a intent compilation fails.
*
* @deprecated in in Hummingbird (1.6.0) use {@link org.onosproject.net.intent.IntentCompilationException} instead.
*/
@Deprecated
public class IntentCompilationException extends IntentException {
private static final long serialVersionUID = 235237603018210810L;
......
......@@ -52,9 +52,9 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6Fl
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import java.util.ArrayList;
import java.util.Collections;
......
......@@ -37,9 +37,9 @@ import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.VlanIdCriterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.resource.Resource;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceService;
......
......@@ -34,10 +34,10 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
......
......@@ -35,6 +35,7 @@ import org.onosproject.core.impl.TestCoreManager;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
......
......@@ -30,6 +30,7 @@ import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.resource.MockResourceService;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......
......@@ -43,6 +43,7 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.net.resource.MockResourceService;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
......
......@@ -47,6 +47,7 @@ import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.MockResourceService;
import java.util.Arrays;
import java.util.Collection;
......
......@@ -31,11 +31,11 @@ import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.intent.impl.IntentProcessor;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.Timestamp;
......