Search in sources :

Example 11 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class SwitchManager method deleteAllNonDefaultRules.

@Override
public List<Long> deleteAllNonDefaultRules(final DatapathId dpid) throws SwitchOperationException {
    List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid);
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    Set<Long> removedRules = new HashSet<>();
    for (OFFlowStatsEntry flowStatsEntry : flowStatsBefore) {
        long flowCookie = flowStatsEntry.getCookie().getValue();
        if (!isDefaultRule(flowCookie)) {
            OFFlowDelete flowDelete = ofFactory.buildFlowDelete().setCookie(U64.of(flowCookie)).setCookieMask(U64.NO_MASK).setTableId(TableId.ALL).build();
            pushFlow(sw, "--DeleteFlow--", flowDelete);
            logger.info("Rule with cookie {} is to be removed from switch {}.", flowCookie, dpid);
            removedRules.add(flowCookie);
        }
    }
    // Wait for OFFlowDelete to be processed.
    sendBarrierRequest(sw);
    List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid);
    Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(Collectors.toSet());
    flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).filter(cookie -> !removedRules.contains(cookie)).forEach(cookie -> {
        logger.warn("Rule with cookie {} has been removed although not requested. Switch {}.", cookie, dpid);
        removedRules.add(cookie);
    });
    cookiesAfter.stream().filter(removedRules::contains).forEach(cookie -> {
        logger.warn("Rule with cookie {} was requested to be removed, but it still remains. Switch {}.", cookie, dpid);
        removedRules.remove(cookie);
    });
    return new ArrayList<>(removedRules);
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) TableId(org.projectfloodlight.openflow.types.TableId) U64(org.projectfloodlight.openflow.types.U64) Arrays(java.util.Arrays) DEFAULT_METERS(org.openkilda.model.MeterId.DEFAULT_METERS) OFPortMod(org.projectfloodlight.openflow.protocol.OFPortMod) MeteredFlowGenerator(org.openkilda.floodlight.switchmanager.factory.generator.MeteredFlowGenerator) DROP_VERIFICATION_LOOP_RULE_COOKIE(org.openkilda.model.cookie.Cookie.DROP_VERIFICATION_LOOP_RULE_COOKIE) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) VERIFICATION_UNICAST_VXLAN_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_UNICAST_VXLAN_RULE_COOKIE) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) Collections.singletonList(java.util.Collections.singletonList) InetAddress(java.net.InetAddress) MULTITABLE_POST_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_POST_INGRESS_DROP_COOKIE) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) Future(java.util.concurrent.Future) SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest) OFMeterModCommand(org.projectfloodlight.openflow.protocol.OFMeterModCommand) Match(org.projectfloodlight.openflow.protocol.match.Match) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFGroupType(org.projectfloodlight.openflow.protocol.OFGroupType) OFBarrierReply(org.projectfloodlight.openflow.protocol.OFBarrierReply) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) OFGroupAdd(org.projectfloodlight.openflow.protocol.OFGroupAdd) OFMeterConfigStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsRequest) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE) Set(java.util.Set) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) RuleType(org.openkilda.messaging.command.flow.RuleType) IRestApiService(net.floodlightcontroller.restserver.IRestApiService) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) ROUND_TRIP_LATENCY_RULE_COOKIE(org.openkilda.model.cookie.Cookie.ROUND_TRIP_LATENCY_RULE_COOKIE) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) Stream(java.util.stream.Stream) LLDP_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_INGRESS_COOKIE) Meter(org.openkilda.model.Meter) OF_12(org.projectfloodlight.openflow.protocol.OFVersion.OF_12) OF_13(org.projectfloodlight.openflow.protocol.OFVersion.OF_13) SwitchFlowUtils.isOvs(org.openkilda.floodlight.switchmanager.SwitchFlowUtils.isOvs) OFBufferId(org.projectfloodlight.openflow.types.OFBufferId) OFOxms(org.projectfloodlight.openflow.protocol.oxm.OFOxms) LLDP_POST_INGRESS_ONE_SWITCH_METER_ID(org.openkilda.model.MeterId.LLDP_POST_INGRESS_ONE_SWITCH_METER_ID) OFInstructionWriteMetadata(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata) IOFSwitchService(net.floodlightcontroller.core.internal.IOFSwitchService) LLDP_POST_INGRESS_VXLAN_METER_ID(org.openkilda.model.MeterId.LLDP_POST_INGRESS_VXLAN_METER_ID) CollectionUtils(org.apache.commons.collections4.CollectionUtils) VERIFICATION_UNICAST_VXLAN_METER_ID(org.openkilda.model.MeterId.VERIFICATION_UNICAST_VXLAN_METER_ID) ArrayList(java.util.ArrayList) EthType(org.projectfloodlight.openflow.types.EthType) Lists(com.google.common.collect.Lists) OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFActionType(org.projectfloodlight.openflow.protocol.OFActionType) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) MacAddress(org.projectfloodlight.openflow.types.MacAddress) Cookie.isDefaultRule(org.openkilda.model.cookie.Cookie.isDefaultRule) SwitchFlowFactory(org.openkilda.floodlight.switchmanager.factory.SwitchFlowFactory) LLDP_TRANSIT_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_TRANSIT_COOKIE) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) ErrorType(org.openkilda.messaging.error.ErrorType) OFInstructionGotoTable(org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) ARP_INPUT_PRE_DROP_METER_ID(org.openkilda.model.MeterId.ARP_INPUT_PRE_DROP_METER_ID) DROP_RULE_COOKIE(org.openkilda.model.cookie.Cookie.DROP_RULE_COOKIE) ARP_POST_INGRESS_VXLAN_METER_ID(org.openkilda.model.MeterId.ARP_POST_INGRESS_VXLAN_METER_ID) FeatureDetectorService(org.openkilda.floodlight.service.FeatureDetectorService) OFActions(org.projectfloodlight.openflow.protocol.action.OFActions) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) ExecutionException(java.util.concurrent.ExecutionException) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired) RoutingMetadata(org.openkilda.floodlight.utils.metadata.RoutingMetadata) FloodlightModuleConfigurationProvider(org.openkilda.floodlight.config.provider.FloodlightModuleConfigurationProvider) OFMeterBandDrop(org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop) VERIFICATION_UNICAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_UNICAST_RULE_COOKIE) OFMeterMod(org.projectfloodlight.openflow.protocol.OFMeterMod) IFloodlightService(net.floodlightcontroller.core.module.IFloodlightService) ARP_POST_INGRESS_METER_ID(org.openkilda.model.MeterId.ARP_POST_INGRESS_METER_ID) IpProtocol(org.projectfloodlight.openflow.types.IpProtocol) OFFlowDelete(org.projectfloodlight.openflow.protocol.OFFlowDelete) ARP_POST_INGRESS_ONE_SWITCH_METER_ID(org.openkilda.model.MeterId.ARP_POST_INGRESS_ONE_SWITCH_METER_ID) DatapathId(org.projectfloodlight.openflow.types.DatapathId) VERIFICATION_BROADCAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_BROADCAST_RULE_COOKIE) VERIFICATION_BROADCAST_METER_ID(org.openkilda.model.MeterId.VERIFICATION_BROADCAST_METER_ID) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) OfPortDescConverter(org.openkilda.floodlight.converter.OfPortDescConverter) ARP_POST_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_COOKIE) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) KildaCore(org.openkilda.floodlight.KildaCore) SwitchFeature(org.openkilda.model.SwitchFeature) LLDP_POST_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_COOKIE) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) ARP_INPUT_PRE_DROP_COOKIE(org.openkilda.model.cookie.Cookie.ARP_INPUT_PRE_DROP_COOKIE) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) ARP_TRANSIT_METER_ID(org.openkilda.model.MeterId.ARP_TRANSIT_METER_ID) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) FlowModUtils(net.floodlightcontroller.util.FlowModUtils) TransportPort(org.projectfloodlight.openflow.types.TransportPort) ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) LLDP_TRANSIT_METER_ID(org.openkilda.model.MeterId.LLDP_TRANSIT_METER_ID) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Collectors.toSet(java.util.stream.Collectors.toSet) LLDP_POST_INGRESS_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_VXLAN_COOKIE) OFGroupDelete(org.projectfloodlight.openflow.protocol.OFGroupDelete) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) ImmutableSet(com.google.common.collect.ImmutableSet) OFPortConfig(org.projectfloodlight.openflow.protocol.OFPortConfig) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) LLDP_POST_INGRESS_METER_ID(org.openkilda.model.MeterId.LLDP_POST_INGRESS_METER_ID) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) NOVIFLOW_PUSH_POP_VXLAN(org.openkilda.model.SwitchFeature.NOVIFLOW_PUSH_POP_VXLAN) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) VERIFICATION_UNICAST_METER_ID(org.openkilda.model.MeterId.VERIFICATION_UNICAST_METER_ID) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IOFMessageListener(net.floodlightcontroller.core.IOFMessageListener) Objects(java.util.Objects) OFPort(org.projectfloodlight.openflow.types.OFPort) MULTITABLE_EGRESS_PASS_THROUGH_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_EGRESS_PASS_THROUGH_COOKIE) List(java.util.List) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) SwitchFlowTuple(org.openkilda.floodlight.switchmanager.factory.SwitchFlowTuple) OFMetadata(org.projectfloodlight.openflow.types.OFMetadata) IFloodlightProviderService(net.floodlightcontroller.core.IFloodlightProviderService) Optional(java.util.Optional) ARP_POST_INGRESS_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_VXLAN_COOKIE) OFType(org.projectfloodlight.openflow.protocol.OFType) ARP_INGRESS_COOKIE(org.openkilda.model.cookie.Cookie.ARP_INGRESS_COOKIE) OFGroup(org.projectfloodlight.openflow.types.OFGroup) MULTITABLE_TRANSIT_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_TRANSIT_DROP_COOKIE) SERVER_42_FLOW_RTT_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_TURNING_COOKIE) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SwitchFlowGenerator(org.openkilda.floodlight.switchmanager.factory.generator.SwitchFlowGenerator) HashMap(java.util.HashMap) KILDA_OVS_PUSH_POP_MATCH_VXLAN(org.openkilda.model.SwitchFeature.KILDA_OVS_PUSH_POP_MATCH_VXLAN) ARP_POST_INGRESS_ONE_SWITCH_COOKIE(org.openkilda.model.cookie.Cookie.ARP_POST_INGRESS_ONE_SWITCH_COOKIE) CATCH_BFD_RULE_COOKIE(org.openkilda.model.cookie.Cookie.CATCH_BFD_RULE_COOKIE) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) MULTITABLE_INGRESS_DROP_COOKIE(org.openkilda.model.cookie.Cookie.MULTITABLE_INGRESS_DROP_COOKIE) IPathVerificationService(org.openkilda.floodlight.pathverification.IPathVerificationService) Cookie(org.openkilda.model.cookie.Cookie) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Logger(org.slf4j.Logger) POST_INGRESS(org.openkilda.messaging.command.flow.RuleType.POST_INGRESS) ARP_INGRESS_METER_ID(org.openkilda.model.MeterId.ARP_INGRESS_METER_ID) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) ARP_TRANSIT_COOKIE(org.openkilda.model.cookie.Cookie.ARP_TRANSIT_COOKIE) LLDP_INPUT_PRE_DROP_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_INPUT_PRE_DROP_COOKIE) SwitchManagerWebRoutable(org.openkilda.floodlight.switchmanager.web.SwitchManagerWebRoutable) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) SwitchFlowUtils.convertDpIdToMac(org.openkilda.floodlight.switchmanager.SwitchFlowUtils.convertDpIdToMac) MeterId.createMeterIdForDefaultRule(org.openkilda.model.MeterId.createMeterIdForDefaultRule) FloodlightModuleException(net.floodlightcontroller.core.module.FloodlightModuleException) IFloodlightModule(net.floodlightcontroller.core.module.IFloodlightModule) MeterId(org.openkilda.model.MeterId) TimeUnit(java.util.concurrent.TimeUnit) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Collectors.toList(java.util.stream.Collectors.toList) SERVER_42_ISL_RTT_TURNING_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_TURNING_COOKIE) LLDP_INPUT_PRE_DROP_METER_ID(org.openkilda.model.MeterId.LLDP_INPUT_PRE_DROP_METER_ID) OfInstallException(org.openkilda.floodlight.error.OfInstallException) SwitchId(org.openkilda.model.SwitchId) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Destination(org.openkilda.messaging.Destination) MatchField(org.projectfloodlight.openflow.protocol.match.MatchField) LLDP_INGRESS_METER_ID(org.openkilda.model.MeterId.LLDP_INGRESS_METER_ID) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LATENCY_PACKET_UDP_PORT(org.openkilda.floodlight.pathverification.PathVerificationService.LATENCY_PACKET_UDP_PORT) ErrorData(org.openkilda.messaging.error.ErrorData) GroupId(org.openkilda.model.GroupId) Collections(java.util.Collections) LLDP_POST_INGRESS_ONE_SWITCH_COOKIE(org.openkilda.model.cookie.Cookie.LLDP_POST_INGRESS_ONE_SWITCH_COOKIE) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFFlowDelete(org.projectfloodlight.openflow.protocol.OFFlowDelete) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 12 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class SwitchManager method safeModeTick.

