use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class TopologyMutationDriver method severLink.
// Picks a random active link and severs it.
private LinkDescription severLink() {
LinkDescription link = getRandomLink(activeLinks);
linkProviderService.linkVanished(link);
linkProviderService.linkVanished(reverse(link));
return link;
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class TopologyMutationDriver method repairLink.
/**
* Repairs the link between the specified end-points in both directions.
*
* @param one link endpoint
* @param two link endpoint
*/
void repairLink(ConnectPoint one, ConnectPoint two) {
LinkDescription link = new DefaultLinkDescription(one, two, DIRECT);
linkProviderService.linkDetected(link);
linkProviderService.linkDetected(reverse(link));
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class LinkDiscoveryAristaImpl method createLinksDescs.
private Set<LinkDescription> createLinksDescs(Optional<JsonNode> response) {
DriverHandler handler = checkNotNull(handler());
DeviceId localDeviceId = checkNotNull(handler.data().deviceId());
DeviceService deviceService = handler.get(DeviceService.class);
Set<LinkDescription> linkDescriptions = Sets.newHashSet();
List<Port> ports = deviceService.getPorts(localDeviceId);
if (ports.isEmpty() || Objects.isNull(response)) {
return linkDescriptions;
}
if (!response.isPresent()) {
return linkDescriptions;
}
log.debug("response: {}, {}", response, localDeviceId.toString());
JsonNode res = response.get();
if (res == null) {
log.warn("result is null");
return linkDescriptions;
}
JsonNode lldpNeighbors = res.findValue(LLDP_NEIGHBORS);
if (lldpNeighbors == null) {
log.warn("{} is null", LLDP_NEIGHBORS);
return linkDescriptions;
}
Iterator<Map.Entry<String, JsonNode>> lldpNeighborsIter = lldpNeighbors.fields();
while (lldpNeighborsIter.hasNext()) {
Map.Entry<String, JsonNode> neighbor = lldpNeighborsIter.next();
String lldpLocalPort = neighbor.getKey();
JsonNode neighborValue = neighbor.getValue();
log.debug("lldpLocalPort: {}", lldpLocalPort);
log.debug("neighborValue: {}", neighborValue.toString());
if (lldpLocalPort.isEmpty()) {
continue;
}
JsonNode neighborInfo = neighborValue.findValue(LLDP_NEIGHBOR_INFO);
if (neighborInfo == null) {
log.warn("{} is null", LLDP_NEIGHBOR_INFO);
continue;
}
Iterator<JsonNode> neighborInfoIter = neighborInfo.elements();
while (neighborInfoIter.hasNext()) {
JsonNode info = neighborInfoIter.next();
String chassisIdType = info.get(CHASSIS_ID_TYPE).asText("");
if (chassisIdType == null) {
log.warn("{} is null", CHASSIS_ID_TYPE);
continue;
}
if (!chassisIdType.equals(CHASSIS_ID_TYPE_MAC)) {
log.warn("{} is not mac: {}", CHASSIS_ID_TYPE_MAC, chassisIdType);
continue;
}
JsonNode remotePortNameNode = info.findValue(PORT_ID);
if (remotePortNameNode == null) {
continue;
}
String remoteChassisId = info.get(CHASSIS_ID).asText("");
String remotePortName = remotePortNameNode.asText("");
log.debug("{}: {}, {}: {}", CHASSIS_ID, remoteChassisId, PORT_ID, remotePortName);
Optional<Port> localPort = findLocalPortByName(ports, lldpLocalPort);
if (!localPort.isPresent()) {
log.warn("local port not found. lldpLocalPort value: {}", lldpLocalPort);
continue;
}
Optional<Device> remoteDevice = findRemoteDeviceByChassisId(deviceService, remoteChassisId);
if (!remoteDevice.isPresent()) {
log.warn("remote device not found. remoteChassisId value: {}", remoteChassisId);
continue;
}
Optional<Port> remotePort = findDestinationPortByName(remotePortName, deviceService, remoteDevice.get());
if (!remotePort.isPresent()) {
log.warn("remote port not found. remotePortName value: {}", remotePortName);
continue;
}
if (!localPort.get().isEnabled() || !remotePort.get().isEnabled()) {
log.debug("Ports are disabled. Cannot create a link between {}/{} and {}/{}", localDeviceId, localPort.get(), remoteDevice.get().id(), remotePort.get());
continue;
}
linkDescriptions.addAll(buildLinkPair(localDeviceId, localPort.get(), remoteDevice.get().id(), remotePort.get()));
}
}
log.debug("returning linkDescriptions: {}", linkDescriptions);
return linkDescriptions;
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class DeviceDiscoveryTest method getLinksTest.
@Test
public void getLinksTest() {
Ciena5162DeviceDescription targetUnderTest1 = new Ciena5162DeviceDescription();
Ciena5162DeviceDescription targetUnderTest2 = new Ciena5162DeviceDescription();
Ciena5162DeviceDescription.TEMPLATE_MANAGER.setRequestDriver(mockRequestDriver);
DeviceId mId = DeviceId.deviceId("netconf:1.2.3.4:830");
targetUnderTest1.setHandler(mockDriverHandlers.get(mId));
deviceService.addDevice(new MockDevice(mId, targetUnderTest1.discoverDeviceDetails()));
mId = DeviceId.deviceId("netconf:5.6.7.8:830");
targetUnderTest2.setHandler(mockDriverHandlers.get(mId));
deviceService.addDevice(new MockDevice(mId, targetUnderTest2.discoverDeviceDetails()));
Set<LinkDescription> links1 = targetUnderTest1.getLinks();
Set<LinkDescription> links2 = targetUnderTest2.getLinks();
assertEquals("A to B link count", 1, links1.size());
assertEquals("B to A link count", 1, links2.size());
LinkDescription a2b = links1.toArray(new LinkDescription[0])[0];
LinkDescription b2a = links2.toArray(new LinkDescription[0])[0];
assertEquals("A to B src and dest", a2b.src(), b2a.dst());
assertEquals("B to A src and dest", b2a.src(), a2b.dst());
}
use of org.onosproject.net.link.LinkDescription in project onos by opennetworkinglab.
the class ECLinkStore method injectLink.
private LinkEvent injectLink(Provided<LinkDescription> linkInjectRequest) {
log.trace("Received request to inject link {}", linkInjectRequest);
ProviderId providerId = linkInjectRequest.providerId();
LinkDescription linkDescription = linkInjectRequest.key();
final DeviceId deviceId = linkDescription.dst().deviceId();
if (!deviceClockService.isTimestampAvailable(deviceId)) {
// workaround for ONOS-1208
log.warn("Not ready to accept update. Dropping {}", linkInjectRequest);
return null;
}
return createOrUpdateLink(providerId, linkDescription);
}
Aggregations