Search in sources :

Example 11 with GroupId

use of org.openkilda.model.GroupId in project open-kilda by telstra.

the class FermaMirrorGroupRepositoryTest method findUnassignedMirrorGroupAndCreate.

private long findUnassignedMirrorGroupAndCreate(String flowId, String pathId) {
    GroupId availableGroupId = mirrorGroupRepository.findFirstUnassignedGroupId(theSwitch.getSwitchId(), MIN_GROUP_ID, MAX_GROUP_ID).get();
    MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(theSwitch.getSwitchId()).groupId(availableGroupId).pathId(new PathId(flowId + "_" + pathId)).flowId(flowId).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
    mirrorGroupRepository.add(mirrorGroup);
    return availableGroupId.getValue();
}
Also used : PathId(org.openkilda.model.PathId) MirrorGroup(org.openkilda.model.MirrorGroup) GroupId(org.openkilda.model.GroupId)

Example 12 with GroupId

use of org.openkilda.model.GroupId 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 13 with GroupId

use of org.openkilda.model.GroupId in project open-kilda by telstra.

the class SimpleSwitchRuleConverterTest method buildFlow.

private Flow buildFlow(FlowEncapsulationType flowEncapsulationType, boolean checkWithGroup) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_VALUE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).status(FlowPathStatus.ACTIVE).bandwidth(FLOW_A_BANDWIDTH).build();
    flow.setForwardPath(forwardFlowPath);
    PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
    PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
    forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
    if (checkWithGroup) {
        FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(switchA).mirrorGroup(MirrorGroup.builder().switchId(TEST_SWITCH_ID_A).groupId(new GroupId(FLOW_GROUP_ID_A)).pathId(FLOW_A_FORWARD_PATH_ID).flowId(TEST_FLOW_ID_A).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build()).build();
        FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("mirror_path")).mirrorSwitch(switchA).egressSwitch(switchA).egressPort(FLOW_GROUP_ID_A_OUT_PORT).egressOuterVlan(FLOW_GROUP_ID_A_OUT_VLAN).build();
        flowMirrorPoints.addPaths(flowMirrorPath);
        forwardFlowPath.addFlowMirrorPoints(flowMirrorPoints);
    }
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId)

Example 14 with GroupId

use of org.openkilda.model.GroupId in project open-kilda by telstra.

the class FermaMirrorGroupRepository method findFirstUnassignedGroupId.

@Override
public Optional<GroupId> findFirstUnassignedGroupId(SwitchId switchId, GroupId lowestGroupId, GroupId highestGroupId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long lowestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(lowestGroupId);
    Long highestGroupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(highestGroupId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.gte(lowestGroupIdAsLong)).has(MirrorGroupFrame.GROUP_ID_PROPERTY, P.lt(highestGroupIdAsLong)).values(MirrorGroupFrame.GROUP_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).values(MirrorGroupFrame.GROUP_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
        if (traversal.hasNext()) {
            return traversal.tryNext().map(l -> ((Double) l).longValue()).map(GroupIdConverter.INSTANCE::toEntityAttribute);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(MirrorGroupFrame.FRAME_LABEL).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr).has(MirrorGroupFrame.GROUP_ID_PROPERTY, lowestGroupIdAsLong)).getRawTraversal()) {
        if (!traversal.hasNext()) {
            return Optional.of(lowestGroupId);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    return Optional.empty();
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MirrorGroupData(org.openkilda.model.MirrorGroup.MirrorGroupData) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) MirrorGroup(org.openkilda.model.MirrorGroup) MirrorGroupFrame(org.openkilda.persistence.ferma.frames.MirrorGroupFrame) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 15 with GroupId

use of org.openkilda.model.GroupId in project open-kilda by telstra.

the class CommandBuilderImpl method makeMirrorConfig.

private MirrorConfig makeMirrorConfig(@NonNull FlowPath flowPath, @NonNull SwitchId mirrorSwitchId, int mirrorPort) {
    MirrorConfig mirrorConfig = null;
    FlowMirrorPoints flowMirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(mirrorPoints -> mirrorSwitchId.equals(mirrorPoints.getMirrorSwitchId())).findFirst().orElse(null);
    if (flowMirrorPoints != null) {
        Set<MirrorConfigData> mirrorConfigDataSet = flowMirrorPoints.getMirrorPaths().stream().map(mirrorPath -> new MirrorConfigData(mirrorPath.getEgressPort(), mirrorPath.getEgressOuterVlan())).collect(Collectors.toSet());
        if (!mirrorConfigDataSet.isEmpty()) {
            mirrorConfig = MirrorConfig.builder().groupId(flowMirrorPoints.getMirrorGroupId()).flowPort(mirrorPort).mirrorConfigDataSet(mirrorConfigDataSet).build();
        }
    }
    return mirrorConfig;
}
Also used : ModifyDefaultMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyDefaultMeterForSwitchManagerRequest) MirrorConfig(org.openkilda.model.MirrorConfig) NoArgGenerator(com.fasterxml.uuid.NoArgGenerator) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowPath(org.openkilda.model.FlowPath) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) NumberUtils(org.apache.commons.lang.math.NumberUtils) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) Flow(org.openkilda.model.Flow) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) ModifyFlowMeterForSwitchManagerRequest(org.openkilda.messaging.command.flow.ModifyFlowMeterForSwitchManagerRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) NonNull(lombok.NonNull) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Set(java.util.Set) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) InstallServer42FlowBuilder(org.openkilda.messaging.command.flow.InstallServer42Flow.InstallServer42FlowBuilder) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) Optional(java.util.Optional) FlowCommandFactory(org.openkilda.wfm.share.flow.service.FlowCommandFactory) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathSegment(org.openkilda.model.PathSegment) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) CommandBuilder(org.openkilda.wfm.topology.switchmanager.service.CommandBuilder) PathId(org.openkilda.model.PathId) SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) SharedSegmentType(org.openkilda.model.cookie.FlowSharedSegmentCookie.SharedSegmentType) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) SERVER_42_ISL_RTT_OUTPUT_COOKIE(org.openkilda.model.cookie.Cookie.SERVER_42_ISL_RTT_OUTPUT_COOKIE) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) SwitchId(org.openkilda.model.SwitchId) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Generators(com.fasterxml.uuid.Generators) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) GroupId(org.openkilda.model.GroupId) Collections(java.util.Collections) MirrorConfig(org.openkilda.model.MirrorConfig) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints)

Aggregations

GroupId (org.openkilda.model.GroupId)20 MirrorGroup (org.openkilda.model.MirrorGroup)9 ArrayList (java.util.ArrayList)8 PathId (org.openkilda.model.PathId)8 SwitchId (org.openkilda.model.SwitchId)6 List (java.util.List)5 Test (org.junit.Test)5 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)5 Switch (org.openkilda.model.Switch)5 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)5 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)5 OFBucket (org.projectfloodlight.openflow.protocol.OFBucket)5 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 MirrorGroupRepository (org.openkilda.persistence.repositories.MirrorGroupRepository)4 Bucket (org.openkilda.rulemanager.group.Bucket)4 Set (java.util.Set)3 Generators (com.fasterxml.uuid.Generators)2 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2