Search in sources :

Example 6 with DeleteRulesCriteria

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());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Example 7 with DeleteRulesCriteria

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());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Example 8 with DeleteRulesCriteria

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();
}
Also used : FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) SwitchId(org.openkilda.model.SwitchId) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) NumberUtils(org.apache.commons.lang.math.NumberUtils) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with DeleteRulesCriteria

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;
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria)

Example 10 with DeleteRulesCriteria

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));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Aggregations

DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)17 Test (org.junit.Test)13 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)10 EasyMock.anyLong (org.easymock.EasyMock.anyLong)9 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)3 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)3 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)3 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)3 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)3 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)2 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1