Search in sources :

Example 1 with SwitchConnectedDevice

use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.

the class PacketServiceTest method testHandleLldpDataSameTimeOnCreate.

@Test
public void testHandleLldpDataSameTimeOnCreate() {
    LldpInfoData data = createLldpInfoDataData();
    packetService.handleLldpData(data);
    Collection<SwitchConnectedDevice> devices = switchConnectedDeviceRepository.findAll();
    assertEquals(1, devices.size());
    assertEquals(devices.iterator().next().getTimeFirstSeen(), devices.iterator().next().getTimeLastSeen());
}
Also used : LldpInfoData(org.openkilda.messaging.info.event.LldpInfoData) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with SwitchConnectedDevice

use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.

the class PacketService method getOrCreateLldpDevice.

private SwitchConnectedDevice getOrCreateLldpDevice(LldpInfoData data, int vlan) {
    Optional<SwitchConnectedDevice> device = switchConnectedDeviceRepository.findLldpByUniqueFieldCombination(data.getSwitchId(), data.getPortNumber(), vlan, data.getMacAddress(), data.getChassisId(), data.getPortId());
    if (device.isPresent()) {
        return device.get();
    }
    Optional<Switch> sw = switchRepository.findById(data.getSwitchId());
    if (!sw.isPresent()) {
        log.warn("Got LLDP packet from non existent switch {}. Port number '{}', vlan '{}', mac address '{}', " + "chassis id '{}', port id '{}'", data.getSwitchId(), data.getPortNumber(), vlan, data.getMacAddress(), data.getChassisId(), data.getPortId());
        return null;
    }
    SwitchConnectedDevice connectedDevice = SwitchConnectedDevice.builder().switchObj(sw.get()).portNumber(data.getPortNumber()).vlan(vlan).macAddress(data.getMacAddress()).type(LLDP).chassisId(data.getChassisId()).portId(data.getPortId()).timeFirstSeen(Instant.ofEpochMilli(data.getTimestamp())).build();
    switchConnectedDeviceRepository.add(connectedDevice);
    return connectedDevice;
}
Also used : Switch(org.openkilda.model.Switch) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Example 3 with SwitchConnectedDevice

use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.

the class PacketService method getOrCreateArpDevice.

private SwitchConnectedDevice getOrCreateArpDevice(ArpInfoData data, int vlan) {
    Optional<SwitchConnectedDevice> device = switchConnectedDeviceRepository.findArpByUniqueFieldCombination(data.getSwitchId(), data.getPortNumber(), vlan, data.getMacAddress(), data.getIpAddress());
    if (device.isPresent()) {
        return device.get();
    }
    Optional<Switch> sw = switchRepository.findById(data.getSwitchId());
    if (!sw.isPresent()) {
        log.warn("Got ARP packet from non existent switch {}. Port number '{}', vlan '{}', mac address '{}', " + "ip address '{}'", data.getSwitchId(), data.getPortNumber(), vlan, data.getMacAddress(), data.getIpAddress());
        return null;
    }
    SwitchConnectedDevice connectedDevice = SwitchConnectedDevice.builder().switchObj(sw.get()).portNumber(data.getPortNumber()).vlan(vlan).macAddress(data.getMacAddress()).type(ARP).ipAddress(data.getIpAddress()).timeFirstSeen(Instant.ofEpochMilli(data.getTimestamp())).build();
    switchConnectedDeviceRepository.add(connectedDevice);
    return connectedDevice;
}
Also used : Switch(org.openkilda.model.Switch) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Example 4 with SwitchConnectedDevice

use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.

the class FermaSwitchConnectedDevicesRepositoryTest method setUp.