@Override
public void safeModeTick() {
    // this may be called sporadically, so we'll need to measure the time between calls ..
    long time = System.currentTimeMillis();
    if (time - lastRun < tick_length) {
        return;
    }
    lastRun = time;
    Collection<SafeData> values = safeSwitches.values();
    for (SafeData safeData : values) {
        // Grab switch rule stats .. X pre and post .. X for 0, X for 1 .. make a decision.
        try {
            safeData.consumeData(time, dumpFlowTable(safeData.dpid));
            int datapoints = safeData.timestamps.size();
            if (safeData.dropRuleStage < RULE_TESTED) {
                logger.debug("SAFE MODE: Collected Data during Drop Rule Stage for '{}' ", safeData.dpid);
                if (safeData.shouldApplyRule(DROP_STAGE)) {
                    logger.info("SAFE MODE: APPLY Drop Rule for '{}' ", safeData.dpid);
                    safeData.dropRuleStage = RULE_APPLIED;
                    installDropFlow(safeData.dpid);
                } else if (safeData.shouldTestRule(DROP_STAGE)) {
                    List<Integer> ruleEffect = safeData.getRuleEffect(DROP_STAGE);
                    if (safeData.isRuleOkay(ruleEffect)) {
                        logger.info("SAFE MODE: Drop Rule is GOOD for '{}' ", safeData.dpid);
                        safeData.dropRuleStage = RULE_IS_GOOD;
                    } else {
                        logger.warn("SAFE MODE: Drop Rule is BAD for '{}'. " + "Good Packet Count: {}. Bad Packet Count: {} ", safeData.dpid, ruleEffect.get(0), ruleEffect.get(1));
                        safeData.dropRuleStage = RULE_NO_GOOD;
                        deleteRulesWithCookie(safeData.dpid, DROP_RULE_COOKIE);
                    }
                }
            } else if (safeData.broadcastRuleStage < RULE_TESTED) {
                logger.debug("SAFE MODE: Collected Data during Broadcast Verification Rule " + "Stage for '{}' ", safeData.dpid);
                if (safeData.shouldApplyRule(BROADCAST_STAGE)) {
                    logger.info("SAFE MODE: APPLY Broadcast Verification Rule for '{}' ", safeData.dpid);
                    safeData.broadcastRuleStage = RULE_APPLIED;
                    installVerificationRule(safeData.dpid, BROADCAST);
                } else if (safeData.shouldTestRule(BROADCAST_STAGE)) {
                    List<Integer> ruleEffect = safeData.getRuleEffect(BROADCAST_STAGE);
                    if (safeData.isRuleOkay(ruleEffect)) {
                        logger.info("SAFE MODE: Broadcast Verification Rule is GOOD for '{}' ", safeData.dpid);
                        safeData.broadcastRuleStage = RULE_IS_GOOD;
                    } else {
                        logger.warn("SAFE MODE: Broadcast Verification Rule is BAD for '{}'. " + "Good Packet Count: {}. Bad Packet Count: {} ", safeData.dpid, ruleEffect.get(0), ruleEffect.get(1));
                        safeData.broadcastRuleStage = RULE_NO_GOOD;
                        deleteRulesWithCookie(safeData.dpid, VERIFICATION_BROADCAST_RULE_COOKIE);
                    }
                }
            } else if (safeData.unicastRuleStage < RULE_TESTED) {
                // TODO: make this smarter and advance the unicast if unicast not applied.
                logger.debug("SAFE MODE: Collected Data during Unicast Verification Rule Stage " + "for '{}' ", safeData.dpid);
                if (safeData.shouldApplyRule(UNICAST_STAGE)) {
                    logger.info("SAFE MODE: APPLY Unicast Verification Rule for '{}' ", safeData.dpid);
                    safeData.unicastRuleStage = RULE_APPLIED;
                    installVerificationRule(safeData.dpid, !BROADCAST);
                } else if (safeData.shouldTestRule(UNICAST_STAGE)) {
                    List<Integer> ruleEffect = safeData.getRuleEffect(UNICAST_STAGE);
                    if (safeData.isRuleOkay(ruleEffect)) {
                        logger.info("SAFE MODE: Unicast Verification Rule is GOOD for '{}' ", safeData.dpid);
                        safeData.unicastRuleStage = RULE_IS_GOOD;
                    } else {
                        logger.warn("SAFE MODE: Unicast Verification Rule is BAD for '{}'. " + "Good Packet Count: {}. Bad Packet Count: {} ", safeData.dpid, ruleEffect.get(0), ruleEffect.get(1));
                        safeData.unicastRuleStage = RULE_NO_GOOD;
                        deleteRulesWithCookie(safeData.dpid, VERIFICATION_UNICAST_RULE_COOKIE);
                    }
                }
            } else {
                // once done with installing rules, we need to notify kilda that the switch is up
                // and that ports up.
                logger.info("SAFE MODE: COMPLETED base rules for '{}' ", safeData.dpid);
                IOFSwitch sw = lookupSwitch(safeData.dpid);
                switchTracking.completeSwitchActivation(sw.getId());
                // WE ARE DONE!! Remove ourselves from the list.
                // will be reflected in safeSwitches
                values.remove(safeData);
            }
        } catch (SwitchOperationException e) {
            logger.error("Error while switch {} was in safe mode. Removing switch from safe " + "mode and NOT SENDING ACTIVATION. \nERROR: {}", safeData.dpid, e);
            values.remove(safeData);
        }
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList)

Example 13 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class SwitchManager method processMeter.

@VisibleForTesting
void processMeter(IOFSwitch sw, OFMeterMod meterMod) {
    long meterId = meterMod.getMeterId();
    OFMeterConfig actualMeterConfig;
    try {
        actualMeterConfig = getMeter(sw.getId(), meterId);
    } catch (SwitchOperationException e) {
        logger.warn("Meter {} won't be installed on the switch {}: {}", meterId, sw.getId(), e.getMessage());
        return;
    }
    OFMeterBandDrop actualMeterBandDrop = Optional.ofNullable(actualMeterConfig).map(OFMeterConfig::getEntries).flatMap(entries -> entries.stream().findFirst()).map(OFMeterBandDrop.class::cast).orElse(null);
    try {
        OFMeterBandDrop expectedMeterBandDrop = sw.getOFFactory().getVersion().compareTo(OF_13) > 0 ? (OFMeterBandDrop) meterMod.getBands().get(0) : (OFMeterBandDrop) meterMod.getMeters().get(0);
        long expectedRate = expectedMeterBandDrop.getRate();
        long expectedBurstSize = expectedMeterBandDrop.getBurstSize();
        Set<OFMeterFlags> expectedFlags = meterMod.getFlags();
        if (actualMeterBandDrop != null && actualMeterBandDrop.getRate() == expectedRate && actualMeterBandDrop.getBurstSize() == expectedBurstSize && CollectionUtils.isEqualCollection(actualMeterConfig.getFlags(), expectedFlags)) {
            logger.debug("Meter {} won't be reinstalled on switch {}. It already exists", meterId, sw.getId());
            return;
        }
        if (actualMeterBandDrop != null) {
            logger.info("Meter {} on switch {} has rate={}, burst size={} and flags={} but it must have " + "rate={}, burst size={} and flags={}. Meter will be reinstalled.", meterId, sw.getId(), actualMeterBandDrop.getRate(), actualMeterBandDrop.getBurstSize(), actualMeterConfig.getFlags(), expectedRate, expectedBurstSize, expectedFlags);
            buildAndDeleteMeter(sw, sw.getId(), meterId);
            sendBarrierRequest(sw);
        }
        installMeterMod(sw, meterMod);
    } catch (SwitchOperationException e) {
        logger.warn("Failed to (re)install meter {} on switch {}: {}", meterId, sw.getId(), e.getMessage());
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) OFMeterFlags(org.projectfloodlight.openflow.protocol.OFMeterFlags) OFMeterBandDrop(org.projectfloodlight.openflow.protocol.meterband.OFMeterBandDrop) OFMeterConfig(org.projectfloodlight.openflow.protocol.OFMeterConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException 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);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) ArrayList(java.util.ArrayList) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) DatapathId(org.projectfloodlight.openflow.types.DatapathId) MacAddress(org.openkilda.model.MacAddress) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) FlowEndpoint(org.openkilda.model.FlowEndpoint) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) DeleteRulesAction(org.openkilda.messaging.command.switches.DeleteRulesAction) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)

