Search in sources :

Example 1 with GroupEntry

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

the class OfFlowStatsMapperTest method testFlowGroupEntry.

@Test
public void testFlowGroupEntry() {
    OFGroupDescStatsEntry entry = buildFlowGroupEntry();
    GroupEntry result = OfFlowStatsMapper.INSTANCE.toFlowGroupEntry(entry);
    assertEquals(entry.getGroup().getGroupNumber(), result.getGroupId());
    assertEquals(entry.getGroupType().toString(), result.getGroupType());
    assertEquals(entry.getBuckets().size(), result.getBuckets().size());
    GroupBucket firstBucket = result.getBuckets().get(0);
    assertEquals("12", firstBucket.getApplyActions().getFlowOutput());
    GroupBucket secondBucket = result.getBuckets().get(1);
    assertEquals(EthType.VLAN_FRAME.toString(), secondBucket.getApplyActions().getPushVlan());
    assertEquals("vlan_vid", secondBucket.getApplyActions().getSetFieldActions().get(0).getFieldName());
    assertEquals("12", secondBucket.getApplyActions().getSetFieldActions().get(0).getFieldValue());
    assertEquals("1", secondBucket.getApplyActions().getFlowOutput());
}
Also used : GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) Test(org.junit.Test)

Example 2 with GroupEntry

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

the class YFlowSwitchFlowEntriesBuilder method getGroupEntries.

/**
 * Construct a set of {@link GroupEntry} that corresponds to the builder's y-flow.
 */
public Map<SwitchId, Collection<GroupEntry>> getGroupEntries() {
    MultiValuedMap<SwitchId, GroupEntry> groupEntries = new ArrayListValuedHashMap<>();
    yFlow.getSubFlows().forEach(subFlow -> {
        Flow flow = subFlow.getFlow();
        SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
        builder.getSwitchGroupEntries().forEach(entries -> groupEntries.putAll(entries.getSwitchId(), entries.getGroupEntries()));
    });
    return groupEntries.asMap();
}
Also used : GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) SwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder) SwitchId(org.openkilda.model.SwitchId) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 3 with GroupEntry

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

the class YFlowValidationHubServiceTest method handleSpeakerRequests.

private void handleSpeakerRequests(YFlowValidationHubService service, String yFlowFsmKey, Map<SwitchId, Collection<FlowEntry>> flowEntries, Map<SwitchId, Collection<MeterEntry>> meterEntries, Map<SwitchId, Collection<GroupEntry>> groupEntries) {
    handleSpeakerRequests(pair -> {
        CommandData commandData = pair.getValue();
        InfoData result = null;
        if (commandData instanceof DumpRulesForFlowHsRequest) {
            SwitchId switchId = ((DumpRulesForFlowHsRequest) commandData).getSwitchId();
            Collection<FlowEntry> foundFlowEntries = flowEntries.get(switchId);
            result = SwitchFlowEntries.builder().switchId(switchId).flowEntries(foundFlowEntries != null ? new ArrayList<>(foundFlowEntries) : emptyList()).build();
        } else if (commandData instanceof DumpMetersForFlowHsRequest) {
            SwitchId switchId = ((DumpMetersForFlowHsRequest) commandData).getSwitchId();
            Collection<MeterEntry> foundMeterEntries = meterEntries.get(switchId);
            result = SwitchMeterEntries.builder().switchId(switchId).meterEntries(foundMeterEntries != null ? new ArrayList<>(foundMeterEntries) : emptyList()).build();
        } else if (commandData instanceof DumpGroupsForFlowHsRequest) {
            SwitchId switchId = ((DumpGroupsForFlowHsRequest) commandData).getSwitchId();
            Collection<GroupEntry> foundGroupEntries = groupEntries.get(switchId);
            result = SwitchGroupEntries.builder().switchId(switchId).groupEntries(foundGroupEntries != null ? new ArrayList<>(foundGroupEntries) : emptyList()).build();
        } else {
            fail();
        }
        String flowId = pair.getKey();
        service.handleAsyncResponse(yFlowFsmKey, flowId, result);
    });
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) Collection(java.util.Collection) CommandData(org.openkilda.messaging.command.CommandData) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry)

