Naoki Shiota
Committed by Gerrit Code Review

Made OpticalPathProvisioner to store connectivity data in distributed store. (ONOS-4518)

Change-Id: I7f9ef02cab4aa1848c8926d2e88478e035076c99
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//core/store/serializers:onos-core-serializers',
'//lib:org.apache.karaf.shell.console',
'//cli:onos-cli',
]
......
......@@ -89,6 +89,12 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-serializers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<scope>test</scope>
......
......@@ -22,14 +22,14 @@ import org.onlab.util.Bandwidth;
import org.onosproject.newoptical.api.OpticalConnectivityId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import java.time.Duration;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
/**
* Entity to store optical connectivity request and related information.
......@@ -42,48 +42,48 @@ public class OpticalConnectivity {
private final Bandwidth requestBandwidth;
private final Duration requestLatency;
// Bandwidth capacity of optical layer
private Bandwidth opticalCapacity;
private final Set<PacketLinkRealizedByOptical> realizingLinks = new HashSet<>();
private State state = State.CREATED;
public enum State {
CREATED,
INSTALLING,
INSTALLED,
WITHDRAWING,
WITHDRAWN,
FAILED
}
public OpticalConnectivity(OpticalConnectivityId id, Path path, Bandwidth requestBandwidth,
Duration requestLatency) {
/**
* Set of packet link that is not yet established.
* Packet links in this set are expected to be discovered after underlying (optical) path has been provisioned.
*/
private final ImmutableSet<PacketLinkRealizedByOptical> unestablishedLinks;
/**
* Set of packet link that is already established.
*/
private final ImmutableSet<PacketLinkRealizedByOptical> establishedLinks;
public OpticalConnectivity(OpticalConnectivityId id,
List<Link> links,
Bandwidth requestBandwidth,
Duration requestLatency,
Set<PacketLinkRealizedByOptical> unestablishedLinks,
Set<PacketLinkRealizedByOptical> establishedLinks) {
this.id = id;
this.links = ImmutableList.copyOf(path.links());
this.links = ImmutableList.copyOf(links);
this.requestBandwidth = requestBandwidth;
this.requestLatency = requestLatency;
this.unestablishedLinks = ImmutableSet.copyOf(unestablishedLinks);
this.establishedLinks = ImmutableSet.copyOf(establishedLinks);
}
public void setLinkEstablished(ConnectPoint src, ConnectPoint dst) {
realizingLinks.stream().filter(l -> l.isBetween(src, dst))
.findAny()
.ifPresent(l -> l.setEstablished(true));
}
public void setLinkRemoved(ConnectPoint src, ConnectPoint dst) {
realizingLinks.stream().filter(l -> l.isBetween(src, dst))
.findAny()
.ifPresent(l -> l.setEstablished(false));
private OpticalConnectivity(OpticalConnectivity connectivity) {
this.id = connectivity.id;
this.links = ImmutableList.copyOf(connectivity.links);
this.requestBandwidth = connectivity.requestBandwidth;
this.requestLatency = connectivity.requestLatency;
this.unestablishedLinks = ImmutableSet.copyOf(connectivity.unestablishedLinks);
this.establishedLinks = ImmutableSet.copyOf(connectivity.establishedLinks);
}
public boolean isAllRealizingLinkEstablished() {
return realizingLinks.stream().allMatch(PacketLinkRealizedByOptical::isEstablished);
// Check if all links are established
return unestablishedLinks.isEmpty();
}
public boolean isAllRealizingLinkNotEstablished() {
return !realizingLinks.stream().anyMatch(PacketLinkRealizedByOptical::isEstablished);
// Check if any link is not established
return establishedLinks.isEmpty();
}
public OpticalConnectivityId id() {
......@@ -102,59 +102,64 @@ public class OpticalConnectivity {
return requestLatency;
}
public State state() {
return state;
}
public boolean state(State state) {
boolean valid = true;
// reject invalid state transition
switch (this.state) {
case CREATED:
valid = (state == State.INSTALLING || state == State.FAILED);
break;
case INSTALLING:
valid = (state == State.INSTALLED || state == State.FAILED);
break;
case INSTALLED:
valid = (state == State.WITHDRAWING || state == State.FAILED);
break;
case WITHDRAWING:
valid = (state == State.WITHDRAWN || state == State.FAILED);
break;
case FAILED:
valid = (state == State.INSTALLING || state == State.WITHDRAWING || state == State.FAILED);
break;
default:
break;
public Set<PacketLinkRealizedByOptical> getEstablishedLinks() {
return establishedLinks;
}
public Set<PacketLinkRealizedByOptical> getUnestablishedLinks() {
return unestablishedLinks;
}
public OpticalConnectivity setLinkEstablished(ConnectPoint src,
ConnectPoint dst,
boolean established) {
Set<PacketLinkRealizedByOptical> newEstablishedLinks;
Set<PacketLinkRealizedByOptical> newUnestablishedLinks;
if (established) {
// move PacketLink from unestablished set to established set
Optional<PacketLinkRealizedByOptical> link = this.unestablishedLinks.stream()
.filter(l -> l.isBetween(src, dst)).findAny();
checkState(link.isPresent());
newUnestablishedLinks = this.unestablishedLinks.stream()
.filter(l -> !l.isBetween(src, dst))
.collect(Collectors.toSet());
newEstablishedLinks = ImmutableSet.<PacketLinkRealizedByOptical>builder()
.addAll(this.establishedLinks)
.add(link.get())
.build();
} else {
// move PacketLink from established set to unestablished set
Optional<PacketLinkRealizedByOptical> link = this.establishedLinks.stream()
.filter(l -> l.isBetween(src, dst)).findAny();
checkState(link.isPresent());
newEstablishedLinks = this.establishedLinks.stream()
.filter(l -> !l.isBetween(src, dst))
.collect(Collectors.toSet());
newUnestablishedLinks = ImmutableSet.<PacketLinkRealizedByOptical>builder()
.addAll(this.unestablishedLinks)
.add(link.get())
.build();
}
if (valid) {
this.state = state;
}
return valid;
}
public Bandwidth getOpticalCapacity() {
return opticalCapacity;
}
public void setOpticalCapacity(Bandwidth opticalCapacity) {
this.opticalCapacity = opticalCapacity;
return new OpticalConnectivity(this.id,
this.links,
this.requestBandwidth,
this.requestLatency,
newUnestablishedLinks,
newEstablishedLinks);
}
public void addRealizingLink(PacketLinkRealizedByOptical link) {
checkNotNull(link);
realizingLinks.add(link);
}
public void removeRealizingLink(PacketLinkRealizedByOptical link) {
checkNotNull(link);
realizingLinks.remove(link);
public Set<PacketLinkRealizedByOptical> getRealizingLinks() {
return ImmutableSet.<PacketLinkRealizedByOptical>builder()
.addAll(unestablishedLinks)
.addAll(establishedLinks)
.build();
}
public Set<PacketLinkRealizedByOptical> getRealizingLinks() {
return ImmutableSet.copyOf(realizingLinks);
public static OpticalConnectivity copyOf(OpticalConnectivity connectivity) {
return new OpticalConnectivity(connectivity);
}
}
......
......@@ -33,9 +33,6 @@ public class PacketLinkRealizedByOptical {
private final Bandwidth bandwidth;
// TODO should be list of Intent Key?
private final Key realizingIntentKey;
// established=false represents that this (packet) link is expected to be
// discovered after underlying (optical) path has been provisioned.
private boolean established;
/**
* Creates instance with specified parameters.
......@@ -51,7 +48,6 @@ public class PacketLinkRealizedByOptical {
this.dst = dst;
this.realizingIntentKey = realizingIntentKey;
this.bandwidth = bandwidth;
this.established = false;
}
/**
......@@ -129,24 +125,6 @@ public class PacketLinkRealizedByOptical {
}
/**
* Returns whether packet link is realized or not.
*
* @return true if packet link is realized. false if not.
*/
public boolean isEstablished() {
return established;
}
/**
* Sets packet link to be established.
*
* @param established status of packet link
*/
public void setEstablished(boolean established) {
this.established = established;
}
/**
* Check if packet link is between specified two connect points.
*
* @param src source connect point
......@@ -157,4 +135,36 @@ public class PacketLinkRealizedByOptical {
return (this.src.equals(src) && this.dst.equals(dst));
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PacketLinkRealizedByOptical that = (PacketLinkRealizedByOptical) o;
if (!src.equals(that.src)) {
return false;
}
if (!dst.equals(that.dst)) {
return false;
}
if (!bandwidth.equals(that.bandwidth)) {
return false;
}
return realizingIntentKey.equals(that.realizingIntentKey);
}
@Override
public int hashCode() {
int result = src.hashCode();
result = 31 * result + dst.hashCode();
result = 31 * result + bandwidth.hashCode();
result = 31 * result + realizingIntentKey.hashCode();
return result;
}
}
......
......@@ -33,7 +33,7 @@ import java.util.Optional;
public interface OpticalPathService extends ListenerService<OpticalPathEvent, OpticalPathListener> {
/**
* Calculates optical path between connect points and sets up connectivity.
* Calculates multi-layer path between connect points and sets up connectivity.
*
* @param ingress ingress port
* @param egress egress port
......@@ -45,9 +45,9 @@ public interface OpticalPathService extends ListenerService<OpticalPathEvent, Op
Bandwidth bandwidth, Duration latency);
/**
* Sets up connectivity along given optical path.
* Sets up connectivity along given multi-layer path including cross-connect links.
*
* @param path path along which connectivity will be set up
* @param path multi-layer path along which connectivity will be set up
* @param bandwidth required bandwidth. No bandwidth is assured if null.
* @param latency required latency. No latency is assured if null.
* @return true if successful. false otherwise.
......
......@@ -16,6 +16,7 @@
package org.onosproject.newoptical;
import com.google.common.collect.ImmutableSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -39,7 +40,9 @@ import org.onosproject.net.provider.ProviderId;
import org.onosproject.newoptical.api.OpticalConnectivityId;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -94,10 +97,9 @@ public class OpticalConnectivityTest {
Link link2 = createLink(cp22, cp31);
List<Link> links = Stream.of(link1, link2).collect(Collectors.toList());
Path path = new MockPath(cp12, cp31, links);
OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
OpticalConnectivity oc = new OpticalConnectivity(cid, links, bandwidth, latency,
Collections.emptySet(), Collections.emptySet());
assertNotNull(oc);
assertEquals(oc.id(), cid);
......@@ -133,8 +135,6 @@ public class OpticalConnectivityTest {
Link link6 = createLink(cp62, cp71);
List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
Path path = new MockPath(cp12, cp71, links);
// Mocks 2 intents to create OduCtl connectivity
OpticalConnectivityIntent connIntent1 = createConnectivityIntent(cp21, cp32);
PacketLinkRealizedByOptical oduLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
......@@ -144,29 +144,29 @@ public class OpticalConnectivityTest {
PacketLinkRealizedByOptical oduLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
connIntent2);
Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(oduLink1, oduLink2);
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
oc.addRealizingLink(oduLink1);
oc.addRealizingLink(oduLink2);
OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
plinks, Collections.emptySet());
assertTrue(oc.isAllRealizingLinkNotEstablished());
assertFalse(oc.isAllRealizingLinkEstablished());
assertTrue(oc1.isAllRealizingLinkNotEstablished());
assertFalse(oc1.isAllRealizingLinkEstablished());
// Sets link realized by connIntent1 to be established
oc.setLinkEstablished(cp12, cp41);
OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
assertFalse(oc.isAllRealizingLinkNotEstablished());
assertFalse(oc.isAllRealizingLinkEstablished());
assertFalse(oc2.isAllRealizingLinkNotEstablished());
assertFalse(oc2.isAllRealizingLinkEstablished());
// Sets link realized by connIntent2 to be established
oc.setLinkEstablished(cp42, cp71);
OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
assertFalse(oc.isAllRealizingLinkNotEstablished());
assertTrue(oc.isAllRealizingLinkEstablished());
assertFalse(oc3.isAllRealizingLinkNotEstablished());
assertTrue(oc3.isAllRealizingLinkEstablished());
}
/**
......@@ -196,8 +196,6 @@ public class OpticalConnectivityTest {
Link link6 = createLink(cp62, cp71);
List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
Path path = new MockPath(cp12, cp71, links);
// Mocks 2 intents to create Och connectivity
OpticalCircuitIntent circuitIntent1 = createCircuitIntent(cp21, cp32);
PacketLinkRealizedByOptical ochLink1 = PacketLinkRealizedByOptical.create(cp12, cp41,
......@@ -207,29 +205,29 @@ public class OpticalConnectivityTest {
PacketLinkRealizedByOptical ochLink2 = PacketLinkRealizedByOptical.create(cp42, cp71,
circuitIntent2);
Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2);
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
OpticalConnectivity oc = new OpticalConnectivity(cid, path, bandwidth, latency);
oc.addRealizingLink(ochLink1);
oc.addRealizingLink(ochLink2);
OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency,
plinks, Collections.emptySet());
assertTrue(oc.isAllRealizingLinkNotEstablished());
assertFalse(oc.isAllRealizingLinkEstablished());
assertTrue(oc1.isAllRealizingLinkNotEstablished());
assertFalse(oc1.isAllRealizingLinkEstablished());
// Sets link realized by circuitIntent1 to be established
oc.setLinkEstablished(cp12, cp41);
OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
assertFalse(oc.isAllRealizingLinkNotEstablished());
assertFalse(oc.isAllRealizingLinkEstablished());
assertFalse(oc2.isAllRealizingLinkNotEstablished());
assertFalse(oc2.isAllRealizingLinkEstablished());
// Sets link realized by circuitIntent2 to be established
oc.setLinkEstablished(cp42, cp71);
OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
assertFalse(oc.isAllRealizingLinkNotEstablished());
assertTrue(oc.isAllRealizingLinkEstablished());
assertFalse(oc3.isAllRealizingLinkNotEstablished());
assertTrue(oc3.isAllRealizingLinkEstablished());
}
private ConnectPoint createConnectPoint(long devIdNum, long portIdNum) {
......