Example 15 with SwitchOperationException

use of org.openkilda.floodlight.error.SwitchOperationException in project open-kilda by telstra.

the class RecordHandler method doInstallSwitchRules.

private void doInstallSwitchRules(final CommandMessage message) {
    SwitchRulesInstallRequest request = (SwitchRulesInstallRequest) message.getData();
    logger.info("Installing rules on '{}' switch: action={}", request.getSwitchId(), request.getInstallRulesAction());
    final IKafkaProducerService producerService = getKafkaProducer();
    final String replyToTopic = context.getKafkaSwitchManagerTopic();
    DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
    ISwitchManager switchManager = context.getSwitchManager();
    InstallRulesAction installAction = request.getInstallRulesAction();
    List<Long> installedRules = new ArrayList<>();
    try {
        if (installAction == InstallRulesAction.INSTALL_DROP) {
            installedRules.add(switchManager.installDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_BROADCAST) {
            installedRules.add(switchManager.installVerificationRule(dpid, true));
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST) {
            // TODO: this isn't always added (ie if OF1.2). Is there a better response?
            installedRules.add(switchManager.installVerificationRule(dpid, false));
        } else if (installAction == InstallRulesAction.INSTALL_DROP_VERIFICATION_LOOP) {
            installedRules.add(switchManager.installDropLoopRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_BFD_CATCH) {
            // TODO: this isn't installed as well. Refactor this section
            installedRules.add(switchManager.installBfdCatchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ROUND_TRIP_LATENCY) {
            // TODO: this isn't installed as well. Refactor this section
            installedRules.add(switchManager.installRoundTripLatencyFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_UNICAST_VXLAN) {
            installedRules.add(switchManager.installUnicastVerificationRuleVxlan(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_PRE_INGRESS_PASS_THROUGH) {
            installedRules.add(switchManager.installPreIngressTablePassThroughDefaultRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_INGRESS_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, INGRESS_TABLE_ID, MULTITABLE_INGRESS_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_POST_INGRESS_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, POST_INGRESS_TABLE_ID, MULTITABLE_POST_INGRESS_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_EGRESS_PASS_THROUGH) {
            installedRules.add(switchManager.installEgressTablePassThroughDefaultRule(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_MULTITABLE_TRANSIT_DROP) {
            installedRules.add(switchManager.installDropFlowForTable(dpid, TRANSIT_TABLE_ID, MULTITABLE_TRANSIT_DROP_COOKIE));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_INPUT_PRE_DROP) {
            installedRules.add(switchManager.installLldpInputPreDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_INGRESS) {
            installedRules.add(switchManager.installLldpIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS) {
            installedRules.add(switchManager.installLldpPostIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS_VXLAN) {
            installedRules.add(switchManager.installLldpPostIngressVxlanFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_POST_INGRESS_ONE_SWITCH) {
            installedRules.add(switchManager.installLldpPostIngressOneSwitchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_LLDP_TRANSIT) {
            installedRules.add(switchManager.installLldpTransitFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_INPUT_PRE_DROP) {
            installedRules.add(switchManager.installArpInputPreDropFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_INGRESS) {
            installedRules.add(switchManager.installArpIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS) {
            installedRules.add(switchManager.installArpPostIngressFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS_VXLAN) {
            installedRules.add(switchManager.installArpPostIngressVxlanFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_POST_INGRESS_ONE_SWITCH) {
            installedRules.add(switchManager.installArpPostIngressOneSwitchFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_ARP_TRANSIT) {
            installedRules.add(switchManager.installArpTransitFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_OUTPUT_VLAN || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_OUTPUT_VLAN) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42FlowRttOutputVlanFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_OUTPUT_VXLAN || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_OUTPUT_VXLAN) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42FlowRttOutputVxlanFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_TURNING || installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_TURNING) {
            installedRules.add(switchManager.installServer42FlowRttTurningFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_FLOW_RTT_VXLAN_TURNING) {
            installedRules.add(switchManager.installServer42FlowRttVxlanTurningFlow(dpid));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_ISL_RTT_OUTPUT) {
            validateServer42Fields(request, installAction);
            installedRules.add(switchManager.installServer42IslRttOutputFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
        } else if (installAction == InstallRulesAction.INSTALL_SERVER_42_ISL_RTT_TURNING) {
            installedRules.add(switchManager.installServer42IslRttTurningFlow(dpid));
        } else {
            installedRules.addAll(switchManager.installDefaultRules(dpid));
            if (request.isMultiTable()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_INGRESS_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_POST_INGRESS_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_EGRESS_PASS_THROUGH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_TRANSIT_DROP_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_VXLAN_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_ONE_SWITCH_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_VXLAN_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_ONE_SWITCH_COOKIE));
                for (int port : request.getIslPorts()) {
                    installedRules.addAll(switchManager.installMultitableEndpointIslRules(dpid, port));
                }
                for (int port : request.getFlowPorts()) {
                    installedRules.add(switchManager.installIntermediateIngressRule(dpid, port));
                }
                for (Integer port : request.getFlowLldpPorts()) {
                    installedRules.add(switchManager.installLldpInputCustomerFlow(dpid, port));
                }
                for (Integer port : request.getFlowArpPorts()) {
                    installedRules.add(switchManager.installArpInputCustomerFlow(dpid, port));
                }
                if (request.isSwitchLldp()) {
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INPUT_PRE_DROP_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_TRANSIT_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INGRESS_COOKIE));
                }
                if (request.isSwitchArp()) {
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INPUT_PRE_DROP_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_TRANSIT_COOKIE));
                    installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INGRESS_COOKIE));
                }
            }
            Integer server42Port = request.getServer42Port();
            Integer server42Vlan = request.getServer42Vlan();
            MacAddress server42MacAddress = request.getServer42MacAddress();
            if (request.isServer42FlowRttFeatureToggle()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_FLOW_RTT_TURNING_COOKIE));
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE));
                if (request.isServer42FlowRttSwitchProperty() && server42Port != null && server42Vlan != null && server42MacAddress != null) {
                    installedRules.add(switchManager.installServer42FlowRttOutputVlanFlow(dpid, server42Port, server42Vlan, server42MacAddress));
                    installedRules.add(switchManager.installServer42FlowRttOutputVxlanFlow(dpid, server42Port, server42Vlan, server42MacAddress));
                    for (Integer port : request.getServer42FlowRttPorts()) {
                        installedRules.add(switchManager.installServer42FlowRttInputFlow(dpid, server42Port, port, server42MacAddress));
                    }
                }
            }
            if (request.isServer42IslRttEnabled()) {
                installedRules.add(processInstallDefaultFlowByCookie(request.getSwitchId(), SERVER_42_ISL_RTT_TURNING_COOKIE));
                installedRules.add(switchManager.installServer42IslRttOutputFlow(dpid, request.getServer42Port(), request.getServer42Vlan(), request.getServer42MacAddress()));
                for (Integer port : request.getIslPorts()) {
                    installedRules.add(switchManager.installServer42IslRttInputFlow(dpid, server42Port, port));
                }
            }
        }
        SwitchRulesResponse response = new SwitchRulesResponse(installedRules.stream().filter(Objects::nonNull).collect(Collectors.toList()));
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, record.key(), infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Failed to install rules on switch '{}'", request.getSwitchId(), e);
        anError(ErrorType.CREATION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) InstallRulesAction(org.openkilda.messaging.command.switches.InstallRulesAction) ArrayList(java.util.ArrayList) DatapathId(org.projectfloodlight.openflow.types.DatapathId) MacAddress(org.openkilda.model.MacAddress) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Objects(java.util.Objects)

Aggregations

SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)28 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)25 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)13 InfoMessage (org.openkilda.messaging.info.InfoMessage)13 DatapathId (org.projectfloodlight.openflow.types.DatapathId)13 ErrorData (org.openkilda.messaging.error.ErrorData)9 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)8 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)8 SwitchId (org.openkilda.model.SwitchId)8 ArrayList (java.util.ArrayList)7 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)7 OFMeterConfig (org.projectfloodlight.openflow.protocol.OFMeterConfig)7 HashSet (java.util.HashSet)6 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)6 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 Objects (java.util.Objects)5 String.format (java.lang.String.format)4