Naoki Shiota
Committed by Yuta HIGUCHI

Removed IntentId which is used only for allocating resources. (ONOS-4406)

Change-Id: I9a4ee5fbb5c0e569c058f34c1271ca573c8eb2f1
......@@ -23,7 +23,6 @@ import org.onosproject.newoptical.api.OpticalConnectivityId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.IntentId;
import java.time.Duration;
import java.util.HashSet;
......@@ -48,11 +47,6 @@ public class OpticalConnectivity {
private final Set<PacketLinkRealizedByOptical> realizingLinks = new HashSet<>();
// TODO: This IntentId is used only to reserve bandwidth resource.
// After ResourceManager is made to accept app-defined ResourceConsumer,
// this Intent should be replaced with OpticalConnectivityId.
private IntentId intentId;
private State state = State.CREATED;
public enum State {
......@@ -163,12 +157,4 @@ public class OpticalConnectivity {
public Set<PacketLinkRealizedByOptical> getRealizingLinks() {
return ImmutableSet.copyOf(realizingLinks);
}
public IntentId getIntentId() {
return intentId;
}
public void setIntentId(IntentId intentId) {
this.intentId = intentId;
}
}
......
......@@ -52,13 +52,10 @@ import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.link.LinkListener;
import org.onosproject.net.link.LinkService;
......@@ -242,18 +239,6 @@ public class OpticalPathProvisioner
OpticalConnectivityId id = OpticalConnectivityId.of(idCounter.getAndIncrement());
OpticalConnectivity connectivity = new OpticalConnectivity(id, path, bandwidth, latency);
ConnectPoint ingress = path.src();
ConnectPoint egress = path.dst();
Intent pktIntent = PointToPointIntent.builder()
.appId(appId)
.ingressPoint(ingress)
.egressPoint(egress)
.key(Key.of(id.id(), appId))
.build();
connectivity.setIntentId(pktIntent.id());
// store connectivity information
connectivities.put(connectivity.id(), connectivity);
......@@ -470,10 +455,7 @@ public class OpticalPathProvisioner
* @param connectivity Optical connectivity
*/
private void updateBandwidthUsage(OpticalConnectivity connectivity) {
IntentId intentId = connectivity.getIntentId();
if (intentId == null) {
return;
}
OpticalConnectivityId connectivityId = connectivity.id();
List<Link> links = connectivity.links();
......@@ -483,14 +465,14 @@ public class OpticalPathProvisioner
Bandwidth.class).resource(connectivity.bandwidth().bps()))
.collect(Collectors.toList());
log.debug("allocating bandwidth for {} : {}", connectivity.getIntentId(), resources);
List<ResourceAllocation> allocations = resourceService.allocate(intentId, resources);
log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
if (allocations.isEmpty()) {
log.warn("Failed to allocate bandwidth {} to {}",
connectivity.bandwidth().bps(), resources);
// TODO any recovery?
}
log.debug("Done allocating bandwidth for {}", connectivity.getIntentId());
log.debug("Done allocating bandwidth for {}", connectivityId);
}
/**
......@@ -498,18 +480,15 @@ public class OpticalPathProvisioner
* @param connectivity Optical connectivity
*/
private void releaseBandwidthUsage(OpticalConnectivity connectivity) {
IntentId intentId = connectivity.getIntentId();
if (intentId == null) {
return;
}
OpticalConnectivityId connectivityId = connectivity.id();
log.debug("releasing bandwidth allocated to {}", connectivity.getIntentId());
if (!resourceService.release(connectivity.getIntentId())) {
log.debug("releasing bandwidth allocated to {}", connectivityId);
if (!resourceService.release(connectivityId)) {
log.warn("Failed to release bandwidth allocated to {}",
connectivity.getIntentId());
connectivityId);
// TODO any recovery?
}
log.debug("DONE releasing bandwidth for {}", connectivity.getIntentId());
log.debug("DONE releasing bandwidth for {}", connectivityId);
}
private class BandwidthLinkWeight implements LinkWeight {
......
......@@ -18,6 +18,8 @@ package org.onosproject.newoptical.api;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import org.onlab.util.Identifier;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.net.resource.ResourceConsumerId;
// TODO: After ResourceManager is made to accept app-defined ResourceConsumer,
// this class should be implemented as ResourceConsumer.
......@@ -25,7 +27,7 @@ import org.onlab.util.Identifier;
* ID for optical connectivity.
*/
@Beta
public final class OpticalConnectivityId extends Identifier<Long> {
public final class OpticalConnectivityId extends Identifier<Long> implements ResourceConsumer {
public static OpticalConnectivityId of(long value) {
return new OpticalConnectivityId(value);
......@@ -36,6 +38,11 @@ public final class OpticalConnectivityId extends Identifier<Long> {
}
@Override
public ResourceConsumerId consumerId() {
return ResourceConsumerId.of(this);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("value", id())
......