@Test public void findByArpUniqueFields() { connectedDeviceRepository.add(lldpConnectedDeviceA); connectedDeviceRepository.add(arpConnectedDeviceC); connectedDeviceRepository.add(arpConnectedDeviceD); runFindByArpUniqueFields(lldpConnectedDeviceA); runFindByArpUniqueFields(arpConnectedDeviceC); runFindByArpUniqueFields(arpConnectedDeviceD); assertFalse(connectedDeviceRepository.findLldpByUniqueFieldCombination( firstSwitch.getSwitchId(), 999, 999, "fake", CHASSIS_ID, PORT_ID).isPresent()); }
@Override public Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination( SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId) { Collection<? extends SwitchConnectedDeviceFrame> devices = framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(SwitchConnectedDeviceFrame.PORT_NUMBER_PROPERTY, portNumber) .has(SwitchConnectedDeviceFrame.VLAN_PROPERTY, vlan) .has(SwitchConnectedDeviceFrame.MAC_ADDRESS_PROPERTY, macAddress) .has(SwitchConnectedDeviceFrame.TYPE_PROPERTY, ConnectedDeviceTypeConverter.INSTANCE.toGraphProperty(ConnectedDeviceType.LLDP)) .has(SwitchConnectedDeviceFrame.CHASSIS_ID_PROPERTY, chassisId) .has(SwitchConnectedDeviceFrame.PORT_ID_PROPERTY, portId)) .toListExplicit(SwitchConnectedDeviceFrame.class); if (devices.size() > 1) { throw new PersistenceException(format("Found more that 1 LLDP Connected Device by switch ID '%s', " + "port number '%d', vlan '%d', mac address '%s', chassis ID '%s' and port ID '%s'", switchId, portNumber, vlan, macAddress, chassisId, portId)); } return devices.isEmpty() ? Optional.empty() : Optional.of(devices.iterator().next()).map(SwitchConnectedDevice::new); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination( SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId) { Collection<? extends SwitchConnectedDeviceFrame> devices = framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(SwitchConnectedDeviceFrame.PORT_NUMBER_PROPERTY, portNumber) .has(SwitchConnectedDeviceFrame.VLAN_PROPERTY, vlan) .has(SwitchConnectedDeviceFrame.MAC_ADDRESS_PROPERTY, macAddress) .has(SwitchConnectedDeviceFrame.TYPE_PROPERTY, ConnectedDeviceTypeConverter.INSTANCE.toGraphProperty(ConnectedDeviceType.LLDP)) .has(SwitchConnectedDeviceFrame.CHASSIS_ID_PROPERTY, chassisId) .has(SwitchConnectedDeviceFrame.PORT_ID_PROPERTY, portId)) .toListExplicit(SwitchConnectedDeviceFrame.class); if (devices.size() > 1) { throw new PersistenceException(format("Found more that 1 LLDP Connected Device by switch ID '%s', " + "port number '%d', vlan '%d', mac address '%s', chassis ID '%s' and port ID '%s'", switchId, portNumber, vlan, macAddress, chassisId, portId)); } return devices.isEmpty() ? Optional.empty() : Optional.of(devices.iterator().next()).map(SwitchConnectedDevice::new); } }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination( SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId) { Collection<? extends SwitchConnectedDeviceFrame> devices = framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(SwitchConnectedDeviceFrame.PORT_NUMBER_PROPERTY, portNumber) .has(SwitchConnectedDeviceFrame.VLAN_PROPERTY, vlan) .has(SwitchConnectedDeviceFrame.MAC_ADDRESS_PROPERTY, macAddress) .has(SwitchConnectedDeviceFrame.TYPE_PROPERTY, ConnectedDeviceTypeConverter.INSTANCE.toGraphProperty(ConnectedDeviceType.LLDP)) .has(SwitchConnectedDeviceFrame.CHASSIS_ID_PROPERTY, chassisId) .has(SwitchConnectedDeviceFrame.PORT_ID_PROPERTY, portId)) .toListExplicit(SwitchConnectedDeviceFrame.class); if (devices.size() > 1) { throw new PersistenceException(format("Found more that 1 LLDP Connected Device by switch ID '%s', " + "port number '%d', vlan '%d', mac address '%s', chassis ID '%s' and port ID '%s'", switchId, portNumber, vlan, macAddress, chassisId, portId)); } return devices.isEmpty() ? Optional.empty() : Optional.of(devices.iterator().next()).map(SwitchConnectedDevice::new); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination( SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId) { Collection<? extends SwitchConnectedDeviceFrame> devices = framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(SwitchConnectedDeviceFrame.PORT_NUMBER_PROPERTY, portNumber) .has(SwitchConnectedDeviceFrame.VLAN_PROPERTY, vlan) .has(SwitchConnectedDeviceFrame.MAC_ADDRESS_PROPERTY, macAddress) .has(SwitchConnectedDeviceFrame.TYPE_PROPERTY, ConnectedDeviceTypeConverter.INSTANCE.toGraphProperty(ConnectedDeviceType.LLDP)) .has(SwitchConnectedDeviceFrame.CHASSIS_ID_PROPERTY, chassisId) .has(SwitchConnectedDeviceFrame.PORT_ID_PROPERTY, portId)) .toListExplicit(SwitchConnectedDeviceFrame.class); if (devices.size() > 1) { throw new PersistenceException(format("Found more that 1 LLDP Connected Device by switch ID '%s', " + "port number '%d', vlan '%d', mac address '%s', chassis ID '%s' and port ID '%s'", switchId, portNumber, vlan, macAddress, chassisId, portId)); } return devices.isEmpty() ? Optional.empty() : Optional.of(devices.iterator().next()).map(SwitchConnectedDevice::new); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchConnectedDevice> findAll(); @Override Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId); @Override Collection<SwitchConnectedDevice> findByFlowId(String flowId); @Override Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination(
            SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId); @Override Optional<SwitchConnectedDevice> findArpByUniqueFieldCombination(
            SwitchId switchId, int portNumber, int vlan, String macAddress, String ipAddress); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination( SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId) { Collection<? extends SwitchConnectedDeviceFrame> devices = framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(SwitchConnectedDeviceFrame.PORT_NUMBER_PROPERTY, portNumber) .has(SwitchConnectedDeviceFrame.VLAN_PROPERTY, vlan) .has(SwitchConnectedDeviceFrame.MAC_ADDRESS_PROPERTY, macAddress) .has(SwitchConnectedDeviceFrame.TYPE_PROPERTY, ConnectedDeviceTypeConverter.INSTANCE.toGraphProperty(ConnectedDeviceType.LLDP)) .has(SwitchConnectedDeviceFrame.CHASSIS_ID_PROPERTY, chassisId) .has(SwitchConnectedDeviceFrame.PORT_ID_PROPERTY, portId)) .toListExplicit(SwitchConnectedDeviceFrame.class); if (devices.size() > 1) { throw new PersistenceException(format("Found more that 1 LLDP Connected Device by switch ID '%s', " + "port number '%d', vlan '%d', mac address '%s', chassis ID '%s' and port ID '%s'", switchId, portNumber, vlan, macAddress, chassisId, portId)); } return devices.isEmpty() ? Optional.empty() : Optional.of(devices.iterator().next()).map(SwitchConnectedDevice::new); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchConnectedDevice> findAll(); @Override Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId); @Override Collection<SwitchConnectedDevice> findByFlowId(String flowId); @Override Optional<SwitchConnectedDevice> findLldpByUniqueFieldCombination(
            SwitchId switchId, int portNumber, int vlan, String macAddress, String chassisId, String portId); @Override Optional<SwitchConnectedDevice> findArpByUniqueFieldCombination(
            SwitchId switchId, int portNumber, int vlan, String macAddress, String ipAddress);  }