use of org.onosproject.net.AnnotationKeys.PORT_NAME 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.AnnotationKeys.PORT_NAME in project onos by opennetworkinglab.
the class ScalableGatewayManager method getUplinkPort.
@Override
public PortNumber getUplinkPort(DeviceId deviceId) {
GatewayNode gatewayNode = gatewayNodeMap.get(deviceId).value();
if (gatewayNode == null) {
log.warn("Gateway with device ID {} does not exist");
return null;
}
Optional<Port> port = deviceService.getPorts(deviceId).stream().filter(p -> Objects.equals(p.annotations().value(PORT_NAME), gatewayNode.getUplinkIntf())).findFirst();
if (!port.isPresent()) {
log.warn("Cannot find uplink interface from gateway {}", deviceId);
return null;
}
return port.get().number();
}
use of org.onosproject.net.AnnotationKeys.PORT_NAME in project onos by opennetworkinglab.
the class LinkDiscoveryCiscoImpl method findDestinationPortByName.
private Port findDestinationPortByName(String remotePortName, String remotePortDesc, DeviceService deviceService, Device remoteDevice) {
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(PORT_NAME))).findAny();
if (remotePort.isPresent()) {
return remotePort.get();
} else {
Optional<Port> remotePortByDesc = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortDesc.equals(port.annotations().value(PORT_NAME))).findAny();
if (remotePortByDesc.isPresent()) {
return remotePortByDesc.get();
} else {
int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
return new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber), true, annotations.build());
}
}
}
Aggregations