use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class ECLinkStore method composeLink.
private Link composeLink(LinkKey linkKey) {
ProviderId baseProviderId = getBaseProviderId(linkKey);
if (baseProviderId == null) {
// parent component.
return null;
}
LinkDescription base = linkDescriptions.get(new Provided<>(linkKey, baseProviderId));
// short circuit if link description no longer exists
if (base == null) {
return null;
}
ConnectPoint src = base.src();
ConnectPoint dst = base.dst();
Type type = base.type();
DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
builder.putAll(base.annotations());
getAllProviders(linkKey).stream().map(p -> new Provided<>(linkKey, p)).forEach(key -> {
LinkDescription linkDescription = linkDescriptions.get(key);
if (linkDescription != null) {
builder.putAll(linkDescription.annotations());
}
});
DefaultAnnotations annotations = builder.build();
Link.State initialLinkState;
boolean isExpected;
if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE) {
initialLinkState = ACTIVE;
isExpected = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
} else {
initialLinkState = base.isExpected() ? ACTIVE : INACTIVE;
isExpected = base.isExpected();
}
return DefaultLink.builder().providerId(baseProviderId).src(src).dst(dst).type(type).state(initialLinkState).isExpected(isExpected).annotations(annotations).build();
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class LinkDiscoveryProvider method discoverLinks.
private void discoverLinks(Device device) {
DeviceId deviceId = device.id();
Set<LinkDescription> response = null;
try {
response = CompletableFuture.supplyAsync(() -> device.as(LinkDiscovery.class).getLinks(), linkDiscoveryExecutor).exceptionally(e -> {
log.error("Exception is occurred during update the links. Device id {} {}", deviceId, e);
return null;
}).get(linkDiscoveryTimeoutSeconds, SECONDS);
} catch (TimeoutException e) {
log.error("Timout is occurred during update the links. Device id {}, Timeout {}", deviceId, linkDiscoveryTimeoutSeconds);
} catch (InterruptedException | ExecutionException e) {
log.warn("Exception is occurred during update the links. Device id {}, Timeout {}", deviceId, linkDiscoveryTimeoutSeconds);
}
if (Objects.isNull(response)) {
return;
}
evaluateLinks(deviceId, response);
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class PolatisLinkDiscovery method getLinks.
/**
* Returns the set of LinkDescriptions originating from a Polatis switch.
* <p>
* This is the callback required by the LinkDiscovery behaviour.
* @return Set of outbound unidirectional links as LinkDescriptions
*/
@Override
public Set<LinkDescription> getLinks() {
Set<LinkDescription> links = new HashSet<>();
DeviceId deviceID = handler().data().deviceId();
log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceID) == null) {
log.warn("NETCONF session to device {} not yet established, will try again...", deviceID);
return links;
}
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
Device device = deviceService.getDevice(deviceID);
int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
log.trace("Talking to device " + handler().data().deviceId().toString());
String reply = netconfGet(handler(), getPortsFilter());
// Get port details from switch as PortDescription objects
List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
int numPeerPortEntries = 0;
int numPortsScanned = 0;
ObjectMapper mapper = new ObjectMapper();
for (PortDescription port : ports) {
numPortsScanned++;
if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
String peerPortData = port.annotations().value(KEY_PORTPEER);
if (!peerPortData.equals("")) {
numPeerPortEntries++;
if (peerPortData.charAt(0) == '{') {
ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
ConnectPoint farEndCP = null;
try {
farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
} catch (JsonProcessingException jpe) {
log.debug("Error processing peer-port JSON: {}", jpe.toString());
}
if (farEndCP != null) {
log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(), farEndCP.toString());
if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
log.trace("Peer {} checks out", farEndCP.toString());
// now add link to Set<LinkDescription>
DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_LINKBIDIR, VALUE_FALSE).set(KEY_LINKALLOWED, VALUE_TRUE).build();
ConnectPoint aEndCP = nearEndCP;
ConnectPoint bEndCP = farEndCP;
// reverse direction of unidirectional link if near-end port is INPUT
if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
aEndCP = farEndCP;
bEndCP = nearEndCP;
}
LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP, Link.Type.OPTICAL, true, annotations);
links.add(newLinkDesc);
log.debug("Adding link {}", newLinkDesc);
}
}
}
}
}
}
log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries, links.size(), links.size() == 1 ? "is" : "are");
log.trace("Links found on this iteration: {}", links);
return links;
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class NetworkConfigLinksProviderTest method testNotConfiguredLink.
/**
* Tests discovery of a link that is not expected in the configuration.
*/
@Test
public void testNotConfiguredLink() {
PacketContext pktCtx = new TestPacketContext(src, dst);
testProcessor.process(pktCtx);
assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
DeviceId destination = providerService.discoveredLinks().get(dev1.id());
assertThat(destination, notNullValue());
LinkKey key = LinkKey.linkKey(src, dst);
LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
assertThat(linkDescription, notNullValue());
assertThat(linkDescription.isExpected(), is(false));
}
Aggregations