use of org.openkilda.messaging.command.switches.DeleteRulesAction in project open-kilda by telstra.
the class SwitchController method deleteSwitchRules.
/**
* Delete switch rules.
*
* @param switchId switch id to delete rules from
* @param deleteAction defines what to do about the default rules
* @param cookie the cookie to use if deleting a rule (could be any rule)
* @param inPort the in port to use if deleting a rule
* @param inVlan the in vlan to use if deleting a rule
* @param outPort the out port to use if deleting a rule
* @return list of the cookies of the rules that have been deleted
*/
@ApiOperation(value = "Delete switch rules. Requires special authorization", response = Long.class, responseContainer = "List")
@DeleteMapping(value = "/{switch-id}/rules")
@ExtraAuthRequired
@ResponseStatus(HttpStatus.OK)
public CompletableFuture<List<Long>> deleteSwitchRules(@PathVariable("switch-id") SwitchId switchId, @ApiParam(value = "default: IGNORE_DEFAULTS. Can be one of DeleteRulesAction: " + "DROP_ALL,DROP_ALL_ADD_DEFAULTS,IGNORE_DEFAULTS,OVERWRITE_DEFAULTS," + "REMOVE_DROP,REMOVE_BROADCAST,REMOVE_UNICAST,REMOVE_VERIFICATION_LOOP,REMOVE_BFD_CATCH," + "REMOVE_ROUND_TRIP_LATENCY,REMOVE_UNICAST_VXLAN,REMOVE_MULTITABLE_PRE_INGRESS_PASS_THROUGH," + "REMOVE_MULTITABLE_INGRESS_DROP,REMOVE_MULTITABLE_POST_INGRESS_DROP," + "REMOVE_MULTITABLE_EGRESS_PASS_THROUGH,REMOVE_MULTITABLE_TRANSIT_DROP," + "REMOVE_LLDP_INPUT_PRE_DROP, REMOVE_LLDP_INGRESS,REMOVE_LLDP_POST_INGRESS," + "REMOVE_LLDP_POST_INGRESS_VXLAN,REMOVE_LLDP_POST_INGRESS_ONE_SWITCH,REMOVE_LLDP_TRANSIT," + "REMOVE_ARP_INPUT_PRE_DROP,REMOVE_ARP_INGRESS,REMOVE_ARP_POST_INGRESS," + "REMOVE_ARP_POST_INGRESS_VXLAN,REMOVE_ARP_POST_INGRESS_ONE_SWITCH,REMOVE_ARP_TRANSIT," + "REMOVE_SERVER_42_FLOW_RTT_TURNING,REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VLAN," + "REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VXLAN," + "REMOVE_SERVER_42_ISL_RTT_TURNING,REMOVE_SERVER_42_ISL_RTT_OUTPUT," + "REMOVE_DEFAULTS,REMOVE_ADD_DEFAULTS,REMOVE_SERVER_42_FLOW_RTT_VXLAN_TURNING", required = false) @RequestParam(value = "delete-action", required = false) Optional<DeleteRulesAction> deleteAction, @RequestParam(value = "cookie", required = false) Optional<Long> cookie, @RequestParam(value = "in-port", required = false) Optional<Integer> inPort, @RequestParam(value = "in-vlan", required = false) Optional<Integer> inVlan, @RequestParam(value = "encapsulation-type", required = false) Optional<String> encapsulationType, @RequestParam(value = "priority", required = false) Optional<Integer> priority, @RequestParam(value = "out-port", required = false) Optional<Integer> outPort) {
CompletableFuture<List<Long>> result;
// TODO: "priority" can't be used as a standalone criterion - because currently it's ignored in OFFlowDelete.
if (cookie.isPresent() || inPort.isPresent() || inVlan.isPresent() || /*|| priority.isPresent()*/
outPort.isPresent() || encapsulationType.isPresent()) {
if (deleteAction.isPresent()) {
throw new MessageException(RequestCorrelationId.getId(), System.currentTimeMillis(), PARAMETERS_INVALID, "Criteria parameters and delete-action are both provided.", "Either criteria parameters or delete-action should be provided.");
}
if (inVlan.isPresent() != encapsulationType.isPresent()) {
throw new MessageException(RequestCorrelationId.getId(), System.currentTimeMillis(), PARAMETERS_INVALID, "Encapsulation criteria is not full.", "In VLAN and encapsulation type should be provided.");
}
DeleteRulesCriteriaBuilder builder = DeleteRulesCriteria.builder();
cookie.ifPresent(builder::cookie);
inPort.ifPresent(builder::inPort);
inVlan.ifPresent(builder::encapsulationId);
priority.ifPresent(builder::priority);
outPort.ifPresent(builder::outPort);
if (encapsulationType.isPresent()) {
try {
builder.encapsulationType(FlowEncapsulationType.valueOf(encapsulationType.get().toUpperCase()));
} catch (IllegalArgumentException e) {
throw new MessageException(RequestCorrelationId.getId(), System.currentTimeMillis(), PARAMETERS_INVALID, "Encapsulation type is not right.", "The correct encapsulation type should be provided.");
}
}
result = switchService.deleteRules(switchId, builder.build());
} else {
DeleteRulesAction deleteRulesAction = deleteAction.orElse(DeleteRulesAction.IGNORE_DEFAULTS);
result = switchService.deleteRules(switchId, deleteRulesAction);
}
return result;
}
use of org.openkilda.messaging.command.switches.DeleteRulesAction in project open-kilda by telstra.
the class RecordHandler method doDeleteSwitchRules.
private void doDeleteSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
logger.debug("Deleting rules from '{}' switch: action={}", request.getSwitchId(), request.getDeleteRulesAction());
DatapathId dpid = DatapathId.of(request.getSwitchId());
ISwitchManager switchManager = context.getSwitchManager();
DeleteRulesAction deleteAction = request.getDeleteRulesAction();
List<Long> removedRules = new ArrayList<>();
try {
/*
* This first part .. we are either deleting one rule, or all non-default rules (the else)
*/
List<Long> toRemove = new ArrayList<>();
if (deleteAction == DeleteRulesAction.ONE) {
toRemove.add(request.getOneCookie());
} else if (deleteAction == DeleteRulesAction.REMOVE_DROP) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_BROADCAST) {
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_UNICAST) {
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_DEFAULTS || deleteAction == DeleteRulesAction.REMOVE_ADD) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
}
// toRemove is > 0 only if we are trying to delete base rule(s).
if (toRemove.size() > 0) {
removedRules.addAll(switchManager.deleteRuleWithCookie(dpid, toRemove));
if (deleteAction == DeleteRulesAction.REMOVE_ADD) {
switchManager.installDefaultRules(dpid);
}
} else {
removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
/*
* The Second part - only for a subset of actions.
*/
if (deleteAction == DeleteRulesAction.DROP) {
List<Long> removedDefaultRules = switchManager.deleteDefaultRules(dpid);
// Return removedDefaultRules as a part of the result list.
removedRules.addAll(removedDefaultRules);
} else if (deleteAction == DeleteRulesAction.DROP_ADD) {
switchManager.deleteDefaultRules(dpid);
switchManager.installDefaultRules(dpid);
} else if (deleteAction == DeleteRulesAction.OVERWRITE) {
switchManager.installDefaultRules(dpid);
}
}
SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
ErrorData errorData = new ErrorData(ErrorType.DELETION_FAILURE, e.getMessage(), request.getSwitchId());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, error);
}
}
use of org.openkilda.messaging.command.switches.DeleteRulesAction in project open-kilda by telstra.
the class RecordHandler method doDeleteSwitchRules.
private void doDeleteSwitchRules(final CommandMessage message) {
SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
logger.info("Deleting rules from '{}' switch: action={}, criteria={}", request.getSwitchId(), request.getDeleteRulesAction(), request.getCriteria());
final IKafkaProducerService producerService = getKafkaProducer();
final String replyToTopic = context.getKafkaSwitchManagerTopic();
DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
DeleteRulesAction deleteAction = request.getDeleteRulesAction();
DeleteRulesCriteria criteria = request.getCriteria();
ISwitchManager switchManager = context.getSwitchManager();
try {
List<Long> removedRules = new ArrayList<>();
if (deleteAction != null) {
switch(deleteAction) {
case REMOVE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(DROP_RULE_COOKIE).build();
break;
case REMOVE_BROADCAST:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_BROADCAST_RULE_COOKIE).build();
break;
case REMOVE_UNICAST:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_UNICAST_RULE_COOKIE).build();
break;
case REMOVE_VERIFICATION_LOOP:
criteria = DeleteRulesCriteria.builder().cookie(DROP_VERIFICATION_LOOP_RULE_COOKIE).build();
break;
case REMOVE_BFD_CATCH:
criteria = DeleteRulesCriteria.builder().cookie(CATCH_BFD_RULE_COOKIE).build();
break;
case REMOVE_ROUND_TRIP_LATENCY:
criteria = DeleteRulesCriteria.builder().cookie(ROUND_TRIP_LATENCY_RULE_COOKIE).build();
break;
case REMOVE_UNICAST_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_UNICAST_VXLAN_RULE_COOKIE).build();
break;
case REMOVE_MULTITABLE_PRE_INGRESS_PASS_THROUGH:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE).build();
break;
case REMOVE_MULTITABLE_INGRESS_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_INGRESS_DROP_COOKIE).build();
break;
case REMOVE_MULTITABLE_POST_INGRESS_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_POST_INGRESS_DROP_COOKIE).build();
break;
case REMOVE_MULTITABLE_EGRESS_PASS_THROUGH:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_EGRESS_PASS_THROUGH_COOKIE).build();
break;
case REMOVE_MULTITABLE_TRANSIT_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_TRANSIT_DROP_COOKIE).build();
break;
case REMOVE_LLDP_INPUT_PRE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_INPUT_PRE_DROP_COOKIE).build();
break;
case REMOVE_LLDP_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_INGRESS_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_VXLAN_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS_ONE_SWITCH:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_ONE_SWITCH_COOKIE).build();
break;
case REMOVE_LLDP_TRANSIT:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_TRANSIT_COOKIE).build();
break;
case REMOVE_ARP_INPUT_PRE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(ARP_INPUT_PRE_DROP_COOKIE).build();
break;
case REMOVE_ARP_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(ARP_INGRESS_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_VXLAN_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS_ONE_SWITCH:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_ONE_SWITCH_COOKIE).build();
break;
case REMOVE_ARP_TRANSIT:
criteria = DeleteRulesCriteria.builder().cookie(ARP_TRANSIT_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_TURNING:
case REMOVE_SERVER_42_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_VXLAN_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VLAN:
case REMOVE_SERVER_42_OUTPUT_VLAN:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VXLAN:
case REMOVE_SERVER_42_OUTPUT_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE).build();
break;
case REMOVE_SERVER_42_ISL_RTT_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_ISL_RTT_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_ISL_RTT_OUTPUT:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_ISL_RTT_OUTPUT_COOKIE).build();
break;
default:
logger.warn("Received unexpected delete switch rule action: {}", deleteAction);
}
// The cases when we delete all non-default rules.
if (deleteAction.nonDefaultRulesToBeRemoved()) {
removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
}
// The cases when we delete the default rules.
if (deleteAction.defaultRulesToBeRemoved()) {
removedRules.addAll(switchManager.deleteDefaultRules(dpid, request.getIslPorts(), request.getFlowPorts(), request.getFlowLldpPorts(), request.getFlowArpPorts(), request.getServer42FlowRttPorts(), request.isMultiTable(), request.isSwitchLldp(), request.isSwitchArp(), request.isServer42FlowRttFeatureToggle() && request.isServer42FlowRttSwitchProperty(), request.isServer42IslRttEnabled()));
}
}
// The case when we either delete by criteria or a specific default rule.
if (criteria != null) {
removedRules.addAll(switchManager.deleteRulesByCriteria(dpid, false, null, criteria));
}
// The cases when we (re)install the default rules.
if (deleteAction != null && deleteAction.defaultRulesToBeInstalled()) {
switchManager.installDefaultRules(dpid);
if (request.isMultiTable()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_INGRESS_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_POST_INGRESS_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_EGRESS_PASS_THROUGH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_TRANSIT_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_VXLAN_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_ONE_SWITCH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_VXLAN_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_ONE_SWITCH_COOKIE);
for (int port : request.getIslPorts()) {
switchManager.installMultitableEndpointIslRules(dpid, port);
}
for (int port : request.getFlowPorts()) {
switchManager.installIntermediateIngressRule(dpid, port);
}
for (Integer port : request.getFlowLldpPorts()) {
switchManager.installLldpInputCustomerFlow(dpid, port);
}
for (Integer port : request.getFlowArpPorts()) {
switchManager.installArpInputCustomerFlow(dpid, port);
}
if (request.isSwitchLldp()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INPUT_PRE_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_TRANSIT_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INGRESS_COOKIE);
}
if (request.isSwitchArp()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INPUT_PRE_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_TRANSIT_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INGRESS_COOKIE);
}
}
Integer server42Port = request.getServer42Port();
Integer server42Vlan = request.getServer42Vlan();
MacAddress server42MacAddress = request.getServer42MacAddress();
if (request.isServer42FlowRttFeatureToggle()) {
switchManager.installServer42FlowRttTurningFlow(dpid);
switchManager.installServer42FlowRttVxlanTurningFlow(dpid);
if (request.isServer42FlowRttSwitchProperty() && server42Port != null && server42Vlan != null && server42MacAddress != null) {
switchManager.installServer42FlowRttOutputVlanFlow(dpid, server42Port, server42Vlan, server42MacAddress);
switchManager.installServer42FlowRttOutputVxlanFlow(dpid, server42Port, server42Vlan, server42MacAddress);
for (Integer port : request.getServer42FlowRttPorts()) {
switchManager.installServer42FlowRttInputFlow(dpid, server42Port, port, server42MacAddress);
}
}
}
if (request.isServer42IslRttEnabled()) {
switchManager.installServer42IslRttTurningFlow(dpid);
switchManager.installServer42IslRttOutputFlow(dpid, server42Port, server42Vlan, server42MacAddress);
for (Integer port : request.getIslPorts()) {
switchManager.installServer42IslRttInputFlow(dpid, server42Port, port);
}
}
}
SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, record.key(), infoMessage);
} catch (SwitchNotFoundException e) {
logger.error("Deleting switch rules was unsuccessful. Switch '{}' not found", request.getSwitchId());
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
} catch (SwitchOperationException e) {
logger.error("Failed to delete switch '{}' rules.", request.getSwitchId(), e);
anError(ErrorType.DELETION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
}
}
Aggregations