Search in sources :

Example 1 with GroupBucket

use of org.openkilda.messaging.info.rule.GroupBucket 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 GroupBucket

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

the class FlowValidationTestBase method getSwitchGroupEntries.

protected List<SwitchGroupEntries> getSwitchGroupEntries() {
    List<SwitchGroupEntries> switchGroupEntries = new ArrayList<>();
    switchGroupEntries.add(SwitchGroupEntries.builder().switchId(TEST_SWITCH_ID_A).groupEntries(Lists.newArrayList(GroupEntry.builder().groupId(FLOW_GROUP_ID_A).buckets(Lists.newArrayList(new GroupBucket(0, FlowApplyActions.builder().flowOutput(String.valueOf(FLOW_GROUP_ID_A_OUT_PORT)).setFieldActions(Collections.singletonList(getFlowSetFieldAction(FLOW_GROUP_ID_A_OUT_VLAN))).build()), new GroupBucket(0, FlowApplyActions.builder().flowOutput(String.valueOf(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED)).build()))).build())).build());
    switchGroupEntries.add(SwitchGroupEntries.builder().switchId(TEST_SWITCH_ID_C).groupEntries(Collections.emptyList()).build());
    return switchGroupEntries;
}
Also used : ArrayList(java.util.ArrayList) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket)

Example 3 with GroupBucket

use of org.openkilda.messaging.info.rule.GroupBucket 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 4 with GroupBucket

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

the class SimpleSwitchRuleConverter method mapGroupBuckets.

private List<SimpleGroupBucket> mapGroupBuckets(List<GroupBucket> buckets) {
    List<SimpleGroupBucket> simpleGroupBuckets = new ArrayList<>();
    for (GroupBucket bucket : buckets) {
        FlowApplyActions actions = bucket.getApplyActions();
        if (actions == null || !NumberUtils.isParsable(actions.getFlowOutput())) {
            continue;
        }
        int bucketPort = NumberUtils.toInt(actions.getFlowOutput());
        int bucketVlan = 0;
        if (actions.getSetFieldActions() != null && actions.getSetFieldActions().size() == 1) {
            FlowSetFieldAction setFieldAction = actions.getSetFieldActions().get(0);
            if (VLAN_VID.equals(setFieldAction.getFieldName())) {
                bucketVlan = NumberUtils.toInt(setFieldAction.getFieldValue());
            }
        }
        int bucketVni = 0;
        if (actions.getPushVxlan() != null) {
            bucketVni = NumberUtils.toInt(actions.getPushVxlan());
        }
        simpleGroupBuckets.add(new SimpleGroupBucket(bucketPort, bucketVlan, bucketVni));
    }
    simpleGroupBuckets.sort(this::compareSimpleGroupBucket);
    return simpleGroupBuckets;
}
Also used : FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) ArrayList(java.util.ArrayList) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Aggregations

GroupBucket (org.openkilda.messaging.info.rule.GroupBucket)4 ArrayList (java.util.ArrayList)2 GroupEntry (org.openkilda.messaging.info.rule.GroupEntry)2 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors.toList (java.util.stream.Collectors.toList)1 Test (org.junit.Test)1 SpeakerCommandProcessor (org.openkilda.floodlight.command.SpeakerCommandProcessor)1 OfFlowStatsMapper (org.openkilda.floodlight.converter.OfFlowStatsMapper)1 SwitchIncorrectMirrorGroupException (org.openkilda.floodlight.error.SwitchIncorrectMirrorGroupException)1 SwitchMissingGroupException (org.openkilda.floodlight.error.SwitchMissingGroupException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 FlowTransitData (org.openkilda.floodlight.model.FlowTransitData)1 CompletableFutureAdapter (org.openkilda.floodlight.utils.CompletableFutureAdapter)1 MessageContext (org.openkilda.messaging.MessageContext)1 FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)1 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)1