-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportFile.java
188 lines (149 loc) · 5.72 KB
/
importFile.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/******************************************************************************/
/* PROJET : NoC Simulator */
/* SOCIETE : Oran University */
/* TAG : NoC_20151122 */
/* NOM DU FICHIER : importFile.java */
/* Laboratory : LAPECI */
/* DESCRIPTION : */
/* L'objet de cette classe est d'instancier les Flits/paquets */
/* a partir du fichier scenario.xml */
/* Les Flit sont généré avec : Scr, Dest, Type */
/* */
/* */
/* Intput: Scenario.xml */
/* Output: ListPaquet */
/******************************************************************************/
/* Date de creation : 01/06/15 */
/******************************************************************************/
package Router;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class importFile {
int NocSize;
int VcBufferSize;
int NumberVCbuffer;
ArrayList<Paquet> ListPaquet;
public importFile(String FileName) {
FileInputStream fstream;
boolean RunSimulation = false;
boolean scenarioBegin = false;
boolean paquetBegin = false;
ListPaquet = new ArrayList<Paquet>();
try {
fstream = new FileInputStream(FileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String temp2[];
while (((strLine = br.readLine()) != null)
&& RunSimulation == false) {
// System.out.println(strLine);
String[] temp = strLine.split(" ");
/***************************************************/
if (temp.length > 0 && temp[0].equals("<Noc")) {
temp2=temp[1].split("=");
NocSize = Integer.parseInt(temp2[1]);
}
/***************************************************/
if (temp.length > 0 && temp[0].equals("<Router")) {
temp2=temp[1].split("=");
VcBufferSize = Integer.parseInt(temp2[1]);
temp2=temp[2].split("=");
NumberVCbuffer = Integer.parseInt(temp2[1]);
}
/***************************************************/
if (temp.length > 0 && temp[0].equals("<scenario>"))
scenarioBegin = true;
// ------------------------------------------------//
while (scenarioBegin) {
strLine = br.readLine();
temp = strLine.split(" ");
int vc = 0;
if (temp.length > 0 && temp[0].equals("<paquet")) {
paquetBegin = true;
Paquet p = new Paquet();
// dans le paquet-----------------------------
while (paquetBegin) {
//******************************** traitement pour VC
temp2 = temp[1].split("=");
if (temp2.length > 0 && temp2[0].equals("Vc")) {
p.addVc(Integer.parseInt(temp2[1]));
}
//******************************** traitement pour ArrivalCycle
temp2 = temp[2].split("=");
if (temp2.length > 0
&& temp2[0].equals("ArrivalCycle")) {
p.ArrivalCycle = Integer.parseInt(temp2[1]);
}
//********************************** traitement pour Priority
temp2 = temp[3].split("=");
if (temp2.length > 0
&& temp2[0].equals("Priority")) {
p.Priority = Integer.parseInt(temp2[1]);
}
// Lire la deuxieme ligne du paquet et construire les flit
strLine = br.readLine();
temp = strLine.split(" ");
Flit flit = new Flit();
if ((strLine) != null && temp.length > 0
&& temp[0].equals("<Flit")) {
if (temp[1].equals("type=1")) {
temp2 = temp[1].split("=");
flit.setType(Integer.parseInt(temp2[1]));
flit.Priority=p.Priority;
temp2 = temp[2].split("=");
flit.setSrc(Integer.parseInt(temp2[1]));
temp2 = temp[3].split("=");
flit.setDest(Integer.parseInt(temp2[1]));
temp2 = temp[4].split("=");
flit.setNumberFlit(Integer.parseInt(temp2[1]));
flit.ArivelTime=p.ArrivalCycle;//le flit chargé ariveletime de paquet
} else {
temp2 = temp[1].split("=");
flit.setType(Integer.parseInt(temp2[1]));
flit.ArivelTime=p.ArrivalCycle;//le flit chargé ariveletime de paquet
flit.Priority=p.Priority;
}
p.addFlit(flit);
}
if (temp.length > 0
&& (temp[0].equals("</paquet>"))) {
paquetBegin = false;
ListPaquet.add(p);
}
}
}
if (temp.length > 0 && temp[0].equals("</scenario>")) {
scenarioBegin = false;
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Affichier les Flit
/*for(int i=0;i<3;i++)
{
System.out.println("le Paquet 1 son flit "+i);
System.out.println("********************** Priority= "+ListPaquet.get(6).paquet.get(i).Priority);
}*/
}
public int getNocSize() {
return NocSize;
}
public int getVcBufferSize() {
return VcBufferSize;
}
public int getNumberVCbuffer() {
return NumberVCbuffer;
}
}