@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);  }