use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.
the class PacketServiceTest method runHandleLldpDataWithUpdatedDevice.
private void runHandleLldpDataWithUpdatedDevice(LldpInfoData updatedData) throws InterruptedException {
LldpInfoData data = createLldpInfoDataData();
packetService.handleLldpData(data);
Collection<SwitchConnectedDevice> oldDevices = switchConnectedDeviceRepository.findAll();
assertEquals(1, oldDevices.size());
assertLldpInfoDataDataEqualsSwitchConnectedDevice(data, oldDevices.iterator().next());
SwitchConnectedDevice originalDevice = new SwitchConnectedDevice(oldDevices.iterator().next());
// Need to have a different timestamp in 'data' and 'updatedData' messages.
// More info https://github.com/telstra/open-kilda/issues/3064
updatedData.setTimestamp(data.getTimestamp() + 1000);
// we must update old device
packetService.handleLldpData(updatedData);
Collection<SwitchConnectedDevice> newDevices = switchConnectedDeviceRepository.findAll();
assertEquals(1, newDevices.size());
assertLldpInfoDataDataEqualsSwitchConnectedDevice(updatedData, newDevices.iterator().next());
// time must be updated
assertNotEquals(originalDevice.getTimeLastSeen(), newDevices.iterator().next().getTimeLastSeen());
}
use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.
the class PacketService method handleLldpData.
/**
* Handle LLDP info data.
*/
public void handleLldpData(LldpInfoData data) {
transactionManager.doInTransaction(() -> {
FlowRelatedData flowRelatedData = findFlowRelatedData(data);
if (flowRelatedData == null) {
return;
}
SwitchConnectedDevice device = getOrCreateLldpDevice(data, flowRelatedData.originalVlan);
if (device == null) {
return;
}
device.setTtl(data.getTtl());
device.setPortDescription(data.getPortDescription());
device.setSystemName(data.getSystemName());
device.setSystemDescription(data.getSystemDescription());
device.setSystemCapabilities(data.getSystemCapabilities());
device.setManagementAddress(data.getManagementAddress());
device.setTimeLastSeen(Instant.ofEpochMilli(data.getTimestamp()));
device.setFlowId(flowRelatedData.flowId);
device.setSource(flowRelatedData.source);
});
}
use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.
the class PacketService method handleArpData.
/**
* Handle Arp info data.
*/
public void handleArpData(ArpInfoData data) {
transactionManager.doInTransaction(() -> {
FlowRelatedData flowRelatedData = findFlowRelatedData(data);
if (flowRelatedData == null) {
return;
}
SwitchConnectedDevice device = getOrCreateArpDevice(data, flowRelatedData.originalVlan);
if (device == null) {
return;
}
device.setTimeLastSeen(Instant.ofEpochMilli(data.getTimestamp()));
device.setFlowId(flowRelatedData.flowId);
device.setSource(flowRelatedData.source);
});
}
use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.
the class SwitchOperationsBolt method getSwitchConnectedDevices.
private SwitchConnectedDevicesResponse getSwitchConnectedDevices(GetSwitchConnectedDevicesRequest request) {
Collection<SwitchConnectedDevice> devices;
try {
devices = switchOperationsService.getSwitchConnectedDevices(request.getSwitchId());
} catch (SwitchNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent switch");
}
Map<Integer, List<SwitchConnectedDevice>> deviceByPort = devices.stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.groupingBy(SwitchConnectedDevice::getPortNumber, Collectors.toList()));
List<SwitchPortConnectedDevicesDto> ports = new ArrayList<>();
for (Entry<Integer, List<SwitchConnectedDevice>> entry : deviceByPort.entrySet()) {
List<SwitchConnectedDeviceDto> lldpDevices = new ArrayList<>();
List<SwitchConnectedDeviceDto> arpDevices = new ArrayList<>();
for (SwitchConnectedDevice device : entry.getValue()) {
if (device.getType() == LLDP) {
lldpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
} else if (device.getType() == ARP) {
arpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
}
}
lldpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
arpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
ports.add(new SwitchPortConnectedDevicesDto(entry.getKey(), lldpDevices, arpDevices));
}
return new SwitchConnectedDevicesResponse(ports);
}
Aggregations