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());
}
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;
}
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;
}
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);
}
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);
}
Aggregations