use of org.openkilda.messaging.command.switches.DeleteRulesCriteria.DeleteRulesCriteriaBuilder 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;
}
Aggregations