Search in sources :

Example 16 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class AnalysisModel method populateConnectionPropagationPaths.

/**
 * find the propagation paths between component instances with error propagations.
 * This method handles different levels.
 * It also handles both complete and incomplete connection instances (the latter are out only and in only connections
 * @param connectionInstance
 * @param level LEAF (lowest), TOP (highest), ALL (all combinations)
 */
protected void populateConnectionPropagationPaths(ConnectionInstance connectionInstance, PropagationPathLevel level) {
    SystemOperationMode som = connectionInstance.getSystemInstance().getCurrentSystemOperationMode();
    if (!connectionInstance.isActive(som)) {
        return;
    }
    EList<ConnectionReference> connrefs = connectionInstance.getConnectionReferences();
    if (connrefs.isEmpty()) {
        return;
    }
    ErrorPropagation srcprop = null;
    ComponentInstance srcCI = null;
    ErrorPropagation dstprop = null;
    ComponentInstance dstCI = null;
    ConnectionReference first = connrefs.get(0);
    // inonly is an incomplete connection instance that is only incoming,
    // i.e., we only have incoming propagations.
    boolean inonly = (first.getSource().getComponentInstance() == first.getContext());
    ConnectionReference last = connrefs.get(connrefs.size() - 1);
    // outonly is an incomplete connection instance that is only outgoing,
    // i.e., we only have outgoing propagations.
    boolean outonly = (last.getDestination().getComponentInstance() == last.getContext());
    // list of additional source error propagations (i.e., those of
    // enclosing components.
    List<ComponentInstance> addlSrcCI = new ArrayList<ComponentInstance>();
    List<ErrorPropagation> addlSrcEP = new ArrayList<ErrorPropagation>();
    List<ComponentInstance> addlDstCI = new ArrayList<ComponentInstance>();
    List<ErrorPropagation> addlDstEP = new ArrayList<ErrorPropagation>();
    for (ConnectionReference connectionReference : connrefs) {
        if (!connectionReference.isActive(som)) {
            continue;
        }
        ConnectionInstanceEnd src = connectionReference.getSource();
        ConnectionInstanceEnd dst = connectionReference.getDestination();
        // remember the first (lowest in the hierarchy) src component
        // instance with Error propagation
        // srcprop is null until we found the source error propagation
        ErrorPropagation foundEP = null;
        if (src instanceof FeatureInstance) {
            if (inonly) {
                foundEP = EMV2Util.getIncomingErrorPropagation((FeatureInstance) src);
            } else {
                foundEP = EMV2Util.getOutgoingErrorPropagation((FeatureInstance) src);
            }
        } else if (src instanceof ComponentInstance) {
            // instance instead of a feature instance
            if (inonly) {
                foundEP = EMV2Util.getIncomingAccessErrorPropagation((ComponentInstance) src);
            } else {
                foundEP = EMV2Util.getOutgoingAccessErrorPropagation((ComponentInstance) src);
            }
        }
        if (foundEP != null) {
            switch(level) {
                case TOP:
                    srcprop = foundEP;
                    srcCI = src.getComponentInstance();
                    break;
                case LEAF:
                    if (srcprop == null) {
                        srcprop = foundEP;
                        srcCI = src.getComponentInstance();
                    }
                    break;
                case ALL:
                    addlSrcEP.add(foundEP);
                    addlSrcCI.add(src.getComponentInstance());
                    break;
            }
        }
        // We look for destination error propagations
        // it should be incoming except when outonly
        ErrorPropagation founddst = null;
        if (dst instanceof FeatureInstance) {
            if (outonly) {
                founddst = EMV2Util.getOutgoingErrorPropagation((FeatureInstance) dst);
            } else {
                founddst = EMV2Util.getIncomingErrorPropagation((FeatureInstance) dst);
            }
        } else if (dst instanceof ComponentInstance) {
            // a shared model element
            if (outonly) {
                founddst = EMV2Util.getOutgoingAccessErrorPropagation((ComponentInstance) dst);
            } else {
                founddst = EMV2Util.getIncomingAccessErrorPropagation((ComponentInstance) dst);
            }
        }
        if (founddst != null) {
            switch(level) {
                case TOP:
                    if (dstprop == null) {
                        dstprop = founddst;
                        dstCI = dst.getComponentInstance();
                    }
                    break;
                case LEAF:
                    dstprop = founddst;
                    dstCI = dst.getComponentInstance();
                    break;
                case ALL:
                    addlDstEP.add(foundEP);
                    addlDstCI.add(src.getComponentInstance());
                    break;
            }
        }
    }
    // record the results
    switch(level) {
        case TOP:
        case LEAF:
            if (srcprop != null && dstprop != null) {
                // we found a source and destination. Add it if not already
                // there.
                addPropagationpathRecord(srcCI, srcprop, dstCI, dstprop, connectionInstance);
            } else {
                if (srcprop != null && addlSrcEP.size() > 1) {
                    dstprop = addlSrcEP.get(addlSrcEP.size() - 1);
                    dstCI = addlSrcCI.get(addlSrcCI.size() - 1);
                }
            }
            break;
        case ALL:
            // FIXME: this is obviously wrong
            for (int i = 0; i < addlSrcCI.size(); i++) {
                for (int j = 0; i < addlDstCI.size(); i++) {
                    srcCI = addlSrcCI.get(i);
                    srcprop = addlSrcEP.get(i);
                    dstCI = addlDstCI.get(i);
                    dstprop = addlDstEP.get(i);
                    addPropagationpathRecord(srcCI, srcprop, dstCI, dstprop, connectionInstance);
                }
            }
            break;
    }
    if (connectionInstance.isBidirectional()) {
        // now work in the inverse direction since the conneciton is
        // bi-directional
        srcprop = null;
        srcCI = null;
        dstprop = null;
        dstCI = null;
        addlSrcCI.clear();
        addlSrcEP.clear();
        addlDstCI.clear();
        addlDstEP.clear();
        for (int i = connrefs.size() - 1; i >= 0; i--) {
            ConnectionReference connectionReference = connrefs.get(i);
            if (!connectionReference.isActive(som)) {
                continue;
            }
            ConnectionInstanceEnd dst = connectionReference.getSource();
            ConnectionInstanceEnd src = connectionReference.getDestination();
            ErrorPropagation foundEP = null;
            if (src instanceof FeatureInstance) {
                if (inonly) {
                    foundEP = EMV2Util.getIncomingErrorPropagation((FeatureInstance) src);
                } else {
                    foundEP = EMV2Util.getOutgoingErrorPropagation((FeatureInstance) src);
                }
            } else if (src instanceof ComponentInstance) {
                // instance instead of a feature instance
                if (inonly) {
                    foundEP = EMV2Util.getIncomingAccessErrorPropagation((ComponentInstance) src);
                } else {
                    foundEP = EMV2Util.getOutgoingAccessErrorPropagation((ComponentInstance) src);
                }
            }
            if (foundEP != null) {
                switch(level) {
                    case TOP:
                        srcprop = foundEP;
                        srcCI = src.getComponentInstance();
                        break;
                    case LEAF:
                        if (srcprop == null) {
                            srcprop = foundEP;
                            srcCI = src.getComponentInstance();
                        }
                        break;
                    case ALL:
                        addlSrcEP.add(foundEP);
                        addlSrcCI.add(src.getComponentInstance());
                        break;
                }
            }
            // We look for destination error propagations
            // it should be incoming except when outonly
            ErrorPropagation founddst = null;
            if (dst instanceof FeatureInstance) {
                if (outonly) {
                    founddst = EMV2Util.getOutgoingErrorPropagation((FeatureInstance) dst);
                } else {
                    founddst = EMV2Util.getIncomingErrorPropagation((FeatureInstance) dst);
                }
            } else if (dst instanceof ComponentInstance) {
                // a shared model element
                if (outonly) {
                    founddst = EMV2Util.getOutgoingAccessErrorPropagation((ComponentInstance) dst);
                } else {
                    founddst = EMV2Util.getIncomingAccessErrorPropagation((ComponentInstance) dst);
                }
            }
            if (founddst != null) {
                switch(level) {
                    case TOP:
                        if (dstprop == null) {
                            dstprop = founddst;
                            dstCI = dst.getComponentInstance();
                        }
                        break;
                    case LEAF:
                        dstprop = founddst;
                        dstCI = dst.getComponentInstance();
                        break;
                    case ALL:
                        addlDstEP.add(foundEP);
                        addlDstCI.add(src.getComponentInstance());
                        break;
                }
            }
        }
        // record the results
        switch(level) {
            case TOP:
            case LEAF:
                if (srcprop != null && dstprop != null) {
                    // we found a source and destination. Add it if not already
                    // there.
                    addPropagationpathRecord(srcCI, srcprop, dstCI, dstprop, connectionInstance);
                } else {
                    if (srcprop != null && addlSrcEP.size() > 1) {
                        dstprop = addlSrcEP.get(addlSrcEP.size() - 1);
                        dstCI = addlSrcCI.get(addlSrcCI.size() - 1);
                    }
                }
                break;
            case ALL:
                // FIXME: this is obviously wrong
                for (int i = 0; i < addlSrcCI.size(); i++) {
                    for (int j = 0; i < addlDstCI.size(); i++) {
                        srcCI = addlSrcCI.get(i);
                        srcprop = addlSrcEP.get(i);
                        dstCI = addlDstCI.get(i);
                        dstprop = addlDstEP.get(i);
                        addPropagationpathRecord(srcCI, srcprop, dstCI, dstprop, connectionInstance);
                    }
                }
                break;
        }
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ArrayList(java.util.ArrayList) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Example 17 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class EMV2Util method findConnectionErrorSourceForConnection.

/**
 * Find ConnectionErrorSource with given classifier by looking through all connection error sources
 * @param conni the connection instance whose connection declarations we're using
 * @return the connection error source or null
 */
public static ErrorSource findConnectionErrorSourceForConnection(ConnectionInstance conni) {
    for (ConnectionReference connref : conni.getConnectionReferences()) {
        Connection conn = connref.getConnection();
        Classifier cl = getAssociatedClassifier(conn);
        if (cl != null) {
            Collection<ErrorSource> ceslist = getAllConnectionErrorSources(cl);
            for (ErrorSource ces : ceslist) {
                if (ces.isAll() || ces.getSourceModelElement().getName().equalsIgnoreCase(conn.getName())) {
                    return ces;
                }
            }
        }
    }
    return null;
}
Also used : ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Connection(org.osate.aadl2.Connection) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier)

Example 18 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class FaultTreeUtils method addBasicEvent.

public static void addBasicEvent(Event parent, ConnectionInstance conni, NamedElement namedElement, TypeToken type) {
    Event newEvent = createBasicEvent((FaultTree) parent.eContainer(), conni, namedElement, type);
    parent.getSubEvents().add(newEvent);
}
Also used : Event(org.osate.aadl2.errormodel.FaultTree.Event) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)

