Search in sources :

Example 1 with GroupId

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

the class FermaMirrorGroupRepository method exists.

@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
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 2 with GroupId

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

the class RecordHandler method doDeleteGroupRequest.

private void doDeleteGroupRequest(CommandMessage message) {
    SwitchId switchId = ((DeleteGroupRequest) message.getData()).getSwitchId();
    GroupId groupId = ((DeleteGroupRequest) message.getData()).getGroupId();
    logger.debug("Delete group '{}' for switch '{}'", groupId, switchId);
    handleSpeakerCommand(new GroupRemoveCommand(new MessageContext(message), switchId, groupId));
    DeleteGroupResponse response = new DeleteGroupResponse(true);
    String correlationId = message.getCorrelationId();
    InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Also used : DeleteGroupResponse(org.openkilda.messaging.info.switches.DeleteGroupResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) GroupRemoveCommand(org.openkilda.floodlight.command.group.GroupRemoveCommand) SwitchId(org.openkilda.model.SwitchId) MessageContext(org.openkilda.messaging.MessageContext) DeleteGroupRequest(org.openkilda.messaging.command.switches.DeleteGroupRequest) GroupId(org.openkilda.model.GroupId)

Example 3 with GroupId

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

the class CommandBuilderImpl method buildGroupInstallContexts.

@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
    List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
    Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
    groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
    flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
            Flow flow = flowPath.getFlow();
            if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            }
        }
    });
    flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
        if (mirrorGroups.containsKey(flowPath.getPathId())) {
            Flow flow = getFlow(flowPath);
            if (flowPath.isOneSwitchFlow()) {
                SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
                int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
                MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
                groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
                log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
            } else if (flowPath.getSrcSwitchId().equals(switchId)) {
                if (flowPath.getSegments().isEmpty()) {
                    log.warn("Output port was not found for mirror config");
                } else {
                    PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                    MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
                    EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
                    groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
                    log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
                }
            }
        }
    });
    return groupInstallContexts;
}
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) MirrorGroup(org.openkilda.model.MirrorGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) Flow(org.openkilda.model.Flow) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) PathId(org.openkilda.model.PathId) GroupInstallContext(org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) MirrorConfig(org.openkilda.model.MirrorConfig) Stream(java.util.stream.Stream)

Example 4 with GroupId

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

the class OfInstructionsConverter method convertToRuleManagerAction.

/**
 * Converts action.
 */