Example 4 with GroupEntry

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

the class RecordHandler method dumpGroupsRequest.

private void dumpGroupsRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
    try {
        logger.debug("Loading installed groups for switch {}", switchId);
        List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = context.getSwitchManager().dumpGroups(DatapathId.of(switchId.toLong()));
        List<GroupEntry> groups = ofGroupDescStatsEntries.stream().map(OfFlowStatsMapper.INSTANCE::toFlowGroupEntry).collect(Collectors.toList());
        SwitchGroupEntries response = SwitchGroupEntries.builder().switchId(switchId).groupEntries(groups).build();
        sender.accept(response);
    } catch (SwitchOperationException e) {
        logger.error("Dumping of groups 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 groups dump.").buildData();
        sender.accept(errorData);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) FlowCommandErrorData(org.openkilda.messaging.error.rule.FlowCommandErrorData) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 5 with GroupEntry

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

the class GroupVerifyCommand method fromStatsEntry.

private MirrorConfig fromStatsEntry(OFGroupDescStatsEntry entry) {
    GroupEntry groupEntry = OfFlowStatsMapper.INSTANCE.toFlowGroupEntry(entry);
    GroupId groupId = new GroupId(groupEntry.getGroupId());
    if (groupEntry.getBuckets().size() < 2) {
        return null;
    }
    GroupBucket flowBucket = groupEntry.getBuckets().get(0);
    int flowPort = Integer.parseInt(flowBucket.getApplyActions().getFlowOutput());
    Set<MirrorConfigData> mirrorConfigDataSet = new HashSet<>();
    for (int i = 1; i < groupEntry.getBuckets().size(); ++i) {
        GroupBucket mirrorBucket = groupEntry.getBuckets().get(i);
        int mirrorPort = Integer.parseInt(mirrorBucket.getApplyActions().getFlowOutput());
        int mirrorVlan = mirrorBucket.getApplyActions().getSetFieldActions().stream().filter(action -> (MatchField.VLAN_VID.getName().equals(action.getFieldName()))).map(action -> Integer.valueOf(action.getFieldValue())).findFirst().orElse(0);
        mirrorConfigDataSet.add(new MirrorConfigData(mirrorPort, mirrorVlan));
    }
    return MirrorConfig.builder().groupId(groupId).flowPort(flowPort).mirrorConfigDataSet(mirrorConfigDataSet).build();
}
Also used : MirrorConfig(org.openkilda.model.MirrorConfig) CompletableFuture(java.util.concurrent.CompletableFuture) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) SwitchIncorrectMirrorGroupException(org.openkilda.floodlight.error.SwitchIncorrectMirrorGroupException) HashSet(java.util.HashSet) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) CompletableFutureAdapter(org.openkilda.floodlight.utils.CompletableFutureAdapter) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) FlowTransitData(org.openkilda.floodlight.model.FlowTransitData) MessageContext(org.openkilda.messaging.MessageContext) Set(java.util.Set) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SpeakerCommandProcessor(org.openkilda.floodlight.command.SpeakerCommandProcessor) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) MatchField(org.projectfloodlight.openflow.protocol.match.MatchField) SwitchMissingGroupException(org.openkilda.floodlight.error.SwitchMissingGroupException) DatapathId(org.projectfloodlight.openflow.types.DatapathId) GroupId(org.openkilda.model.GroupId) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) GroupId(org.openkilda.model.GroupId) HashSet(java.util.HashSet)

Aggregations

GroupEntry (org.openkilda.messaging.info.rule.GroupEntry)6 SwitchId (org.openkilda.model.SwitchId)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Test (org.junit.Test)2 OfFlowStatsMapper (org.openkilda.floodlight.converter.OfFlowStatsMapper)2 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)2 CommandData (org.openkilda.messaging.command.CommandData)2 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors.toList (java.util.stream.Collectors.toList)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1