@Before
public void setUp() {
    switchRepository = repositoryFactory.createSwitchRepository();
    connectedDeviceRepository = repositoryFactory.createSwitchConnectedDeviceRepository();
    firstSwitch = createTestSwitch(FIRST_SWITCH_ID.getId());
    secondSwitch = createTestSwitch(SECOND_SWITCH_ID.getId());
    lldpConnectedDeviceA = new SwitchConnectedDevice(firstSwitch, FIRST_PORT_NUMBER, FIRST_VLAN, FIRST_FLOW_ID, true, MAC_ADDRESS_1, LLDP, null, CHASSIS_ID, PORT_ID, TTL, PORT, SYSTEM_NAME, SYSTEM_DESCRIPTION, CAPABILITIES, MANAGEMENT_ADDRESS, TIME_FIRST_SEEN, TIME_LAST_SEEN);
    lldpConnectedDeviceB = new SwitchConnectedDevice(secondSwitch, FIRST_PORT_NUMBER, FIRST_VLAN, SECOND_FLOW_ID, false, MAC_ADDRESS_1, LLDP, null, CHASSIS_ID, PORT_ID, TTL, PORT, SYSTEM_NAME, SYSTEM_DESCRIPTION, CAPABILITIES, MANAGEMENT_ADDRESS, TIME_FIRST_SEEN, TIME_LAST_SEEN);
    arpConnectedDeviceC = new SwitchConnectedDevice(secondSwitch, SECOND_PORT_NUMBER, SECOND_VLAN, null, null, MAC_ADDRESS_2, ARP, IP_ADDRESS_1, null, null, TTL, PORT, SYSTEM_NAME, SYSTEM_DESCRIPTION, CAPABILITIES, MANAGEMENT_ADDRESS, TIME_FIRST_SEEN, TIME_LAST_SEEN);
    arpConnectedDeviceD = new SwitchConnectedDevice(secondSwitch, SECOND_PORT_NUMBER, SECOND_VLAN, SECOND_FLOW_ID, null, MAC_ADDRESS_2, ARP, IP_ADDRESS_2, null, null, TTL, PORT, SYSTEM_NAME, SYSTEM_DESCRIPTION, CAPABILITIES, MANAGEMENT_ADDRESS, TIME_FIRST_SEEN, TIME_LAST_SEEN);
}
Also used : SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) Before(org.junit.Before)

Example 5 with SwitchConnectedDevice

use of org.openkilda.model.SwitchConnectedDevice in project open-kilda by telstra.

the class FlowOperationsBolt method processFlowConnectedDeviceRequest.

private List<FlowConnectedDevicesResponse> processFlowConnectedDeviceRequest(FlowConnectedDeviceRequest request) {
    Collection<SwitchConnectedDevice> devices;
    try {
        devices = flowOperationsService.getFlowConnectedDevice(request.getFlowId()).stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.toList());
    } catch (FlowNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent flow");
    }
    FlowConnectedDevicesResponse response = new FlowConnectedDevicesResponse(new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()), new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()));
    for (SwitchConnectedDevice device : devices) {
        ConnectedDeviceDto deviceDto = ConnectedDeviceMapper.INSTANCE.mapSwitchDeviceToFlowDeviceDto(device);
        if (device.getSource() == null) {
            log.warn("Switch Connected Device {} has Flow ID {} but has no 'source' property.", device, device.getFlowId());
        } else if (device.getSource()) {
            if (device.getType() == LLDP) {
                response.getSource().getLldp().add(deviceDto);
            } else if (device.getType() == ARP) {
                response.getSource().getArp().add(deviceDto);
            }
        } else {
            if (device.getType() == LLDP) {
                response.getDestination().getLldp().add(deviceDto);
            } else if (device.getType() == ARP) {
                response.getDestination().getArp().add(deviceDto);
            }
        }
    }
    return Collections.singletonList(response);
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) ConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.ConnectedDeviceDto) MessageException(org.openkilda.messaging.error.MessageException) ArrayList(java.util.ArrayList) TypedConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.TypedConnectedDevicesDto) FlowConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.FlowConnectedDevicesResponse) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

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