Search in sources :

Example 1 with OFGroupDescStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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 OFGroupDescStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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 3 with OFGroupDescStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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 4 with OFGroupDescStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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)

Example 5 with OFGroupDescStatsEntry

use of org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry 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)

Aggregations

OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)7 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)3 GroupEntry (org.openkilda.messaging.info.rule.GroupEntry)3 OFBucket (org.projectfloodlight.openflow.protocol.OFBucket)3 OFGroupDescStatsReply (org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 Test (org.junit.Test)2 OfFlowStatsMapper (org.openkilda.floodlight.converter.OfFlowStatsMapper)2 SwitchMissingGroupException (org.openkilda.floodlight.error.SwitchMissingGroupException)2 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 FlowCommandErrorData (org.openkilda.messaging.error.rule.FlowCommandErrorData)2 GroupBucket (org.openkilda.messaging.info.rule.GroupBucket)2 GroupId (org.openkilda.model.GroupId)2 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)2 OFGroupDescStatsRequest (org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest)2 ImmutableList (com.google.common.collect.ImmutableList)1