Search in sources :

Example 6 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class SwitchSyncServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    Properties configProps = new Properties();
    configProps.setProperty("flow.meter-id.max", "40");
    configProps.setProperty("flow.vlan.max", "50");
    PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
    FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
    service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
    service.commandBuilder = commandBuilder;
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
    flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
    InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
    when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
    missingRules = singletonList(flowEntry.getCookie());
    excessRules = emptyList();
    misconfiguredRules = emptyList();
    excessMeters = emptyList();
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) PropertiesBasedConfigurationProvider(org.openkilda.config.provider.PropertiesBasedConfigurationProvider) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Properties(java.util.Properties) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Before(org.junit.Before)

Example 7 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class RecordHandler method processDumpRulesRequest.

private void processDumpRulesRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Loading installed rules for switch {}", switchId);
        List<OFFlowStatsEntry> flowEntries = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId.toLong()));
        List<FlowEntry> flows = flowEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowEntry).collect(Collectors.toList());
        SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
        sender.accept(response);
    } catch (SwitchOperationException e) {
        logger.error("Dumping of rules on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
        ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a rules dump.").buildData();
        sender.accept(errorData);
    }
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 8 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class IOFSwitchConverter method buildSwitchInfoDataExtended.

/**
 * Transforms {@link IOFSwitch} to object that is used throughout kilda in all components.
 * @param sw switch data.
 * @param eventType switch state.
 * @param flowStats installed flows.
 * @return converted switch.
 */
public static SwitchInfoExtendedData buildSwitchInfoDataExtended(IOFSwitch sw, SwitchState eventType, OFFlowStatsReply flowStats) {
    SwitchInfoData switchInfoData = buildSwitchInfoData(sw, eventType);
    List<FlowEntry> flows = flowStats.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
    return new SwitchInfoExtendedData(switchInfoData, flows);
}
Also used : SwitchInfoExtendedData(org.openkilda.messaging.info.event.SwitchInfoExtendedData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry)

Example 9 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.

/**
 * Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
 */
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
    MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
    yFlow.getSubFlows().forEach(subFlow -> {
        Flow flow = subFlow.getFlow();
        SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
        int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
        int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
        Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
        Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
        builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
        FlowPath forwardPath = flow.getForwardPath();
        PathSegment firstSegment = forwardPath.getSegments().get(0);
        FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
        boolean isVxlan = flow.getEncapsulationType() == VXLAN;
        flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
        if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
                    flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
                }
            }
        }
        if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getProtectedReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
                    flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
                }
            }
        }
    });
    return flowEntries.asMap();
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) SwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder) FlowPath(org.openkilda.model.FlowPath) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap)

Example 10 with FlowEntry

use of org.openkilda.messaging.info.rule.FlowEntry in project open-kilda by telstra.

the class OfFlowStatsMapperTest method testFlowEntry.

@Test
public void testFlowEntry() {
    OFFlowStatsEntry ofEntry = buildFlowStatsEntry();
    FlowEntry entry = OfFlowStatsMapper.INSTANCE.toFlowEntry(ofEntry);
    assertEquals(tableId, entry.getTableId());
    assertEquals(cookie, entry.getCookie());
    assertEquals(packetCount, entry.getPacketCount());
    assertEquals(byteCount, entry.getByteCount());
    assertEquals(durationSec, entry.getDurationSeconds());
    assertEquals(durationNsec, entry.getDurationNanoSeconds());
    assertEquals(hardTimeout, entry.getHardTimeout());
    assertEquals(idleTimeout, entry.getIdleTimeout());
    assertEquals(priority, entry.getPriority());
    assertEquals(String.valueOf(vlanVid.getVlan()), entry.getMatch().getVlanVid());
    assertEquals(ethType.toString(), entry.getMatch().getEthType());
    assertEquals(ethDst.toString(), entry.getMatch().getEthDst());
    assertEquals(port.toString(), entry.getMatch().getInPort());
    assertEquals(ipProto.toString(), entry.getMatch().getIpProto());
    assertEquals(udpSrc.toString(), entry.getMatch().getUdpSrc());
    assertEquals(udpDst.toString(), entry.getMatch().getUdpDst());
    FlowSetFieldAction flowSetEthSrcAction = new FlowSetFieldAction("eth_src", MAC_ADDRESS_1);
    FlowSetFieldAction flowSetEthDstAction = new FlowSetFieldAction("eth_dst", MAC_ADDRESS_2);
    FlowCopyFieldAction flowCopyFieldAction = FlowCopyFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
    FlowSwapFieldAction flowSwapFieldAction = FlowSwapFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
    FlowApplyActions applyActions = new FlowApplyActions(port.toString(), Lists.newArrayList(flowSetEthSrcAction, flowSetEthDstAction), ethType.toString(), null, null, null, group.toString(), flowCopyFieldAction, flowSwapFieldAction);
    FlowInstructions instructions = new FlowInstructions(applyActions, null, meterId, goToTable.getValue());
    assertEquals(instructions, entry.getInstructions());
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) FlowSwapFieldAction(org.openkilda.messaging.info.rule.FlowSwapFieldAction) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowCopyFieldAction(org.openkilda.messaging.info.rule.FlowCopyFieldAction) Test(org.junit.Test)

Aggregations

FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)13 Test (org.junit.Test)6 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)6 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)4 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 SwitchId (org.openkilda.model.SwitchId)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Before (org.junit.Before)2 CommandData (org.openkilda.messaging.command.CommandData)2 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)2 Flow (org.openkilda.model.Flow)2 YFlow (org.openkilda.model.YFlow)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1