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 shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort() { Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue(); String inPort = "1"; String inVlan = "10"; String outPort = "in_port"; FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false); RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry); assertEquals(cookie, removeFlow.getCookie()); DeleteRulesCriteria criteria = removeFlow.getCriteria(); assertEquals(cookie, criteria.getCookie()); assertEquals(Integer.valueOf(inPort), criteria.getInPort()); assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId()); assertNull(criteria.getOutPort()); }
@VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
@Test public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress() { Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue(); String inPort = "1"; String outPort = "2"; String tunnelId = "10"; FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, true); RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry); assertEquals(cookie, removeFlow.getCookie()); DeleteRulesCriteria criteria = removeFlow.getCriteria(); assertEquals(cookie, criteria.getCookie()); assertEquals(Integer.valueOf(inPort), criteria.getInPort()); assertEquals(Integer.valueOf(tunnelId), criteria.getEncapsulationId()); assertEquals(Integer.valueOf(outPort), criteria.getOutPort()); }
@VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
@Test public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress() { Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue(); String inPort = "1"; String outPort = "2"; String tunnelId = "10"; FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, false); RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry); assertEquals(cookie, removeFlow.getCookie()); DeleteRulesCriteria criteria = removeFlow.getCriteria(); assertEquals(cookie, criteria.getCookie()); assertEquals(Integer.valueOf(inPort), criteria.getInPort()); assertEquals(Integer.valueOf(tunnelId), criteria.getEncapsulationId()); assertEquals(Integer.valueOf(outPort), criteria.getOutPort()); }
@VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
CommandBuilderImpl implements CommandBuilder { @VisibleForTesting RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) { Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch()); Optional<FlowInstructions> instructions = Optional.ofNullable(entry.getInstructions()); Optional<FlowApplyActions> applyActions = instructions.map(FlowInstructions::getApplyActions); Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null); FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN; Integer encapsulationId = null; Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null); if (vlan != null) { encapsulationId = vlan; } else { Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::valueOf).orElse(null); if (tunnelId == null) { tunnelId = applyActions.map(FlowApplyActions::getPushVxlan).map(Integer::valueOf).orElse(null); } if (tunnelId != null) { encapsulationId = tunnelId; encapsulationType = FlowEncapsulationType.VXLAN; } } Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()) .map(FlowInstructions::getApplyActions); Integer outPort = actions .map(FlowApplyActions::getFlowOutput) .filter(NumberUtils::isNumber) .map(Integer::valueOf) .orElse(null); SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null); DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId); return RemoveFlow.builder() .transactionId(transactionIdGenerator.generate()) .flowId("SWMANAGER_BATCH_REMOVE") .cookie(entry.getCookie()) .switchId(switchId) .criteria(criteria) .build(); } CommandBuilderImpl(PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules); @Override List<RemoveFlow> buildCommandsToRemoveExcessRules(SwitchId switchId, List<FlowEntry> flows, List<Long> excessRulesCookies); }
@Test public void receiveOnlyRules() { handleRequestAndInitDataReceive(); service.handleFlowEntriesResponse(KEY, new SwitchFlowEntries(SWITCH_ID, singletonList(flowEntry))); verifyNoMoreInteractions(carrier); verifyNoMoreInteractions(validationService); }
@Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
@Test public void doNothingWhenFsmNotFound() { service.handleFlowEntriesResponse(KEY, new SwitchFlowEntries(SWITCH_ID, singletonList(flowEntry))); verifyZeroInteractions(carrier); verifyZeroInteractions(validationService); }
@Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleFlowEntriesResponse(String key, SwitchFlowEntries data) { handle(key, SwitchValidateEvent.RULES_RECEIVED, SwitchValidateContext.builder().flowEntries(data.getFlowEntries()).build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
@Test public void getFlowsForEndpointNotReturnFlowsForOrphanedPaths() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); Switch switchC = createSwitch(SWITCH_ID_3); Switch switchD = createSwitch(SWITCH_ID_4); Flow flow = createFlow(FLOW_ID_1, switchA, 1, switchC, 2, FORWARD_PATH_1, REVERSE_PATH_1, switchB); createOrphanFlowPaths(flow, switchA, 1, switchC, 2, FORWARD_PATH_3, REVERSE_PATH_3, switchD); assertEquals(0, flowOperationsService.getFlowsForEndpoint(switchD.getSwitchId(), null).size()); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void errorResponseOnSwitchNotFound() { request = SwitchValidateRequest .builder().switchId(SWITCH_ID_MISSING).performSync(true).processMeters(true).build(); service.handleSwitchValidateRequest(KEY, request); verify(carrier).cancelTimeoutCallback(eq(KEY)); verify(carrier).errorResponse( eq(KEY), eq(ErrorType.NOT_FOUND), eq(String.format("Switch '%s' not found", request.getSwitchId()))); verifyNoMoreInteractions(carrier); verifyNoMoreInteractions(validationService); }
@Override public void handleSwitchValidateRequest(String key, SwitchValidateRequest request) { SwitchValidateFsm fsm = builder.newStateMachine( SwitchValidateState.START, carrier, key, request, validationService, repositoryFactory); fsms.put(key, fsm); fsm.start(); handle(fsm, SwitchValidateEvent.NEXT, SwitchValidateContext.builder().build()); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleSwitchValidateRequest(String key, SwitchValidateRequest request) { SwitchValidateFsm fsm = builder.newStateMachine( SwitchValidateState.START, carrier, key, request, validationService, repositoryFactory); fsms.put(key, fsm); fsm.start(); handle(fsm, SwitchValidateEvent.NEXT, SwitchValidateContext.builder().build()); } }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleSwitchValidateRequest(String key, SwitchValidateRequest request) { SwitchValidateFsm fsm = builder.newStateMachine( SwitchValidateState.START, carrier, key, request, validationService, repositoryFactory); fsms.put(key, fsm); fsm.start(); handle(fsm, SwitchValidateEvent.NEXT, SwitchValidateContext.builder().build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleSwitchValidateRequest(String key, SwitchValidateRequest request) { SwitchValidateFsm fsm = builder.newStateMachine( SwitchValidateState.START, carrier, key, request, validationService, repositoryFactory); fsms.put(key, fsm); fsm.start(); handle(fsm, SwitchValidateEvent.NEXT, SwitchValidateContext.builder().build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
SwitchValidateServiceImpl implements SwitchValidateService { @Override public void handleSwitchValidateRequest(String key, SwitchValidateRequest request) { SwitchValidateFsm fsm = builder.newStateMachine( SwitchValidateState.START, carrier, key, request, validationService, repositoryFactory); fsms.put(key, fsm); fsm.start(); handle(fsm, SwitchValidateEvent.NEXT, SwitchValidateContext.builder().build()); } SwitchValidateServiceImpl( SwitchManagerCarrier carrier, PersistenceManager persistenceManager, ValidationService validationService); @Override void handleSwitchValidateRequest(String key, SwitchValidateRequest request); @Override void handleFlowEntriesResponse(String key, SwitchFlowEntries data); @Override void handleGroupEntriesResponse(String key, SwitchGroupEntries data); @Override void handleExpectedDefaultFlowEntriesResponse(String key, SwitchExpectedDefaultFlowEntries data); @Override void handleExpectedDefaultMeterEntriesResponse(String key, SwitchExpectedDefaultMeterEntries data); @Override void handleMeterEntriesResponse(String key, SwitchMeterEntries data); @Override void handleMetersUnsupportedResponse(String key); @Override void handleTaskError(String key, ErrorMessage message); @Override void handleTaskTimeout(String key); }
@Test public void validateRulesEmpty() throws SwitchNotFoundException { ValidationService validationService = new ValidationServiceImpl(persistenceManager().build(), topologyConfig); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, emptyList(), emptyList()); assertTrue(response.getMissingRules().isEmpty()); assertTrue(response.getProperRules().isEmpty()); assertTrue(response.getExcessRules().isEmpty()); }
@Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
@Test public void validateRulesSimpleSegmentCookies() throws SwitchNotFoundException { ValidationService validationService = new ValidationServiceImpl(persistenceManager().withSegmentsCookies(2L, 3L).build(), topologyConfig); List<FlowEntry> flowEntries = Lists.newArrayList(FlowEntry.builder().cookie(1L).build(), FlowEntry.builder().cookie(2L).build()); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, flowEntries, emptyList()); assertEquals(ImmutableList.of(3L), response.getMissingRules()); assertEquals(ImmutableList.of(2L), response.getProperRules()); assertEquals(ImmutableList.of(1L), response.getExcessRules()); }
@Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
@Test public void validateRulesSegmentAndIngressCookies() throws SwitchNotFoundException { ValidationService validationService = new ValidationServiceImpl(persistenceManager().withSegmentsCookies(2L).withIngressCookies(1L).build(), topologyConfig); List<FlowEntry> flowEntries = Lists.newArrayList(FlowEntry.builder().cookie(1L).build(), FlowEntry.builder().cookie(2L).build()); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, flowEntries, emptyList()); assertTrue(response.getMissingRules().isEmpty()); assertEquals(ImmutableSet.of(1L, 2L), new HashSet<>(response.getProperRules())); assertTrue(response.getExcessRules().isEmpty()); }
@Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
@Test public void validateRulesSegmentAndIngressCookiesWithServer42Rules() { SwitchProperties switchProperties = SwitchProperties.builder() .server42FlowRtt(true) .build(); ValidationService validationService = new ValidationServiceImpl(persistenceManager() .withIngressCookies(1L) .withSwitchProperties(switchProperties) .build(), topologyConfig); List<FlowEntry> flowEntries = Lists.newArrayList(FlowEntry.builder().cookie(0xC0000000000001L).build(), FlowEntry.builder().cookie(1L).build()); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, flowEntries, emptyList()); assertTrue(response.getMissingRules().isEmpty()); assertEquals(ImmutableSet.of(0xC0000000000001L, 1L), new HashSet<>(response.getProperRules())); assertTrue(response.getExcessRules().isEmpty()); }
@Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { @Override public ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules) { log.debug("Validating rules on switch {}", switchId); Set<Long> expectedCookies = getExpectedFlowRules(switchId); return makeRulesResponse(expectedCookies, presentRules, expectedDefaultRules, switchId); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
@Test public void validateDefaultRules() throws SwitchNotFoundException { ValidationService validationService = new ValidationServiceImpl(persistenceManager().build(), topologyConfig); List<FlowEntry> flowEntries = Lists.newArrayList(FlowEntry.builder().cookie(0x8000000000000001L).priority(1).byteCount(123).build(), FlowEntry.builder().cookie(0x8000000000000001L).priority(2).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(1).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(2).build(), FlowEntry.builder().cookie(0x8000000000000004L).priority(1).build()); List<FlowEntry> expectedDefaultFlowEntries = Lists.newArrayList(FlowEntry.builder().cookie(0x8000000000000001L).priority(1).byteCount(321).build(), FlowEntry.builder().cookie(0x8000000000000002L).priority(3).build(), FlowEntry.builder().cookie(0x8000000000000003L).priority(1).build()); ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, flowEntries, expectedDefaultFlowEntries); assertEquals(ImmutableSet.of(0x8000000000000001L), new HashSet<>(response.getProperRules())); assertEquals(ImmutableSet.of(0x8000000000000001L, 0x8000000000000002L), new HashSet<>(response.getMisconfiguredRules())); assertEquals(ImmutableSet.of(0x8000000000000003L), new HashSet<>(response.getMissingRules())); assertEquals(ImmutableSet.of(0x8000000000000004L), new HashSet<>(response.getExcessRules())); }
private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
ValidationServiceImpl implements ValidationService { private void validateDefaultRules(List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules, Set<Long> missingRules, Set<Long> properRules, Set<Long> excessRules, Set<Long> misconfiguredRules) { List<FlowEntry> presentDefaultRules = presentRules.stream() .filter(rule -> Cookie.isDefaultRule(rule.getCookie())) .collect(toList()); expectedDefaultRules.forEach(expectedDefaultRule -> { List<FlowEntry> defaultRule = presentDefaultRules.stream() .filter(rule -> rule.getCookie() == expectedDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { missingRules.add(expectedDefaultRule.getCookie()); } else { if (defaultRule.contains(expectedDefaultRule)) { properRules.add(expectedDefaultRule.getCookie()); } else { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } if (defaultRule.size() > 1) { log.info("Misconfigured rule: {} : expected : {}", defaultRule, expectedDefaultRule); misconfiguredRules.add(expectedDefaultRule.getCookie()); } } }); presentDefaultRules.forEach(presentDefaultRule -> { List<FlowEntry> defaultRule = expectedDefaultRules.stream() .filter(rule -> rule.getCookie() == presentDefaultRule.getCookie()) .collect(toList()); if (defaultRule.isEmpty()) { excessRules.add(presentDefaultRule.getCookie()); } }); } ValidationServiceImpl(PersistenceManager persistenceManager, SwitchManagerTopologyConfig topologyConfig); @Override ValidateRulesResult validateRules(SwitchId switchId, List<FlowEntry> presentRules, List<FlowEntry> expectedDefaultRules); @Override ValidateGroupsResult validateGroups(SwitchId switchId, List<GroupEntry> presentGroups); @Override ValidateMetersResult validateMeters(SwitchId switchId, List<MeterEntry> presentMeters, List<MeterEntry> expectedDefaultMeters); }
@Test public void handleNothingRulesToSync() { missingRules = emptyList(); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(carrier).response(eq(KEY), any(InfoMessage.class)); verify(carrier).cancelTimeoutCallback(eq(KEY)); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }
@Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
@Test public void handleCommandBuilderMissingRulesException() { String errorMessage = "test error"; when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())) .thenThrow(new IllegalArgumentException(errorMessage)); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(commandBuilder).buildCommandsToSyncMissingRules(eq(SWITCH_ID), eq(missingRules)); ArgumentCaptor<ErrorMessage> errorCaptor = ArgumentCaptor.forClass(ErrorMessage.class); verify(carrier).cancelTimeoutCallback(eq(KEY)); verify(carrier).response(eq(KEY), errorCaptor.capture()); assertEquals(errorMessage, errorCaptor.getValue().getData().getErrorMessage()); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }
@Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
@Test public void doNothingWhenFsmNotFound() { service.handleInstallRulesResponse(KEY); verifyZeroInteractions(carrier); verifyZeroInteractions(commandBuilder); }
@Override public void handleInstallRulesResponse(String key) { SwitchSyncFsm fsm = fsms.get(key); if (fsm == null) { logFsmNotFound(key); return; } fsm.fire(SwitchSyncEvent.RULES_INSTALLED); process(fsm); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleInstallRulesResponse(String key) { SwitchSyncFsm fsm = fsms.get(key); if (fsm == null) { logFsmNotFound(key); return; } fsm.fire(SwitchSyncEvent.RULES_INSTALLED); process(fsm); } }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleInstallRulesResponse(String key) { SwitchSyncFsm fsm = fsms.get(key); if (fsm == null) { logFsmNotFound(key); return; } fsm.fire(SwitchSyncEvent.RULES_INSTALLED); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleInstallRulesResponse(String key) { SwitchSyncFsm fsm = fsms.get(key); if (fsm == null) { logFsmNotFound(key); return; } fsm.fire(SwitchSyncEvent.RULES_INSTALLED); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleInstallRulesResponse(String key) { SwitchSyncFsm fsm = fsms.get(key); if (fsm == null) { logFsmNotFound(key); return; } fsm.fire(SwitchSyncEvent.RULES_INSTALLED); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
@Test public void handleNothingToSyncWithExcess() { request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build(); missingRules = emptyList(); service.handleSwitchSync(KEY, request, makeValidationResult()); verify(carrier).cancelTimeoutCallback(eq(KEY)); verify(carrier).response(eq(KEY), any(InfoMessage.class)); verifyNoMoreInteractions(commandBuilder); verifyNoMoreInteractions(carrier); }
@Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
SwitchSyncServiceImpl implements SwitchSyncService { @Override public void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult) { SwitchSyncFsm fsm = builder.newStateMachine(SwitchSyncState.INITIALIZED, carrier, key, commandBuilder, request, validationResult); process(fsm); } SwitchSyncServiceImpl(SwitchManagerCarrier carrier, PersistenceManager persistenceManager, FlowResourcesConfig flowResourcesConfig); @Override void handleSwitchSync(String key, SwitchValidateRequest request, ValidationResult validationResult); @Override void handleInstallRulesResponse(String key); @Override void handleRemoveRulesResponse(String key); @Override void handleReinstallDefaultRulesResponse(String key, FlowReinstallResponse response); @Override void handleRemoveMetersResponse(String key); @Override void handleTaskTimeout(String key); @Override void handleTaskError(String key, ErrorMessage message); }
@Test public void getFlowsForEndpointOneSwitchFlowNoPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); createFlow(FLOW_ID_1, switchA, 1, switchA, 2, FORWARD_PATH_1, REVERSE_PATH_1, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, null), FLOW_ID_1); createFlow(FLOW_ID_2, switchA, 3, switchA, 4, FORWARD_PATH_2, REVERSE_PATH_2, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, null), FLOW_ID_1, FLOW_ID_2); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldConvertToGraphProperty() { FlowPathStatusConverter converter = new FlowPathStatusConverter(); assertEquals("active", converter.toGraphProperty(FlowPathStatus.ACTIVE)); assertEquals("inactive", converter.toGraphProperty(FlowPathStatus.INACTIVE)); assertEquals("in_progress", converter.toGraphProperty(FlowPathStatus.IN_PROGRESS)); }
@Override public String toGraphProperty(FlowPathStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public String toGraphProperty(FlowPathStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public String toGraphProperty(FlowPathStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public String toGraphProperty(FlowPathStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(FlowPathStatus value); @Override FlowPathStatus toEntityAttribute(String value); }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public String toGraphProperty(FlowPathStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(FlowPathStatus value); @Override FlowPathStatus toEntityAttribute(String value); }
@Test public void shouldConvertToEntity() { FlowPathStatusConverter converter = new FlowPathStatusConverter(); assertEquals(FlowPathStatus.ACTIVE, converter.toEntityAttribute("ACTIVE")); assertEquals(FlowPathStatus.ACTIVE, converter.toEntityAttribute("active")); assertEquals(FlowPathStatus.IN_PROGRESS, converter.toEntityAttribute("In_Progress")); }
@Override public FlowPathStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowPathStatus.valueOf(value.toUpperCase()); }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public FlowPathStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowPathStatus.valueOf(value.toUpperCase()); } }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public FlowPathStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowPathStatus.valueOf(value.toUpperCase()); } }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public FlowPathStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowPathStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(FlowPathStatus value); @Override FlowPathStatus toEntityAttribute(String value); }
FlowPathStatusConverter implements AttributeConverter<FlowPathStatus, String> { @Override public FlowPathStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowPathStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(FlowPathStatus value); @Override FlowPathStatus toEntityAttribute(String value); }
@Test public void shouldConvertIdToString() { PathId pathId = new PathId("test_path_id"); String graphObject = PathIdConverter.INSTANCE.toGraphProperty(pathId); assertEquals(pathId.getId(), graphObject); }
@Override public String toGraphProperty(PathId value) { if (value == null) { return null; } return value.getId(); }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public String toGraphProperty(PathId value) { if (value == null) { return null; } return value.getId(); } }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public String toGraphProperty(PathId value) { if (value == null) { return null; } return value.getId(); } }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public String toGraphProperty(PathId value) { if (value == null) { return null; } return value.getId(); } @Override String toGraphProperty(PathId value); @Override PathId toEntityAttribute(String value); }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public String toGraphProperty(PathId value) { if (value == null) { return null; } return value.getId(); } @Override String toGraphProperty(PathId value); @Override PathId toEntityAttribute(String value); static final PathIdConverter INSTANCE; }
@Test public void shouldConvertStringToId() { PathId pathId = new PathId("test_path_id"); PathId actualEntity = PathIdConverter.INSTANCE.toEntityAttribute(pathId.getId()); assertEquals(pathId, actualEntity); }
@Override public PathId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new PathId(value); }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public PathId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new PathId(value); } }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public PathId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new PathId(value); } }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public PathId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new PathId(value); } @Override String toGraphProperty(PathId value); @Override PathId toEntityAttribute(String value); }
PathIdConverter implements AttributeConverter<PathId, String> { @Override public PathId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new PathId(value); } @Override String toGraphProperty(PathId value); @Override PathId toEntityAttribute(String value); static final PathIdConverter INSTANCE; }
@Test public void shouldConvertIdToString() { SwitchId switchId = new SwitchId((long) 0x123); String graphObject = SwitchIdConverter.INSTANCE.toGraphProperty(switchId); assertEquals(switchId.toString(), graphObject); }
@Override public String toGraphProperty(SwitchId value) { if (value == null) { return null; } return value.toString(); }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public String toGraphProperty(SwitchId value) { if (value == null) { return null; } return value.toString(); } }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public String toGraphProperty(SwitchId value) { if (value == null) { return null; } return value.toString(); } }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public String toGraphProperty(SwitchId value) { if (value == null) { return null; } return value.toString(); } @Override String toGraphProperty(SwitchId value); @Override SwitchId toEntityAttribute(String value); }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public String toGraphProperty(SwitchId value) { if (value == null) { return null; } return value.toString(); } @Override String toGraphProperty(SwitchId value); @Override SwitchId toEntityAttribute(String value); static final SwitchIdConverter INSTANCE; }
@Test public void shouldConvertStringToId() { SwitchId switchId = new SwitchId((long) 0x123); SwitchId actualEntity = SwitchIdConverter.INSTANCE.toEntityAttribute(switchId.toString()); assertEquals(switchId, actualEntity); }
@Override public SwitchId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new SwitchId(value); }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public SwitchId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new SwitchId(value); } }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public SwitchId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new SwitchId(value); } }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public SwitchId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new SwitchId(value); } @Override String toGraphProperty(SwitchId value); @Override SwitchId toEntityAttribute(String value); }
SwitchIdConverter implements AttributeConverter<SwitchId, String> { @Override public SwitchId toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return new SwitchId(value); } @Override String toGraphProperty(SwitchId value); @Override SwitchId toEntityAttribute(String value); static final SwitchIdConverter INSTANCE; }
@Test public void shouldConvertToGraphProperty() { FlowStatusConverter converter = FlowStatusConverter.INSTANCE; assertEquals("up", converter.toGraphProperty(FlowStatus.UP)); assertEquals("down", converter.toGraphProperty(FlowStatus.DOWN)); assertEquals("in_progress", converter.toGraphProperty(FlowStatus.IN_PROGRESS)); }
@Override public String toGraphProperty(FlowStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public String toGraphProperty(FlowStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public String toGraphProperty(FlowStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public String toGraphProperty(FlowStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(FlowStatus value); @Override FlowStatus toEntityAttribute(String value); }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public String toGraphProperty(FlowStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(FlowStatus value); @Override FlowStatus toEntityAttribute(String value); static final FlowStatusConverter INSTANCE; }
@Test public void shouldConvertToEntity() { FlowStatusConverter converter = FlowStatusConverter.INSTANCE; assertEquals(FlowStatus.UP, converter.toEntityAttribute("UP")); assertEquals(FlowStatus.UP, converter.toEntityAttribute("up")); assertEquals(FlowStatus.IN_PROGRESS, converter.toEntityAttribute("In_Progress")); }
@Override public FlowStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return FlowStatus.UP; } return FlowStatus.valueOf(value.toUpperCase()); }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public FlowStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return FlowStatus.UP; } return FlowStatus.valueOf(value.toUpperCase()); } }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public FlowStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return FlowStatus.UP; } return FlowStatus.valueOf(value.toUpperCase()); } }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public FlowStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return FlowStatus.UP; } return FlowStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(FlowStatus value); @Override FlowStatus toEntityAttribute(String value); }
FlowStatusConverter implements AttributeConverter<FlowStatus, String> { @Override public FlowStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return FlowStatus.UP; } return FlowStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(FlowStatus value); @Override FlowStatus toEntityAttribute(String value); static final FlowStatusConverter INSTANCE; }
@Test public void shouldConvertIdToLong() { ExclusionCookie cookie = new ExclusionCookie((long) 0x123); Long graphObject = new ExclusionCookieConverter().toGraphProperty(cookie); assertEquals(cookie.getValue(), (long) graphObject); }
@Override public Long toGraphProperty(ExclusionCookie value) { if (value == null) { return null; } return value.getValue(); }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public Long toGraphProperty(ExclusionCookie value) { if (value == null) { return null; } return value.getValue(); } }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public Long toGraphProperty(ExclusionCookie value) { if (value == null) { return null; } return value.getValue(); } }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public Long toGraphProperty(ExclusionCookie value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(ExclusionCookie value); @Override ExclusionCookie toEntityAttribute(Long value); }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public Long toGraphProperty(ExclusionCookie value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(ExclusionCookie value); @Override ExclusionCookie toEntityAttribute(Long value); static final ExclusionCookieConverter INSTANCE; }
@Test public void shouldConvertLongToId() { ExclusionCookie cookie = new ExclusionCookie((long) 0x123); Cookie actualEntity = new ExclusionCookieConverter().toEntityAttribute(cookie.getValue()); assertEquals(cookie, actualEntity); }
@Override public ExclusionCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new ExclusionCookie(value); }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public ExclusionCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new ExclusionCookie(value); } }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public ExclusionCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new ExclusionCookie(value); } }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public ExclusionCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new ExclusionCookie(value); } @Override Long toGraphProperty(ExclusionCookie value); @Override ExclusionCookie toEntityAttribute(Long value); }
ExclusionCookieConverter implements AttributeConverter<ExclusionCookie, Long> { @Override public ExclusionCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new ExclusionCookie(value); } @Override Long toGraphProperty(ExclusionCookie value); @Override ExclusionCookie toEntityAttribute(Long value); static final ExclusionCookieConverter INSTANCE; }
@Test public void getFlowsForEndpointMultiSwitchFlowNoPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); createFlow(FLOW_ID_1, switchA, 1, switchB, 2, FORWARD_PATH_1, REVERSE_PATH_1, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, null), FLOW_ID_1); createFlow(FLOW_ID_2, switchB, 3, switchA, 4, FORWARD_PATH_2, REVERSE_PATH_2, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, null), FLOW_ID_1, FLOW_ID_2); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldDeletePortPropertiesWhenDeletingSwitch() throws SwitchNotFoundException { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); PortProperties portProperties = PortProperties.builder().switchObj(sw).port(7).discoveryEnabled(false).build(); portPropertiesRepository.add(portProperties); switchOperationsService.deleteSwitch(TEST_SWITCH_ID, false); assertFalse(switchRepository.findById(TEST_SWITCH_ID).isPresent()); assertTrue(portPropertiesRepository.findAll().isEmpty()); }
public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } SwitchOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager, SwitchOperationsServiceCarrier carrier); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } 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 boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException { transactionManager.doInTransaction(() -> { Switch sw = switchRepository.findById(switchId) .orElseThrow(() -> new SwitchNotFoundException(switchId)); switchPropertiesRepository.findBySwitchId(sw.getSwitchId()) .ifPresent(sp -> switchPropertiesRepository.remove(sp)); portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()) .forEach(portPropertiesRepository::remove); if (force) { switchRepository.remove(sw); } else { switchRepository.removeIfNoDependant(sw); } }); return !switchRepository.exists(switchId); } 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 shouldConvertIdToLong() { FlowSegmentCookie cookie = new FlowSegmentCookie((long) 0x123); Long graphObject = FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie); assertEquals(cookie.getValue(), (long) graphObject); }
@Override public Long toGraphProperty(FlowSegmentCookie value) { if (value == null) { return null; } return value.getValue(); }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public Long toGraphProperty(FlowSegmentCookie value) { if (value == null) { return null; } return value.getValue(); } }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public Long toGraphProperty(FlowSegmentCookie value) { if (value == null) { return null; } return value.getValue(); } }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public Long toGraphProperty(FlowSegmentCookie value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(FlowSegmentCookie value); @Override FlowSegmentCookie toEntityAttribute(Long value); }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public Long toGraphProperty(FlowSegmentCookie value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(FlowSegmentCookie value); @Override FlowSegmentCookie toEntityAttribute(Long value); static final FlowSegmentCookieConverter INSTANCE; }
@Test public void shouldConvertLongToId() { FlowSegmentCookie cookie = new FlowSegmentCookie((long) 0x123); FlowSegmentCookie actualEntity = FlowSegmentCookieConverter.INSTANCE.toEntityAttribute(cookie.getValue()); assertEquals(cookie, actualEntity); }
@Override public FlowSegmentCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new FlowSegmentCookie(value); }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public FlowSegmentCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new FlowSegmentCookie(value); } }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public FlowSegmentCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new FlowSegmentCookie(value); } }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public FlowSegmentCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new FlowSegmentCookie(value); } @Override Long toGraphProperty(FlowSegmentCookie value); @Override FlowSegmentCookie toEntityAttribute(Long value); }
FlowSegmentCookieConverter implements AttributeConverter<FlowSegmentCookie, Long> { @Override public FlowSegmentCookie toEntityAttribute(Long value) { if (value == null) { return null; } return new FlowSegmentCookie(value); } @Override Long toGraphProperty(FlowSegmentCookie value); @Override FlowSegmentCookie toEntityAttribute(Long value); static final FlowSegmentCookieConverter INSTANCE; }
@Test public void shouldConvertToGraphProperty() { SwitchStatusConverter converter = SwitchStatusConverter.INSTANCE; assertEquals("active", converter.toGraphProperty(SwitchStatus.ACTIVE)); assertEquals("inactive", converter.toGraphProperty(SwitchStatus.INACTIVE)); }
@Override public String toGraphProperty(SwitchStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public String toGraphProperty(SwitchStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public String toGraphProperty(SwitchStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public String toGraphProperty(SwitchStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(SwitchStatus value); @Override SwitchStatus toEntityAttribute(String value); }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public String toGraphProperty(SwitchStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(SwitchStatus value); @Override SwitchStatus toEntityAttribute(String value); static final SwitchStatusConverter INSTANCE; }
@Test public void shouldConvertToEntity() { SwitchStatusConverter converter = SwitchStatusConverter.INSTANCE; assertEquals(SwitchStatus.ACTIVE, converter.toEntityAttribute("ACTIVE")); assertEquals(SwitchStatus.ACTIVE, converter.toEntityAttribute("active")); assertEquals(SwitchStatus.INACTIVE, converter.toEntityAttribute("InActive")); }
@Override public SwitchStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return SwitchStatus.valueOf(value.toUpperCase()); }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public SwitchStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return SwitchStatus.valueOf(value.toUpperCase()); } }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public SwitchStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return SwitchStatus.valueOf(value.toUpperCase()); } }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public SwitchStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return SwitchStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(SwitchStatus value); @Override SwitchStatus toEntityAttribute(String value); }
SwitchStatusConverter implements AttributeConverter<SwitchStatus, String> { @Override public SwitchStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return SwitchStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(SwitchStatus value); @Override SwitchStatus toEntityAttribute(String value); static final SwitchStatusConverter INSTANCE; }
@Test public void shouldConvertToGraphProperty() { assertEquals("TRANSIT_VLAN", FlowEncapsulationTypeConverter.INSTANCE.toGraphProperty(FlowEncapsulationType.TRANSIT_VLAN)); }
@Override public String toGraphProperty(FlowEncapsulationType value) { if (value == null) { return null; } return value.name(); }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public String toGraphProperty(FlowEncapsulationType value) { if (value == null) { return null; } return value.name(); } }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public String toGraphProperty(FlowEncapsulationType value) { if (value == null) { return null; } return value.name(); } }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public String toGraphProperty(FlowEncapsulationType value) { if (value == null) { return null; } return value.name(); } @Override String toGraphProperty(FlowEncapsulationType value); @Override FlowEncapsulationType toEntityAttribute(String value); }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public String toGraphProperty(FlowEncapsulationType value) { if (value == null) { return null; } return value.name(); } @Override String toGraphProperty(FlowEncapsulationType value); @Override FlowEncapsulationType toEntityAttribute(String value); static final FlowEncapsulationTypeConverter INSTANCE; }
@Test public void shouldConvertToEntity() { assertEquals(FlowEncapsulationType.TRANSIT_VLAN, FlowEncapsulationTypeConverter.INSTANCE.toEntityAttribute("TRANSIT_VLAN")); }
@Override public FlowEncapsulationType toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowEncapsulationType.valueOf(value); }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public FlowEncapsulationType toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowEncapsulationType.valueOf(value); } }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public FlowEncapsulationType toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowEncapsulationType.valueOf(value); } }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public FlowEncapsulationType toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowEncapsulationType.valueOf(value); } @Override String toGraphProperty(FlowEncapsulationType value); @Override FlowEncapsulationType toEntityAttribute(String value); }
FlowEncapsulationTypeConverter implements AttributeConverter<FlowEncapsulationType, String> { @Override public FlowEncapsulationType toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return FlowEncapsulationType.valueOf(value); } @Override String toGraphProperty(FlowEncapsulationType value); @Override FlowEncapsulationType toEntityAttribute(String value); static final FlowEncapsulationTypeConverter INSTANCE; }
@Test public void shouldConvertIdToString() { MeterId meterId = new MeterId(0x123); Long graphObject = MeterIdConverter.INSTANCE.toGraphProperty(meterId); assertEquals(meterId.getValue(), (long) graphObject); }
@Override public Long toGraphProperty(MeterId value) { if (value == null) { return null; } return value.getValue(); }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public Long toGraphProperty(MeterId value) { if (value == null) { return null; } return value.getValue(); } }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public Long toGraphProperty(MeterId value) { if (value == null) { return null; } return value.getValue(); } }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public Long toGraphProperty(MeterId value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(MeterId value); @Override MeterId toEntityAttribute(Long value); }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public Long toGraphProperty(MeterId value) { if (value == null) { return null; } return value.getValue(); } @Override Long toGraphProperty(MeterId value); @Override MeterId toEntityAttribute(Long value); static final MeterIdConverter INSTANCE; }
@Test public void shouldConvertStringToId() { MeterId meterId = new MeterId(0x123); MeterId actualEntity = MeterIdConverter.INSTANCE.toEntityAttribute(meterId.getValue()); assertEquals(meterId, actualEntity); }
@Override public MeterId toEntityAttribute(Long value) { if (value == null) { return null; } return new MeterId(value); }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public MeterId toEntityAttribute(Long value) { if (value == null) { return null; } return new MeterId(value); } }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public MeterId toEntityAttribute(Long value) { if (value == null) { return null; } return new MeterId(value); } }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public MeterId toEntityAttribute(Long value) { if (value == null) { return null; } return new MeterId(value); } @Override Long toGraphProperty(MeterId value); @Override MeterId toEntityAttribute(Long value); }
MeterIdConverter implements AttributeConverter<MeterId, Long> { @Override public MeterId toEntityAttribute(Long value) { if (value == null) { return null; } return new MeterId(value); } @Override Long toGraphProperty(MeterId value); @Override MeterId toEntityAttribute(Long value); static final MeterIdConverter INSTANCE; }
@Test public void shouldConvertToGraphProperty() { IslStatusConverter converter = IslStatusConverter.INSTANCE; assertEquals("active", converter.toGraphProperty(IslStatus.ACTIVE)); assertEquals("inactive", converter.toGraphProperty(IslStatus.INACTIVE)); }
@Override public String toGraphProperty(IslStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public String toGraphProperty(IslStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public String toGraphProperty(IslStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public String toGraphProperty(IslStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(IslStatus value); @Override IslStatus toEntityAttribute(String value); }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public String toGraphProperty(IslStatus value) { if (value == null) { return null; } return value.name().toLowerCase(); } @Override String toGraphProperty(IslStatus value); @Override IslStatus toEntityAttribute(String value); static final IslStatusConverter INSTANCE; }
@Test public void shouldConvertToEntity() { IslStatusConverter converter = IslStatusConverter.INSTANCE; assertEquals(IslStatus.ACTIVE, converter.toEntityAttribute("ACTIVE")); assertEquals(IslStatus.ACTIVE, converter.toEntityAttribute("active")); assertEquals(IslStatus.INACTIVE, converter.toEntityAttribute("InActive")); }
@Override public IslStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return IslStatus.valueOf(value.toUpperCase()); }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public IslStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return IslStatus.valueOf(value.toUpperCase()); } }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public IslStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return IslStatus.valueOf(value.toUpperCase()); } }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public IslStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return IslStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(IslStatus value); @Override IslStatus toEntityAttribute(String value); }
IslStatusConverter implements AttributeConverter<IslStatus, String> { @Override public IslStatus toEntityAttribute(String value) { if (value == null || value.trim().isEmpty()) { return null; } return IslStatus.valueOf(value.toUpperCase()); } @Override String toGraphProperty(IslStatus value); @Override IslStatus toEntityAttribute(String value); static final IslStatusConverter INSTANCE; }
@Test public void getFlowsForEndpointTransitSwitchFlowNoPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); Switch switchC = createSwitch(SWITCH_ID_3); createFlow(FLOW_ID_1, switchA, 1, switchC, 2, FORWARD_PATH_1, REVERSE_PATH_1, switchB); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, null), FLOW_ID_1); createFlow(FLOW_ID_2, switchC, 3, switchA, 4, FORWARD_PATH_2, REVERSE_PATH_2, switchB); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, null), FLOW_ID_1, FLOW_ID_2); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldCreatePortPropertiesWithRelation() { Switch origSwitch = createTestSwitch(TEST_SWITCH_ID.getId()); PortProperties portProperties = PortProperties.builder() .switchObj(origSwitch) .discoveryEnabled(false) .build(); portPropertiesRepository.add(portProperties); Collection<PortProperties> portPropertiesResult = portPropertiesRepository.findAll(); assertEquals(1, portPropertiesResult.size()); assertNotNull(portPropertiesResult.iterator().next().getSwitchObj()); }
@Override public Collection<PortProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL)) .toListExplicit(PortPropertiesFrame.class).stream() .map(PortProperties::new) .collect(Collectors.toList()); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Collection<PortProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL)) .toListExplicit(PortPropertiesFrame.class).stream() .map(PortProperties::new) .collect(Collectors.toList()); } }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Collection<PortProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL)) .toListExplicit(PortPropertiesFrame.class).stream() .map(PortProperties::new) .collect(Collectors.toList()); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Collection<PortProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL)) .toListExplicit(PortPropertiesFrame.class).stream() .map(PortProperties::new) .collect(Collectors.toList()); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<PortProperties> findAll(); @Override Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port); @Override Collection<PortProperties> getAllBySwitchId(SwitchId switchId); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Collection<PortProperties> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL)) .toListExplicit(PortPropertiesFrame.class).stream() .map(PortProperties::new) .collect(Collectors.toList()); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<PortProperties> findAll(); @Override Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port); @Override Collection<PortProperties> getAllBySwitchId(SwitchId switchId); }
@Test public void shouldGetPortPropertiesBySwitchIdAndPort() { Switch origSwitch = createTestSwitch(TEST_SWITCH_ID.getId()); int port = 7; PortProperties portProperties = PortProperties.builder() .switchObj(origSwitch) .port(port) .discoveryEnabled(false) .build(); portPropertiesRepository.add(portProperties); Optional<PortProperties> portPropertiesResult = portPropertiesRepository.getBySwitchIdAndPort(origSwitch.getSwitchId(), port); assertTrue(portPropertiesResult.isPresent()); assertEquals(origSwitch.getSwitchId(), portPropertiesResult.get().getSwitchObj().getSwitchId()); assertEquals(port, portPropertiesResult.get().getPort()); assertFalse(portPropertiesResult.get().isDiscoveryEnabled()); }
@Override public Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port) { List<? extends PortPropertiesFrame> portPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL) .has(PortPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortPropertiesFrame.PORT_NO_PROPERTY, port)) .toListExplicit(PortPropertiesFrame.class); return portPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(portPropertiesFrames.get(0)) .map(PortProperties::new); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port) { List<? extends PortPropertiesFrame> portPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL) .has(PortPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortPropertiesFrame.PORT_NO_PROPERTY, port)) .toListExplicit(PortPropertiesFrame.class); return portPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(portPropertiesFrames.get(0)) .map(PortProperties::new); } }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port) { List<? extends PortPropertiesFrame> portPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL) .has(PortPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortPropertiesFrame.PORT_NO_PROPERTY, port)) .toListExplicit(PortPropertiesFrame.class); return portPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(portPropertiesFrames.get(0)) .map(PortProperties::new); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port) { List<? extends PortPropertiesFrame> portPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL) .has(PortPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortPropertiesFrame.PORT_NO_PROPERTY, port)) .toListExplicit(PortPropertiesFrame.class); return portPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(portPropertiesFrames.get(0)) .map(PortProperties::new); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<PortProperties> findAll(); @Override Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port); @Override Collection<PortProperties> getAllBySwitchId(SwitchId switchId); }
FermaPortPropertiesRepository extends FermaGenericRepository<PortProperties, PortPropertiesData, PortPropertiesFrame> implements PortPropertiesRepository { @Override public Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port) { List<? extends PortPropertiesFrame> portPropertiesFrames = framedGraph().traverse(g -> g.V() .hasLabel(PortPropertiesFrame.FRAME_LABEL) .has(PortPropertiesFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortPropertiesFrame.PORT_NO_PROPERTY, port)) .toListExplicit(PortPropertiesFrame.class); return portPropertiesFrames.isEmpty() ? Optional.empty() : Optional.of(portPropertiesFrames.get(0)) .map(PortProperties::new); } FermaPortPropertiesRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<PortProperties> findAll(); @Override Optional<PortProperties> getBySwitchIdAndPort(SwitchId switchId, int port); @Override Collection<PortProperties> getAllBySwitchId(SwitchId switchId); }
@Test public void shouldCreateFlowCookie() { createFlowCookie(); Collection<FlowCookie> allCookies = flowCookieRepository.findAll(); FlowCookie foundCookie = allCookies.iterator().next(); assertEquals(TEST_COOKIE, foundCookie.getUnmaskedCookie()); assertEquals(TEST_FLOW_ID, foundCookie.getFlowId()); }
@Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
@Test public void shouldDeleteFlowCookie() { FlowCookie cookie = createFlowCookie(); transactionManager.doInTransaction(() -> flowCookieRepository.remove(cookie)); assertEquals(0, flowCookieRepository.findAll().size()); }
@Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
@Test public void shouldDeleteFoundFlowCookie() { createFlowCookie(); transactionManager.doInTransaction(() -> { Collection<FlowCookie> allCookies = flowCookieRepository.findAll(); FlowCookie foundCookie = allCookies.iterator().next(); flowCookieRepository.remove(foundCookie); }); assertEquals(0, flowCookieRepository.findAll().size()); }
@Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Collection<FlowCookie> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL)) .toListExplicit(FlowCookieFrame.class).stream() .map(FlowCookie::new) .collect(Collectors.toList()); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
@Test public void shouldSelectNextInOrderResourceWhenFindUnassignedCookie() { long first = findUnassignedCookieAndCreate("flow_1"); assertEquals(5, first); long second = findUnassignedCookieAndCreate("flow_2"); assertEquals(6, second); long third = findUnassignedCookieAndCreate("flow_3"); assertEquals(7, third); transactionManager.doInTransaction(() -> flowCookieRepository.findByCookie(second).ifPresent(flowCookieRepository::remove)); long fourth = findUnassignedCookieAndCreate("flow_4"); assertEquals(6, fourth); long fifth = findUnassignedCookieAndCreate("flow_5"); assertEquals(8, fifth); }
@Override public Optional<FlowCookie> findByCookie(long unmaskedCookie) { List<? extends FlowCookieFrame> flowCookieFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL) .has(FlowCookieFrame.UNMASKED_COOKIE_PROPERTY, unmaskedCookie)) .toListExplicit(FlowCookieFrame.class); return flowCookieFrames.isEmpty() ? Optional.empty() : Optional.of(flowCookieFrames.get(0)) .map(FlowCookie::new); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Optional<FlowCookie> findByCookie(long unmaskedCookie) { List<? extends FlowCookieFrame> flowCookieFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL) .has(FlowCookieFrame.UNMASKED_COOKIE_PROPERTY, unmaskedCookie)) .toListExplicit(FlowCookieFrame.class); return flowCookieFrames.isEmpty() ? Optional.empty() : Optional.of(flowCookieFrames.get(0)) .map(FlowCookie::new); } }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Optional<FlowCookie> findByCookie(long unmaskedCookie) { List<? extends FlowCookieFrame> flowCookieFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL) .has(FlowCookieFrame.UNMASKED_COOKIE_PROPERTY, unmaskedCookie)) .toListExplicit(FlowCookieFrame.class); return flowCookieFrames.isEmpty() ? Optional.empty() : Optional.of(flowCookieFrames.get(0)) .map(FlowCookie::new); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Optional<FlowCookie> findByCookie(long unmaskedCookie) { List<? extends FlowCookieFrame> flowCookieFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL) .has(FlowCookieFrame.UNMASKED_COOKIE_PROPERTY, unmaskedCookie)) .toListExplicit(FlowCookieFrame.class); return flowCookieFrames.isEmpty() ? Optional.empty() : Optional.of(flowCookieFrames.get(0)) .map(FlowCookie::new); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
FermaFlowCookieRepository extends FermaGenericRepository<FlowCookie, FlowCookieData, FlowCookieFrame> implements FlowCookieRepository { @Override public Optional<FlowCookie> findByCookie(long unmaskedCookie) { List<? extends FlowCookieFrame> flowCookieFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowCookieFrame.FRAME_LABEL) .has(FlowCookieFrame.UNMASKED_COOKIE_PROPERTY, unmaskedCookie)) .toListExplicit(FlowCookieFrame.class); return flowCookieFrames.isEmpty() ? Optional.empty() : Optional.of(flowCookieFrames.get(0)) .map(FlowCookie::new); } FermaFlowCookieRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowCookie> findAll(); @Override boolean exists(long unmaskedCookie); @Override Optional<FlowCookie> findByCookie(long unmaskedCookie); @Override Optional<Long> findFirstUnassignedCookie(long lowestCookieValue, long highestCookieValue); }
@Test public void shouldFlowPathUpdateKeepRelations() { createTestFlowPathPair(); Flow foundFlow = flowRepository.findById(TEST_FLOW_ID).get(); assertThat(foundFlow.getPaths(), hasSize(2)); FlowPath foundPath = flowPathRepository.findById(flow.getForwardPathId()).get(); foundPath.setStatus(FlowPathStatus.INACTIVE); foundFlow = flowRepository.findById(TEST_FLOW_ID).get(); assertThat(foundFlow.getPaths(), hasSize(2)); }
@Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFlowPathUpdateKeepFlowRelations() { createTestFlowPathPair(); Flow foundFlow = flowRepository.findById(TEST_FLOW_ID).get(); assertThat(foundFlow.getPaths(), hasSize(2)); FlowPath flowPath = foundFlow.getPaths().stream() .filter(path -> path.getPathId().equals(flow.getReversePathId())) .findAny().get(); flowPath.setStatus(FlowPathStatus.INACTIVE); foundFlow = flowRepository.findById(TEST_FLOW_ID).get(); assertThat(foundFlow.getPaths(), hasSize(2)); }
@Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathById() { FlowPath flowPath = createTestFlowPath(); Optional<FlowPath> foundPath = flowPathRepository.findById(flowPath.getPathId()); assertTrue(foundPath.isPresent()); }
@Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathByFlowIdAndCookie() { FlowPath flowPath = createTestFlowPath(); Optional<FlowPath> foundPath = flowPathRepository.findByFlowIdAndCookie(TEST_FLOW_ID, flowPath.getCookie()); assertTrue(foundPath.isPresent()); }
@Override public Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId) .has(FlowPathFrame.COOKIE_PROPERTY, FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie))) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.size() > 1) { throw new PersistenceException(format("Found more that 1 FlowPath entity by (%s, %s)", flowId, cookie)); } return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)).map(FlowPath::new); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId) .has(FlowPathFrame.COOKIE_PROPERTY, FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie))) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.size() > 1) { throw new PersistenceException(format("Found more that 1 FlowPath entity by (%s, %s)", flowId, cookie)); } return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)).map(FlowPath::new); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId) .has(FlowPathFrame.COOKIE_PROPERTY, FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie))) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.size() > 1) { throw new PersistenceException(format("Found more that 1 FlowPath entity by (%s, %s)", flowId, cookie)); } return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)).map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId) .has(FlowPathFrame.COOKIE_PROPERTY, FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie))) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.size() > 1) { throw new PersistenceException(format("Found more that 1 FlowPath entity by (%s, %s)", flowId, cookie)); } return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)).map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId) .has(FlowPathFrame.COOKIE_PROPERTY, FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie))) .toListExplicit(FlowPathFrame.class); if (flowPathFrames.size() > 1) { throw new PersistenceException(format("Found more that 1 FlowPath entity by (%s, %s)", flowId, cookie)); } return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)).map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void getFlowsForEndpointSeveralFlowNoPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); Switch switchC = createSwitch(SWITCH_ID_3); createFlow(FLOW_ID_1, switchB, 1, switchB, 2, FORWARD_PATH_1, REVERSE_PATH_1, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, null), FLOW_ID_1); createFlow(FLOW_ID_2, switchA, 3, switchB, 4, FORWARD_PATH_2, REVERSE_PATH_2, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, null), FLOW_ID_1, FLOW_ID_2); createFlow(FLOW_ID_3, switchA, 5, switchC, 6, FORWARD_PATH_3, REVERSE_PATH_3, switchB); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, null), FLOW_ID_1, FLOW_ID_2, FLOW_ID_3); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldFindByEndpointSwitch() { createTestFlowPathPair(); Collection<FlowPath> paths = flowPathRepository.findByEndpointSwitch(switchA.getSwitchId()); assertThat(paths, containsInAnyOrder(flow.getForwardPath(), flow.getReversePath())); }
@Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldNotFindProtectedIngressByEndpointSwitch() { createTestFlowPathPair(); FlowPath protect = createFlowPath(flow, "_protectedpath", 10, 10, switchA, switchB); flow.setProtectedForwardPath(protect); Collection<FlowPath> paths = flowPathRepository.findByEndpointSwitch(switchA.getSwitchId()); assertThat(paths, containsInAnyOrder(flow.getForwardPath(), flow.getReversePath())); }
@Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindProtectedPathsByEndpointSwitchIncludeProtected() { createTestFlowPathPair(); flow.setProtectedForwardPath(createFlowPath(flow, "_forward_protected", 10, 10, switchA, switchB)); flow.setProtectedReversePath(createFlowPath(flow, "_reverse_protected", 11, 11, switchB, switchA)); Collection<FlowPath> paths = flowPathRepository.findByEndpointSwitch(switchA.getSwitchId(), true); assertThat(paths, containsInAnyOrder(flow.getForwardPath(), flow.getReversePath(), flow.getProtectedForwardPath(), flow.getProtectedReversePath())); }
@Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindProtectedPathsBySrcSwitchIncludeProtected() { createTestFlowPathPair(); flow.setProtectedForwardPath(createFlowPath(flow, "_forward_protected", 10, 10, switchA, switchB)); flow.setProtectedReversePath(createFlowPath(flow, "_reverse_protected", 11, 11, switchB, switchA)); assertThat(flowPathRepository.findBySrcSwitch(switchA.getSwitchId(), true), containsInAnyOrder(flow.getForwardPath(), flow.getProtectedForwardPath())); assertThat(flowPathRepository.findBySrcSwitch(switchB.getSwitchId(), true), containsInAnyOrder(flow.getReversePath(), flow.getProtectedReversePath())); }
@Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindBySrcSwitch() { createTestFlowPathPair(); Collection<FlowPath> paths = flowPathRepository.findBySrcSwitch(switchA.getSwitchId()); assertThat(paths, containsInAnyOrder(flow.getForwardPath())); }
@Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindFlowPathsForIsl() { FlowPath flowPath = createTestFlowPathWithIntermediate(switchC, 100); flow.setForwardPath(flowPath); Collection<FlowPath> paths = flowPathRepository.findWithPathSegment(switchA.getSwitchId(), 1, switchC.getSwitchId(), 100); assertThat(paths, Matchers.hasSize(1)); assertThat(paths, containsInAnyOrder(flow.getForwardPath())); }
@Override public Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId)) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, srcPort) .has(PathSegmentFrame.DST_PORT_PROPERTY, dstPort) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId)) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, srcPort) .has(PathSegmentFrame.DST_PORT_PROPERTY, dstPort) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId)) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, srcPort) .has(PathSegmentFrame.DST_PORT_PROPERTY, dstPort) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId)) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, srcPort) .has(PathSegmentFrame.DST_PORT_PROPERTY, dstPort) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId)) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, srcPort) .has(PathSegmentFrame.DST_PORT_PROPERTY, dstPort) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindActiveAffectedPaths() { FlowPath flowPath = createTestFlowPathWithIntermediate(switchC, 100); flow.setForwardPath(flowPath); Collection<FlowPath> paths = flowPathRepository.findBySegmentEndpoint( switchC.getSwitchId(), 100); assertThat(paths, containsInAnyOrder(flowPath)); }
@Override public Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.DST_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.DST_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.DST_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.DST_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.SRC_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PathSegmentFrame.DST_PORT_PROPERTY, port) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathByFlowId() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findByFlowId(TEST_FLOW_ID); assertThat(foundPaths, hasSize(1)); }
@Override public Collection<FlowPath> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathBySrc() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findBySrcSwitch(switchA.getSwitchId()); assertThat(foundPaths, hasSize(1)); }
@Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldNotFindPathByWrongSrc() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findBySrcSwitch(switchB.getSwitchId()); assertThat(foundPaths, Matchers.empty()); }
@Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected) { List<FlowPath> result = new ArrayList<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.add(new FlowPath(frame))); if (includeProtected) { return result; } else { return result.stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void getFlowsForEndpointOneSwitchFlowWithPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); createFlow(FLOW_ID_1, switchA, 1, switchA, 2, FORWARD_PATH_1, REVERSE_PATH_1, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, 1), FLOW_ID_1); createFlow(FLOW_ID_2, switchA, 3, switchA, 4, FORWARD_PATH_2, REVERSE_PATH_2, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, 1), FLOW_ID_1); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldFindPathByEndpointSwitch() { createTestFlowPath(); Collection<FlowPath> foundPaths = flowPathRepository.findByEndpointSwitch(switchB.getSwitchId()); assertThat(foundPaths, hasSize(1)); }
@Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); if (includeProtected) { return result.values(); } else { return result.values().stream() .filter(path -> !(path.isProtected() && switchId.equals(path.getSrcSwitchId()))) .collect(Collectors.toList()); } } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathBySegmentSwitch() { FlowPath flowPath = createTestFlowPathWithIntermediate(switchC, 100); flow.setForwardPath(flowPath); Collection<FlowPath> foundPaths = flowPathRepository.findBySegmentSwitch(switchC.getSwitchId()); assertThat(foundPaths, hasSize(1)); }
@Override public Collection<FlowPath> findBySegmentSwitch(SwitchId switchId) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentSwitch(SwitchId switchId) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentSwitch(SwitchId switchId) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentSwitch(SwitchId switchId) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentSwitch(SwitchId switchId) { Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindInactivePathBySegmentSwitch() { Flow activeFlow = Flow.builder() .flowId("active flow") .srcSwitch(switchA) .srcPort(1) .destSwitch(switchB) .destPort(2) .status(FlowStatus.UP) .build(); flowRepository.add(activeFlow); FlowPath activeFlowPath = createFlowPath(activeFlow, "active", 100L, 200L, switchA, switchB); activeFlow.addPaths(activeFlowPath); activeFlowPath.getFlow().setStatus(FlowStatus.DOWN); FlowPath expectedFlowPath = createTestFlowPathWithIntermediate(switchC, 100); activeFlow.addPaths(expectedFlowPath); expectedFlowPath.getFlow().setStatus(FlowStatus.DOWN); Collection<FlowPath> foundPaths = flowPathRepository.findInactiveBySegmentSwitch(switchA.getSwitchId()); assertThat(foundPaths, hasSize(1)); FlowPath actualFlowPath = foundPaths.stream().findFirst().orElse(null); assertEquals(expectedFlowPath, actualFlowPath); }
@Override public Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId) { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId) { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId) { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId) { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId) { String downFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DOWN); String degragedFlowStatus = FlowStatusConverter.INSTANCE.toGraphProperty(FlowStatus.DEGRADED); Map<PathId, FlowPath> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL).as("p") .in(FlowFrame.OWNS_PATHS_EDGE) .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.STATUS_PROPERTY, P.within(downFlowStatus, degragedFlowStatus)) .select("p")) .frameExplicit(FlowPathFrame.class) .forEachRemaining(frame -> result.put(frame.getPathId(), new FlowPath(frame))); return result.values(); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindPathBySegmentDestSwitch() { FlowPath flowPath = createTestFlowPathWithIntermediate(switchC, 100); flow.setForwardPath(flowPath); Collection<FlowPath> foundPaths = flowPathRepository.findBySegmentDestSwitch(switchC.getSwitchId()); assertThat(foundPaths, hasSize(1)); }
@Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldNotFindPathByWrongSegmentDestSwitch() { FlowPath flowPath = createTestFlowPathWithIntermediate(switchC, 100); flow.setForwardPath(flowPath); Collection<FlowPath> foundPaths = flowPathRepository.findBySegmentDestSwitch(switchA.getSwitchId()); assertThat(foundPaths, Matchers.empty()); }
@Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(PathSegmentFrame.FRAME_LABEL) .has(PathSegmentFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .in(FlowPathFrame.OWNS_SEGMENTS_EDGE) .hasLabel(FlowPathFrame.FRAME_LABEL)) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldKeepSegmentsOrdered() { FlowPath flowPath = createTestFlowPath(); List<PathSegment> segments = asList(PathSegment.builder() .srcSwitch(switchA) .destSwitch(switchC) .build(), PathSegment.builder() .srcSwitch(switchC) .destSwitch(switchB) .build()); flowPath.setSegments(segments); Optional<FlowPath> foundPath = flowPathRepository.findById(flowPath.getPathId()); assertEquals(foundPath.get().getSegments().get(0).getDestSwitchId(), switchC.getSwitchId()); }
@Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Optional<FlowPath> findById(PathId pathId) { List<? extends FlowPathFrame> flowPathFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))) .toListExplicit(FlowPathFrame.class); return flowPathFrames.isEmpty() ? Optional.empty() : Optional.of(flowPathFrames.get(0)) .map(FlowPath::new); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldFindFlowPathIdsByFlowIds() { Flow flowA = buildTestProtectedFlow(TEST_FLOW_ID_1, switchA, PORT_1, VLAN_1, switchB, PORT_2, VLAN_2); flowRepository.add(flowA); Flow flowB = buildTestFlow(TEST_FLOW_ID_2, switchA, PORT_1, VLAN_2, switchB, PORT_2, 0); flowRepository.add(flowB); Flow flowC = buildTestProtectedFlow(TEST_FLOW_ID_3, switchB, PORT_1, VLAN_1, switchB, PORT_3, VLAN_1); flowRepository.add(flowC); Collection<FlowPath> flowPaths = flowPathRepository.findActualByFlowIds(Sets.newHashSet(TEST_FLOW_ID_1, TEST_FLOW_ID_2)); Collection<PathId> pathIds = flowPaths.stream().map(FlowPath::getPathId).collect(Collectors.toList()); assertEquals(6, pathIds.size()); assertTrue(pathIds.contains(flowA.getForwardPathId())); assertTrue(pathIds.contains(flowA.getReversePathId())); assertTrue(pathIds.contains(flowA.getProtectedForwardPathId())); assertTrue(pathIds.contains(flowA.getProtectedReversePathId())); assertTrue(pathIds.contains(flowB.getForwardPathId())); assertTrue(pathIds.contains(flowB.getReversePathId())); }
@Override public Collection<FlowPath> findActualByFlowIds(Set<String> flowIds) { Set<String> pathIds = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.FORWARD_PATH_ID_PROPERTY, FlowFrame.REVERSE_PATH_ID_PROPERTY, FlowFrame.PROTECTED_FORWARD_PATH_ID_PROPERTY, FlowFrame.PROTECTED_REVERSE_PATH_ID_PROPERTY)) .getRawTraversal() .forEachRemaining(pathId -> pathIds.add((String) pathId)); return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, P.within(pathIds))) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findActualByFlowIds(Set<String> flowIds) { Set<String> pathIds = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.FORWARD_PATH_ID_PROPERTY, FlowFrame.REVERSE_PATH_ID_PROPERTY, FlowFrame.PROTECTED_FORWARD_PATH_ID_PROPERTY, FlowFrame.PROTECTED_REVERSE_PATH_ID_PROPERTY)) .getRawTraversal() .forEachRemaining(pathId -> pathIds.add((String) pathId)); return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, P.within(pathIds))) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findActualByFlowIds(Set<String> flowIds) { Set<String> pathIds = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.FORWARD_PATH_ID_PROPERTY, FlowFrame.REVERSE_PATH_ID_PROPERTY, FlowFrame.PROTECTED_FORWARD_PATH_ID_PROPERTY, FlowFrame.PROTECTED_REVERSE_PATH_ID_PROPERTY)) .getRawTraversal() .forEachRemaining(pathId -> pathIds.add((String) pathId)); return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, P.within(pathIds))) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findActualByFlowIds(Set<String> flowIds) { Set<String> pathIds = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.FORWARD_PATH_ID_PROPERTY, FlowFrame.REVERSE_PATH_ID_PROPERTY, FlowFrame.PROTECTED_FORWARD_PATH_ID_PROPERTY, FlowFrame.PROTECTED_REVERSE_PATH_ID_PROPERTY)) .getRawTraversal() .forEachRemaining(pathId -> pathIds.add((String) pathId)); return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, P.within(pathIds))) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
FermaFlowPathRepository extends FermaGenericRepository<FlowPath, FlowPathData, FlowPathFrame> implements FlowPathRepository { @Override public Collection<FlowPath> findActualByFlowIds(Set<String> flowIds) { Set<String> pathIds = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, P.within(flowIds)) .values(FlowFrame.FORWARD_PATH_ID_PROPERTY, FlowFrame.REVERSE_PATH_ID_PROPERTY, FlowFrame.PROTECTED_FORWARD_PATH_ID_PROPERTY, FlowFrame.PROTECTED_REVERSE_PATH_ID_PROPERTY)) .getRawTraversal() .forEachRemaining(pathId -> pathIds.add((String) pathId)); return framedGraph().traverse(g -> g.V() .hasLabel(FlowPathFrame.FRAME_LABEL) .has(FlowPathFrame.PATH_ID_PROPERTY, P.within(pathIds))) .toListExplicit(FlowPathFrame.class).stream() .map(FlowPath::new) .collect(Collectors.toList()); } FermaFlowPathRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowPath> findAll(); @Override Optional<FlowPath> findById(PathId pathId); @Override Optional<FlowPath> findByFlowIdAndCookie(String flowId, FlowSegmentCookie cookie); @Override Collection<FlowPath> findByFlowId(String flowId); @Override Collection<FlowPath> findByFlowGroupId(String flowGroupId); @Override Collection<PathId> findPathIdsByFlowGroupId(String flowGroupId); @Override Collection<FlowPath> findActualByFlowIds(Set<String> flowIds); @Override Collection<FlowPath> findBySrcSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findByEndpointSwitch(SwitchId switchId, boolean includeProtected); @Override Collection<FlowPath> findBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findInactiveBySegmentSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentSwitchWithMultiTable(SwitchId switchId, boolean multiTable); @Override Collection<FlowPath> findWithPathSegment(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Collection<FlowPath> findBySegmentDestSwitch(SwitchId switchId); @Override Collection<FlowPath> findBySegmentEndpoint(SwitchId switchId, int port); @Override void updateStatus(PathId pathId, FlowPathStatus pathStatus); @Override long getUsedBandwidthBetweenEndpoints(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort); @Override Optional<FlowPath> remove(PathId pathId); }
@Test public void shouldLookupRuleByMatchAndFlow() { ApplicationRule ruleA = buildRuleA(); ApplicationRule foundRule = applicationRepository.lookupRuleByMatchAndFlow(ruleA.getSwitchId(), ruleA.getFlowId(), ruleA.getSrcIp(), ruleA.getSrcPort(), ruleA.getDstIp(), ruleA.getDstPort(), ruleA.getProto(), ruleA.getEthType(), ruleA.getMetadata()).get(); assertEquals(ruleA, foundRule); }
@Override public Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
@Test public void shouldLookupRuleByMatchAndCookie() { ApplicationRule ruleA = buildRuleA(); ApplicationRule foundRule = applicationRepository.lookupRuleByMatchAndCookie(ruleA.getSwitchId(), ruleA.getCookie(), ruleA.getSrcIp(), ruleA.getSrcPort(), ruleA.getDstIp(), ruleA.getDstPort(), ruleA.getProto(), ruleA.getEthType(), ruleA.getMetadata()).get(); assertEquals(ruleA, foundRule); }
@Override public Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.COOKIE_PROPERTY, ExclusionCookieConverter.INSTANCE.toGraphProperty(cookie)) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.COOKIE_PROPERTY, ExclusionCookieConverter.INSTANCE.toGraphProperty(cookie)) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.COOKIE_PROPERTY, ExclusionCookieConverter.INSTANCE.toGraphProperty(cookie)) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.COOKIE_PROPERTY, ExclusionCookieConverter.INSTANCE.toGraphProperty(cookie)) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata) { List<? extends ApplicationRuleFrame> applicationRuleFrames = framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(ApplicationRuleFrame.COOKIE_PROPERTY, ExclusionCookieConverter.INSTANCE.toGraphProperty(cookie)) .has(ApplicationRuleFrame.SRC_IP_PROPERTY, srcIp) .has(ApplicationRuleFrame.SRC_PORT_PROPERTY, srcPort) .has(ApplicationRuleFrame.DST_IP_PROPERTY, dstIp) .has(ApplicationRuleFrame.DST_PORT_PROPERTY, dstPort) .has(ApplicationRuleFrame.PROTO_PROPERTY, proto) .has(ApplicationRuleFrame.ETH_TYPE_PROPERTY, ethType) .has(ApplicationRuleFrame.METADATA_PROPERTY, metadata)) .toListExplicit(ApplicationRuleFrame.class); return applicationRuleFrames.isEmpty() ? Optional.empty() : Optional.of(applicationRuleFrames.get(0)) .map(ApplicationRule::new); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
@Test public void shouldFindBySwitchId() { Collection<ApplicationRule> foundRules = applicationRepository.findBySwitchId(TEST_SWITCH_ID); assertEquals(2, foundRules.size()); assertTrue(foundRules.contains(buildRuleA())); assertTrue(foundRules.contains(buildRuleC())); }
@Override public Collection<ApplicationRule> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findBySwitchId(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
@Test public void getFlowsForEndpointMultiSwitchFlowWithPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); createFlow(FLOW_ID_1, switchA, 1, switchB, 2, FORWARD_PATH_1, REVERSE_PATH_1, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, 1), FLOW_ID_1); createFlow(FLOW_ID_2, switchB, 3, switchA, 1, FORWARD_PATH_2, REVERSE_PATH_2, null); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_1, 1), FLOW_ID_1, FLOW_ID_2); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldFindByFlowId() { Collection<ApplicationRule> foundRules = applicationRepository.findByFlowId(TEST_FLOW_ID); assertEquals(2, foundRules.size()); assertTrue(foundRules.contains(buildRuleA())); assertTrue(foundRules.contains(buildRuleB())); }
@Override public Collection<ApplicationRule> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
FermaApplicationRepository extends FermaGenericRepository<ApplicationRule, ApplicationRuleData, ApplicationRuleFrame> implements ApplicationRepository { @Override public Collection<ApplicationRule> findByFlowId(String flowId) { return framedGraph().traverse(g -> g.V() .hasLabel(ApplicationRuleFrame.FRAME_LABEL) .has(ApplicationRuleFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(ApplicationRuleFrame.class).stream() .map(ApplicationRule::new) .collect(Collectors.toList()); } FermaApplicationRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Optional<ApplicationRule> lookupRuleByMatchAndFlow(SwitchId switchId, String flowId, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Optional<ApplicationRule> lookupRuleByMatchAndCookie(SwitchId switchId, ExclusionCookie cookie, String srcIp, Integer srcPort, String dstIp, Integer dstPort, String proto, String ethType, Long metadata); @Override Collection<ApplicationRule> findBySwitchId(SwitchId switchId); @Override Collection<ApplicationRule> findByFlowId(String flowId); }
@Test public void findByFlowIdAndTimeFrameOrderTest() { List<FlowEvent> expected = new ArrayList<>(); expected.add(buildFlowEvent(FLOW_1, ACTION_1, TIME_1)); expected.add(buildFlowEvent(FLOW_1, ACTION_2, TIME_2)); expected.add(buildFlowEvent(FLOW_1, ACTION_3, TIME_3)); for (FlowEvent flowHistory : expected) { repository.add(flowHistory); } List<FlowEvent> actual = new ArrayList<>(repository.findByFlowIdAndTimeFrame( FLOW_1, TIME_1.minusSeconds(1), TIME_3.plusSeconds(1), 100)); assertEquals(expected, actual); assertTrue(actual.get(0).getTimestamp().isBefore(actual.get(1).getTimestamp())); assertTrue(actual.get(1).getTimestamp().isBefore(actual.get(2).getTimestamp())); }
@Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
@Test public void findByFlowIdAndTimeFrameTest() { repository.add(buildFlowEvent(FLOW_1, ACTION_1, TIME_1)); repository.add(buildFlowEvent(FLOW_1, ACTION_2, TIME_2)); repository.add(buildFlowEvent(FLOW_1, ACTION_3, TIME_3)); repository.add(buildFlowEvent(FLOW_1, ACTION_4, TIME_4)); repository.add(buildFlowEvent(FLOW_2, ACTION_5, TIME_3)); List<FlowEvent> events = new ArrayList<>(repository.findByFlowIdAndTimeFrame( FLOW_1, TIME_2, TIME_3, 1000)); assertEquals(2, events.size()); assertEquals(ACTION_2, events.get(0).getAction()); assertEquals(ACTION_3, events.get(1).getAction()); assertTrue(events.get(0).getTimestamp().isBefore(events.get(1).getTimestamp())); }
@Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
@Test public void findByFlowIdTimeFrameAndMaxCountTest() { repository.add(buildFlowEvent(FLOW_1, ACTION_1, TIME_1)); repository.add(buildFlowEvent(FLOW_1, ACTION_2, TIME_2)); repository.add(buildFlowEvent(FLOW_1, ACTION_3, TIME_3)); repository.add(buildFlowEvent(FLOW_1, ACTION_4, TIME_4)); repository.add(buildFlowEvent(FLOW_2, ACTION_5, TIME_3)); List<FlowEvent> events = new ArrayList<>(repository.findByFlowIdAndTimeFrame( FLOW_1, TIME_1, TIME_4, 2)); assertEquals(2, events.size()); assertEquals(ACTION_3, events.get(0).getAction()); assertEquals(ACTION_4, events.get(1).getAction()); assertTrue(events.get(0).getTimestamp().isBefore(events.get(1).getTimestamp())); }
@Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
@Test public void shouldCreateFlow() { createTestFlow(TEST_FLOW_ID, switchA, switchB); Collection<Flow> allFlows = flowRepository.findAll(); Flow foundFlow = allFlows.iterator().next(); assertEquals(switchA.getSwitchId(), foundFlow.getSrcSwitchId()); assertEquals(switchB.getSwitchId(), foundFlow.getDestSwitchId()); }
@Override public Collection<Flow> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL)) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL)) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL)) .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> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL)) .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> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL)) .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 shouldNotFindByIdWithEndpoints() { assertFalse(flowRepository.findById("Non_existent").isPresent()); }
@Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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 shouldCheckForExistence() { createTestFlow(TEST_FLOW_ID, switchA, switchB); assertTrue(flowRepository.exists(TEST_FLOW_ID)); }
@Override public boolean exists(String flowId) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .getRawTraversal()) { return traversal.hasNext(); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public boolean exists(String flowId) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .getRawTraversal()) { return traversal.hasNext(); } catch (Exception e) { throw new PersistenceException("Failed to traverse", e); } } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public boolean exists(String flowId) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .getRawTraversal()) { return traversal.hasNext(); } 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 boolean exists(String flowId) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .getRawTraversal()) { return traversal.hasNext(); } 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 boolean exists(String flowId) { try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .getRawTraversal()) { return traversal.hasNext(); } 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 shouldFindFlowById() { createTestFlow(TEST_FLOW_ID, switchA, switchB); Optional<Flow> foundFlow = flowRepository.findById(TEST_FLOW_ID); assertTrue(foundFlow.isPresent()); }
@Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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 shouldFind2SegmentFlowById() { Switch switchC = createTestSwitch(TEST_SWITCH_C_ID.getId()); createTestFlowWithIntermediate(TEST_FLOW_ID, switchA, switchC, 100, switchB); Optional<Flow> foundFlow = flowRepository.findById(TEST_FLOW_ID); assertTrue(foundFlow.isPresent()); }
@Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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<Flow> findById(String flowId) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.FLOW_ID_PROPERTY, flowId)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)) .map(Flow::new); } 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 shouldFindFlowByGroupId() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); flow.setGroupId(TEST_GROUP_ID); List<Flow> foundFlow = Lists.newArrayList(flowRepository.findByGroupId(TEST_GROUP_ID)); assertThat(foundFlow, Matchers.hasSize(1)); assertEquals(Collections.singletonList(flow), foundFlow); }
@Override public Collection<Flow> findByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId)) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId)) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId)) .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> findByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId)) .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> findByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId)) .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 getFlowsForEndpointTransitSwitchFlowWithPortTest() throws SwitchNotFoundException { Switch switchA = createSwitch(SWITCH_ID_1); Switch switchB = createSwitch(SWITCH_ID_2); Switch switchC = createSwitch(SWITCH_ID_3); createFlow(FLOW_ID_1, switchA, 1, switchC, 2, FORWARD_PATH_1, REVERSE_PATH_1, switchB); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, 2), FLOW_ID_1); createFlow(FLOW_ID_2, switchC, 2, switchA, 4, FORWARD_PATH_2, REVERSE_PATH_2, switchB); assertFlows(flowOperationsService.getFlowsForEndpoint(SWITCH_ID_2, 2), FLOW_ID_1, FLOW_ID_2); }
public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port) throws SwitchNotFoundException { flowDashboardLogger.onFlowPathsDumpByEndpoint(switchId, port); if (!switchRepository.findById(switchId).isPresent()) { throw new SwitchNotFoundException(switchId); } if (port != null) { return getFlowsForEndpoint(flowPathRepository.findBySegmentEndpoint(switchId, port), flowRepository.findByEndpoint(switchId, port)); } else { return getFlowsForEndpoint(flowPathRepository.findBySegmentSwitch(switchId), flowRepository.findByEndpointSwitch(switchId)); } } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort, SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests( Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
@Test public void shouldFindFlowsIdByGroupId() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); flow.setGroupId(TEST_GROUP_ID); List<String> foundFlowId = Lists.newArrayList(flowRepository.findFlowsIdByGroupId(TEST_GROUP_ID)); assertThat(foundFlowId, Matchers.hasSize(1)); assertEquals(Collections.singletonList(TEST_FLOW_ID), foundFlowId); }
@Override public Collection<String> findFlowsIdByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .map(i -> (String) i) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .map(i -> (String) i) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .map(i -> (String) i) .collect(Collectors.toList()); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .map(i -> (String) i) .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<String> findFlowsIdByGroupId(String flowGroupId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.GROUP_ID_PROPERTY, flowGroupId) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .map(i -> (String) i) .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 shouldFindFlowByEndpointSwitchWithEnabledArp() { createFlowWithArp(TEST_FLOW_ID, switchA, false, switchB, false); createFlowWithArp(TEST_FLOW_ID_2, switchA, true, switchB, false); createFlowWithArp(TEST_FLOW_ID_3, switchB, false, switchA, true); createFlowWithArp(TEST_FLOW_ID_4, switchA, true, switchA, true); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitchWithEnabledArp(TEST_SWITCH_A_ID); Set<String> foundFlowIds = foundFlows.stream() .map(Flow::getFlowId) .collect(Collectors.toSet()); assertEquals(Sets.newHashSet(TEST_FLOW_ID_2, TEST_FLOW_ID_3, TEST_FLOW_ID_4), foundFlowIds); }
@Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldFindOneFlowByEndpointSwitchWithEnabledArp() { createFlowWithArp(TEST_FLOW_ID, switchA, true, switchA, true); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitchWithEnabledArp(TEST_SWITCH_A_ID); assertEquals(1, foundFlows.size()); assertEquals(TEST_FLOW_ID, foundFlows.iterator().next().getFlowId()); }
@Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitchWithEnabledArp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_ARP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldFindFlowByEndpoint() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); Collection<Flow> foundFlows = flowRepository.findByEndpoint(TEST_SWITCH_A_ID, 1); Set<String> foundFlowIds = foundFlows.stream().map(foundFlow -> flow.getFlowId()).collect(Collectors.toSet()); assertThat(foundFlowIds, Matchers.hasSize(1)); }
@Override public Collection<Flow> findByEndpoint(SwitchId switchId, int port) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpoint(SwitchId switchId, int port) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpoint(SwitchId switchId, int port) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpoint(SwitchId switchId, int port) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpoint(SwitchId switchId, int port) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldNotFindFlowByEndpointAndVlan() { assertFalse(flowRepository.findByEndpointAndVlan(new SwitchId(1234), 999, 999).isPresent()); }
@Override public Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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<Flow> findByEndpointAndVlan(SwitchId switchId, int port, int vlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_VLAN_PROPERTY, vlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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 shouldNotFindOneSwitchFlowBySwitchIdInPortAndOutVlanIfFlowNotExist() { assertFalse(flowRepository.findOneSwitchFlowBySwitchIdInPortAndOutVlan( new SwitchId(1234), 999, 999).isPresent()); }
@Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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 shouldNotFindNotOneSwitchFlowBySwitchIdInPortAndOutVlan() { createTestFlow(TEST_FLOW_ID, switchA, PORT_1, VLAN_1, switchB, PORT_2, VLAN_2); Optional<Flow> flow = flowRepository.findOneSwitchFlowBySwitchIdInPortAndOutVlan( switchA.getSwitchId(), PORT_1, VLAN_2); assertFalse(flow.isPresent()); }
@Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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 shouldFindOnlyOneSwitchFlowBySwitchIdInPortAndOutVlan() { createTestFlow(TEST_FLOW_ID, switchA, PORT_1, VLAN_1, switchA, PORT_2, VLAN_2); createTestFlow(TEST_FLOW_ID_2, switchA, PORT_1, VLAN_3, switchB, PORT_2, VLAN_2); Optional<Flow> flow = flowRepository.findOneSwitchFlowBySwitchIdInPortAndOutVlan( switchA.getSwitchId(), PORT_1, VLAN_2); assertTrue(flow.isPresent()); assertEquals(TEST_FLOW_ID, flow.get().getFlowId()); }
@Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Optional<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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<Flow> findOneSwitchFlowBySwitchIdInPortAndOutVlan(SwitchId switchId, int inPort, int outVlan) { List<? extends FlowFrame> flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, inPort) .has(FlowFrame.DST_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); if (!flowFrames.isEmpty()) { return Optional.of(flowFrames.get(0)).map(Flow::new); } flowFrames = framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, inPort) .has(FlowFrame.SRC_VLAN_PROPERTY, outVlan)) .toListExplicit(FlowFrame.class); return flowFrames.isEmpty() ? Optional.empty() : Optional.of(flowFrames.get(0)).map(Flow::new); } 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 shouldFindIsByEndpointWithMultiTableSupport() { createTestFlow(TEST_FLOW_ID, switchA, PORT_1, VLAN_1, switchB, PORT_2, VLAN_2, true); createTestFlow(TEST_FLOW_ID_2, switchA, PORT_1, VLAN_2, switchB, PORT_2, 0, true); createTestFlow(TEST_FLOW_ID_3, switchA, PORT_1, VLAN_3, switchB, PORT_2, 0, false); createTestFlow(TEST_FLOW_ID_4, switchB, PORT_1, VLAN_1, switchB, PORT_3, VLAN_1, true); Collection<String> flowIds = flowRepository.findFlowsIdsByEndpointWithMultiTableSupport(switchA.getSwitchId(), PORT_1); assertEquals(2, flowIds.size()); assertTrue(flowIds.contains(TEST_FLOW_ID)); assertTrue(flowIds.contains(TEST_FLOW_ID_2)); }
@Override public Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } 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<String> findFlowsIdsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } 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 shouldFindFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport() { createTestFlow(TEST_FLOW_ID, switchA, PORT_1, VLAN_1, switchB, PORT_2, VLAN_2, true); createTestFlow(TEST_FLOW_ID_2, switchA, PORT_2, VLAN_2, switchB, PORT_2, 0, true); createTestFlow(TEST_FLOW_ID_3, switchA, PORT_1, VLAN_3, switchB, PORT_2, 0, false); createTestFlow(TEST_FLOW_ID_4, switchA, PORT_1, VLAN_1, switchA, PORT_3, VLAN_1, true); Collection<String> flowIds = flowRepository.findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport( switchA.getSwitchId(), PORT_1); assertEquals(1, flowIds.size()); assertEquals(TEST_FLOW_ID, flowIds.iterator().next()); }
@Override public Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } 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<String> findFlowIdsForMultiSwitchFlowsByEndpointWithMultiTableSupport(SwitchId switchId, int port) { Set<String> result = new HashSet<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_PORT_PROPERTY, port) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_PORT_PROPERTY, port) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, P.neq(SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .values(FlowFrame.FLOW_ID_PROPERTY)) .getRawTraversal().toStream() .forEach(i -> result.add((String) i)); return result; } 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 findNPathsByTransitVlanAndCost() throws SwitchNotFoundException, RecoverableException, UnroutableFlowException { List<PathsInfoData> paths = pathsService.getPaths(SWITCH_ID_1, SWITCH_ID_2, TRANSIT_VLAN, COST); assertEquals(MAX_PATH_COUNT, paths.size()); for (PathsInfoData path : paths) { assertEquals(3, path.getPath().getNodes().size()); assertEquals(SWITCH_ID_1, path.getPath().getNodes().get(0).getSwitchId()); assertEquals(SWITCH_ID_2, path.getPath().getNodes().get(2).getSwitchId()); } for (int i = 0; i < paths.size(); i++) { assertTrue(paths.get(i).getPath().getNodes().get(1).getSwitchId().getId() <= MAX_PATH_COUNT + 3); if (i > 0) { assertTrue(paths.get(i - 1).getPath().getBandwidth() >= paths.get(i).getPath().getBandwidth()); } } }
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 shouldFindFlowBySwitchEndpoint() { Flow flow = createTestFlow(TEST_FLOW_ID, switchA, switchB); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitch(TEST_SWITCH_A_ID); Set<String> foundFlowIds = foundFlows.stream().map(foundFlow -> flow.getFlowId()).collect(Collectors.toSet()); assertThat(foundFlowIds, Matchers.hasSize(1)); }
@Override public Collection<Flow> findByEndpointSwitch(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitch(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitch(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitch(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitch(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldFindFlowBySwitchEndpointWithMultiTable() { Flow firstFlow = createTestFlow(TEST_FLOW_ID, switchA, switchB); firstFlow.setSrcWithMultiTable(true); Flow secondFlow = createTestFlow(TEST_FLOW_ID_2, switchA, switchB); secondFlow.setSrcWithMultiTable(false); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitchWithMultiTableSupport(TEST_SWITCH_A_ID); Set<String> foundFlowIds = foundFlows.stream().map(Flow::getFlowId).collect(Collectors.toSet()); assertEquals(Collections.singleton(firstFlow.getFlowId()), foundFlowIds); }
@Override public Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitchWithMultiTableSupport(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_MULTI_TABLE_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldFindFlowByEndpointSwitchWithEnabledLldp() { createFlowWithLldp(TEST_FLOW_ID, switchA, false, switchB, false); createFlowWithLldp(TEST_FLOW_ID_2, switchA, true, switchB, false); createFlowWithLldp(TEST_FLOW_ID_3, switchB, false, switchA, true); createFlowWithLldp(TEST_FLOW_ID_4, switchA, true, switchA, true); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitchWithEnabledLldp(TEST_SWITCH_A_ID); Set<String> foundFlowIds = foundFlows.stream() .map(Flow::getFlowId) .collect(Collectors.toSet()); assertEquals(Sets.newHashSet(TEST_FLOW_ID_2, TEST_FLOW_ID_3, TEST_FLOW_ID_4), foundFlowIds); }
@Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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 shouldFindOneFlowByEndpoint() { Flow flow1 = createTestFlow(TEST_FLOW_ID, switchA, switchA); flow1.setSrcPort(1); flow1.setDestPort(2); Flow flow2 = createTestFlow(TEST_FLOW_ID_2, switchB, switchB); flow2.setSrcPort(1); flow2.setDestPort(2); createTestFlow(TEST_FLOW_ID_3, switchA, switchB); Collection<Flow> foundFlows = flowRepository.findOneSwitchFlows(switchA.getSwitchId()); assertEquals(1, foundFlows.size()); assertEquals(TEST_FLOW_ID, foundFlows.iterator().next().getFlowId()); }
@Override public Collection<Flow> findOneSwitchFlows(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findOneSwitchFlows(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .toListExplicit(FlowFrame.class).stream() .map(Flow::new) .collect(Collectors.toList()); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findOneSwitchFlows(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .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> findOneSwitchFlows(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .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> findOneSwitchFlows(SwitchId switchId) { return framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId))) .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 shouldFindOneFlowByEndpointSwitchWithEnabledLldp() { createFlowWithLldp(TEST_FLOW_ID, switchA, true, switchA, true); Collection<Flow> foundFlows = flowRepository.findByEndpointSwitchWithEnabledLldp(TEST_SWITCH_A_ID); assertEquals(1, foundFlows.size()); assertEquals(TEST_FLOW_ID, foundFlows.iterator().next().getFlowId()); }
@Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } FermaFlowRepository(FramedGraphFactory<?> graphFactory, FlowPathRepository flowPathRepository, TransactionManager transactionManager); }
FermaFlowRepository extends FermaGenericRepository<Flow, FlowData, FlowFrame> implements FlowRepository { @Override public Collection<Flow> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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> findByEndpointSwitchWithEnabledLldp(SwitchId switchId) { Map<String, Flow> result = new HashMap<>(); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.SRC_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); framedGraph().traverse(g -> g.V() .hasLabel(FlowFrame.FRAME_LABEL) .has(FlowFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(FlowFrame.DST_LLDP_PROPERTY, true)) .frameExplicit(FlowFrame.class) .forEachRemaining(frame -> result.put(frame.getFlowId(), new Flow(frame))); return result.values(); } 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); }