Search in sources :

Example 6 with SwitchConnectedDevice

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());
}
Also used : LldpInfoData(org.openkilda.messaging.info.event.LldpInfoData) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Example 7 with SwitchConnectedDevice

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);
    });
}
Also used : SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Example 8 with SwitchConnectedDevice

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);
    });
}
Also used : SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Example 9 with SwitchConnectedDevice

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);
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) GetPortPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetPortPropertiesRequest) KeyProvider(org.openkilda.wfm.share.utils.KeyProvider) FlowPath(org.openkilda.model.FlowPath) FlowOperationsService(org.openkilda.wfm.topology.nbworker.services.FlowOperationsService) DeactivateSwitchInfoData(org.openkilda.messaging.info.event.DeactivateSwitchInfoData) StreamType(org.openkilda.wfm.topology.nbworker.StreamType) SwitchLagPortResponse(org.openkilda.messaging.nbtopology.response.SwitchLagPortResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) LLDP(org.openkilda.model.ConnectedDeviceType.LLDP) MessageException(org.openkilda.messaging.error.MessageException) GetSwitchesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchesRequest) ILinkOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.ILinkOperationsServiceCarrier) Map(java.util.Map) SwitchPatchRequest(org.openkilda.messaging.nbtopology.request.SwitchPatchRequest) DeleteSwitchResponse(org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse) LagPortMapper(org.openkilda.wfm.share.mappers.LagPortMapper) PortMapper(org.openkilda.wfm.share.mappers.PortMapper) GetSwitchRequest(org.openkilda.messaging.nbtopology.request.GetSwitchRequest) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) IslEndpoint(org.openkilda.model.IslEndpoint) IllegalSwitchStateException(org.openkilda.wfm.error.IllegalSwitchStateException) ActivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringOnSwitchInfoData) DeactivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.DeactivateIslMonitoringOnSwitchInfoData) IllegalSwitchPropertiesException(org.openkilda.wfm.error.IllegalSwitchPropertiesException) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Collection(java.util.Collection) Set(java.util.Set) InfoData(org.openkilda.messaging.info.InfoData) CommandContext(org.openkilda.wfm.CommandContext) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Fields(org.apache.storm.tuple.Fields) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) SwitchOperationsService(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsService) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) PortProperties(org.openkilda.model.PortProperties) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PortPropertiesPayload(org.openkilda.messaging.payload.switches.PortPropertiesPayload) Entry(java.util.Map.Entry) UpdateSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest) BaseRequest(org.openkilda.messaging.nbtopology.request.BaseRequest) GetSwitchConnectedDevicesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest) ActivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.ActivateIslMonitoringOnSwitchInfoData) GetSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchPropertiesRequest) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) GetSwitchLagPortsRequest(org.openkilda.messaging.nbtopology.request.GetSwitchLagPortsRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) PersistenceManager(org.openkilda.persistence.PersistenceManager) DeactivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.DeactivateFlowMonitoringOnSwitchInfoData) UpdateSwitchUnderMaintenanceRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchUnderMaintenanceRequest) Switch(org.openkilda.model.Switch) ConnectedDeviceMapper(org.openkilda.wfm.share.mappers.ConnectedDeviceMapper) ErrorType(org.openkilda.messaging.error.ErrorType) DeleteSwitchRequest(org.openkilda.messaging.nbtopology.request.DeleteSwitchRequest) Endpoint(org.openkilda.wfm.share.model.Endpoint) SwitchOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsServiceCarrier) ARP(org.openkilda.model.ConnectedDeviceType.ARP) SwitchPropertiesResponse(org.openkilda.messaging.nbtopology.response.SwitchPropertiesResponse) SwitchConnectionsRequest(org.openkilda.messaging.nbtopology.request.SwitchConnectionsRequest) GetAllSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetAllSwitchPropertiesRequest) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse) SwitchId(org.openkilda.model.SwitchId) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) Comparator(java.util.Comparator) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) ArrayList(java.util.ArrayList) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) List(java.util.List) ArrayList(java.util.ArrayList) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse)

Aggregations

SwitchConnectedDevice (org.openkilda.model.SwitchConnectedDevice)9 ArrayList (java.util.ArrayList)2 MessageException (org.openkilda.messaging.error.MessageException)2 LldpInfoData (org.openkilda.messaging.info.event.LldpInfoData)2 Switch (org.openkilda.model.Switch)2 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 OutputFieldsDeclarer (org.apache.storm.topology.OutputFieldsDeclarer)1 Fields (org.apache.storm.tuple.Fields)1 Tuple (org.apache.storm.tuple.Tuple)1 Values (org.apache.storm.tuple.Values)1