Example 19 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class FaultTreeUtils method createBasicEvent.

public static Event createBasicEvent(FaultTree ftaModel, ConnectionInstance conni, NamedElement namedElement, TypeToken type) {
    String name = buildName(conni, namedElement, type);
    Event result = findEvent(ftaModel, name);
    if (result != null) {
        return result;
    }
    Event newEvent = FaultTreeFactory.eINSTANCE.createEvent();
    ftaModel.getEvents().add(newEvent);
    newEvent.setName(name);
    newEvent.setType(EventType.BASIC);
    newEvent.setRelatedInstanceObject(conni);
    newEvent.setRelatedEMV2Object(namedElement);
    newEvent.setRelatedErrorType(type);
    return newEvent;
}
Also used : Event(org.osate.aadl2.errormodel.FaultTree.Event) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)

Example 20 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class PropagateErrorSources method startConnectionSourceFlows.

/**
 * Start with the source of a connection instance
 * @param ci component instance
 */
public void startConnectionSourceFlows(ComponentInstance root) {
    Collection<ErrorSource> ceslist = EMV2Util.getAllConnectionErrorSources(root.getComponentClassifier());
    if (ceslist.isEmpty()) {
        return;
    }
    for (ErrorSource ces : ceslist) {
        if (!Util.conditionHolds(ces, root)) {
            continue;
        }
        EMSUtil.unsetAll(root.getSystemInstance());
        // find connection instances that this connection is part of
        String connName = ces.getSourceModelElement().getName();
        ConnectionInstance conni = InstanceUtil.findConnectionInstance(root, (Connection) ces.getSourceModelElement());
        EList<PropagationPathEnd> ends = Util.getAllPropagationDestinationEnds(faultModel, conni);
        if (ends.size() == 0) {
            return;
        }
        PropagationPathEnd ppe = ends.get(0);
        ErrorPropagation destEP = ppe.getErrorPropagation();
        ComponentInstance destci = ppe.getComponentInstance();
        TypeSet fmType = ces.getFailureModeType();
        String failuremodeDesc = ces.getFailureModeDescription();
        TypeSet tsep = ces.getTypeTokenConstraint();
        EList<TypeToken> result = tsep.getTypeTokens();
        // XXX use this if we want all leaf types: EM2TypeSetUtil.generateAllLeafTypeTokens(tsep,EMV2Util.getContainingTypeUseContext(errorSource));
        for (TypeToken typeToken : result) {
            String failuremodeText;
            if (failuremodeDesc == null) {
                failuremodeText = generateOriginalFailureModeText(fmType != null ? fmType : typeToken);
            } else {
                failuremodeText = failuremodeDesc;
            }
            String effectText = generateOriginalFailureModeText(typeToken);
            String connText = generateComponentPropagationPointText(destci, destEP);
            traceErrorFlows(destci, destEP, typeToken, 0, "Connection " + connName + "," + failuremodeText + "," + effectText + " -> " + connText);
        }
    }
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropagationPathEnd(org.osate.aadl2.errormodel.PropagationGraph.PropagationPathEnd) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Aggregations

ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)73 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)66 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)33 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)29 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)26 Classifier (org.osate.aadl2.Classifier)23 InstanceObject (org.osate.aadl2.instance.InstanceObject)21 ArrayList (java.util.ArrayList)17 Connection (org.osate.aadl2.Connection)17 Element (org.osate.aadl2.Element)16 NamedElement (org.osate.aadl2.NamedElement)15 PropertyExpression (org.osate.aadl2.PropertyExpression)14 SystemInstance (org.osate.aadl2.instance.SystemInstance)14 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)13 ComponentClassifier (org.osate.aadl2.ComponentClassifier)12 ListValue (org.osate.aadl2.ListValue)11 List (java.util.List)10 ComponentImplementation (org.osate.aadl2.ComponentImplementation)10 Feature (org.osate.aadl2.Feature)10 BasicEList (org.eclipse.emf.common.util.BasicEList)9