Search in sources :

Example 1 with OFGroupDescStatsReply

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply in project open-kilda by telstra.

the class GroupVerifyCommand method handleGroupStats.

private MirrorConfig handleGroupStats(List<OFGroupDescStatsReply> groupDescStatsReply) {
    OFGroupDescStatsEntry target = null;
    List<OFGroupDescStatsEntry> groupDescStatsEntries = groupDescStatsReply.stream().map(OFGroupDescStatsReply::getEntries).flatMap(List::stream).collect(toList());
    for (OFGroupDescStatsEntry entry : groupDescStatsEntries) {
        if (mirrorConfig.getGroupId().intValue() == entry.getGroup().getGroupNumber()) {
            target = entry;
            break;
        }
    }
    if (target == null) {
        throw maskCallbackException(new SwitchMissingGroupException(getSw().getId(), mirrorConfig.getGroupId()));
    }
    validateGroupConfig(target);
    return mirrorConfig;
}
Also used : SwitchMissingGroupException(org.openkilda.floodlight.error.SwitchMissingGroupException) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply)

Example 2 with OFGroupDescStatsReply

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply in project open-kilda by telstra.

the class OfBatchExecutor method verifyGroups.

private void verifyGroups() {
    log.debug("Verify groups with key: {} (hasGroups={})", kafkaKey, hasGroups);
    if (!hasGroups) {
        return;
    }
    try {
        List<OFGroupDescStatsReply> replies = groupStats.get();
        List<GroupSpeakerData> switchGroups = new ArrayList<>();
        replies.forEach(reply -> switchGroups.addAll(OfGroupConverter.INSTANCE.convertToGroupSpeakerData(reply)));
        for (GroupSpeakerData switchGroup : switchGroups) {
            GroupSpeakerData expectedGroup = holder.getByGroupId(switchGroup.getGroupId());
            if (expectedGroup != null) {
                if (switchGroup.equals(expectedGroup)) {
                    holder.recordSuccessUuid(expectedGroup.getUuid());
                } else {
                    holder.recordFailedUuid(expectedGroup.getUuid(), format("Failed to validate group on a switch. Expected: %s, actual: %s", expectedGroup, switchGroup));
                }
            }
        }
    } catch (Exception e) {
        log.error("Failed to verify groups for message", e);
    }
}
Also used : GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) ArrayList(java.util.ArrayList) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply)

Example 3 with OFGroupDescStatsReply

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply in project open-kilda by telstra.

the class SwitchManagerTest method mockGetGroupsRequest.

private void mockGetGroupsRequest(List<Integer> groupIds) throws Exception {
    List<OFGroupDescStatsEntry> meterConfigs = new ArrayList<>(groupIds.size());
    for (Integer groupId : groupIds) {
        OFBucket firstBucket = mock(OFBucket.class);
        OFBucket secondBucket = mock(OFBucket.class);
        OFActionSetField setDestMacAction = ofFactory.actions().buildSetField().setField(ofFactory.oxms().buildEthDst().setValue(convertDpIdToMac(dpid)).build()).build();
        OFActionOutput sendToControllerAction = ofFactory.actions().output(OFPort.CONTROLLER, 0xFFFFFFFF);
        TransportPort udpPort = TransportPort.of(LATENCY_PACKET_UDP_PORT);
        OFActionSetField setUdpDstAction = ofFactory.actions().setField(ofFactory.oxms().udpDst(udpPort));
        OFActionOutput sendInPortAction = ofFactory.actions().output(OFPort.IN_PORT, 0xFFFFFFFF);
        expect(firstBucket.getActions()).andStubReturn(Lists.newArrayList(setDestMacAction, sendToControllerAction));
        expect(secondBucket.getActions()).andStubReturn(Lists.newArrayList(setUdpDstAction, sendInPortAction));
        OFGroupDescStatsEntry groupEntry = mock(OFGroupDescStatsEntry.class);
        expect(groupEntry.getGroup()).andStubReturn(OFGroup.of(groupId));
        expect(groupEntry.getBuckets()).andStubReturn(Lists.newArrayList(firstBucket, secondBucket));
        replay(firstBucket, secondBucket, groupEntry);
        meterConfigs.add(groupEntry);
    }
    OFGroupDescStatsReply statsReply = mock(OFGroupDescStatsReply.class);
    expect(statsReply.getEntries()).andStubReturn(meterConfigs);
    ListenableFuture<List<OFGroupDescStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
    expect(iofSwitch.writeStatsRequest(isA(OFGroupDescStatsRequest.class))).andStubReturn(ofStatsFuture);
    replay(statsReply, ofStatsFuture);
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) ArrayList(java.util.ArrayList) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) TransportPort(org.projectfloodlight.openflow.types.TransportPort) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest)

Example 4 with OFGroupDescStatsReply

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply in project open-kilda by telstra.

the class SwitchManager method dumpGroups.

private List<OFGroupDescStatsEntry> dumpGroups(IOFSwitch sw) {
    OFFactory ofFactory = sw.getOFFactory();
    OFGroupDescStatsRequest groupRequest = ofFactory.buildGroupDescStatsRequest().build();
    List<OFGroupDescStatsReply> replies;
    try {
        ListenableFuture<List<OFGroupDescStatsReply>> future = sw.writeStatsRequest(groupRequest);
        replies = future.get(10, TimeUnit.SECONDS);
    } catch (ExecutionException | TimeoutException e) {
        logger.error("Could not dump groups on switch {}.", sw.getId(), e);
        return Collections.emptyList();
    } catch (InterruptedException e) {
        logger.error("Could not dump groups on switch {}.", sw.getId(), e);
        Thread.currentThread().interrupt();
        return Collections.emptyList();
    }
    return replies.stream().map(OFGroupDescStatsReply::getEntries).flatMap(List::stream).collect(toList());
}
Also used : OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) 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) ExecutionException(java.util.concurrent.ExecutionException) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

OFGroupDescStatsReply (org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)2 OFGroupDescStatsRequest (org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest)2 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 SwitchMissingGroupException (org.openkilda.floodlight.error.SwitchMissingGroupException)1 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)1 OFBucket (org.projectfloodlight.openflow.protocol.OFBucket)1 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)1 OFActionOutput (org.projectfloodlight.openflow.protocol.action.OFActionOutput)1 OFActionSetField (org.projectfloodlight.openflow.protocol.action.OFActionSetField)1 TransportPort (org.projectfloodlight.openflow.types.TransportPort)1