use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.
the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress.
@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress() {
Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
String inPort = "1";
String outPort = "2";
String tunnelId = "10";
String metadataValue = "0x15";
String metadataMask = "0xFF";
FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, true, metadataValue, metadataMask);
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());
assertNull(criteria.getEncapsulationId());
assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
assertEquals(Long.decode(metadataValue), criteria.getMetadataValue());
assertEquals(Long.decode(metadataMask), criteria.getMetadataMask());
}
use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.
the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress.
@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, null, null);
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());
assertNull(criteria.getMetadataValue());
assertNull(criteria.getMetadataMask());
}
use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.
the class CommandBuilderImpl method buildRemoveFlowWithoutMeterFromFlowEntry.
@VisibleForTesting
RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) {
Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch());
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::decode).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);
Long metadataValue = entryMatch.map(FlowMatchField::getMetadataValue).map(Long::decode).orElse(null);
Long metadataMask = entryMatch.map(FlowMatchField::getMetadataMask).map(Long::decode).orElse(null);
DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId, metadataValue, metadataMask);
return RemoveFlow.builder().transactionId(transactionIdGenerator.generate()).flowId("SWMANAGER_BATCH_REMOVE").cookie(entry.getCookie()).switchId(switchId).criteria(criteria).build();
}
use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.
the class RecordHandler method processDeleteFlow.
private List<Long> processDeleteFlow(RemoveFlow command, DatapathId dpid) throws SwitchOperationException {
logger.info("Deleting flow {} from switch {}", command.getId(), dpid);
if (command.isCleanUpIngress()) {
context.getSwitchManager().removeIntermediateIngressRule(dpid, command.getCriteria().getInPort());
}
if (command.isCleanUpIngressLldp()) {
context.getSwitchManager().removeLldpInputCustomerFlow(dpid, command.getCriteria().getInPort());
}
if (command.isCleanUpIngressArp()) {
context.getSwitchManager().removeArpInputCustomerFlow(dpid, command.getCriteria().getInPort());
}
DeleteRulesCriteria criteria = Optional.ofNullable(command.getCriteria()).orElseGet(() -> DeleteRulesCriteria.builder().cookie(command.getCookie()).build());
ISwitchManager switchManager = context.getSwitchManager();
List<Long> cookiesOfRemovedRules = switchManager.deleteRulesByCriteria(dpid, command.isMultiTable(), command.getRuleType(), criteria);
if (cookiesOfRemovedRules.isEmpty()) {
logger.warn("No rules were removed by criteria {} for flow {} from switch {}", criteria, command.getId(), dpid);
}
Long meterId = command.getMeterId();
if (meterId != null) {
try {
switchManager.deleteMeter(dpid, meterId);
} catch (UnsupportedOperationException e) {
logger.info("Skip meter {} deletion from switch {}: {}", meterId, dpid, e.getMessage());
} catch (SwitchOperationException e) {
logger.error("Failed to delete meter {} from switch {}: {}", meterId, dpid, e.getMessage());
}
}
return cookiesOfRemovedRules;
}
use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.
the class SwitchManagerTest method shouldDeleteRuleByInVlan.
@Test
public void shouldDeleteRuleByInVlan() throws Exception {
// given
final short testInVlan = 101;
FlowEncapsulationType flowEncapsulationType = FlowEncapsulationType.TRANSIT_VLAN;
expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
mockBarrierRequest();
mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
expectLastCall();
replay(ofSwitchService, iofSwitch);
// when
DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().encapsulationId((int) testInVlan).encapsulationType(flowEncapsulationType).build();
List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
// then
final OFFlowMod actual = capture.getValue();
assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
assertEquals(testInVlan, actual.getMatch().get(MatchField.VLAN_VID).getVlan());
assertNull(actual.getMatch().get(MatchField.IN_PORT));
assertEquals("any", actual.getOutPort().toString());
assertEquals(0, actual.getInstructions().size());
assertEquals(0L, actual.getCookie().getValue());
assertEquals(0L, actual.getCookieMask().getValue());
assertThat(deletedRules, containsInAnyOrder(cookie));
}
Aggregations