/* This function checks if the Tx trace is active for the given rx trace */ private bool IsSyncActive(List <Csp.Trace> syncActiveList, Csp.Trace trace) { /* Create the tx trace search name */ String sTxTraceName = String.Format("!{0}", trace.Name.TrimStart(new char[] { '?' })); return(syncActiveList.Any(p => p.Name == sTxTraceName)); }
/* This function checks that the specified trace has not been observed since its tx trace was observed */ /* NOTE: This function assumes that a txTrace is present */ private bool HasBeenSeen(List <Csp.Trace> historyList, Csp.Trace trace) { /* Create the tx trace search name */ String sTxTraceName = String.Format("!{0}", trace.Name.TrimStart(new char[] { '?' })); /* Backtrack the history */ if (historyList.Count > 0) { for (int i = historyList.Count - 1; i >= 0; i--) { if ((historyList[i].Name == trace.Name) && (historyList[i].ProcessId == trace.ProcessId)) { /* The trace has been seen, return true */ return(true); } else if (historyList[i].Name == sTxTraceName) { /* The tx trace has been seen. If we get here, it means that the input trace has not been seen. */ return(false); } } } return(false); }
/* This function adds a transmit trace */ public void AddRxTrace(Csp.Trace trace, Channel.enChannelType chanType) { RxAlphabet.Add(trace); /* Create a transmit channel for this trace */ AddChannel(trace, chanType); }
/* This function adds a tx trace to the supplied SyncActive list */ private void AddSyncActive(ref List <Csp.Trace> syncActiveList, Csp.Trace trace) { if (!syncActiveList.Any(p => p.Name == trace.Name)) { syncActiveList.Add(new Csp.Trace(trace)); } }
private static string GetTraceName(Csp.Trace trace) { String retString = null; if (trace.Name.Contains("!")) { retString = trace.Name.Replace("!", "tx"); } else if (trace.Name.Contains("?")) { retString = trace.Name.Replace("?", "rx");; } else { retString = trace.Name; } return(retString); }
/* The channel alphabet is constructed from its connected processes */ public void ParseGraphHalfDuplex(EdgeList adj) { if (adj != null) { List <Tuple <string, int> > vertices = adj.GetVertices(); /* A list of processes and a list of channels */ NodeList = new List <Node>(); /* Go through the list, create and reuse where nessesary */ foreach (var process in vertices) { String sSyncTrace = GetSyncTraceFromIndex(process.Item2); Node node = null; if (!NodeList.Any(p => p.NodeId == process.Item1)) { Console.WriteLine(String.Format("Creating node {0}", process.Item1)); /* Add the new node to the list */ node = new Node(process.Item1); /* Add the node to the node list */ NodeList.Add(node); } else { Console.WriteLine(String.Format("Using node {0}", process.Item1)); /* Get the existing node */ node = NodeList.First(p => p.NodeId == process.Item1); } /* Add the event to the node */ Csp.Trace nodeTrace = new Csp.Trace() { ProcessId = node.NodeId, Name = sSyncTrace, synchronisation = true }; node.AddTxRxTrace(nodeTrace, Channel.enChannelType.Transceive); } } }
/* This function gets the traces, built from its connected channels */ public List <List <Trace> > GetTracesAdvancedOld3() { List <List <Trace> > retList = new List <List <Trace> >(); List <List <List <Trace> > > txList = new List <List <List <Trace> > >(); List <List <List <Trace> > > rxList = new List <List <List <Trace> > >(); /* Iterate through the channels of this process and get the synchronisations */ foreach (Channel chan in Channels) { foreach (Trace trace in chan.Alphabet) { if (trace.Name.Contains("!")) { /* TX trace */ /* We create a copy and rename the trace so that it belongs to this node process */ Csp.Trace nodeTrace = new Csp.Trace(trace); nodeTrace.ProcessId = NodeId; txList.Add(new List <List <Trace> >() { new List <Trace>() { nodeTrace } }); } else if (trace.Name.Contains("?")) { /* RX Trace */ /* We create a copy and rename the trace so that it belongs to this node process */ Csp.Trace nodeTrace = new Csp.Trace(trace); nodeTrace.ProcessId = NodeId; rxList.Add(new List <List <Trace> >() { new List <Trace>() { nodeTrace } }); } } } /* Now we need all variations and permutations of the TX traces and the RX traces */ /* Trace calculations can be used with the interleaving operator */ List <List <Csp.Trace> > alphaTxTrace = txList[0]; for (int k = 1; k < txList.Count; k++) { Operators op = new Operators(); alphaTxTrace = op.OptParallelAdvanced(alphaTxTrace, txList[k], new List <Trace>()); } List <List <Csp.Trace> > alphaRxTrace = rxList[0]; for (int k = 1; k < rxList.Count; k++) { Operators op = new Operators(); alphaRxTrace = op.OptParallelAdvanced(alphaRxTrace, rxList[k], new List <Trace>()); } retList.AddRange(alphaTxTrace); retList.AddRange(alphaRxTrace); return(retList); }
/* the channel alphabet is constructed from its connected processes */ /* Each process only has ONE transmit trace */ public void ParseGraphP2P(EdgeList adj) { if (adj != null) { List <Tuple <string, string> > edges = adj.GetEdges(); /* A list of processes and a list of channels */ NodeList = new List <Node>(); ChannelList = new List <Channel>(); Node leftNode = null; Node rightNode = null; Csp.Trace leftNodeTxTrace = null; Csp.Trace rightNodeTxTrace = null; char syncChar = 'A'; /* Go through the list, create and reuse where nessesary */ foreach (var connection in edges) { /* Left Node */ if (NodeList.Any(p => p.NodeId == connection.Item1)) { Console.WriteLine(String.Format("Using node {0}", connection.Item1)); /* Get the existing Node */ leftNode = NodeList.First(p => p.NodeId == connection.Item1); /* Add the tx event to the node */ leftNodeTxTrace = new Csp.Trace() { ProcessId = leftNode.NodeId, Name = String.Format("!{0}", syncChar++), synchronisation = true }; leftNode.TxAlphabet.Add(leftNodeTxTrace); } else { Console.WriteLine(String.Format("Creating node {0}", connection.Item1)); /* Add the new node to the list */ leftNode = new Node(connection.Item1); /* Add the tx event to the node */ leftNodeTxTrace = new Csp.Trace() { ProcessId = leftNode.NodeId, Name = String.Format("!{0}", syncChar++), synchronisation = true }; leftNode.TxAlphabet.Add(leftNodeTxTrace); /* Add the node to the node list */ NodeList.Add(leftNode); } /* Right Node */ if (NodeList.Any(p => p.NodeId == connection.Item2)) { Console.WriteLine(String.Format("Using node {0}", connection.Item2)); /* Get the existing Node */ rightNode = NodeList.First(p => p.NodeId == connection.Item2); /* Add the tx event to the node */ rightNodeTxTrace = new Csp.Trace() { ProcessId = rightNode.NodeId, Name = String.Format("!{0}", syncChar++), synchronisation = true }; rightNode.TxAlphabet.Add(rightNodeTxTrace); } else { Console.WriteLine(String.Format("Creating node {0}", connection.Item2)); /* Add the new node to the list */ rightNode = new Node(connection.Item2); /* Add the tx event to the node */ rightNodeTxTrace = new Csp.Trace() { ProcessId = rightNode.NodeId, Name = String.Format("!{0}", syncChar++), synchronisation = true }; rightNode.TxAlphabet.Add(rightNodeTxTrace); /* Add the node to the node list */ NodeList.Add(rightNode); } /* Channel <-> */ Console.WriteLine(String.Format("Creating channel c[{0}:{1}]", connection.Item1, connection.Item2)); /* Add the channel to the channel list */ Channel channel = new Channel(leftNode, rightNode); ChannelList.Add(channel); /* Add communicating traces to the nodes and the channels */ /* Left Node Traces */ Csp.Trace leftNodeTxChan = new Csp.Trace(leftNodeTxTrace) { ProcessId = String.Format("{0}{1}", leftNode.NodeId, rightNode.NodeId) }; /* eg. !A */ Csp.Trace rightNodeRxChan = new Csp.Trace(leftNodeTxChan); /* eg. ?A */ rightNodeRxChan.Name = rightNodeRxChan.Name.Replace('!', '?'); /* Right Node Traces */ Csp.Trace rightNodeTxChan = new Csp.Trace(rightNodeTxTrace) { ProcessId = String.Format("{0}{1}", leftNode.NodeId, rightNode.NodeId) }; /* eg. !B */ Csp.Trace leftNodeRxChan = new Csp.Trace(rightNodeTxChan); /* eg. ?B */ leftNodeRxChan.Name = leftNodeRxChan.Name.Replace('!', '?'); /* Assign left node Tx trace to the channel */ channel.leftTxTrace = leftNodeTxChan; /* eg. !A */ channel.rightRxTrace = rightNodeRxChan; /* eg. ?A */ channel.rightTxTrace = rightNodeTxChan; /* eg. !B */ channel.leftRxTrace = leftNodeRxChan; /* eg. ?B */ /* Link the channel back to the nodes */ leftNode.Channels.Add(channel); rightNode.Channels.Add(channel); /* Add the Rx traces to the nodes */ leftNode.RxAlphabet.Add(new Csp.Trace(leftNodeRxChan) { ProcessId = leftNode.NodeId }); /* eg. ?B */ rightNode.RxAlphabet.Add(new Csp.Trace(rightNodeRxChan) { ProcessId = rightNode.NodeId }); /* eg. ?A */ } } }
/* The channel alphabet is constructed from its connected processes */ /* Each process only has ONE transmit trace */ public void ParseGraphNeigbours(EdgeList adj) { if (adj != null) { List <Tuple <string, string> > edges = adj.GetEdges(); /* A list of processes and a list of channels */ NodeList = new List <Node>(); ChannelList = new List <Channel>(); Node transmitNode = null; Node receiveNode = null; Csp.Trace transmitNodeTrace = null; Csp.Trace receiveNodeTrace = null; /* Go through the list, create and reuse where nessesary */ foreach (var connection in edges) { string sSyncTrace = null; /* Transmit Node */ if (!NodeList.Any(p => p.NodeId == connection.Item1)) { Console.WriteLine(String.Format("Creating node {0}", connection.Item1)); /* Add the new node to the list */ transmitNode = new Node(connection.Item1); /* Add the tx event to the node */ sSyncTrace = GetNextTxTrace(); transmitNodeTrace = new Csp.Trace() { ProcessId = transmitNode.NodeId, Name = sSyncTrace, synchronisation = true }; transmitNode.AddTxTrace(transmitNodeTrace, Channel.enChannelType.Transmit); /* Add the node to the node list */ NodeList.Add(transmitNode); } else { Console.WriteLine(String.Format("Using node {0}", connection.Item1)); /* Get the existing Node */ transmitNode = NodeList.First(p => p.NodeId == connection.Item1); /* Get the existing tx trace, if it does not exist, create one */ sSyncTrace = transmitNode.GetFirstTxTrace(); if (String.IsNullOrEmpty(sSyncTrace)) { /* The channel exists, but a transmit trace is not yet defined, it should be defined now */ sSyncTrace = GetNextTxTrace(); transmitNodeTrace = new Csp.Trace() { ProcessId = transmitNode.NodeId, Name = sSyncTrace, synchronisation = true }; transmitNode.AddTxTrace(transmitNodeTrace, Channel.enChannelType.Transmit); } transmitNodeTrace = transmitNode.TxAlphabet.First(p => p.Name.Contains("!")); } /* Receive Node */ if (!NodeList.Any(p => p.NodeId == connection.Item2)) { Console.WriteLine(String.Format("Creating node {0}", connection.Item2)); /* Add the new node to the list */ receiveNode = new Node(connection.Item2); /* Add the tx event to the node */ receiveNodeTrace = new Csp.Trace() { ProcessId = receiveNode.NodeId, Name = GetRxTrace(sSyncTrace), synchronisation = true }; receiveNode.AddRxTrace(receiveNodeTrace, Channel.enChannelType.Receive); /* Add the node to the node list */ NodeList.Add(receiveNode); } else { Console.WriteLine(String.Format("Using node {0}", connection.Item2)); /* Get the existing Node */ receiveNode = NodeList.First(p => p.NodeId == connection.Item2); /* Add the current rx trace to the existing node */ receiveNodeTrace = new Csp.Trace() { ProcessId = receiveNode.NodeId, Name = GetRxTrace(sSyncTrace), synchronisation = true }; receiveNode.AddRxTrace(receiveNodeTrace, Channel.enChannelType.Receive); } } } }
/* The channel alphabet is constructed from its connected processes */ public void ParseGraphSimplex(EdgeList adj) { if (adj != null) { List <Tuple <string, string> > edges = adj.GetEdges(); /* A list of processes and a list of channels */ NodeList = new List <Node>(); ChannelList = new List <Channel>(); Node transmitNode = null; Node receiveNode = null; Csp.Trace transmitNodeTrace = null; Csp.Trace receiveNodeTrace = null; /* Go through the list, create and reuse where nessesary */ foreach (var connection in edges) { string sSyncTrace = null; /* Transmit Node */ if (!NodeList.Any(p => p.NodeId == connection.Item1)) { Console.WriteLine(String.Format("Creating node {0}", connection.Item1)); /* Add the new node to the list */ transmitNode = new Node(connection.Item1); /* Add the tx event to the node */ sSyncTrace = GetNextTxTrace(); transmitNodeTrace = new Csp.Trace() { ProcessId = transmitNode.NodeId, Name = sSyncTrace, synchronisation = true }; transmitNode.AddTxTrace(transmitNodeTrace, Channel.enChannelType.Transmit); /* Add the node to the node list */ NodeList.Add(transmitNode); } else { Console.WriteLine(String.Format("Using node {0}", connection.Item1)); /* Get the existing Node */ transmitNode = NodeList.First(p => p.NodeId == connection.Item1); /* Add the tx event to the node */ sSyncTrace = GetNextTxTrace(); transmitNodeTrace = new Csp.Trace() { ProcessId = transmitNode.NodeId, Name = sSyncTrace, synchronisation = true }; transmitNode.AddTxTrace(transmitNodeTrace, Channel.enChannelType.Transmit); } /* Receive Node */ if (!NodeList.Any(p => p.NodeId == connection.Item2)) { Console.WriteLine(String.Format("Creating node {0}", connection.Item2)); /* Add the new node to the list */ receiveNode = new Node(connection.Item2); /* Add the tx event to the node */ receiveNodeTrace = new Csp.Trace() { ProcessId = receiveNode.NodeId, Name = GetRxTrace(sSyncTrace), synchronisation = true }; receiveNode.AddRxTrace(receiveNodeTrace, Channel.enChannelType.Receive); /* Add the node to the node list */ NodeList.Add(receiveNode); } else { Console.WriteLine(String.Format("Using node {0}", connection.Item2)); /* Get the existing Node */ receiveNode = NodeList.First(p => p.NodeId == connection.Item2); /* Add the current rx trace to the existing node */ receiveNodeTrace = new Csp.Trace() { ProcessId = receiveNode.NodeId, Name = GetRxTrace(sSyncTrace), synchronisation = true }; receiveNode.AddRxTrace(receiveNodeTrace, Channel.enChannelType.Receive); } } } }