Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package tmltranslator.tonetwork;
import tmltranslator.*;
import java.util.Vector;
/**
* Class TaskNetworkInterfaceOUT
* Creation: 07/05/2019
*
* @author Ludovic Apvrille
* @version 1.0 07/05/2019
*/
public class TaskNetworkInterfaceOUT extends TMLTask {
protected int nbOfVCs;
public TaskNetworkInterfaceOUT(String name, Object referenceToClass, Object referenceToActivityDiagram) {
super(name, referenceToClass, referenceToActivityDiagram);
}
// feedbackEvents: one per vc
// inputEvt, channels: one per task
// outputChannel, output event: only one, common: this is a network interface, only one exit!
public void generate(int nbOfVCs, Vector<TMLEvent> outputFeedbackEvents, TMLEvent packetOutFromOUT,
int i;
this.nbOfVCs = nbOfVCs;
// Attributes
TMLAttribute dst = new TMLAttribute("dst", "dst", new TMLType(TMLType.NATURAL), "0");
this.addAttribute(dst);
TMLAttribute pktlen = new TMLAttribute("pktlen", "pktlen", new TMLType(TMLType.NATURAL), "0");
this.addAttribute(pktlen);
TMLAttribute vc = new TMLAttribute("vc", "vc", new TMLType(TMLType.NATURAL), "0");
this.addAttribute(vc);
TMLAttribute eop = new TMLAttribute("eop", "eop", new TMLType(TMLType.NATURAL), "0");
this.addAttribute(eop);
TMLAttribute chid = new TMLAttribute("chid", "chid", new TMLType(TMLType.NATURAL), "0");
this.addAttribute(chid);
TMLAttribute memSpace = new TMLAttribute("memSpace", "memSpace", new TMLType(TMLType.NATURAL), "4096");
this.addAttribute(memSpace);
// Events and channels
for(TMLEvent evt: outputFeedbackEvents) {
addTMLEvent(evt);
}
addTMLEvent(packetOutFromOUT);
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
addReadTMLChannel(outputChannelFromOUT);
// Activity Diagram
TMLStartState start = new TMLStartState("mainStart", referenceObject);
activity.setFirst(start);
//Main Sequence
TMLSequence mainSequence = new TMLSequence("mainSequence", referenceObject);
addElement(start, mainSequence);
// Left branch of left sequence
// For each VC, send a feedback
TMLActivityElement previous = mainSequence;
for(i=0; i<nbOfVCs; i++) {
TMLSendEvent sendEvtFeedback = new TMLSendEvent("sendEvtFeedback_VC" + i, referenceObject);
sendEvtFeedback.setEvent(outputFeedbackEvents.get(i));
addElement(previous, sendEvtFeedback);
previous = sendEvtFeedback;
}
TMLStopState stopOfLeftBranch = new TMLStopState("stopStateOfLeftBranchOfMainSequence", referenceObject);
addElement(previous, stopOfLeftBranch);
// Right branch of main sequence
//
TMLForLoop loop = new TMLForLoop("mainLoop", referenceObject);
loop.setInfinite(true);
addElement(mainSequence, loop);
// Waiting for a packet from OUT
TMLWaitEvent waitingForPacketFromOUT = new TMLWaitEvent("waitingForPacketFromOUT", referenceObject);
waitingForPacketFromOUT.setEvent(packetOutFromOUT);
waitingForPacketFromOUT.addParam("pktlen");
waitingForPacketFromOUT.addParam("dst");
waitingForPacketFromOUT.addParam("vc");
waitingForPacketFromOUT.addParam("eop");
apvrille
committed
waitingForPacketFromOUT.addParam("chid");
addElement(loop, waitingForPacketFromOUT);
// Reading on channel
TMLReadChannel readFromOUT = new TMLReadChannel("readFromOUT", referenceObject);
readFromOUT.setNbOfSamples("1");
readFromOUT.addChannel(outputChannelFromOUT);
addElement(waitingForPacketFromOUT, readFromOUT);
// subsequence
TMLSequence internalSeq = new TMLSequence("internalSeq", referenceObject);
addElement(readFromOUT, internalSeq);
// Left branch: test on eop
TMLChoice testingEOP = new TMLChoice("testingEOP", referenceObject);
addElement(internalSeq, testingEOP);
// Left branch of choice: eop==1
//New choice on all possible destination depending on chid
packetChoice = new TMLChoice("testingPacket", referenceObject);
addElement(testingEOP, packetChoice);
TMLStopState stopInvalid = new TMLStopState("InvalidCHID", referenceObject);
addElement(packetChoice, stopInvalid);
packetChoice.addGuard("chid == (0-1)");
// Right branch of choice
TMLStopState stopOfRightBranchOfChoice = new TMLStopState("stopOfRightBranchOfChoice", referenceObject);
addElement(testingEOP, stopOfRightBranchOfChoice);
testingEOP.addGuard("not(eop == 1)");
// Right branch of internal seg
// Test on vc
TMLChoice testingVC = new TMLChoice("testingVC", referenceObject);
addElement(internalSeq, testingVC);
for(i=0; i<nbOfVCs; i++) {
TMLSendEvent sendEvtFeedback = new TMLSendEvent("sendEvtFeedback_VC" + i, referenceObject);
sendEvtFeedback.setEvent(outputFeedbackEvents.get(i));
addElement(testingVC, sendEvtFeedback);
testingEOP.addGuard("vc == " + i);
TMLStopState stopVC = new TMLStopState("stopVC" + i, referenceObject);
addElement(sendEvtFeedback, stopVC);
}
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
public void postProcessing(Vector<TMLEvent> packetsAvailable, Vector<String> channelIDs) {
if (packetsAvailable.size() == 0) {
TMLStopState stopOfLeftBranchOfChoice = new TMLStopState("stopNoDestinationTask", referenceObject);
addElement(packetChoice, stopOfLeftBranchOfChoice);
return;
}
for (TMLEvent packetAvailable: packetsAvailable) {
addTMLEvent(packetAvailable);
}
int i = 0;
for(TMLEvent packetAvailable: packetsAvailable) {
TMLSendEvent sendEvtPktAvailable = new TMLSendEvent("sendEvtPktAvailable", referenceObject);
sendEvtPktAvailable.setEvent(packetAvailable);
sendEvtPktAvailable.addParam("pktlen");
sendEvtPktAvailable.addParam("dst");
sendEvtPktAvailable.addParam("vc");
sendEvtPktAvailable.addParam("eop");
sendEvtPktAvailable.addParam("chid");
addElement(packetChoice, sendEvtPktAvailable);
packetChoice.addGuard("chid == " + channelIDs.get(i));
TMLStopState stopOfLeftBranchOfChoice = new TMLStopState("stopOfLeftBranchOfChoice__" + channelIDs.get(i), referenceObject);
addElement(sendEvtPktAvailable, stopOfLeftBranchOfChoice);
i++;
}