use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class LinkDiscoveryJuniperImpl method getLinks.
@Override
public Set<LinkDescription> getLinks() {
DeviceId localDeviceId = this.handler().data().deviceId();
NetconfSession session = lookupNetconfSession(localDeviceId);
String reply;
try {
reply = session.get(requestBuilder(REQ_LLDP_NBR_INFO));
} catch (NetconfException e) {
log.warn("Failed to retrieve lldp-neighbors-information for device {}", localDeviceId);
return ImmutableSet.of();
}
log.debug("Reply from device {} : {}", localDeviceId, reply);
Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(loadXmlString(reply));
log.debug("Set of LinkAbstraction discovered {}", linkAbstractions);
DeviceService deviceService = this.handler().get(DeviceService.class);
Set<LinkDescription> descriptions = new HashSet<>();
// for each lldp neighbor create two LinkDescription
for (LinkAbstraction linkAbs : linkAbstractions) {
// find source port by local port name
Optional<Port> localPort = deviceService.getPorts(localDeviceId).stream().filter(port -> linkAbs.localPortName.equals(port.annotations().value(PORT_NAME))).findAny();
if (!localPort.isPresent()) {
log.warn("Port name {} does not exist in device {}", linkAbs.localPortName, localDeviceId);
continue;
}
// find destination device by remote chassis id
com.google.common.base.Optional<Device> dev = Iterables.tryFind(deviceService.getAvailableDevices(), input -> input.chassisId().equals(linkAbs.remoteChassisId));
if (!dev.isPresent()) {
log.warn("Device with chassis ID {} does not exist. Referenced by {}/{}", linkAbs.remoteChassisId, localDeviceId, linkAbs);
continue;
}
Device remoteDevice = dev.get();
// find destination port by interface index
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> {
if (port.number().toLong() == linkAbs.remotePortIndex) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_MAC) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_MAC).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortId != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortId)) {
return true;
}
if (port.annotations().value(AnnotationKeys.PORT_NAME) != null && linkAbs.remotePortDescription != null && port.annotations().value(AnnotationKeys.PORT_NAME).equals(linkAbs.remotePortDescription)) {
return true;
}
return false;
}).findAny();
if (!remotePort.isPresent()) {
log.warn("Port does not exist in remote device {}. Referenced by {}/{}", remoteDevice.id(), localDeviceId, linkAbs);
continue;
}
if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get());
continue;
}
JuniperUtils.createOneWayLinkDescription(localDeviceId, localPort.get(), remoteDevice.id(), remotePort.get(), descriptions);
}
return descriptions;
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class OpenstackNetworkingUiManager method createLinksConnectedToTargetvDevice.
private void createLinksConnectedToTargetvDevice(Device targetvDevice) {
vDevices.stream().filter(d -> !d.equals(targetvDevice)).forEach(device -> {
if (vxlanPort(targetvDevice.id()).isPresent() && vxlanPort(device.id()).isPresent()) {
ConnectPoint srcConnectPoint = createConnectPoint(targetvDevice.id());
ConnectPoint dstConnectPoint = createConnectPoint(device.id());
LinkDescription linkDescription = createLinkDescription(srcConnectPoint, dstConnectPoint);
linkStore.createOrUpdateLink(new ProviderId(SONA_GUI, APP_ID), linkDescription);
}
});
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class SimpleLinkStore method createOrUpdateLinkDescription.
// Guarded by linkDescs value (=locking each Link)
private LinkDescription createOrUpdateLinkDescription(Map<ProviderId, LinkDescription> descs, ProviderId providerId, LinkDescription linkDescription) {
// merge existing attributes and merge
LinkDescription oldDesc = descs.get(providerId);
LinkDescription newDesc = linkDescription;
if (oldDesc != null) {
// we only allow transition from INDIRECT -> DIRECT
final Type newType;
if (oldDesc.type() == DIRECT) {
newType = DIRECT;
} else {
newType = linkDescription.type();
}
SparseAnnotations merged = union(oldDesc.annotations(), linkDescription.annotations());
newDesc = new DefaultLinkDescription(linkDescription.src(), linkDescription.dst(), newType, merged);
}
return descs.put(providerId, newDesc);
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class SimpleLinkStore method createOrUpdateLink.
@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
LinkKey key = linkKey(linkDescription.src(), linkDescription.dst());
Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key);
synchronized (descs) {
final Link oldLink = links.get(key);
// update description
createOrUpdateLinkDescription(descs, providerId, linkDescription);
final Link newLink = composeLink(descs);
if (oldLink == null) {
return createLink(key, newLink);
}
return updateLink(key, oldLink, newLink);
}
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class CienaWaveserverAiLinkDiscovery method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<>();
DeviceId deviceId = handler().data().deviceId();
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, cannot load links, will be retried", deviceId);
return links;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
DeviceService deviceService = this.handler().get(DeviceService.class);
Iterable<Device> devices = deviceService.getAvailableDevices();
Map<String, Device> lookup = new HashMap<>();
for (Device d : devices) {
lookup.put(d.chassisId().toString(), d);
}
log.debug("MAP: {}", lookup);
XPath xp = XPathFactory.newInstance().newXPath();
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortDetails");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-ports/ports", node, XPathConstants.NODESET);
int count = nodeList.getLength();
Node nodeListItem;
for (int i = 0; i < count; i += 1) {
Long portAsLong;
Long destPortAsLong;
String destChassis = null;
String destPort = null;
nodeListItem = nodeList.item(i);
String port = xp.evaluate("port-id/text()", nodeListItem);
portAsLong = portIdConvert(port);
log.debug("CHECKING: {}", port);
if (xp.evaluate("id/type/text()", nodeListItem).equals("otn")) {
String label = xp.evaluate("id/label/text()", nodeListItem);
final String r1 = "\\$\\{remote_mac:(.*?)\\}";
final Pattern p1 = Pattern.compile(r1);
final Matcher m1 = p1.matcher(label);
if (m1.find()) {
destChassis = m1.group(1).replaceFirst("^0+(?!$)", "");
}
final String r2 = "\\$\\{remote_port:(.*?)\\}";
final Pattern p2 = Pattern.compile(r2);
final Matcher m2 = p2.matcher(label);
if (m2.find()) {
destPort = m2.group(1);
}
destPortAsLong = portIdConvert(destPort);
if (destChassis != null && destPort != null) {
log.debug("LOOKING FOR OTN neighbor chassis: {}", destChassis);
Device dest = lookup.get(destChassis);
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), Link.Type.TUNNEL, true));
} else {
log.error("DEST OTN CHASSIS is NULL for {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else {
log.error("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else if (xp.evaluate("id/type/text()", nodeListItem).equals("ethernet")) {
Map<String, Object> templateContext = new HashMap<>();
templateContext.put("port-number", port);
node = TEMPLATE_MANAGER.doRequest(session, "getLinks", templateContext);
String chassisIdSubtype = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node);
if (chassisIdSubtype.equals("mac-address")) {
destChassis = xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id/text()", node).trim().toLowerCase();
if (destChassis.startsWith("0x")) {
destChassis = destChassis.substring(2);
}
} else {
log.error("Unknown Chassis-id-subtype {}", xp.evaluate("waveserver-lldp/port/remote/chassis/chassis-id/chassis-id-subtype/text()", node));
}
destPort = xp.evaluate("waveserver-lldp/port/remote/port/id/id/text()", node);
destPortAsLong = Long.valueOf(destPort);
if (destChassis != null && !destPort.equals("")) {
log.debug("LOOKING FOR ethernet neighbor chassisId: {}", destChassis);
Device dest = lookup.get(destChassis);
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(deviceId, PortNumber.portNumber(portAsLong, port)), new ConnectPoint(dest.id(), PortNumber.portNumber(destPortAsLong, destPort)), Link.Type.TUNNEL, true));
} else {
log.debug("DEST CHASSIS is NULL for port {}", xp.evaluate("port-id/text()", nodeListItem));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("port-id/text()", nodeListItem));
}
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve links for device {}, {}", deviceId, e);
}
return links;
}
Aggregations