target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void shouldFindDownFlowIdsByEndpoint() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); flow.setStatus(FlowStatus.DOWN); Collection<Flow> foundFlows = flowRepository.findInactiveFlows(); assertThat(foundFlows, Matchers.hasSize(1)); }
@Override public Collection<Flow> findInactiveFlows() { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findInactiveFlows() { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findInactiveFlows() { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findInactiveFlows() { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findInactiveFlows() { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
@Test public void shouldGetFlowGroupIdForFlow() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); flow.setGroupId(TEST_GROUP_ID); Optional<String> groupOptional = flowRepository.getOrCreateFlowGroupId(TEST_FLOW_ID); assertTrue(groupOptional.isPresent()); assertEquals(TEST_GROUP_ID, groupOptional.get()); }
@Override public Optional<String> getOrCreateFlowGroupId(String flowId) { return transactionManager.doInTransaction(() -> findById(flowId) .map(diverseFlow -> { if (diverseFlow.getGroupId() == null) { String groupId = UUID.randomUUID().toString(); diverseFlow.setGroupId(groupId); } return diverseFlow.getGroupId(); })); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<String> getOrCreateFlowGroupId(String flowId) { return transactionManager.doInTransaction(() -> findById(flowId) .map(diverseFlow -> { if (diverseFlow.getGroupId() == null) { String groupId = UUID.randomUUID().toString(); diverseFlow.setGroupId(groupId); } return diverseFlow.getGroupId(); })); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<String> getOrCreateFlowGroupId(String flowId) { return transactionManager.doInTransaction(() -> findById(flowId) .map(diverseFlow -> { if (diverseFlow.getGroupId() == null) { String groupId = UUID.randomUUID().toString(); diverseFlow.setGroupId(groupId); } return diverseFlow.getGroupId(); })); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<String> getOrCreateFlowGroupId(String flowId) { return transactionManager.doInTransaction(() -> findById(flowId) .map(diverseFlow -> { if (diverseFlow.getGroupId() == null) { String groupId = UUID.randomUUID().toString(); diverseFlow.setGroupId(groupId); } return diverseFlow.getGroupId(); })); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<String> getOrCreateFlowGroupId(String flowId) { return transactionManager.doInTransaction(() -> findById(flowId) .map(diverseFlow -> { if (diverseFlow.getGroupId() == null) { String groupId = UUID.randomUUID().toString(); diverseFlow.setGroupId(groupId); } return diverseFlow.getGroupId(); })); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
@Test public void shouldComputeSumOfFlowsBandwidth() { long firstFlowBandwidth = 100000L; long secondFlowBandwidth = 500000L; Flow firstFlow = createTestFlow(TEST_FLOW_ID, switchA, switchB); firstFlow.setBandwidth(firstFlowBandwidth); Flow secondFlow = createTestFlow(TEST_FLOW_ID_2, switchA, switchB); secondFlow.setBandwidth(secondFlowBandwidth); long foundBandwidth = flowRepository.computeFlowsBandwidthSum(Sets.newHashSet(TEST_FLOW_ID, TEST_FLOW_ID_2)); assertEquals(firstFlowBandwidth + secondFlowBandwidth, foundBandwidth); }
@Override public long computeFlowsBandwidthSum(Set<String> flowIds) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.BANDWIDTH_PROPERTY).sum()) .getRawTraversal()) { return traversal.tryNext() .filter(n -> !(n instanceof Double && ((Double) n).isNaN())) .map(l -> (Long) l) .orElse(0L); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public long computeFlowsBandwidthSum(Set<String> flowIds) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.BANDWIDTH_PROPERTY).sum()) .getRawTraversal()) { return traversal.tryNext() .filter(n -> !(n instanceof Double && ((Double) n).isNaN())) .map(l -> (Long) l) .orElse(0L); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public long computeFlowsBandwidthSum(Set<String> flowIds) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.BANDWIDTH_PROPERTY).sum()) .getRawTraversal()) { return traversal.tryNext() .filter(n -> !(n instanceof Double && ((Double) n).isNaN())) .map(l -> (Long) l) .orElse(0L); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public long computeFlowsBandwidthSum(Set<String> flowIds) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.BANDWIDTH_PROPERTY).sum()) .getRawTraversal()) { return traversal.tryNext() .filter(n -> !(n instanceof Double && ((Double) n).isNaN())) .map(l -> (Long) l) .orElse(0L); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public long computeFlowsBandwidthSum(Set<String> flowIds) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.BANDWIDTH_PROPERTY).sum()) .getRawTraversal()) { return traversal.tryNext() .filter(n -> !(n instanceof Double && ((Double) n).isNaN())) .map(l -> (Long) l) .orElse(0L); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
@Test public void shouldGetAllDownFlows() { Flow flowA = createTestFlow(TEST_FLOW_ID, switchA, switchB); flowA.setStatus(FlowStatus.DOWN); Flow flowB = createTestFlow(TEST_FLOW_ID_2, switchA, switchB); flowB.setStatus(FlowStatus.DOWN); createTestFlow(TEST_FLOW_ID_3, switchA, switchB); Collection<String> foundDownFlows = flowRepository.findByFlowFilter(FlowFilter.builder().flowStatus(FlowStatus.DOWN).build()).stream() .map(Flow::getFlowId) .collect(Collectors.toList()); assertEquals(2, foundDownFlows.size()); assertTrue(foundDownFlows.contains(TEST_FLOW_ID)); assertTrue(foundDownFlows.contains(TEST_FLOW_ID_2)); Collection<String> foundFlows = flowRepository.findByFlowFilter(FlowFilter.builder().build()).stream() .map(Flow::getFlowId) .collect(Collectors.toList()); assertEquals(3, foundFlows.size()); }
@Override public Collection<Flow> findByFlowFilter(FlowFilter flowFilter) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowFrame.FRAME_LABEL); if (flowFilter.getFlowStatus() != null) { traversal = traversal.has(FlowFrame.STATUS_PROPERTY, FlowStatusConverter.INSTANCE.toGraphProperty(flowFilter.getFlowStatus())); } return traversal; }).toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByFlowFilter(FlowFilter flowFilter) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowFrame.FRAME_LABEL); if (flowFilter.getFlowStatus() != null) { traversal = traversal.has(FlowFrame.STATUS_PROPERTY, FlowStatusConverter.INSTANCE.toGraphProperty(flowFilter.getFlowStatus())); } return traversal; }).toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByFlowFilter(FlowFilter flowFilter) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowFrame.FRAME_LABEL); if (flowFilter.getFlowStatus() != null) { traversal = traversal.has(FlowFrame.STATUS_PROPERTY, FlowStatusConverter.INSTANCE.toGraphProperty(flowFilter.getFlowStatus())); } return traversal; }).toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByFlowFilter(FlowFilter flowFilter) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowFrame.FRAME_LABEL); if (flowFilter.getFlowStatus() != null) { traversal = traversal.has(FlowFrame.STATUS_PROPERTY, FlowStatusConverter.INSTANCE.toGraphProperty(flowFilter.getFlowStatus())); } return traversal; }).toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByFlowFilter(FlowFilter flowFilter) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowFrame.FRAME_LABEL); if (flowFilter.getFlowStatus() != null) { traversal = traversal.has(FlowFrame.STATUS_PROPERTY, FlowStatusConverter.INSTANCE.toGraphProperty(flowFilter.getFlowStatus())); } return traversal; }).toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); @Override long countFlows(); @Override Collection<Flow> findAll(); @Override boolean exists(String flowId); @Override Optional<Flow> findById(String flowId); @Override Collection<Flow> findByGroupId(String flowGroupId); @Override Collection<String> findFlowsIdByGroupId(String flowGroupId); @Override Collection<Flow> findWithPeriodicPingsEnabled(); @Override Collection<Flow> findByEndpoint(SwitchId switchId, int port); @Override Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan); @Override Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan); @Override Collection<Flow> findOneSwitchFlows(SwitchId switchId); @Override Collection<Flow> findByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port); @Override Collection<Flow> findByEndpointSwitch(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId); @Override Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId); @Override Collection<Flow> findInactiveFlows(); @Override Collection<Flow> findByFlowFilter(FlowFilter flowFilter); @Override Optional<String> getOrCreateFlowGroupId(String flowId); @Override void updateStatus(@NonNull String flowId, @NonNull FlowStatus flowStatus); @Override void updateStatus(String flowId, FlowStatus flowStatus, String flowStatusInfo); @Override void updateStatusInfo(String flowId, String flowStatusInfo); @Override @TransactionRequired void updateStatusSafe(Flow flow, FlowStatus flowStatus, String flowStatusInfo); @Override long computeFlowsBandwidthSum(Set<String> flowIds); @Override Optional<Flow> remove(String flowId); }
@Test public void shouldCreateSwitch() { switchRepository.add(Switch.builder() .switchId(TEST_SWITCH_ID_A) .description("Some description") .build()); assertEquals(1, switchRepository.findAll().size()); }
@Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void findNPathsByTransitVlanAndLatency() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException { List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, TRANSIT_VLAN, LATENCY); assertTransitVlanAndLatencyPaths(paths); }
public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); static final int MAX_PATH_COUNT; }
@Test public void shouldFindActive() { Switch activeSwitch = Switch.builder().switchId(TEST_SWITCH_ID_A) .status(SwitchStatus.ACTIVE).build(); Switch inactiveSwitch = Switch.builder().switchId(TEST_SWITCH_ID_B) .status(SwitchStatus.INACTIVE).build(); switchRepository.add(activeSwitch); switchRepository.add(inactiveSwitch); Collection<Switch> switches = switchRepository.findActive(); assertEquals(1, switches.size()); assertEquals(TEST_SWITCH_ID_A, switches.iterator().next().getSwitchId()); }
@Override public Collection<Switch> findActive() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL) .has(SwitchFrame.STATUS_PROPERTY, SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE))) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findActive() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL) .has(SwitchFrame.STATUS_PROPERTY, SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE))) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findActive() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL) .has(SwitchFrame.STATUS_PROPERTY, SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE))) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findActive() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL) .has(SwitchFrame.STATUS_PROPERTY, SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE))) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findActive() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL) .has(SwitchFrame.STATUS_PROPERTY, SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE))) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void shouldFindSwitchById() { Switch origSwitch = Switch.builder() .switchId(TEST_SWITCH_ID_A) .description("Some description") .build(); switchRepository.add(origSwitch); Switch foundSwitch = switchRepository.findById(TEST_SWITCH_ID_A).get(); assertEquals(origSwitch.getDescription(), foundSwitch.getDescription()); }
@Override public Optional<Switch> findById(SwitchId switchId) { return SwitchFrame.load(framedGraph(), SwitchIdConverter.INSTANCE.toGraphProperty(switchId)).map(Switch::new); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Optional<Switch> findById(SwitchId switchId) { return SwitchFrame.load(framedGraph(), SwitchIdConverter.INSTANCE.toGraphProperty(switchId)).map(Switch::new); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Optional<Switch> findById(SwitchId switchId) { return SwitchFrame.load(framedGraph(), SwitchIdConverter.INSTANCE.toGraphProperty(switchId)).map(Switch::new); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Optional<Switch> findById(SwitchId switchId) { return SwitchFrame.load(framedGraph(), SwitchIdConverter.INSTANCE.toGraphProperty(switchId)).map(Switch::new); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Optional<Switch> findById(SwitchId switchId) { return SwitchFrame.load(framedGraph(), SwitchIdConverter.INSTANCE.toGraphProperty(switchId)).map(Switch::new); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void shouldFindSwitchesByFlowId() { createTwoFlows(); Collection<SwitchId> switches = switchRepository.findSwitchesInFlowPathByFlowId(TEST_FLOW_ID_A).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); assertEquals(2, switches.size()); assertTrue(switches.contains(TEST_SWITCH_ID_A)); assertTrue(switches.contains(TEST_SWITCH_ID_B)); assertFalse(switches.contains(TEST_SWITCH_ID_C)); }
@Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void shouldFindSwitchOfOneSwitchFlowByFlowId() { createOneSwitchFlow(); Collection<SwitchId> switches = switchRepository.findSwitchesInFlowPathByFlowId(TEST_FLOW_ID_A).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); assertEquals(1, switches.size()); assertTrue(switches.contains(TEST_SWITCH_ID_A)); }
@Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.isEmpty()) { return emptyList(); } Map<SwitchId, Switch> result = new HashMap<>(); flowPathFrames.forEach(flowPath -> { Stream.of(flowPath.getSrcSwitch(), flowPath.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); flowPath.getSegments().forEach(pathSegment -> { Stream.of(pathSegment.getSrcSwitch(), pathSegment.getDestSwitch()) .forEach(sw -> result.put(sw.getSwitchId(), sw)); }); }); return result.values(); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void shouldDeleteSwitch() { Switch origSwitch = Switch.builder() .switchId(TEST_SWITCH_ID_A) .description("Some description") .build(); switchRepository.add(origSwitch); transactionManager.doInTransaction(() -> switchRepository.remove(origSwitch)); assertEquals(0, switchRepository.findAll().size()); }
@Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
FermaSwitchRepository extends FermaGenericRepository<Switch, SwitchData, SwitchFrame> implements SwitchRepository { @Override public Collection<Switch> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchFrame.FRAME_LABEL)) .toListExplicit(SwitchFrame.class).stream() .map(Switch::new) .collect(Collectors.toList()); } FermaSwitchRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Switch> findAll(); @Override boolean exists(SwitchId switchId); @Override Collection<Switch> findActive(); @Override Optional<Switch> findById(SwitchId switchId); @Override Collection<Switch> findSwitchesInFlowPathByFlowId(String flowId); @Override @TransactionRequired boolean removeIfNoDependant(Switch entity); }
@Test public void shouldCreateTransitVlan() { TransitVlan vlan = createTransitVlan(); Collection<TransitVlan> allVlans = transitVlanRepository.findAll(); TransitVlan foundVlan = allVlans.iterator().next(); assertEquals(vlan.getVlan(), foundVlan.getVlan()); assertEquals(TEST_FLOW_ID, foundVlan.getFlowId()); }
@Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
@Test public void shouldFindTransitVlan() { TransitVlan vlan = createTransitVlan(); vlan.setVlan(VLAN); Optional<TransitVlan> foundVlan = transitVlanRepository.findByVlan(VLAN); assertTrue(foundVlan.isPresent()); assertEquals(vlan.getVlan(), foundVlan.get().getVlan()); assertEquals(vlan.getFlowId(), foundVlan.get().getFlowId()); assertEquals(vlan.getPathId(), foundVlan.get().getPathId()); }
@Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
@Test public void shouldDeleteTransitVlan() { TransitVlan vlan = createTransitVlan(); transactionManager.doInTransaction(() -> transitVlanRepository.remove(vlan)); assertEquals(0, transitVlanRepository.findAll().size()); }
@Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
@Test public void shouldDeleteFoundTransitVlan() { createTransitVlan(); Collection<TransitVlan> allVlans = transitVlanRepository.findAll(); TransitVlan foundVlan = allVlans.iterator().next(); transactionManager.doInTransaction(() -> transitVlanRepository.remove(foundVlan)); assertEquals(0, transitVlanRepository.findAll().size()); }
@Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Collection<TransitVlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL)) .toListExplicit(TransitVlanFrame.class).stream() .map(TransitVlan::new) .collect(Collectors.toList()); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
@Test public void shouldSelectNextInOrderResourceWhenFindUnassignedTransitVlan() { int first = findUnassignedTransitVlanAndCreate("flow_1"); assertEquals(5, first); int second = findUnassignedTransitVlanAndCreate("flow_2"); assertEquals(6, second); int third = findUnassignedTransitVlanAndCreate("flow_3"); assertEquals(7, third); transactionManager.doInTransaction(() -> transitVlanRepository.findByVlan(second).ifPresent(transitVlanRepository::remove)); int fourth = findUnassignedTransitVlanAndCreate("flow_4"); assertEquals(6, fourth); int fifth = findUnassignedTransitVlanAndCreate("flow_5"); assertEquals(8, fifth); }
@Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
FermaTransitVlanRepository extends FermaGenericRepository<TransitVlan, TransitVlanData, TransitVlanFrame> implements TransitVlanRepository { @Override public Optional<TransitVlan> findByVlan(int vlan) { List<? extends TransitVlanFrame> transitVlanFrames = framedGraph().traverse(g -> g.V() .hasLabel(TransitVlanFrame.FRAME_LABEL) .has(TransitVlanFrame.VLAN_PROPERTY, vlan)) .toListExplicit(TransitVlanFrame.class); return transitVlanFrames.isEmpty() ? Optional.empty() : Optional.of(transitVlanFrames.get(0)) .map(TransitVlan::new); } FermaTransitVlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<TransitVlan> findAll(); @Override Collection<TransitVlan> findByPathId(PathId pathId, PathId oppositePathId); @Override Optional<TransitVlan> findByPathId(PathId pathId); @Override boolean exists(int vlan); @Override Optional<TransitVlan> findByVlan(int vlan); @Override Optional<Integer> findFirstUnassignedVlan(int lowestTransitVlan, int highestTransitVlan); }
@Test public void findNPathsByVxlanAndCost() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException { List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, VXLAN, COST); assertVxlanAndCostPathes(paths); }
public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); static final int MAX_PATH_COUNT; }
@Test public void shouldCreateVxlan() { Vxlan vxlan = createVxlan(); Collection<Vxlan> allVxlans = vxlanRepository.findAll(); Vxlan foundVxlan = allVxlans.iterator().next(); assertEquals(vxlan.getVni(), foundVxlan.getVni()); assertEquals(TEST_FLOW_ID, foundVxlan.getFlowId()); }
@Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
@Test public void shouldDeleteVxlan() { Vxlan vxlan = createVxlan(); transactionManager.doInTransaction(() -> vxlanRepository.remove(vxlan)); assertEquals(0, vxlanRepository.findAll().size()); }
@Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
@Test public void shouldDeleteFoundVxlan() { createVxlan(); transactionManager.doInTransaction(() -> { Collection<Vxlan> allVxlans = vxlanRepository.findAll(); Vxlan foundVxlan = allVxlans.iterator().next(); vxlanRepository.remove(foundVxlan); }); assertEquals(0, vxlanRepository.findAll().size()); }
@Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
@Test public void shouldSelectNextInOrderResourceWhenFindUnassignedVxlan() { int first = findUnassignedVxlanAndCreate("flow_1"); assertEquals(5, first); int second = findUnassignedVxlanAndCreate("flow_2"); assertEquals(6, second); int third = findUnassignedVxlanAndCreate("flow_3"); assertEquals(7, third); transactionManager.doInTransaction(() -> { vxlanRepository.findAll().stream() .filter(vxlan -> vxlan.getVni() == second) .forEach(vxlanRepository::remove); }); int fourth = findUnassignedVxlanAndCreate("flow_4"); assertEquals(6, fourth); int fifth = findUnassignedVxlanAndCreate("flow_5"); assertEquals(8, fifth); }
@Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
FermaVxlanRepository extends FermaGenericRepository<Vxlan, VxlanData, VxlanFrame> implements VxlanRepository { @Override public Collection<Vxlan> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(VxlanFrame.FRAME_LABEL)) .toListExplicit(VxlanFrame.class).stream() .map(Vxlan::new) .collect(Collectors.toList()); } FermaVxlanRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<Vxlan> findAll(); @Override Collection<Vxlan> findByPathId(PathId pathId, PathId oppositePathId); @Override boolean exists(int vxlan); @Override Optional<Integer> findFirstUnassignedVxlan(int lowestVxlan, int highestVxlan); }
@Test public void shouldCreateFlowMeter() { createFlowMeter(); Collection<FlowMeter> allMeters = flowMeterRepository.findAll(); FlowMeter foundMeter = allMeters.iterator().next(); assertEquals(theSwitch.getSwitchId(), foundMeter.getSwitchId()); assertEquals(TEST_FLOW_ID, foundMeter.getFlowId()); }
@Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Ignore("InMemoryGraph doesn't enforce constraint") @Test(expected = PersistenceException.class) public void shouldNotGetMoreThanOneMetersForPath() { createFlowMeter(1, new PathId(TEST_PATH_ID)); createFlowMeter(2, new PathId(TEST_PATH_ID)); flowMeterRepository.findByPathId(new PathId(TEST_PATH_ID)); }
@Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Test public void shouldGetZeroMetersForPath() { Optional<FlowMeter> meters = flowMeterRepository.findByPathId(new PathId(TEST_PATH_ID)); assertFalse(meters.isPresent()); }
@Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Optional<FlowMeter> findByPathId(PathId pathId) { List<? extends FlowMeterFrame> flowMeterFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL) .has(FlowMeterFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowMeterFrame.class); return flowMeterFrames.isEmpty() ? Optional.empty() : Optional.of(flowMeterFrames.get(0)) .map(FlowMeter::new); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Test public void shouldDeleteFlowMeter() { FlowMeter meter = createFlowMeter(); transactionManager.doInTransaction(() -> flowMeterRepository.remove(meter)); assertEquals(0, flowMeterRepository.findAll().size()); }
@Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Test public void shouldDeleteFoundFlowMeter() { createFlowMeter(); transactionManager.doInTransaction(() -> { Collection<FlowMeter> allMeters = flowMeterRepository.findAll(); FlowMeter foundMeter = allMeters.iterator().next(); flowMeterRepository.remove(foundMeter); }); assertEquals(0, flowMeterRepository.findAll().size()); }
@Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Test public void shouldSelectNextInOrderResourceWhenFindUnassignedMeter() { long first = findUnassignedMeterAndCreate("flow_1"); assertEquals(5, first); long second = findUnassignedMeterAndCreate("flow_2"); assertEquals(6, second); long third = findUnassignedMeterAndCreate("flow_3"); assertEquals(7, third); transactionManager.doInTransaction(() -> { flowMeterRepository.findAll().stream() .filter(flowMeter -> flowMeter.getMeterId().getValue() == second) .forEach(flowMeterRepository::remove); }); long fourth = findUnassignedMeterAndCreate("flow_4"); assertEquals(6, fourth); long fifth = findUnassignedMeterAndCreate("flow_5"); assertEquals(8, fifth); }
@Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId); }
@Test public void findNPathsByTransitVlanAndDefaultStrategy() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException { kildaConfigurationRepository.find().ifPresent(config -> { config.setPathComputationStrategy(LATENCY); }); List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, TRANSIT_VLAN, null); assertTransitVlanAndLatencyPaths(paths); }
public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); static final int MAX_PATH_COUNT; }
@Test public void createConnectedDeviceTest() { connectedDeviceRepository.add(lldpConnectedDeviceA); Collection<SwitchConnectedDevice> devices = connectedDeviceRepository.findAll(); assertEquals(lldpConnectedDeviceA, devices.iterator().next()); assertNotNull(devices.iterator().next().getSwitchObj()); }
@Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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 Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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); }
@Test public void deleteConnectedDeviceTest() { transactionManager.doInTransaction(() -> { connectedDeviceRepository.add(lldpConnectedDeviceA); connectedDeviceRepository.add(lldpConnectedDeviceB); assertEquals(2, connectedDeviceRepository.findAll().size()); connectedDeviceRepository.remove(lldpConnectedDeviceA); assertEquals(1, connectedDeviceRepository.findAll().size()); assertEquals(lldpConnectedDeviceB, connectedDeviceRepository.findAll().iterator().next()); connectedDeviceRepository.remove(lldpConnectedDeviceB); assertEquals(0, connectedDeviceRepository.findAll().size()); }); }
@Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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 Collection<SwitchConnectedDevice> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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); }
@Test public void findBySwitchIdTest() { connectedDeviceRepository.add(lldpConnectedDeviceA); connectedDeviceRepository.add(lldpConnectedDeviceB); connectedDeviceRepository.add(arpConnectedDeviceC); connectedDeviceRepository.add(arpConnectedDeviceD); Collection<SwitchConnectedDevice> firstSwitchDevices = connectedDeviceRepository .findBySwitchId(FIRST_SWITCH_ID); assertEquals(1, firstSwitchDevices.size()); assertEquals(lldpConnectedDeviceA, firstSwitchDevices.iterator().next()); Collection<SwitchConnectedDevice> secondFlowDevices = connectedDeviceRepository .findBySwitchId(SECOND_SWITCH_ID); assertEquals(3, secondFlowDevices.size()); assertEquals(newHashSet(lldpConnectedDeviceB, arpConnectedDeviceC, arpConnectedDeviceD), newHashSet(secondFlowDevices)); }
@Override public Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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 Collection<SwitchConnectedDevice> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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); }
@Test public void findByFlowIdTest() { connectedDeviceRepository.add(lldpConnectedDeviceA); connectedDeviceRepository.add(lldpConnectedDeviceB); connectedDeviceRepository.add(arpConnectedDeviceC); connectedDeviceRepository.add(arpConnectedDeviceD); Collection<SwitchConnectedDevice> firstDevice = connectedDeviceRepository.findByFlowId(FIRST_FLOW_ID); assertEquals(1, firstDevice.size()); assertEquals(lldpConnectedDeviceA, firstDevice.iterator().next()); Collection<SwitchConnectedDevice> secondDevices = connectedDeviceRepository.findByFlowId(SECOND_FLOW_ID); assertEquals(2, secondDevices.size()); assertEquals(newHashSet(lldpConnectedDeviceB, arpConnectedDeviceD), newHashSet(secondDevices)); }
@Override public Collection<SwitchConnectedDevice> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } FermaSwitchConnectedDevicesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchConnectedDevicesRepository extends FermaGenericRepository<SwitchConnectedDevice, SwitchConnectedDeviceData, SwitchConnectedDeviceFrame> implements SwitchConnectedDeviceRepository { @Override public Collection<SwitchConnectedDevice> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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 Collection<SwitchConnectedDevice> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchConnectedDeviceFrame.FRAME_LABEL) .has(SwitchConnectedDeviceFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(SwitchConnectedDeviceFrame.class).stream() .map(SwitchConnectedDevice::new) .collect(Collectors.toList()); } 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); }
@Test public void findByLldpUniqueFields() { connectedDeviceRepository.add(lldpConnectedDeviceA); connectedDeviceRepository.add(lldpConnectedDeviceB); connectedDeviceRepository.add(arpConnectedDeviceC); runFindByLldpUniqueFields(lldpConnectedDeviceA); runFindByLldpUniqueFields(lldpConnectedDeviceB); runFindByLldpUniqueFields(arpConnectedDeviceC); 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); }
@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); }
@Test public void shouldFindHistoryRecordsBySwitchByIdAndPortNumber() { Instant start = new Date().toInstant(); Instant end = new Date().toInstant().plus(1, ChronoUnit.DAYS); PortHistory portUp = createPortHistory(SWITCH_ID, PORT_NUMBER, "PORT_UP", start.plus(1, ChronoUnit.HOURS)); PortHistory portDown = createPortHistory(SWITCH_ID, PORT_NUMBER, "PORT_DOWN", end); createPortHistory(new SwitchId(2L), PORT_NUMBER, "TEST1", end); createPortHistory(SWITCH_ID, 3, "TEST2", end); createPortHistory(SWITCH_ID, PORT_NUMBER, "TEST3", start.minus(1, ChronoUnit.SECONDS)); createPortHistory(SWITCH_ID, PORT_NUMBER, "TEST4", end.plus(1, ChronoUnit.HOURS)); Collection<PortHistory> portHistory = repository.findBySwitchIdAndPortNumber(SWITCH_ID, PORT_NUMBER, start, end); assertEquals(2, portHistory.size()); assertTrue(portHistory.contains(portUp)); assertTrue(portHistory.contains(portDown)); }
@Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo); }
@Test public void shouldCreateAndUpdateFeatureToggles() { FeatureToggles featureTogglesA = FeatureToggles.builder() .flowsRerouteOnIslDiscoveryEnabled(false) .createFlowEnabled(false) .updateFlowEnabled(false) .deleteFlowEnabled(false) .useBfdForIslIntegrityCheck(false) .floodlightRoutePeriodicSync(false) .flowsRerouteUsingDefaultEncapType(false) .build(); featureTogglesRepository.add(featureTogglesA); FeatureToggles foundFeatureToggles = featureTogglesRepository.find().get(); assertEquals(featureTogglesA, foundFeatureToggles); foundFeatureToggles.setUpdateFlowEnabled(true); FeatureToggles updatedFeatureToggles = featureTogglesRepository.find().get(); assertTrue(updatedFeatureToggles.getUpdateFlowEnabled()); }
@Override public Optional<FeatureToggles> find() { List<? extends FeatureTogglesFrame> featureTogglesFrames = framedGraph().traverse(g -> g.V() .hasLabel(FeatureTogglesFrame.FRAME_LABEL)) .toListExplicit(FeatureTogglesFrame.class); return featureTogglesFrames.isEmpty() ? Optional.empty() : Optional.of(featureTogglesFrames.get(0)) .map(FeatureToggles::new); }
FermaFeatureTogglesRepository extends FermaGenericRepository<FeatureToggles, FeatureTogglesData, FeatureTogglesFrame> implements FeatureTogglesRepository { @Override public Optional<FeatureToggles> find() { List<? extends FeatureTogglesFrame> featureTogglesFrames = framedGraph().traverse(g -> g.V() .hasLabel(FeatureTogglesFrame.FRAME_LABEL)) .toListExplicit(FeatureTogglesFrame.class); return featureTogglesFrames.isEmpty() ? Optional.empty() : Optional.of(featureTogglesFrames.get(0)) .map(FeatureToggles::new); } }
FermaFeatureTogglesRepository extends FermaGenericRepository<FeatureToggles, FeatureTogglesData, FeatureTogglesFrame> implements FeatureTogglesRepository { @Override public Optional<FeatureToggles> find() { List<? extends FeatureTogglesFrame> featureTogglesFrames = framedGraph().traverse(g -> g.V() .hasLabel(FeatureTogglesFrame.FRAME_LABEL)) .toListExplicit(FeatureTogglesFrame.class); return featureTogglesFrames.isEmpty() ? Optional.empty() : Optional.of(featureTogglesFrames.get(0)) .map(FeatureToggles::new); } FermaFeatureTogglesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFeatureTogglesRepository extends FermaGenericRepository<FeatureToggles, FeatureTogglesData, FeatureTogglesFrame> implements FeatureTogglesRepository { @Override public Optional<FeatureToggles> find() { List<? extends FeatureTogglesFrame> featureTogglesFrames = framedGraph().traverse(g -> g.V() .hasLabel(FeatureTogglesFrame.FRAME_LABEL)) .toListExplicit(FeatureTogglesFrame.class); return featureTogglesFrames.isEmpty() ? Optional.empty() : Optional.of(featureTogglesFrames.get(0)) .map(FeatureToggles::new); } FermaFeatureTogglesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<FeatureToggles> find(); @Override FeatureToggles getOrDefault(); }
FermaFeatureTogglesRepository extends FermaGenericRepository<FeatureToggles, FeatureTogglesData, FeatureTogglesFrame> implements FeatureTogglesRepository { @Override public Optional<FeatureToggles> find() { List<? extends FeatureTogglesFrame> featureTogglesFrames = framedGraph().traverse(g -> g.V() .hasLabel(FeatureTogglesFrame.FRAME_LABEL)) .toListExplicit(FeatureTogglesFrame.class); return featureTogglesFrames.isEmpty() ? Optional.empty() : Optional.of(featureTogglesFrames.get(0)) .map(FeatureToggles::new); } FermaFeatureTogglesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<FeatureToggles> find(); @Override FeatureToggles getOrDefault(); }
@Test public void shouldCreateBfdPort() { createBfdSession(); assertEquals(1, repository.findAll().size()); }
@Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
@Test public void shouldFindBySwitchIdAndPort() { BfdSession bfdSession = createBfdSession(); BfdSession foundPort = repository.findBySwitchIdAndPort(TEST_SWITCH_ID, TEST_PORT).get(); assertEquals(bfdSession.getDiscriminator(), foundPort.getDiscriminator()); }
@Override public Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port) { List<? extends BfdSessionFrame> bfdSessionFrames = framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL) .has(BfdSessionFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(BfdSessionFrame.PORT_PROPERTY, port)) .toListExplicit(BfdSessionFrame.class); return bfdSessionFrames.isEmpty() ? Optional.empty() : Optional.of(bfdSessionFrames.get(0)) .map(BfdSession::new); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port) { List<? extends BfdSessionFrame> bfdSessionFrames = framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL) .has(BfdSessionFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(BfdSessionFrame.PORT_PROPERTY, port)) .toListExplicit(BfdSessionFrame.class); return bfdSessionFrames.isEmpty() ? Optional.empty() : Optional.of(bfdSessionFrames.get(0)) .map(BfdSession::new); } }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port) { List<? extends BfdSessionFrame> bfdSessionFrames = framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL) .has(BfdSessionFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(BfdSessionFrame.PORT_PROPERTY, port)) .toListExplicit(BfdSessionFrame.class); return bfdSessionFrames.isEmpty() ? Optional.empty() : Optional.of(bfdSessionFrames.get(0)) .map(BfdSession::new); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port) { List<? extends BfdSessionFrame> bfdSessionFrames = framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL) .has(BfdSessionFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(BfdSessionFrame.PORT_PROPERTY, port)) .toListExplicit(BfdSessionFrame.class); return bfdSessionFrames.isEmpty() ? Optional.empty() : Optional.of(bfdSessionFrames.get(0)) .map(BfdSession::new); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port) { List<? extends BfdSessionFrame> bfdSessionFrames = framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL) .has(BfdSessionFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(BfdSessionFrame.PORT_PROPERTY, port)) .toListExplicit(BfdSessionFrame.class); return bfdSessionFrames.isEmpty() ? Optional.empty() : Optional.of(bfdSessionFrames.get(0)) .map(BfdSession::new); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
@Test public void findNPathsByDefaultEncapsulationAndCost() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException { kildaConfigurationRepository.find().ifPresent(config -> { config.setFlowEncapsulationType(VXLAN); }); List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, null, COST); assertVxlanAndCostPathes(paths); }
public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); }
PathsService { public List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException { if (Objects.equals(srcSwitchId, dstSwitchId)) { throw new IllegalArgumentException( String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId)); } if (!switchRepository.exists(srcSwitchId)) { throw new SwitchNotFoundException(srcSwitchId); } if (!switchRepository.exists(dstSwitchId)) { throw new SwitchNotFoundException(dstSwitchId); } KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault(); FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType) .orElse(kildaConfiguration.getFlowEncapsulationType()); PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy) .orElse(kildaConfiguration.getPathComputationStrategy()); List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy); return flowPaths.stream().map(PathMapper.INSTANCE::map) .map(path -> PathsInfoData.builder().path(path).build()) .collect(Collectors.toList()); } PathsService(RepositoryFactory repositoryFactory, PathComputerConfig pathComputerConfig); List<PathsInfoData> getPaths( SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy); static final int MAX_PATH_COUNT; }
@Test(expected = IllegalSwitchPropertiesException.class) public void shouldValidateSupportedEncapsulationTypeWhenUpdatingSwitchProperties() { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); createSwitchProperties(sw, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), false, false, false); switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, new SwitchPropertiesDto()); }
public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) { if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) { throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty"); } SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto); UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> { SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId) .orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId)); validateSwitchProperties(switchId, update); final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update); switchProperties.setMultiTable(update.isMultiTable()); switchProperties.setSwitchLldp(update.isSwitchLldp()); switchProperties.setSwitchArp(update.isSwitchArp()); switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation()); switchProperties.setServer42FlowRtt(update.isServer42FlowRtt()); switchProperties.setServer42Port(update.getServer42Port()); switchProperties.setServer42Vlan(update.getServer42Vlan()); switchProperties.setServer42MacAddress(update.getServer42MacAddress()); return new UpdateSwitchPropertiesResult( SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded); }); if (result.isSwitchSyncRequired()) { carrier.requestSwitchSync(switchId); } if (switchPropertiesDto.isServer42FlowRtt()) { carrier.enableServer42FlowRttOnSwitch(switchId); } else { carrier.disableServer42FlowRttOnSwitch(switchId); } return result.switchPropertiesDto; }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) { if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) { throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty"); } SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto); UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> { SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId) .orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId)); validateSwitchProperties(switchId, update); final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update); switchProperties.setMultiTable(update.isMultiTable()); switchProperties.setSwitchLldp(update.isSwitchLldp()); switchProperties.setSwitchArp(update.isSwitchArp()); switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation()); switchProperties.setServer42FlowRtt(update.isServer42FlowRtt()); switchProperties.setServer42Port(update.getServer42Port()); switchProperties.setServer42Vlan(update.getServer42Vlan()); switchProperties.setServer42MacAddress(update.getServer42MacAddress()); return new UpdateSwitchPropertiesResult( SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded); }); if (result.isSwitchSyncRequired()) { carrier.requestSwitchSync(switchId); } if (switchPropertiesDto.isServer42FlowRtt()) { carrier.enableServer42FlowRttOnSwitch(switchId); } else { carrier.disableServer42FlowRttOnSwitch(switchId); } return result.switchPropertiesDto; } }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) { if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) { throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty"); } SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto); UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> { SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId) .orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId)); validateSwitchProperties(switchId, update); final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update); switchProperties.setMultiTable(update.isMultiTable()); switchProperties.setSwitchLldp(update.isSwitchLldp()); switchProperties.setSwitchArp(update.isSwitchArp()); switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation()); switchProperties.setServer42FlowRtt(update.isServer42FlowRtt()); switchProperties.setServer42Port(update.getServer42Port()); switchProperties.setServer42Vlan(update.getServer42Vlan()); switchProperties.setServer42MacAddress(update.getServer42MacAddress()); return new UpdateSwitchPropertiesResult( SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded); }); if (result.isSwitchSyncRequired()) { carrier.requestSwitchSync(switchId); } if (switchPropertiesDto.isServer42FlowRtt()) { carrier.enableServer42FlowRttOnSwitch(switchId); } else { carrier.disableServer42FlowRttOnSwitch(switchId); } return result.switchPropertiesDto; } SwitchOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager, SwitchOperationsServiceCarrier carrier); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) { if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) { throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty"); } SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto); UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> { SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId) .orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId)); validateSwitchProperties(switchId, update); final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update); switchProperties.setMultiTable(update.isMultiTable()); switchProperties.setSwitchLldp(update.isSwitchLldp()); switchProperties.setSwitchArp(update.isSwitchArp()); switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation()); switchProperties.setServer42FlowRtt(update.isServer42FlowRtt()); switchProperties.setServer42Port(update.getServer42Port()); switchProperties.setServer42Vlan(update.getServer42Vlan()); switchProperties.setServer42MacAddress(update.getServer42MacAddress()); return new UpdateSwitchPropertiesResult( SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded); }); if (result.isSwitchSyncRequired()) { carrier.requestSwitchSync(switchId); } if (switchPropertiesDto.isServer42FlowRtt()) { carrier.enableServer42FlowRttOnSwitch(switchId); } else { carrier.disableServer42FlowRttOnSwitch(switchId); } return result.switchPropertiesDto; } SwitchOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager, SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices( SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) { if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) { throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty"); } SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto); UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> { SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId) .orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId)); validateSwitchProperties(switchId, update); final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update); switchProperties.setMultiTable(update.isMultiTable()); switchProperties.setSwitchLldp(update.isSwitchLldp()); switchProperties.setSwitchArp(update.isSwitchArp()); switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation()); switchProperties.setServer42FlowRtt(update.isServer42FlowRtt()); switchProperties.setServer42Port(update.getServer42Port()); switchProperties.setServer42Vlan(update.getServer42Vlan()); switchProperties.setServer42MacAddress(update.getServer42MacAddress()); return new UpdateSwitchPropertiesResult( SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded); }); if (result.isSwitchSyncRequired()) { carrier.requestSwitchSync(switchId); } if (switchPropertiesDto.isServer42FlowRtt()) { carrier.enableServer42FlowRttOnSwitch(switchId); } else { carrier.disableServer42FlowRttOnSwitch(switchId); } return result.switchPropertiesDto; } SwitchOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager, SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices( SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data); }
@Test public void shouldDeleteBfdPort() { BfdSession bfdSession = createBfdSession(); assertEquals(1, repository.findAll().size()); transactionManager.doInTransaction(() -> repository.remove(bfdSession)); assertEquals(0, repository.findAll().size()); }
@Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
@Ignore("Need to fix: in-memory persistence doesn't impose constraints") @Test(expected = ConstraintViolationException.class) public void createUseCaseTest() { assertEquals(TEST_DISCRIMINATOR, getDiscriminator(TEST_SWITCH_ID, TEST_PORT, TEST_DISCRIMINATOR)); assertEquals(TEST_DISCRIMINATOR, getDiscriminator(TEST_SWITCH_ID, TEST_PORT, TEST_DISCRIMINATOR)); assertEquals(1, repository.findAll().size()); assertEquals(TEST_DISCRIMINATOR, getDiscriminator(TEST_SWITCH_ID, TEST_PORT + 1, TEST_DISCRIMINATOR)); }
@Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
@Test public void deleteUseCaseTest() { getDiscriminator(TEST_SWITCH_ID, TEST_PORT, TEST_DISCRIMINATOR); assertEquals(1, repository.findAll().size()); freeDiscriminator(TEST_SWITCH_ID, TEST_PORT); assertEquals(0, repository.findAll().size()); }
@Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
FermaBfdSessionRepository extends FermaGenericRepository<BfdSession, BfdSessionData, BfdSessionFrame> implements BfdSessionRepository { @Override public Collection<BfdSession> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(BfdSessionFrame.FRAME_LABEL)) .toListExplicit(BfdSessionFrame.class).stream() .map(BfdSession::new) .collect(Collectors.toList()); } FermaBfdSessionRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<BfdSession> findAll(); @Override boolean exists(SwitchId switchId, Integer port); @Override Optional<BfdSession> findBySwitchIdAndPort(SwitchId switchId, Integer port); }
@Test public void shouldCreateSwitchPropertiesWithRelation() { Switch origSwitch = Switch.builder() .switchId(TEST_SWITCH_ID) .description("Some description") .build(); switchRepository.add(origSwitch); SwitchProperties switchProperties = SwitchProperties.builder() .switchObj(origSwitch) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES) .build(); switchPropertiesRepository.add(switchProperties); List<SwitchProperties> switchPropertiesResult = new ArrayList<>(switchPropertiesRepository.findAll()); assertEquals(1, switchPropertiesResult.size()); assertNotNull(switchPropertiesResult.get(0).getSwitchObj()); }
@Override public Collection<SwitchProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL)) .toListExplicit(SwitchPropertiesFrame.class).stream() .map(SwitchProperties::new) .collect(Collectors.toList()); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Collection<SwitchProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL)) .toListExplicit(SwitchPropertiesFrame.class).stream() .map(SwitchProperties::new) .collect(Collectors.toList()); } }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Collection<SwitchProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL)) .toListExplicit(SwitchPropertiesFrame.class).stream() .map(SwitchProperties::new) .collect(Collectors.toList()); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Collection<SwitchProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL)) .toListExplicit(SwitchPropertiesFrame.class).stream() .map(SwitchProperties::new) .collect(Collectors.toList()); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Collection<SwitchProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL)) .toListExplicit(SwitchPropertiesFrame.class).stream() .map(SwitchProperties::new) .collect(Collectors.toList()); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
@Test public void shouldFindSwitchPropertiesBySwitchId() { Switch origSwitch = Switch.builder() .switchId(TEST_SWITCH_ID) .description("Some description") .build(); switchRepository.add(origSwitch); SwitchProperties switchProperties = SwitchProperties.builder() .switchObj(origSwitch) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES) .build(); switchPropertiesRepository.add(switchProperties); Optional<SwitchProperties> switchPropertiesOptional = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID); assertTrue(switchPropertiesOptional.isPresent()); }
@Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
@Test public void shouldCreatePropertiesWithServer42Props() { Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID) .description("Some description").build(); switchRepository.add(origSwitch); SwitchProperties switchProperties = SwitchProperties.builder() .switchObj(origSwitch) .server42FlowRtt(true) .server42Port(SERVER_42_PORT) .server42Vlan(SERVER_42_VLAN) .server42MacAddress(SERVER_42_MAC_ADDRESS) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES) .build(); switchPropertiesRepository.add(switchProperties); Optional<SwitchProperties> switchPropertiesOptional = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID); assertTrue(switchPropertiesOptional.isPresent()); assertTrue(switchPropertiesOptional.get().isServer42FlowRtt()); assertEquals(SERVER_42_PORT, switchPropertiesOptional.get().getServer42Port()); assertEquals(SERVER_42_VLAN, switchPropertiesOptional.get().getServer42Vlan()); assertEquals(SERVER_42_MAC_ADDRESS, switchPropertiesOptional.get().getServer42MacAddress()); }
@Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
@Test public void shouldCreatePropertiesWithNullServer42Props() { Switch origSwitch = Switch.builder().switchId(TEST_SWITCH_ID) .description("Some description").build(); switchRepository.add(origSwitch); SwitchProperties switchProperties = SwitchProperties.builder() .switchObj(origSwitch) .server42Port(null) .server42Vlan(null) .server42MacAddress(null) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).build(); switchPropertiesRepository.add(switchProperties); Optional<SwitchProperties> switchPropertiesOptional = switchPropertiesRepository.findBySwitchId(TEST_SWITCH_ID); assertTrue(switchPropertiesOptional.isPresent()); assertFalse(switchPropertiesOptional.get().isServer42FlowRtt()); assertNull(switchPropertiesOptional.get().getServer42Port()); assertNull(switchPropertiesOptional.get().getServer42MacAddress()); }
@Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
FermaSwitchPropertiesRepository extends FermaGenericRepository<SwitchProperties, SwitchPropertiesData, SwitchPropertiesFrame> implements SwitchPropertiesRepository { @Override public Optional<SwitchProperties> findBySwitchId(SwitchId switchId) { List<? extends SwitchPropertiesFrame> switchPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(SwitchPropertiesFrame.FRAME_LABEL) .has(SwitchPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(SwitchPropertiesFrame.class); return switchPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(switchPropertiesFrames.get(0)) .map(SwitchProperties::new); } FermaSwitchPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<SwitchProperties> findAll(); @Override Optional<SwitchProperties> findBySwitchId(SwitchId switchId); }
@Test public void shouldCreateLinkProps() { createLinkProps(1); assertEquals(1, linkPropsRepository.findAll().size()); }
@Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void shouldDeleteLinkProps() { LinkProps linkProps = createLinkProps(1); transactionManager.doInTransaction(() -> { linkPropsRepository.remove(linkProps); }); assertEquals(0, linkPropsRepository.findAll().size()); }
@Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL)) .toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void shouldFindLinkPropsByEndpoints() { createLinkProps(2); List<LinkProps> foundLinkProps = Lists.newArrayList( linkPropsRepository.findByEndpoints(TEST_SWITCH_A_ID, 1, TEST_SWITCH_B_ID, 2)); assertThat(foundLinkProps, Matchers.hasSize(1)); }
@Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void shouldGetSwitchIdListByFlowId() { buildTransitVlanFlow(""); List<SwitchId> switchIds = service.getSwitchIdListByFlowId(TEST_FLOW_ID_A); assertEquals(4, switchIds.size()); buildOneSwitchPortFlow(); switchIds = service.getSwitchIdListByFlowId(TEST_FLOW_ID_B); assertEquals(1, switchIds.size()); }
public List<SwitchId> getSwitchIdListByFlowId(String flowId) { return switchRepository.findSwitchesInFlowPathByFlowId(flowId).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); }
FlowValidationService { public List<SwitchId> getSwitchIdListByFlowId(String flowId) { return switchRepository.findSwitchesInFlowPathByFlowId(flowId).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); } }
FlowValidationService { public List<SwitchId> getSwitchIdListByFlowId(String flowId) { return switchRepository.findSwitchesInFlowPathByFlowId(flowId).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<SwitchId> getSwitchIdListByFlowId(String flowId) { return switchRepository.findSwitchesInFlowPathByFlowId(flowId).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<SwitchId> getSwitchIdListByFlowId(String flowId) { return switchRepository.findSwitchesInFlowPathByFlowId(flowId).stream() .map(Switch::getSwitchId) .collect(Collectors.toList()); } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
@Test public void shouldFindLinkPropsBySrcEndpoint() { createLinkProps(2); List<LinkProps> foundLinkProps = Lists.newArrayList( linkPropsRepository.findByEndpoints(TEST_SWITCH_A_ID, 1, null, null)); assertThat(foundLinkProps, Matchers.hasSize(1)); }
@Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void shouldFindLinkPropsByDestEndpoint() { createLinkProps(2); List<LinkProps> foundLinkProps = Lists.newArrayList( linkPropsRepository.findByEndpoints(null, null, TEST_SWITCH_B_ID, 2)); assertThat(foundLinkProps, Matchers.hasSize(1)); }
@Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void shouldFindLinkPropsBySrcAndDestSwitches() { createLinkProps(1); List<LinkProps> foundLinkProps = Lists.newArrayList( linkPropsRepository.findByEndpoints(TEST_SWITCH_A_ID, null, TEST_SWITCH_B_ID, null)); assertThat(foundLinkProps, Matchers.hasSize(1)); }
@Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
FermaLinkPropsRepository extends FermaGenericRepository<LinkProps, LinkPropsData, LinkPropsFrame> implements LinkPropsRepository { @Override public Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(LinkPropsFrame.FRAME_LABEL); if (srcSwitch != null) { traversal = traversal.has(LinkPropsFrame.SRC_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitch)); } if (srcPort != null) { traversal = traversal.has(LinkPropsFrame.SRC_PORT_PROPERTY, srcPort); } if (dstSwitch != null) { traversal = traversal.has(LinkPropsFrame.DST_SWITCH_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitch)); } if (dstPort != null) { traversal = traversal.has(LinkPropsFrame.DST_PORT_PROPERTY, dstPort); } return traversal; }).toListExplicit(LinkPropsFrame.class).stream() .map(LinkProps::new) .collect(Collectors.toList()); } FermaLinkPropsRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<LinkProps> findAll(); @Override Collection<LinkProps> findByEndpoints(SwitchId srcSwitch, Integer srcPort, SwitchId dstSwitch, Integer dstPort); }
@Test public void testRemove() { OneToOneMapping subject = makeSubject(); subject.add(SWITCH_ALPHA, REGION_A); subject.add(SWITCH_BETA, REGION_A); subject.remove(SWITCH_ALPHA); Optional<String> result = subject.lookup(SWITCH_ALPHA); Assert.assertTrue(result.isPresent()); Assert.assertEquals(REGION_A, result.get()); Assert.assertTrue(subject.lookup(SWITCH_ALPHA).isPresent()); clock.adjust(staleDelay.plus(Duration.ofSeconds(1))); Assert.assertFalse(subject.lookup(SWITCH_ALPHA).isPresent()); Assert.assertTrue(subject.lookup(SWITCH_BETA).isPresent()); }
public void remove(SwitchId switchId, String region) { remove(switchId); }
OneToOneMapping implements MappingApproach { public void remove(SwitchId switchId, String region) { remove(switchId); } }
OneToOneMapping implements MappingApproach { public void remove(SwitchId switchId, String region) { remove(switchId); } OneToOneMapping(Clock clock, Duration staleWipeDelay); }
OneToOneMapping implements MappingApproach { public void remove(SwitchId switchId, String region) { remove(switchId); } OneToOneMapping(Clock clock, Duration staleWipeDelay); Optional<String> lookup(SwitchId switchId); @Override void set(SwitchId switchId, String region); void add(SwitchId switchId, String region); void remove(SwitchId switchId, String region); void remove(SwitchId switchId); Map<String, Set<SwitchId>> makeReversedMapping(); }
OneToOneMapping implements MappingApproach { public void remove(SwitchId switchId, String region) { remove(switchId); } OneToOneMapping(Clock clock, Duration staleWipeDelay); Optional<String> lookup(SwitchId switchId); @Override void set(SwitchId switchId, String region); void add(SwitchId switchId, String region); void remove(SwitchId switchId, String region); void remove(SwitchId switchId); Map<String, Set<SwitchId>> makeReversedMapping(); }
@Test public void multipleConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); verify(carrier, times(1)) .switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_A, subject.isReadWriteMode()))); subject.handleSwitchStatusNotification(connectEvent, REGION_B); verify(carrier, times(1)) .switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier, never()).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_B, subject.isReadWriteMode()))); }
@Override protected boolean isReadWriteMode() { return true; }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
@Test public void disconnectOneOfOneConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); verify(carrier).switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_A, subject.isReadWriteMode()))); Instant now = clock.adjust(Duration.ofSeconds(1)); Assert.assertTrue(subject.isAvailable()); SwitchInfoData disconnectEvent = makeDisconnectNotification(connectEvent.getSwitchId()); subject.handleSwitchStatusNotification(disconnectEvent, REGION_A); verify(carrier).switchStatusUpdateNotification( eq(disconnectEvent.getSwitchId()), ArgumentMatchers.eq(disconnectEvent)); Assert.assertFalse(subject.isAvailable()); Assert.assertEquals(now, subject.getBecomeUnavailableAt()); }
@Override protected boolean isReadWriteMode() { return true; }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
@Test public void disconnectTwoOfTwoConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); subject.handleSwitchStatusNotification(connectEvent, REGION_B); Assert.assertTrue(subject.isAvailable()); SwitchInfoData disconnectEvent = makeDisconnectNotification(connectEvent.getSwitchId()); clock.adjust(Duration.ofSeconds(1)); subject.handleSwitchStatusNotification(disconnectEvent, REGION_A); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(disconnectEvent.getSwitchId(), REGION_B, subject.isReadWriteMode()))); reset(carrier); Instant failedAt = clock.adjust(Duration.ofSeconds(1)); subject.handleSwitchStatusNotification(disconnectEvent, REGION_B); Assert.assertFalse(subject.isAvailable()); Assert.assertEquals(failedAt, subject.getBecomeUnavailableAt()); verify(carrier).switchStatusUpdateNotification(eq(disconnectEvent.getSwitchId()), eq(disconnectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingRemove(disconnectEvent.getSwitchId(), null, subject.isReadWriteMode()))); verifyNoMoreInteractions(carrier); }
@Override protected boolean isReadWriteMode() { return true; }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId); }
@Test public void regularSwitchConnectSequence() { SwitchMonitorService subject = makeSubject(); SwitchInfoData swAdd = new SwitchInfoData(SWITCH_ALPHA, SwitchChangeType.ADDED); subject.handleStatusUpdateNotification(swAdd, REGION_ALPHA); verify(carrier).regionUpdateNotification( eq(new RegionMappingAdd(swAdd.getSwitchId(), REGION_ALPHA, false))); verifyNoMoreInteractions(carrier); SwitchInfoData swActivate = makeSwitchActivateNotification(swAdd.getSwitchId()); subject.handleStatusUpdateNotification(swActivate, REGION_ALPHA); verify(carrier).switchStatusUpdateNotification(eq(swActivate.getSwitchId()), eq(swActivate)); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(swActivate.getSwitchId(), REGION_ALPHA, true))); verifyNoMoreInteractions(carrier); }
public void handleStatusUpdateNotification(SwitchInfoData notification, String region) { SwitchMonitorEntry entry = lookupOrCreateSwitchMonitor(notification.getSwitchId()); entry.handleStatusUpdateNotification(notification, region); }
SwitchMonitorService { public void handleStatusUpdateNotification(SwitchInfoData notification, String region) { SwitchMonitorEntry entry = lookupOrCreateSwitchMonitor(notification.getSwitchId()); entry.handleStatusUpdateNotification(notification, region); } }
SwitchMonitorService { public void handleStatusUpdateNotification(SwitchInfoData notification, String region) { SwitchMonitorEntry entry = lookupOrCreateSwitchMonitor(notification.getSwitchId()); entry.handleStatusUpdateNotification(notification, region); } SwitchMonitorService(Clock clock, SwitchMonitorCarrier carrier); }
SwitchMonitorService { public void handleStatusUpdateNotification(SwitchInfoData notification, String region) { SwitchMonitorEntry entry = lookupOrCreateSwitchMonitor(notification.getSwitchId()); entry.handleStatusUpdateNotification(notification, region); } SwitchMonitorService(Clock clock, SwitchMonitorCarrier carrier); void handleTimerTick(); void handleRegionOfflineNotification(String region); void handleStatusUpdateNotification(SwitchInfoData notification, String region); void handleNetworkDumpResponse(NetworkDumpSwitchData response, String region); }
SwitchMonitorService { public void handleStatusUpdateNotification(SwitchInfoData notification, String region) { SwitchMonitorEntry entry = lookupOrCreateSwitchMonitor(notification.getSwitchId()); entry.handleStatusUpdateNotification(notification, region); } SwitchMonitorService(Clock clock, SwitchMonitorCarrier carrier); void handleTimerTick(); void handleRegionOfflineNotification(String region); void handleStatusUpdateNotification(SwitchInfoData notification, String region); void handleNetworkDumpResponse(NetworkDumpSwitchData response, String region); }
@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()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void testHandleArpDataSameTimeOnCreate() { packetService.handleArpData(createArpInfoData()); Collection<SwitchConnectedDevice> devices = switchConnectedDeviceRepository.findAll(); assertEquals(1, devices.size()); assertEquals(devices.iterator().next().getTimeFirstSeen(), devices.iterator().next().getTimeLastSeen()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void shouldValidateFlowWithTransitVlanEncapsulation() throws FlowNotFoundException, SwitchNotFoundException { buildTransitVlanFlow(""); validateFlow(true); }
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
@Test public void testHandleLldpDataDifferentTimeOnUpdate() throws InterruptedException { packetService.handleLldpData(createLldpInfoDataData()); Thread.sleep(10); packetService.handleLldpData(createLldpInfoDataData()); Collection<SwitchConnectedDevice> devices = switchConnectedDeviceRepository.findAll(); assertEquals(1, devices.size()); assertNotEquals(devices.iterator().next().getTimeFirstSeen(), devices.iterator().next().getTimeLastSeen()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void testHandleArpDataDifferentTimeOnUpdate() throws InterruptedException { packetService.handleArpData(createArpInfoData()); Thread.sleep(10); packetService.handleArpData(createArpInfoData()); Collection<SwitchConnectedDevice> devices = switchConnectedDeviceRepository.findAll(); assertEquals(1, devices.size()); assertNotEquals(devices.iterator().next().getTimeFirstSeen(), devices.iterator().next().getTimeLastSeen()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void testHandleLldpDataNonExistentSwitch() { LldpInfoData data = createLldpInfoDataData(); data.setSwitchId(new SwitchId("12345")); packetService.handleLldpData(data); assertTrue(switchConnectedDeviceRepository.findAll().isEmpty()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void testHandleArpDataNonExistentSwitch() { ArpInfoData data = createArpInfoData(); data.setSwitchId(new SwitchId("12345")); packetService.handleArpData(data); assertTrue(switchConnectedDeviceRepository.findAll().isEmpty()); }
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); }); }
PacketService { 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); }); } }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { 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); }); } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test @Parameters(method = "getOneSwitchOnePortFlowParameters") public void findFlowRelatedDataForOneSwitchOnePortFlowTest( int inVlan, int srcVlan, int dstVlan, List<Integer> vlansInPacket, boolean source) { createFlow(FLOW_ID, srcVlan, dstVlan, null, true, true); LldpInfoData data = createLldpInfoDataData(SWITCH_ID_1, vlansInPacket, PORT_NUMBER_1); FlowRelatedData flowRelatedData = packetService.findFlowRelatedDataForOneSwitchFlow(data); assertEquals(FLOW_ID, flowRelatedData.getFlowId()); assertEquals(inVlan, flowRelatedData.getOriginalVlan()); assertEquals(source, flowRelatedData.getSource()); }
@VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test @Parameters(method = "getOneSwitchFlowParameters") public void findFlowRelatedDataForOneSwitchFlowTest( int inVlan, int srcVlan, int dstVlan, List<Integer> vlansInPacket, boolean source) { createFlow(FLOW_ID, srcVlan, dstVlan, null, true, false); LldpInfoData data = createLldpInfoDataData( SWITCH_ID_1, vlansInPacket, source ? PORT_NUMBER_1 : PORT_NUMBER_2); FlowRelatedData flowRelatedData = packetService.findFlowRelatedDataForOneSwitchFlow(data); assertEquals(FLOW_ID, flowRelatedData.getFlowId()); assertEquals(inVlan, flowRelatedData.getOriginalVlan()); assertEquals(source, flowRelatedData.getSource()); }
@VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForOneSwitchFlow(ConnectedDevicePacketBase data) { int outputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; Flow flow = getFlowBySwitchIdInPortAndOutVlan( data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); if (flow == null) { return null; } if (!flow.isOneSwitchFlow()) { log.warn("Found NOT one switch flow {} by SwitchId {}, port number {}, vlan {} from {} packet", flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), outputVlan, getPacketName(data)); return null; } if (flow.getSrcPort() == flow.getDestPort()) { return getOneSwitchOnePortFlowRelatedData(flow, outputVlan, customerVlan, data); } if (data.getPortNumber() == flow.getSrcPort()) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getPortNumber() == flow.getDestPort()) { if (flow.getDestVlan() == FULL_PORT_VLAN) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(outputVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } log.warn("Got LLDP packet from one switch flow {} with non-src/non-dst vlan {}. SwitchId {}, " + "port number {}", flow.getFlowId(), outputVlan, data.getSwitchId(), data.getPortNumber()); return null; } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test @Parameters(method = "getVlanFlowParameters") public void findFlowRelatedDataForVlanFlowTest( int inVlan, int srcVlan, int dstVlan, int transitVlan, List<Integer> vlansInPacket, boolean source) { createFlow(FLOW_ID, srcVlan, dstVlan, transitVlan, false, false); LldpInfoData data = createLldpInfoDataData( source ? SWITCH_ID_1 : SWITCH_ID_2, vlansInPacket, source ? PORT_NUMBER_1 : PORT_NUMBER_2); FlowRelatedData flowRelatedData = packetService.findFlowRelatedDataForVlanFlow(data); assertEquals(FLOW_ID, flowRelatedData.getFlowId()); assertEquals(inVlan, flowRelatedData.getOriginalVlan()); assertEquals(source, flowRelatedData.getSource()); }
@VisibleForTesting FlowRelatedData findFlowRelatedDataForVlanFlow(ConnectedDevicePacketBase data) { if (data.getVlans().isEmpty()) { log.warn("Got {} packet without transit VLAN: {}", getPacketName(data), data); return null; } int transitVlan = data.getVlans().get(0); Flow flow = findFlowByTransitVlan(transitVlan); if (flow == null) { return null; } int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; if (data.getSwitchId().equals(flow.getSrcSwitchId())) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Transit vlan: {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), transitVlan); return null; } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVlanFlow(ConnectedDevicePacketBase data) { if (data.getVlans().isEmpty()) { log.warn("Got {} packet without transit VLAN: {}", getPacketName(data), data); return null; } int transitVlan = data.getVlans().get(0); Flow flow = findFlowByTransitVlan(transitVlan); if (flow == null) { return null; } int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; if (data.getSwitchId().equals(flow.getSrcSwitchId())) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Transit vlan: {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), transitVlan); return null; } } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVlanFlow(ConnectedDevicePacketBase data) { if (data.getVlans().isEmpty()) { log.warn("Got {} packet without transit VLAN: {}", getPacketName(data), data); return null; } int transitVlan = data.getVlans().get(0); Flow flow = findFlowByTransitVlan(transitVlan); if (flow == null) { return null; } int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; if (data.getSwitchId().equals(flow.getSrcSwitchId())) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Transit vlan: {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), transitVlan); return null; } } PacketService(PersistenceManager persistenceManager); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVlanFlow(ConnectedDevicePacketBase data) { if (data.getVlans().isEmpty()) { log.warn("Got {} packet without transit VLAN: {}", getPacketName(data), data); return null; } int transitVlan = data.getVlans().get(0); Flow flow = findFlowByTransitVlan(transitVlan); if (flow == null) { return null; } int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; if (data.getSwitchId().equals(flow.getSrcSwitchId())) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Transit vlan: {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), transitVlan); return null; } } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVlanFlow(ConnectedDevicePacketBase data) { if (data.getVlans().isEmpty()) { log.warn("Got {} packet without transit VLAN: {}", getPacketName(data), data); return null; } int transitVlan = data.getVlans().get(0); Flow flow = findFlowByTransitVlan(transitVlan); if (flow == null) { return null; } int customerVlan = data.getVlans().size() > 1 ? data.getVlans().get(1) : 0; if (data.getSwitchId().equals(flow.getSrcSwitchId())) { if (flow.getSrcVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), true); } else { return new FlowRelatedData(flow.getSrcVlan(), flow.getFlowId(), true); } } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { if (flow.getDestVlan() == FULL_PORT_VLAN) { return new FlowRelatedData(customerVlan, flow.getFlowId(), false); } else { return new FlowRelatedData(flow.getDestVlan(), flow.getFlowId(), false); } } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Transit vlan: {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), transitVlan); return null; } } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test @Parameters(method = "getInOutVlanCombinationForVxlanParameters") public void findFlowRelatedDataForVxlanFlowTest( int inVlan, int srcVlan, int dstVlan, List<Integer> vlansInPacket, boolean source) { createFlow(FLOW_ID, srcVlan, dstVlan, null, false, false); LldpInfoData data = createLldpInfoDataData( source ? SWITCH_ID_1 : SWITCH_ID_2, vlansInPacket, source ? PORT_NUMBER_1 : PORT_NUMBER_2); FlowRelatedData flowRelatedData = packetService.findFlowRelatedDataForVxlanFlow(data); assertEquals(FLOW_ID, flowRelatedData.getFlowId()); assertEquals(inVlan, flowRelatedData.getOriginalVlan()); assertEquals(source, flowRelatedData.getSource()); }
@VisibleForTesting FlowRelatedData findFlowRelatedDataForVxlanFlow(ConnectedDevicePacketBase data) { int inputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); Flow flow = getFlowBySwitchIdPortAndVlan( data.getSwitchId(), data.getPortNumber(), inputVlan, getPacketName(data)); if (flow == null) { return null; } if (data.getSwitchId().equals(flow.getSrcSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), true); } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), false); } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Port number {}, input vlan {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), inputVlan); return null; } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVxlanFlow(ConnectedDevicePacketBase data) { int inputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); Flow flow = getFlowBySwitchIdPortAndVlan( data.getSwitchId(), data.getPortNumber(), inputVlan, getPacketName(data)); if (flow == null) { return null; } if (data.getSwitchId().equals(flow.getSrcSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), true); } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), false); } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Port number {}, input vlan {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), inputVlan); return null; } } }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVxlanFlow(ConnectedDevicePacketBase data) { int inputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); Flow flow = getFlowBySwitchIdPortAndVlan( data.getSwitchId(), data.getPortNumber(), inputVlan, getPacketName(data)); if (flow == null) { return null; } if (data.getSwitchId().equals(flow.getSrcSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), true); } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), false); } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Port number {}, input vlan {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), inputVlan); return null; } } PacketService(PersistenceManager persistenceManager); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVxlanFlow(ConnectedDevicePacketBase data) { int inputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); Flow flow = getFlowBySwitchIdPortAndVlan( data.getSwitchId(), data.getPortNumber(), inputVlan, getPacketName(data)); if (flow == null) { return null; } if (data.getSwitchId().equals(flow.getSrcSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), true); } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), false); } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Port number {}, input vlan {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), inputVlan); return null; } } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); }
PacketService { @VisibleForTesting FlowRelatedData findFlowRelatedDataForVxlanFlow(ConnectedDevicePacketBase data) { int inputVlan = data.getVlans().isEmpty() ? 0 : data.getVlans().get(0); Flow flow = getFlowBySwitchIdPortAndVlan( data.getSwitchId(), data.getPortNumber(), inputVlan, getPacketName(data)); if (flow == null) { return null; } if (data.getSwitchId().equals(flow.getSrcSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), true); } else if (data.getSwitchId().equals(flow.getDestSwitchId())) { return new FlowRelatedData(inputVlan, flow.getFlowId(), false); } else { log.warn("Got {} packet from Flow {} on non-src/non-dst switch {}. Port number {}, input vlan {}", getPacketName(data), flow.getFlowId(), data.getSwitchId(), data.getPortNumber(), inputVlan); return null; } } PacketService(PersistenceManager persistenceManager); void handleLldpData(LldpInfoData data); void handleArpData(ArpInfoData data); static final int FULL_PORT_VLAN; }
@Test public void testRerouteInactivePinnedFlowsOneFailedSegment() { pinnedFlow.setStatus(FlowStatus.DOWN); for (FlowPath flowPath : pinnedFlow.getPaths()) { flowPath.setStatus(FlowPathStatus.INACTIVE); for (PathSegment pathSegment : flowPath.getSegments()) { if (pathSegment.containsNode(SWITCH_ID_A, PORT)) { pathSegment.setFailed(true); } } } RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); FlowRepository flowRepository = mock(FlowRepository.class); when(flowRepository.findInactiveFlows()) .thenReturn(Collections.singletonList(pinnedFlow)); doAnswer(invocation -> { FlowStatus status = invocation.getArgument(1); pinnedFlow.setStatus(status); return null; }).when(flowRepository).updateStatusSafe(eq(pinnedFlow), any(), any()); when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository); FlowPathRepository pathRepository = mock(FlowPathRepository.class); when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository); PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class); when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository); MessageSender messageSender = mock(MessageSender.class); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); TransactionManager transactionManager = mock(TransactionManager.class); doAnswer(invocation -> { TransactionCallbackWithoutResult arg = invocation.getArgument(0); arg.doInTransaction(); return null; }).when(transactionManager).doInTransaction(Mockito.<TransactionCallbackWithoutResult>any()); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND); assertEquals(FlowStatus.UP, pinnedFlow.getStatus()); for (FlowPath fp : pinnedFlow.getPaths()) { assertEquals(FlowPathStatus.ACTIVE, fp.getStatus()); for (PathSegment ps : fp.getSegments()) { if (ps.containsNode(SWITCH_ID_A, PORT)) { assertFalse(ps.isFailed()); } } } }
public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void testRerouteInactivePinnedFlowsTwoFailedSegments() { pinnedFlow.setStatus(FlowStatus.DOWN); for (FlowPath flowPath : pinnedFlow.getPaths()) { flowPath.setStatus(FlowPathStatus.INACTIVE); for (PathSegment pathSegment : flowPath.getSegments()) { pathSegment.setFailed(true); } } RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); FlowRepository flowRepository = mock(FlowRepository.class); when(flowRepository.findInactiveFlows()) .thenReturn(Collections.singletonList(pinnedFlow)); when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository); FlowPathRepository pathRepository = mock(FlowPathRepository.class); when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository); PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class); when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository); MessageSender messageSender = mock(MessageSender.class); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); rerouteService.rerouteInactiveFlows(messageSender, CORRELATION_ID, REROUTE_INACTIVE_FLOWS_COMMAND); verify(pathRepository, times(0)).updateStatus(any(), any()); assertTrue(FlowStatus.DOWN.equals(pinnedFlow.getStatus())); for (FlowPath fp : pinnedFlow.getPaths()) { assertTrue(FlowPathStatus.INACTIVE.equals(fp.getStatus())); for (PathSegment ps : fp.getSegments()) { if (ps.containsNode(SWITCH_ID_A, PORT)) { assertFalse(ps.isFailed()); } else { assertTrue(ps.isFailed()); } } } }
public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); transactionManager.doInTransaction(() -> { Map<Flow, Set<PathId>> flowsForRerouting = getInactiveFlowsForRerouting(); for (Entry<Flow, Set<PathId>> entry : flowsForRerouting.entrySet()) { Flow flow = entry.getKey(); Set<IslEndpoint> allAffectedIslEndpoints = new HashSet<>(); for (FlowPath flowPath : flow.getPaths()) { Set<IslEndpoint> affectedIslEndpoints = new HashSet<>(); PathSegment firstSegment = null; int failedSegmentsCount = 0; for (PathSegment pathSegment : flowPath.getSegments()) { if (firstSegment == null) { firstSegment = pathSegment; } if (pathSegment.isFailed()) { affectedIslEndpoints.add(new IslEndpoint( pathSegment.getSrcSwitchId(), pathSegment.getSrcPort())); affectedIslEndpoints.add(new IslEndpoint( pathSegment.getDestSwitchId(), pathSegment.getDestPort())); if (pathSegment.containsNode(switchId, port)) { pathSegment.setFailed(false); pathSegmentRepository.updateFailedStatus(flowPath, pathSegment, false); } else { failedSegmentsCount++; } } } if (flowPath.getStatus().equals(FlowPathStatus.INACTIVE) && failedSegmentsCount == 0) { updateFlowPathStatus(flowPath, FlowPathStatus.ACTIVE); if (affectedIslEndpoints.isEmpty() && firstSegment != null) { affectedIslEndpoints.add(new IslEndpoint( firstSegment.getSrcSwitchId(), firstSegment.getSrcPort())); } } allAffectedIslEndpoints.addAll(affectedIslEndpoints); } FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute(attempt to restore inactive flows) request for {} (affected ISL " + "endpoints: {})", flow.getFlowId(), allAffectedIslEndpoints); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(allAffectedIslEndpoints) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void shouldValidateFlowWithVxlanEncapsulation() throws FlowNotFoundException, SwitchNotFoundException { buildVxlanFlow(); validateFlow(false); }
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
@Test public void handlePathNoFoundException() { PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0); FlowPathRepository pathRepository = mock(FlowPathRepository.class); when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))) .thenReturn(Arrays.asList(regularFlow.getForwardPath(), regularFlow.getReversePath())); FlowRepository flowRepository = mock(FlowRepository.class); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createPathSegmentRepository()) .thenReturn(mock(PathSegmentRepository.class)); when(repositoryFactory.createFlowPathRepository()) .thenReturn(pathRepository); when(repositoryFactory.createFlowRepository()) .thenReturn(flowRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest"); rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request); verify(flowRepository).updateStatusSafe(eq(regularFlow), eq(FlowStatus.DOWN), any()); FlowThrottlingData expected = FlowThrottlingData.builder() .correlationId(CORRELATION_ID) .priority(regularFlow.getPriority()) .timeCreate(regularFlow.getTimeCreate()) .affectedIsl(Collections.singleton(new IslEndpoint(islSide.getSwitchId(), islSide.getPortNo()))) .force(false) .effectivelyDown(true) .reason(request.getReason()) .build(); verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected)); }
public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void handleUpdateSingleSwitchFlows() { FlowRepository flowRepository = mock(FlowRepository.class); when(flowRepository.findOneSwitchFlows(oneSwitchFlow.getSrcSwitch().getSwitchId())) .thenReturn(Arrays.asList(oneSwitchFlow)); FlowPathRepository flowPathRepository = mock(FlowPathRepository.class); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createFlowRepository()) .thenReturn(flowRepository); when(repositoryFactory.createFlowPathRepository()) .thenReturn(flowPathRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); rerouteService.processSingleSwitchFlowStatusUpdate( new SwitchStateChanged(oneSwitchFlow.getSrcSwitchId(), SwitchStatus.INACTIVE)); assertEquals(format("Switch %s is inactive", oneSwitchFlow.getSrcSwitchId()), FlowStatus.DOWN, oneSwitchFlow.getStatus()); }
public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); }
RerouteService { public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); } }
RerouteService { public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request) { transactionManager.doInTransaction(() -> { Collection<Flow> affectedFlows = flowRepository.findOneSwitchFlows(request.getSwitchId()); FlowStatus newFlowStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowStatus.UP : FlowStatus.DOWN; String newFlowStatusInfo = request.getStatus() == SwitchStatus.ACTIVE ? null : format("Switch %s is inactive", request.getSwitchId()); FlowPathStatus newFlowPathStatus = request.getStatus() == SwitchStatus.ACTIVE ? FlowPathStatus.ACTIVE : FlowPathStatus.INACTIVE; for (Flow flow : affectedFlows) { log.info("Updating flow and path statuses for flow {} to {}, {}", flow.getFlowId(), newFlowStatus, newFlowPathStatus); flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), newFlowStatus); flow.setStatus(newFlowStatus); flow.setStatusInfo(newFlowStatusInfo); flow.getForwardPath().setStatus(newFlowPathStatus); flow.getReversePath().setStatus(newFlowPathStatus); } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment() { PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0); FlowPathRepository pathRepository = mock(FlowPathRepository.class); when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))) .thenReturn(Arrays.asList(regularFlow.getForwardPath(), regularFlow.getReversePath())); FlowRepository flowRepository = mock(FlowRepository.class); PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class); doThrow(new EntityNotFoundException("Not found")) .when(pathSegmentRepository).updateFailedStatus(any(), any(), anyBoolean()); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createPathSegmentRepository()) .thenReturn(pathSegmentRepository); when(repositoryFactory.createFlowPathRepository()) .thenReturn(pathRepository); when(repositoryFactory.createFlowRepository()) .thenReturn(flowRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest"); rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request); verifyZeroInteractions(carrier); }
public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command) { PathNode pathNode = command.getPathNode(); int port = pathNode.getPortNo(); SwitchId switchId = pathNode.getSwitchId(); final IslEndpoint affectedIsl = new IslEndpoint(switchId, port); transactionManager.doInTransaction(() -> { Collection<FlowPath> affectedFlowPaths = getAffectedFlowPaths(pathNode.getSwitchId(), pathNode.getPortNo()); List<FlowPath> pathsForSwapping = getPathsForSwapping(affectedFlowPaths); for (FlowPath path : pathsForSwapping) { sender.emitPathSwapCommand(correlationId, path, command.getReason()); } for (FlowWithAffectedPaths entry : groupPathsForRerouting(affectedFlowPaths)) { Flow flow = entry.getFlow(); boolean flowPathFound = updateFlowPathsStateForFlow(switchId, port, entry.getAffectedPaths()); FlowStatus flowStatus = flow.computeFlowStatus(); String flowStatusInfo = null; if (!FlowStatus.UP.equals(flowStatus)) { flowStatusInfo = command.getReason(); } flowRepository.updateStatusSafe(flow, flowStatus, flowStatusInfo); if (flowPathFound) { FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.singleton(affectedIsl)) .force(false) .effectivelyDown(true) .reason(command.getReason()) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } Set<Flow> affectedPinnedFlows = groupAffectedPinnedFlows(affectedFlowPaths); for (Flow flow : affectedPinnedFlows) { List<FlowPath> flowPaths = new ArrayList<>(flow.getPaths()); updateFlowPathsStateForFlow(switchId, port, flowPaths); if (flow.getStatus() != FlowStatus.DOWN) { flowDashboardLogger.onFlowStatusUpdate(flow.getFlowId(), FlowStatus.DOWN); flowRepository.updateStatusSafe(flow, FlowStatus.DOWN, command.getReason()); } } }); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void handleRerouteInactiveAffectedFlows() { FlowPathRepository pathRepository = mock(FlowPathRepository.class); when(pathRepository.findInactiveBySegmentSwitch(regularFlow.getSrcSwitchId())) .thenReturn(Arrays.asList(regularFlow.getForwardPath(), regularFlow.getReversePath())); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createFlowPathRepository()) .thenReturn(pathRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); regularFlow.setStatus(FlowStatus.DOWN); rerouteService.rerouteInactiveAffectedFlows(carrier, CORRELATION_ID, regularFlow.getSrcSwitchId()); FlowThrottlingData expected = FlowThrottlingData.builder() .correlationId(CORRELATION_ID) .priority(regularFlow.getPriority()) .timeCreate(regularFlow.getTimeCreate()) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", regularFlow.getSrcSwitchId())) .build(); verify(carrier).emitRerouteCommand(eq(regularFlow.getFlowId()), eq(expected)); regularFlow.setStatus(FlowStatus.UP); }
public void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId) { Set<Flow> flowsForRerouting = getAffectedInactiveFlowsForRerouting(switchId); for (Flow flow : flowsForRerouting) { if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute (attempt to restore inactive flow) request for {} (switch online {})", flow.getFlowId(), switchId); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", switchId)) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } }
RerouteService { public void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId) { Set<Flow> flowsForRerouting = getAffectedInactiveFlowsForRerouting(switchId); for (Flow flow : flowsForRerouting) { if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute (attempt to restore inactive flow) request for {} (switch online {})", flow.getFlowId(), switchId); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", switchId)) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } } }
RerouteService { public void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId) { Set<Flow> flowsForRerouting = getAffectedInactiveFlowsForRerouting(switchId); for (Flow flow : flowsForRerouting) { if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute (attempt to restore inactive flow) request for {} (switch online {})", flow.getFlowId(), switchId); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", switchId)) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId) { Set<Flow> flowsForRerouting = getAffectedInactiveFlowsForRerouting(switchId); for (Flow flow : flowsForRerouting) { if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute (attempt to restore inactive flow) request for {} (switch online {})", flow.getFlowId(), switchId); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", switchId)) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId) { Set<Flow> flowsForRerouting = getAffectedInactiveFlowsForRerouting(switchId); for (Flow flow : flowsForRerouting) { if (flow.isPinned()) { log.info("Skipping reroute command for pinned flow {}", flow.getFlowId()); } else { log.info("Produce reroute (attempt to restore inactive flow) request for {} (switch online {})", flow.getFlowId(), switchId); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow) .correlationId(correlationId) .affectedIsl(Collections.emptySet()) .force(false) .effectivelyDown(true) .reason(format("Switch '%s' online", switchId)) .build(); sender.emitRerouteCommand(flow.getFlowId(), flowThrottlingData); } } } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void processManualRerouteRequest() { FlowRepository flowRepository = mock(FlowRepository.class); when(flowRepository.findById(regularFlow.getFlowId())) .thenReturn(Optional.of(regularFlow)); RepositoryFactory repositoryFactory = mock(RepositoryFactory.class); when(repositoryFactory.createFlowRepository()) .thenReturn(flowRepository); PersistenceManager persistenceManager = mock(PersistenceManager.class); when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(persistenceManager.getTransactionManager()).thenReturn(transactionManager); RerouteService rerouteService = new RerouteService(persistenceManager); FlowRerouteRequest request = new FlowRerouteRequest(regularFlow.getFlowId(), true, true, false, Collections.emptySet(), "reason"); rerouteService.processManualRerouteRequest(carrier, CORRELATION_ID, request); FlowThrottlingData expected = FlowThrottlingData.builder() .correlationId(CORRELATION_ID) .priority(regularFlow.getPriority()) .timeCreate(regularFlow.getTimeCreate()) .affectedIsl(Collections.emptySet()) .force(true) .effectivelyDown(true) .reason("reason") .build(); verify(carrier).emitManualRerouteCommand(eq(regularFlow.getFlowId()), eq(expected)); }
public void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request) { Optional<Flow> flow = flowRepository.findById(request.getFlowId()); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow.orElse(null)) .correlationId(correlationId) .affectedIsl(request.getAffectedIsl()) .force(request.isForce()) .effectivelyDown(request.isEffectivelyDown()) .reason(request.getReason()) .build(); sender.emitManualRerouteCommand(request.getFlowId(), flowThrottlingData); }
RerouteService { public void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request) { Optional<Flow> flow = flowRepository.findById(request.getFlowId()); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow.orElse(null)) .correlationId(correlationId) .affectedIsl(request.getAffectedIsl()) .force(request.isForce()) .effectivelyDown(request.isEffectivelyDown()) .reason(request.getReason()) .build(); sender.emitManualRerouteCommand(request.getFlowId(), flowThrottlingData); } }
RerouteService { public void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request) { Optional<Flow> flow = flowRepository.findById(request.getFlowId()); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow.orElse(null)) .correlationId(correlationId) .affectedIsl(request.getAffectedIsl()) .force(request.isForce()) .effectivelyDown(request.isEffectivelyDown()) .reason(request.getReason()) .build(); sender.emitManualRerouteCommand(request.getFlowId(), flowThrottlingData); } RerouteService(PersistenceManager persistenceManager); }
RerouteService { public void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request) { Optional<Flow> flow = flowRepository.findById(request.getFlowId()); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow.orElse(null)) .correlationId(correlationId) .affectedIsl(request.getAffectedIsl()) .force(request.isForce()) .effectivelyDown(request.isEffectivelyDown()) .reason(request.getReason()) .build(); sender.emitManualRerouteCommand(request.getFlowId(), flowThrottlingData); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
RerouteService { public void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request) { Optional<Flow> flow = flowRepository.findById(request.getFlowId()); FlowThrottlingData flowThrottlingData = getFlowThrottlingDataBuilder(flow.orElse(null)) .correlationId(correlationId) .affectedIsl(request.getAffectedIsl()) .force(request.isForce()) .effectivelyDown(request.isEffectivelyDown()) .reason(request.getReason()) .build(); sender.emitManualRerouteCommand(request.getFlowId(), flowThrottlingData); } RerouteService(PersistenceManager persistenceManager); void rerouteAffectedFlows(MessageSender sender, String correlationId, RerouteAffectedFlows command); void rerouteInactiveAffectedFlows(MessageSender sender, String correlationId, SwitchId switchId); void rerouteInactiveFlows(MessageSender sender, String correlationId, RerouteInactiveFlows command); Collection<FlowPath> getAffectedFlowPaths(SwitchId switchId, int port); List<FlowPath> getPathsForSwapping(Collection<FlowPath> paths); List<FlowWithAffectedPaths> groupPathsForRerouting(Collection<FlowPath> paths); Set<Flow> groupAffectedPinnedFlows(Collection<FlowPath> paths); Map<Flow, Set<PathId>> getInactiveFlowsForRerouting(); Set<Flow> getAffectedInactiveFlowsForRerouting(SwitchId switchId); void processManualRerouteRequest(MessageSender sender, String correlationId, FlowRerouteRequest request); void processSingleSwitchFlowStatusUpdate(SwitchStateChanged request); }
@Test public void noFlushEmptyWindow() { assertFalse(extendableTimeWindow.flushIfReady()); }
public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); void registerEvent(); boolean flushIfReady(); }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); void registerEvent(); boolean flushIfReady(); }
@Test public void noFlushEmptyWindow2() { when(clock.instant()).thenReturn(Instant.now()); assertFalse(extendableTimeWindow.flushIfReady()); }
public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); void registerEvent(); boolean flushIfReady(); }
ExtendableTimeWindow { public boolean flushIfReady() { if (firstEventTime == null) { return false; } LocalDateTime now = LocalDateTime.now(clock); boolean isTimeToFlush = lastEventTime.plus(minDelay, ChronoUnit.SECONDS).isBefore(now) || firstEventTime.plus(maxDelay, ChronoUnit.SECONDS).isBefore(now); if (isTimeToFlush) { firstEventTime = null; lastEventTime = null; } return isTimeToFlush; } ExtendableTimeWindow(long minDelay, long maxDelay); ExtendableTimeWindow(long minDelay, long maxDelay, Clock clock); void registerEvent(); boolean flushIfReady(); }
@Test public void newIslWithHistory() { NetworkUniIslService service = new NetworkUniIslService(carrier); Endpoint endpoint1 = Endpoint.of(alphaDatapath, 1); Endpoint endpoint2 = Endpoint.of(alphaDatapath, 2); Switch alphaSwitch = Switch.builder().switchId(alphaDatapath).build(); Switch betaSwitch = Switch.builder().switchId(betaDatapath).build(); Isl islAtoB = Isl.builder() .srcSwitch(alphaSwitch) .srcPort(1) .destSwitch(betaSwitch) .destPort(1).build(); Isl islAtoB2 = Isl.builder() .srcSwitch(alphaSwitch) .srcPort(2) .destSwitch(betaSwitch) .destPort(2).build(); service.uniIslSetup(endpoint1, islAtoB); service.uniIslSetup(endpoint2, islAtoB2); verify(carrier).setupIslFromHistory(endpoint1, IslReference.of(islAtoB), islAtoB); verify(carrier).setupIslFromHistory(endpoint2, IslReference.of(islAtoB2), islAtoB2); }
public void uniIslSetup(Endpoint endpoint, Isl history) { log.info("Uni-ISL service receive SETUP request for {}", endpoint); IslReference reference; if (history != null) { reference = IslReference.of(history); carrier.setupIslFromHistory(endpoint, reference, history); } else { reference = IslReference.of(endpoint); } endpointData.put(endpoint, reference); }
NetworkUniIslService { public void uniIslSetup(Endpoint endpoint, Isl history) { log.info("Uni-ISL service receive SETUP request for {}", endpoint); IslReference reference; if (history != null) { reference = IslReference.of(history); carrier.setupIslFromHistory(endpoint, reference, history); } else { reference = IslReference.of(endpoint); } endpointData.put(endpoint, reference); } }
NetworkUniIslService { public void uniIslSetup(Endpoint endpoint, Isl history) { log.info("Uni-ISL service receive SETUP request for {}", endpoint); IslReference reference; if (history != null) { reference = IslReference.of(history); carrier.setupIslFromHistory(endpoint, reference, history); } else { reference = IslReference.of(endpoint); } endpointData.put(endpoint, reference); } NetworkUniIslService(IUniIslCarrier carrier); }
NetworkUniIslService { public void uniIslSetup(Endpoint endpoint, Isl history) { log.info("Uni-ISL service receive SETUP request for {}", endpoint); IslReference reference; if (history != null) { reference = IslReference.of(history); carrier.setupIslFromHistory(endpoint, reference, history); } else { reference = IslReference.of(endpoint); } endpointData.put(endpoint, reference); } NetworkUniIslService(IUniIslCarrier carrier); void uniIslSetup(Endpoint endpoint, Isl history); void uniIslDiscovery(Endpoint endpoint, IslInfoData speakerDiscoveryEvent); void uniIslFail(Endpoint endpoint); void uniIslPhysicalDown(Endpoint endpoint); void roundTripStatusNotification(RoundTripStatus status); void uniIslBfdStatusUpdate(Endpoint endpoint, BfdStatusUpdate status); void uniIslRemove(Endpoint endpoint); void islRemovedNotification(Endpoint endpoint, IslReference removedIsl); }
NetworkUniIslService { public void uniIslSetup(Endpoint endpoint, Isl history) { log.info("Uni-ISL service receive SETUP request for {}", endpoint); IslReference reference; if (history != null) { reference = IslReference.of(history); carrier.setupIslFromHistory(endpoint, reference, history); } else { reference = IslReference.of(endpoint); } endpointData.put(endpoint, reference); } NetworkUniIslService(IUniIslCarrier carrier); void uniIslSetup(Endpoint endpoint, Isl history); void uniIslDiscovery(Endpoint endpoint, IslInfoData speakerDiscoveryEvent); void uniIslFail(Endpoint endpoint); void uniIslPhysicalDown(Endpoint endpoint); void roundTripStatusNotification(RoundTripStatus status); void uniIslBfdStatusUpdate(Endpoint endpoint, BfdStatusUpdate status); void uniIslRemove(Endpoint endpoint); void islRemovedNotification(Endpoint endpoint, IslReference removedIsl); }
@Test public void newSwitch() { List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews(); SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder() .ports(ports) .build(); SwitchInfoData switchAddEvent = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView); NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); service.switchEvent(switchAddEvent); verifySwitchSync(service); verifyNewSwitchAfterSwitchSync(ports); }
public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void switchFromOnlineToOffline() { List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews(); SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder() .ports(ports) .build(); SwitchInfoData switchAddEvent = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView); NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); service.switchEvent(switchAddEvent); verifySwitchSync(service); resetMocks(); when(switchRepository.findById(alphaDatapath)).thenReturn( Optional.of(Switch.builder().switchId(alphaDatapath) .build())); SwitchInfoData deactivatedSwitch = switchAddEvent.toBuilder().state(SwitchChangeType.DEACTIVATED).build(); service.switchEvent(deactivatedSwitch); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.OFFLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), false); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.OFFLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), false); }
public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void shouldValidateOneSwitchFlow() throws FlowNotFoundException, SwitchNotFoundException { buildOneSwitchPortFlow(); List<SwitchFlowEntries> switchEntries = getSwitchFlowEntriesOneSwitchFlow(); List<SwitchMeterEntries> meterEntries = getSwitchMeterEntriesOneSwitchFlow(); List<FlowValidationResponse> result = service.validateFlow(TEST_FLOW_ID_B, switchEntries, meterEntries); assertEquals(2, result.size()); assertEquals(0, result.get(0).getDiscrepancies().size()); assertEquals(0, result.get(1).getDiscrepancies().size()); }
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
@Test public void switchFromHistoryToOffline() { when(switchRepository.findById(alphaDatapath)).thenReturn( Optional.of(Switch.builder().switchId(alphaDatapath) .build())); HistoryFacts history = new HistoryFacts(alphaDatapath); Switch alphaSwitch = Switch.builder().switchId(alphaDatapath).build(); Switch betaSwitch = Switch.builder().switchId(betaDatapath).build(); Isl islAtoB = Isl.builder() .srcSwitch(alphaSwitch) .srcPort(1) .destSwitch(betaSwitch) .destPort(1).build(); Isl islAtoB2 = Isl.builder() .srcSwitch(alphaSwitch) .srcPort(2) .destSwitch(betaSwitch) .destPort(2).build(); history.addLink(islAtoB); history.addLink(islAtoB2); NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); service.switchAddWithHistory(history); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 1), islAtoB); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 2), islAtoB2); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 1), OnlineStatus.OFFLINE); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 2), OnlineStatus.OFFLINE); }
public void switchAddWithHistory(HistoryFacts history) { log.info("Switch service receive switch ADD from history request for {}", history.getSwitchId()); SwitchFsm switchFsm = controllerFactory.produce(persistenceManager, history.getSwitchId(), options); SwitchFsmContext fsmContext = SwitchFsmContext.builder(carrier) .history(history) .build(); controller.put(history.getSwitchId(), switchFsm); controllerExecutor.fire(switchFsm, SwitchFsmEvent.HISTORY, fsmContext); }
NetworkSwitchService { public void switchAddWithHistory(HistoryFacts history) { log.info("Switch service receive switch ADD from history request for {}", history.getSwitchId()); SwitchFsm switchFsm = controllerFactory.produce(persistenceManager, history.getSwitchId(), options); SwitchFsmContext fsmContext = SwitchFsmContext.builder(carrier) .history(history) .build(); controller.put(history.getSwitchId(), switchFsm); controllerExecutor.fire(switchFsm, SwitchFsmEvent.HISTORY, fsmContext); } }
NetworkSwitchService { public void switchAddWithHistory(HistoryFacts history) { log.info("Switch service receive switch ADD from history request for {}", history.getSwitchId()); SwitchFsm switchFsm = controllerFactory.produce(persistenceManager, history.getSwitchId(), options); SwitchFsmContext fsmContext = SwitchFsmContext.builder(carrier) .history(history) .build(); controller.put(history.getSwitchId(), switchFsm); controllerExecutor.fire(switchFsm, SwitchFsmEvent.HISTORY, fsmContext); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchAddWithHistory(HistoryFacts history) { log.info("Switch service receive switch ADD from history request for {}", history.getSwitchId()); SwitchFsm switchFsm = controllerFactory.produce(persistenceManager, history.getSwitchId(), options); SwitchFsmContext fsmContext = SwitchFsmContext.builder(carrier) .history(history) .build(); controller.put(history.getSwitchId(), switchFsm); controllerExecutor.fire(switchFsm, SwitchFsmEvent.HISTORY, fsmContext); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchAddWithHistory(HistoryFacts history) { log.info("Switch service receive switch ADD from history request for {}", history.getSwitchId()); SwitchFsm switchFsm = controllerFactory.produce(persistenceManager, history.getSwitchId(), options); SwitchFsmContext fsmContext = SwitchFsmContext.builder(carrier) .history(history) .build(); controller.put(history.getSwitchId(), switchFsm); controllerExecutor.fire(switchFsm, SwitchFsmEvent.HISTORY, fsmContext); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void switchFromOnlineToOfflineToOnline() { List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews(); SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder() .ports(ports) .build(); SwitchInfoData switchAddEvent = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView); NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); service.switchEvent(switchAddEvent); verifySwitchSync(service); SwitchInfoData deactivatedSwitch = switchAddEvent.toBuilder().state(SwitchChangeType.DEACTIVATED).build(); service.switchEvent(deactivatedSwitch); List<SpeakerSwitchPortView> ports2 = getSpeakerSwitchPortViewsRevert(); SpeakerSwitchView speakerSwitchView2 = getSpeakerSwitchView().toBuilder() .ports(ports2) .build(); SwitchInfoData switchAddEvent2 = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView2); resetMocks(); service.switchEvent(switchAddEvent2); verifySwitchSync(service); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.ONLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), true); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.ONLINE); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), true); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(2).getNumber()), LinkStatus.of(ports2.get(2).getState())); verify(carrier).setBfdPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(3).getNumber()), LinkStatus.of(ports2.get(3).getState())); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(0).getNumber()), LinkStatus.of(ports2.get(0).getState())); verify(carrier).setBfdPortLinkMode(Endpoint.of(alphaDatapath, ports2.get(1).getNumber()), LinkStatus.of(ports2.get(0).getState())); verify(carrier).sendAffectedFlowRerouteRequest(alphaDatapath); }
public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void switchFromOnlineToOnlineWithLostBfdFeature() { NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); List<SpeakerSwitchPortView> ports = doSpeakerOnline(service, Collections.singleton(SwitchFeature.BFD)); List<SpeakerSwitchPortView> ports2 = swapBfdPortsState(ports); resetMocks(); service.switchBecomeManaged(getSpeakerSwitchView().toBuilder() .features(Collections.emptySet()) .ports(ports2) .build()); verify(carrier).removeBfdPortHandler(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET)); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), null); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), OnlineStatus.ONLINE); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.DOWN); verify(carrier).removeBfdPortHandler(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET)); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), null); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), OnlineStatus.ONLINE); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.UP); }
public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void switchFromOnlineToOnlineWithAcquireBfdFeature() { NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); List<SpeakerSwitchPortView> ports = doSpeakerOnline(service, Collections.emptySet()); List<SpeakerSwitchPortView> ports2 = swapBfdPortsState(ports); resetMocks(); service.switchBecomeManaged(getSpeakerSwitchView().toBuilder() .features(Collections.singleton(SwitchFeature.BFD)) .ports(ports2) .build()); verify(carrier).removePortHandler(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET)); verify(carrier).setupBfdPortHandler(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), 1); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), true); verify(carrier).setBfdPortLinkMode(Endpoint.of(alphaDatapath, 1 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.DOWN); verify(carrier).removePortHandler(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET)); verify(carrier).setupBfdPortHandler(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), 2); verify(carrier).setBfdPortOnlineMode(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), true); verify(carrier).setBfdPortLinkMode(Endpoint.of(alphaDatapath, 2 + BFD_LOGICAL_PORT_OFFSET), LinkStatus.UP); }
public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchBecomeManaged(SpeakerSwitchView switchView) { log.debug("Switch service receive MANAGED notification for {}", switchView.getDatapath()); SwitchFsm fsm = locateControllerCreateIfAbsent(switchView.getDatapath()); SwitchFsmContext context = SwitchFsmContext.builder(carrier) .speakerData(switchView) .build(); controllerExecutor.fire(fsm, SwitchFsmEvent.ONLINE, context); } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test public void switchWithNoBfdSupport() { List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews(); SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder() .ports(ports) .features(Collections.emptySet()) .build(); SwitchInfoData switchAddEvent = new SwitchInfoData( alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView); NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options); service.switchEvent(switchAddEvent); verifySwitchSync(service); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), null); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), null); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), null); verify(carrier).setupPortHandler(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), null); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), OnlineStatus.ONLINE); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), OnlineStatus.ONLINE); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), OnlineStatus.ONLINE); verify(carrier).setOnlineMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), OnlineStatus.ONLINE); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(2).getNumber()), LinkStatus.of(ports.get(2).getState())); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(3).getNumber()), LinkStatus.of(ports.get(3).getState())); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(0).getNumber()), LinkStatus.of(ports.get(0).getState())); verify(carrier).setPortLinkMode(Endpoint.of(alphaDatapath, ports.get(1).getNumber()), LinkStatus.of(ports.get(0).getState())); }
public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
NetworkSwitchService { public void switchEvent(SwitchInfoData payload) { log.info("Switch service receive SWITCH event for {} status:{}", payload.getSwitchId(), payload.getState()); SwitchFsmContext.SwitchFsmContextBuilder fsmContextBuilder = SwitchFsmContext.builder(carrier); SwitchFsmEvent event = null; switch (payload.getState()) { case ACTIVATED: event = SwitchFsmEvent.ONLINE; fsmContextBuilder.speakerData(payload.getSwitchView()); break; case DEACTIVATED: event = SwitchFsmEvent.OFFLINE; break; default: log.info("Ignore switch event {} on {} (no need to handle it)", payload.getState(), payload.getSwitchId()); break; } if (event != null) { SwitchFsm fsm = locateControllerCreateIfAbsent(payload.getSwitchId()); controllerExecutor.fire(fsm, event, fsmContextBuilder.build()); } } NetworkSwitchService(ISwitchCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); void switchAddWithHistory(HistoryFacts history); void switchEvent(SwitchInfoData payload); void switchManagerResponse(SwitchSyncResponse payload, String key); void switchManagerErrorResponse(SwitchSyncErrorData payload, String key); void switchManagerTimeout(SwitchId switchId, String key); void switchBecomeUnmanaged(SwitchId datapath); void switchBecomeManaged(SpeakerSwitchView switchView); void switchPortEvent(PortInfoData payload); void remove(SwitchId datapath); }
@Test @Ignore("incomplete") public void initialUp() { persistenceManager = new InMemoryGraphPersistenceManager( new PropertiesBasedConfigurationProvider().getConfiguration(NetworkConfig.class)); emulateEmptyPersistentDb(); SwitchRepository switchRepository = persistenceManager.getRepositoryFactory() .createSwitchRepository(); Switch swA = Switch.builder() .switchId(endpointAlpha1.getDatapath()) .description("alpha") .build(); switchRepository.add(swA); switchPropertiesRepository.add(SwitchProperties.builder() .multiTable(false) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES) .switchObj(swA).build()); Switch swB = Switch.builder() .switchId(endpointBeta2.getDatapath()) .description("alpha") .build(); switchRepository.add(swB); switchPropertiesRepository.add(SwitchProperties.builder() .multiTable(false) .supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES) .switchObj(swB).build()); IslReference ref = new IslReference(endpointAlpha1, endpointBeta2); IslDataHolder islData = new IslDataHolder(1000, 1000, 1000); service = new NetworkIslService(carrier, persistenceManager, options); service.islUp(ref.getSource(), ref, islData); System.out.println(mockingDetails(carrier).printInvocations()); System.out.println(mockingDetails(islRepository).printInvocations()); }
public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test @Ignore("become invalid due to change initialisation logic") public void initialMoveEvent() { emulateEmptyPersistentDb(); IslReference ref = new IslReference(endpointAlpha1, endpointBeta2); service.islMove(ref.getSource(), ref); verify(carrier, times(2)).triggerReroute(any(RerouteAffectedFlows.class)); verify(islRepository).add(argThat( link -> link.getSrcSwitchId().equals(endpointAlpha1.getDatapath()) && link.getSrcPort() == endpointAlpha1.getPortNumber() && link.getDestSwitchId().equals(endpointBeta2.getDatapath()) && link.getDestPort() == endpointBeta2.getPortNumber() && link.getActualStatus() == IslStatus.INACTIVE && link.getStatus() == IslStatus.INACTIVE)); verify(islRepository).add(argThat( link -> link.getSrcSwitchId().equals(endpointBeta2.getDatapath()) && link.getSrcPort() == endpointBeta2.getPortNumber() && link.getDestSwitchId().equals(endpointAlpha1.getDatapath()) && link.getDestPort() == endpointAlpha1.getPortNumber() && link.getActualStatus() == IslStatus.INACTIVE && link.getStatus() == IslStatus.INACTIVE)); verifyNoMoreInteractions(carrier); }
public void islMove(Endpoint endpoint, IslReference reference) { log.debug("ISL service receive MOVED(FAIL) notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint).build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_MOVE, context); }
NetworkIslService { public void islMove(Endpoint endpoint, IslReference reference) { log.debug("ISL service receive MOVED(FAIL) notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint).build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_MOVE, context); } }
NetworkIslService { public void islMove(Endpoint endpoint, IslReference reference) { log.debug("ISL service receive MOVED(FAIL) notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint).build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_MOVE, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islMove(Endpoint endpoint, IslReference reference) { log.debug("ISL service receive MOVED(FAIL) notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint).build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_MOVE, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islMove(Endpoint endpoint, IslReference reference) { log.debug("ISL service receive MOVED(FAIL) notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint).build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_MOVE, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test public void setIslUnstableTimeOnPortDown() { setupIslStorageStub(); IslReference reference = prepareActiveIsl(); Instant updateTime = clock.adjust(Duration.ofSeconds(1)); service.islDown(endpointAlpha1, reference, IslDownReason.PORT_DOWN); Isl forward = lookupIsl(reference.getSource(), reference.getDest()); Assert.assertEquals(updateTime, forward.getTimeUnstable()); Isl reverse = lookupIsl(reference.getDest(), reference.getSource()); Assert.assertEquals(updateTime, reverse.getTimeUnstable()); }
public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test public void repeatOnTransientDbErrors() { mockPersistenceIsl(endpointAlpha1, endpointBeta2, null); mockPersistenceIsl(endpointBeta2, endpointAlpha1, null); mockPersistenceLinkProps(endpointAlpha1, endpointBeta2, null); mockPersistenceLinkProps(endpointBeta2, endpointAlpha1, null); mockPersistenceBandwidthAllocation(endpointAlpha1, endpointBeta2, 0); mockPersistenceBandwidthAllocation(endpointBeta2, endpointAlpha1, 0); IslReference reference = new IslReference(endpointAlpha1, endpointBeta2); service.islUp(endpointAlpha1, reference, new IslDataHolder(100, 1, 100)); assertEquals(new SwitchId(1), endpointAlpha1.getDatapath()); assertEquals(1, endpointAlpha1.getPortNumber()); }
public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test public void considerLinkPropsDataOnCreate() { setupIslStorageStub(); mockPersistenceLinkProps(endpointAlpha1, endpointBeta2, makeLinkProps(endpointAlpha1, endpointBeta2) .maxBandwidth(50L) .build()); mockPersistenceLinkProps(endpointBeta2, endpointAlpha1, null); mockPersistenceBandwidthAllocation(endpointAlpha1, endpointBeta2, 0L); mockPersistenceBandwidthAllocation(endpointBeta2, endpointAlpha1, 0L); IslReference reference = new IslReference(endpointAlpha1, endpointBeta2); service.islUp(endpointAlpha1, reference, new IslDataHolder(200L, 200L, 200L)); service.islUp(endpointBeta2, reference, new IslDataHolder(200L, 200L, 200L)); verifyIslBandwidthUpdate(50L, 200L); }
public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData) { log.debug("ISL service receive DISCOVERY notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateControllerCreateIfAbsent(endpoint, reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .islData(islData) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_UP, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test(expected = FlowNotFoundException.class) public void shouldValidateFlowUsingNotExistingFlow() throws FlowNotFoundException, SwitchNotFoundException { service.validateFlow("test", new ArrayList<>(), new ArrayList<>()); }
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
FlowValidationService { public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException { Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>(); int rulesCount = 0; int metersCount = 0; for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) { SwitchMeterEntries switchMeters = switchMeterEntries.stream() .filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())) .findFirst() .orElse(null); List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter .convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters); switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules); rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()) .map(List::size) .orElse(0); metersCount += Optional.ofNullable(switchMeters) .map(SwitchMeterEntries::getMeterEntries) .map(List::size) .orElse(0); } Optional<Flow> foundFlow = flowRepository.findById(flowId); if (!foundFlow.isPresent()) { throw new FlowNotFoundException(flowId); } Flow flow = foundFlow.get(); if (flow.getForwardPath() == null) { throw new InvalidPathException(flowId, "Forward path was not returned."); } if (flow.getReversePath() == null) { throw new InvalidPathException(flowId, "Reverse path was not returned."); } List<FlowValidationResponse> flowValidationResponse = new ArrayList<>(); List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath()); flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount)); List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath()); flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount)); if (flow.getProtectedForwardPath() != null) { List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()); flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount)); } if (flow.getProtectedReversePath() != null) { List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath()); flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount)); } return flowValidationResponse; } FlowValidationService(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig, long flowMeterMinBurstSizeInKbits, double flowMeterBurstCoefficient); void checkFlowStatus(String flowId); List<SwitchId> getSwitchIdListByFlowId(String flowId); List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries); }
@Test public void portDownOverriderBfdUp() { setupIslStorageStub(); IslReference reference = prepareBfdEnabledIsl(); reset(dashboardLogger); service.islDown(reference.getSource(), reference, IslDownReason.PORT_DOWN); verify(dashboardLogger).onIslDown(reference); }
public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
NetworkIslService { public void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason) { log.debug("ISL service receive FAIL notification for {} (on {})", reference, endpoint); IslFsm islFsm = locateController(reference).fsm; IslFsmContext context = IslFsmContext.builder(carrier, endpoint) .downReason(reason) .build(); controllerExecutor.fire(islFsm, IslFsmEvent.ISL_DOWN, context); } NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options); @VisibleForTesting NetworkIslService(IIslCarrier carrier, PersistenceManager persistenceManager, NetworkOptions options, NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder, Clock clock); void islSetupFromHistory(Endpoint endpoint, IslReference reference, Isl history); void islUp(Endpoint endpoint, IslReference reference, IslDataHolder islData); void islDown(Endpoint endpoint, IslReference reference, IslDownReason reason); void islMove(Endpoint endpoint, IslReference reference); void roundTripStatusNotification(IslReference reference, RoundTripStatus status); void bfdStatusUpdate(Endpoint endpoint, IslReference reference, BfdStatusUpdate status); void bfdEnableDisable(IslReference reference, IslBfdFlagUpdated payload); void islDefaultRuleInstalled(IslReference reference, InstallIslDefaultRulesResult payload); void islDefaultRuleDeleted(IslReference reference, RemoveIslDefaultRulesResult payload); void islDefaultTimeout(IslReference reference, Endpoint endpoint); void remove(IslReference reference); }
@Test public void upDownUp() { setupAndEnable(); service.updateLinkStatus(alphaLogicalEndpoint, LinkStatus.DOWN); verify(carrier).bfdDownNotification(alphaEndpoint); verifyNoMoreInteractions(carrier); reset(carrier); service.updateLinkStatus(alphaLogicalEndpoint, LinkStatus.UP); verify(carrier).bfdUpNotification(alphaEndpoint); verifyNoMoreInteractions(carrier); }
public void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus) { log.debug("BFD-port service receive logical port status update for {} (logical) status:{}", logicalEndpoint, linkStatus); BfdPortFsm controller = lookupControllerByLogicalEndpoint(logicalEndpoint); controller.updateLinkStatus(carrier, linkStatus); }
NetworkBfdPortService { public void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus) { log.debug("BFD-port service receive logical port status update for {} (logical) status:{}", logicalEndpoint, linkStatus); BfdPortFsm controller = lookupControllerByLogicalEndpoint(logicalEndpoint); controller.updateLinkStatus(carrier, linkStatus); } }
NetworkBfdPortService { public void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus) { log.debug("BFD-port service receive logical port status update for {} (logical) status:{}", logicalEndpoint, linkStatus); BfdPortFsm controller = lookupControllerByLogicalEndpoint(logicalEndpoint); controller.updateLinkStatus(carrier, linkStatus); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); }
NetworkBfdPortService { public void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus) { log.debug("BFD-port service receive logical port status update for {} (logical) status:{}", logicalEndpoint, linkStatus); BfdPortFsm controller = lookupControllerByLogicalEndpoint(logicalEndpoint); controller.updateLinkStatus(carrier, linkStatus); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
NetworkBfdPortService { public void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus) { log.debug("BFD-port service receive logical port status update for {} (logical) status:{}", logicalEndpoint, linkStatus); BfdPortFsm controller = lookupControllerByLogicalEndpoint(logicalEndpoint); controller.updateLinkStatus(carrier, linkStatus); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
@Test public void killDuringInstalling() { setupController(); doAnswer(invocation -> invocation.getArgument(0)) .when(bfdSessionRepository).add(any()); NoviBfdSession session = doEnable(); when(carrier.removeBfdSession(any(NoviBfdSession.class))).thenReturn(removeRequestKey); service.remove(alphaLogicalEndpoint); verifyTerminateSequence(session); }
public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
@Test public void killDuringActiveUp() { NoviBfdSession session = setupAndEnable(); when(carrier.removeBfdSession(any(NoviBfdSession.class))).thenReturn(removeRequestKey); service.remove(alphaLogicalEndpoint); verify(carrier).bfdKillNotification(alphaEndpoint); verifyTerminateSequence(session); }
public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
NetworkBfdPortService { public Endpoint remove(Endpoint logicalEndpoint) { log.info("BFD-port service receive REMOVE request for {} (logical)", logicalEndpoint); BfdPortFsm controller = controllerByLogicalPort.remove(logicalEndpoint); if (controller == null) { throw BfdPortControllerNotFoundException.ofLogical(logicalEndpoint); } controllerByPhysicalPort.remove(controller.getPhysicalEndpoint()); remove(controller); return controller.getPhysicalEndpoint(); } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
@Test public void enableBeforeSetup() { IslReference reference = new IslReference(alphaEndpoint, betaEndpoint); doEnableBeforeSetup(reference); doAnswer(invocation -> invocation.getArgument(0)) .when(bfdSessionRepository).add(any()); mockSwitchLookup(alphaSwitch); mockSwitchLookup(betaSwitch); mockMissingBfdSession(alphaLogicalEndpoint); when(carrier.setupBfdSession(any(NoviBfdSession.class))).thenReturn(setupRequestKey); service.setup(alphaLogicalEndpoint, alphaEndpoint.getPortNumber()); verify(bfdSessionRepository).add(any(BfdSession.class)); verify(carrier).setupBfdSession(argThat( arg -> arg.getTarget().getDatapath().equals(alphaEndpoint.getDatapath()) && arg.getPhysicalPortNumber() == alphaEndpoint.getPortNumber() && arg.getLogicalPortNumber() == alphaLogicalEndpoint.getPortNumber() && arg.getRemote().getDatapath().equals(betaEndpoint.getDatapath()))); verifyNoMoreInteractions(carrier); }
public void setup(Endpoint endpoint, int physicalPortNumber) { log.info("BFD-port service receive SETUP request for {} (physical-port:{})", endpoint, physicalPortNumber); BfdPortFsm controller = controllerFactory.produce(persistenceManager, endpoint, physicalPortNumber); BfdPortFsmContext context = BfdPortFsmContext.builder(carrier).build(); handle(controller, BfdPortFsmEvent.HISTORY, context); controllerByLogicalPort.put(controller.getLogicalEndpoint(), controller); controllerByPhysicalPort.put(controller.getPhysicalEndpoint(), controller); IslReference autostartData = autostart.remove(controller.getPhysicalEndpoint()); if (autostartData != null) { context = BfdPortFsmContext.builder(carrier) .islReference(autostartData) .build(); handle(controller, BfdPortFsmEvent.ENABLE, context); } }
NetworkBfdPortService { public void setup(Endpoint endpoint, int physicalPortNumber) { log.info("BFD-port service receive SETUP request for {} (physical-port:{})", endpoint, physicalPortNumber); BfdPortFsm controller = controllerFactory.produce(persistenceManager, endpoint, physicalPortNumber); BfdPortFsmContext context = BfdPortFsmContext.builder(carrier).build(); handle(controller, BfdPortFsmEvent.HISTORY, context); controllerByLogicalPort.put(controller.getLogicalEndpoint(), controller); controllerByPhysicalPort.put(controller.getPhysicalEndpoint(), controller); IslReference autostartData = autostart.remove(controller.getPhysicalEndpoint()); if (autostartData != null) { context = BfdPortFsmContext.builder(carrier) .islReference(autostartData) .build(); handle(controller, BfdPortFsmEvent.ENABLE, context); } } }
NetworkBfdPortService { public void setup(Endpoint endpoint, int physicalPortNumber) { log.info("BFD-port service receive SETUP request for {} (physical-port:{})", endpoint, physicalPortNumber); BfdPortFsm controller = controllerFactory.produce(persistenceManager, endpoint, physicalPortNumber); BfdPortFsmContext context = BfdPortFsmContext.builder(carrier).build(); handle(controller, BfdPortFsmEvent.HISTORY, context); controllerByLogicalPort.put(controller.getLogicalEndpoint(), controller); controllerByPhysicalPort.put(controller.getPhysicalEndpoint(), controller); IslReference autostartData = autostart.remove(controller.getPhysicalEndpoint()); if (autostartData != null) { context = BfdPortFsmContext.builder(carrier) .islReference(autostartData) .build(); handle(controller, BfdPortFsmEvent.ENABLE, context); } } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); }
NetworkBfdPortService { public void setup(Endpoint endpoint, int physicalPortNumber) { log.info("BFD-port service receive SETUP request for {} (physical-port:{})", endpoint, physicalPortNumber); BfdPortFsm controller = controllerFactory.produce(persistenceManager, endpoint, physicalPortNumber); BfdPortFsmContext context = BfdPortFsmContext.builder(carrier).build(); handle(controller, BfdPortFsmEvent.HISTORY, context); controllerByLogicalPort.put(controller.getLogicalEndpoint(), controller); controllerByPhysicalPort.put(controller.getPhysicalEndpoint(), controller); IslReference autostartData = autostart.remove(controller.getPhysicalEndpoint()); if (autostartData != null) { context = BfdPortFsmContext.builder(carrier) .islReference(autostartData) .build(); handle(controller, BfdPortFsmEvent.ENABLE, context); } } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }
NetworkBfdPortService { public void setup(Endpoint endpoint, int physicalPortNumber) { log.info("BFD-port service receive SETUP request for {} (physical-port:{})", endpoint, physicalPortNumber); BfdPortFsm controller = controllerFactory.produce(persistenceManager, endpoint, physicalPortNumber); BfdPortFsmContext context = BfdPortFsmContext.builder(carrier).build(); handle(controller, BfdPortFsmEvent.HISTORY, context); controllerByLogicalPort.put(controller.getLogicalEndpoint(), controller); controllerByPhysicalPort.put(controller.getPhysicalEndpoint(), controller); IslReference autostartData = autostart.remove(controller.getPhysicalEndpoint()); if (autostartData != null) { context = BfdPortFsmContext.builder(carrier) .islReference(autostartData) .build(); handle(controller, BfdPortFsmEvent.ENABLE, context); } } NetworkBfdPortService(IBfdPortCarrier carrier, PersistenceManager persistenceManager); void setup(Endpoint endpoint, int physicalPortNumber); Endpoint remove(Endpoint logicalEndpoint); void updateLinkStatus(Endpoint logicalEndpoint, LinkStatus linkStatus); void updateOnlineMode(Endpoint endpoint, boolean mode); void enable(Endpoint physicalEndpoint, IslReference reference); void disable(Endpoint physicalEndpoint); void speakerResponse(String key, Endpoint logicalEndpoint, BfdSessionResponse response); void speakerTimeout(String key, Endpoint logicalEndpoint); }