public Action convertToRuleManagerAction(OFAction action) {
    switch(action.getType()) {
        case PUSH_VLAN:
            return new PushVlanAction();
        case POP_VLAN:
            return new PopVlanAction();
        case METER:
            OFActionMeter meterAction = (OFActionMeter) action;
            MeterId meterId = new MeterId(meterAction.getMeterId());
            return new MeterAction(meterId);
        case GROUP:
            OFActionGroup groupAction = (OFActionGroup) action;
            GroupId groupId = new GroupId(groupAction.getGroup().getGroupNumber());
            return new GroupAction(groupId);
        case OUTPUT:
            OFActionOutput outputAction = (OFActionOutput) action;
            PortNumber portNumber = convertPort(outputAction.getPort());
            return new PortOutAction(portNumber);
        case EXPERIMENTER:
            if (action instanceof OFActionNoviflowPushVxlanTunnel) {
                OFActionNoviflowPushVxlanTunnel pushNoviVxlan = (OFActionNoviflowPushVxlanTunnel) action;
                return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_NOVIFLOW).vni((int) pushNoviVxlan.getVni()).srcMacAddress(convertMac(pushNoviVxlan.getEthSrc())).dstMacAddress(convertMac(pushNoviVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Dst())).udpSrc(pushNoviVxlan.getUdpSrc()).build();
            } else if (action instanceof OFActionKildaPushVxlanField) {
                OFActionKildaPushVxlanField pushKildaVxlan = (OFActionKildaPushVxlanField) action;
                return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_OVS).vni((int) pushKildaVxlan.getVni()).srcMacAddress(convertMac(pushKildaVxlan.getEthSrc())).dstMacAddress(convertMac(pushKildaVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Dst())).udpSrc(pushKildaVxlan.getUdpSrc()).build();
            } else if (action instanceof OFActionNoviflowCopyField) {
                OFActionNoviflowCopyField copyField = (OFActionNoviflowCopyField) action;
                return CopyFieldAction.builder().numberOfBits(copyField.getNBits()).srcOffset(copyField.getSrcOffset()).dstOffset(copyField.getDstOffset()).oxmSrcHeader(convertOxmHeader(copyField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(copyField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionNoviflowSwapField) {
                OFActionNoviflowSwapField swapField = (OFActionNoviflowSwapField) action;
                return SwapFieldAction.builder().type(ActionType.NOVI_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionKildaSwapField) {
                OFActionKildaSwapField swapField = (OFActionKildaSwapField) action;
                return SwapFieldAction.builder().type(ActionType.KILDA_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionNoviflowPopVxlanTunnel) {
                return new PopVxlanAction(ActionType.POP_VXLAN_NOVIFLOW);
            } else if (action instanceof OFActionKildaPopVxlanField) {
                return new PopVxlanAction(ActionType.POP_VXLAN_OVS);
            } else {
                throw new IllegalStateException(format("Unknown experimenter action %s", action.getType()));
            }
        case SET_FIELD:
            OFActionSetField setFieldAction = (OFActionSetField) action;
            return convertOxm(setFieldAction.getField());
        case SET_VLAN_VID:
            OFActionSetVlanVid setVlanVid = (OFActionSetVlanVid) action;
            return SetFieldAction.builder().field(Field.VLAN_VID).value(setVlanVid.getVlanVid().getVlan()).build();
        default:
            throw new IllegalStateException(format("Unknown action type %s", action.getType()));
    }
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFActionNoviflowPushVxlanTunnel(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowPushVxlanTunnel) OFActionNoviflowPopVxlanTunnel(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowPopVxlanTunnel) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) OFActionNoviflowCopyField(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowCopyField) OFActionGroup(org.projectfloodlight.openflow.protocol.action.OFActionGroup) OFActionNoviflowSwapField(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowSwapField) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId) GroupAction(org.openkilda.rulemanager.action.GroupAction) OFActionMeter(org.projectfloodlight.openflow.protocol.action.OFActionMeter) OFActionSetVlanVid(org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid) OFActionKildaPushVxlanField(org.projectfloodlight.openflow.protocol.action.OFActionKildaPushVxlanField) OFActionKildaPopVxlanField(org.projectfloodlight.openflow.protocol.action.OFActionKildaPopVxlanField) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) OFActionKildaSwapField(org.projectfloodlight.openflow.protocol.action.OFActionKildaSwapField)

Example 5 with GroupId

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

the class OfGroupConverter method convertToGroupSpeakerData.

/**
 * Convert stats entry.
 */
public GroupSpeakerData convertToGroupSpeakerData(OFGroupDescStatsEntry entry) {
    GroupId groupId = new GroupId(entry.getGroup().getGroupNumber());
    GroupType type = fromOfGroupType(entry.getGroupType());
    List<Bucket> buckets = new ArrayList<>();
    List<OFBucket> ofBuckets = entry.getBuckets();
    for (OFBucket bucket : ofBuckets) {
        buckets.add(fromOfBucket(bucket));
    }
    return GroupSpeakerData.builder().groupId(groupId).type(type).buckets(buckets).build();
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) GroupType(org.openkilda.rulemanager.group.GroupType) OFGroupType(org.projectfloodlight.openflow.protocol.OFGroupType) OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) Bucket(org.openkilda.rulemanager.group.Bucket) ArrayList(java.util.ArrayList) GroupId(org.openkilda.model.GroupId)

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