-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate.adb
194 lines (166 loc) · 8.1 KB
/
simulate.adb
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
189
190
191
192
193
194
with ATMTypes; use ATMTypes;
with switch_element; use switch_element;
with my_io; use my_io;
with sim_bits; use sim_bits;
with Ada.Text_IO; use Ada.Text_IO;
Procedure Simulate is
NetworkNodes : array (1 .. MaxNumberOfNodes) of ATMElement;
CellsInTransit : array (1 .. (NoOfPorts * MaxNumberOfNodes)) of TransitCell;
links : array (1 .. MaxNumberOfNodes, 1 .. NoOfPorts) of LinkStruct;
NewCell : ATMCell := (0, 0, 0);
dummy : character := 'L';
nodeNumber, nodePort, cycleNumber, x, y : integer := 1;
cellReady, nextFreeTransit, TransitCellToSwitch : integer := 1;
------------------------------------------------------------------------------
Procedure setup_screen is
column : Positive_Count;
Begin
my_io.display.cls;
column := (40 - (Title'LENGTH / 2));
display.displayString (Title, 1, column); -- Centres Title on Screen
column := (79 - Author'LENGTH);
my_io.display.displayString (Author, 2, column); -- Right Justifies Author on screen
my_io.display.displayString ("Cycle Number", 4, 10);
End setup_screen;
Procedure setup_file is
Begin
display.DisplayLogMsg("setup_file()" );
my_io.fileInOut.create (fd, datafilename);
my_io.fileInOut.put_str (fd, Title);
my_io.fileInOut.put_str (fd, " Version:");
my_io.fileInOut.put_str (fd, Version);
my_io.fileInOut.put_str (fd, " By:");
my_io.fileInOut.put_str (fd, Author);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, "Number of Switches:");
my_io.fileInOut.put_int (fd, MaxNumberOfNodes, 2);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_str (fd, "Number of Ports per Switch:");
my_io.fileInOut.put_int (fd, NoOfPorts, 2);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_str (fd, "Buffer Size:");
my_io.fileInOut.put_int (fd, MaxBufferSize, 2);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_str (fd, "Number of Routes per Switch:");
my_io.fileInOut.put_int (fd, NoRoutes, 2);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " Switch to Switch Links");
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, "From Switch, Port to Switch, Port");
for x in 1 .. MaxNumberOfNodes loop
display.DisplayLogMsg ("setup_file() loop x=" & Integer'Image(x) );
for y in 1 .. NoOfPorts loop
display.DisplayLogMsg ("setup_file() loop y=" & Integer'Image(y) );
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_int (fd, x, 2);
my_io.fileInOut.put_str (fd, ",");
my_io.fileInOut.put_int (fd, y, 2);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_int (fd, links (x, y).Switch, 2);
my_io.fileInOut.put_str (fd, ",");
my_io.fileInOut.put_int (fd, links (x, y).Port, 2);
end loop;
end loop;
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
for x in 1 .. MaxNumberOfNodes loop
display.DisplayLogMsg ("setup_file() initialising node " & Integer'Image (x) );
NetworkNodes(x).Initialise (x);
end loop;
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " Cycle No Switch No InPort Cell Header Outport Cell Header No. Cells");
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " In After Route In Buffer");
display.DisplayLogMsg ("setup_file() end" );
End setup_file;
Function GenerateNewCell (port : INTEGER) return ATMCell is
GeneratedCell : ATMCell;
Begin
GeneratedCell.Port := port;
GeneratedCell.CellHeader := random (noRoutes)+1;
GeneratedCell.CellBody := random (99)+1;
return GeneratedCell;
End GenerateNewCell;
Begin
for nodeNumber in 1 .. MaxNumberOfNodes loop
for y in 1 .. NoOfPorts loop
links (nodeNumber, y).Port := random (NoOfPorts)+1;
links (nodeNumber, y).Switch := random (MaxNumberOfNodes)+1;
end loop;
end loop;
setup_screen;
setup_file;
dummy := 'l';
cycleNumber := 1;
loop -- One loop is a single time cycle
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_int (fd, cycleNumber, 3);
my_io.display.displayint (cycleNumber, 3, 5, 24);
for nodeNumber in 1 .. MaxNumberOfNodes loop
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, " ");
my_io.fileInOut.put_int (fd, nodeNumber, 2);
for nodePort in 1 .. NoOfPorts loop
if Random (2) = 0 then
NetworkNodes (nodeNumber).CellDeparture (cellReady,nodePort,NewCell);
else
CellReady := 0;
end if;
if CellReady = 1 then
CellsInTransit (nextFreeTransit).CellHeader := NewCell.CellHeader;
CellsInTransit (nextFreeTransit).CellBody := NewCell.CellBody;
CellsInTransit (nextFreeTransit).ToPort := links (nodeNumber,nodePort).Port;
CellsInTransit (nextFreeTransit).ToSwitch := links (nodeNumber,nodePort).Switch;
end if;
TransitCellToSwitch := 0;
for x in 1 .. nextFreeTransit loop
if (CellsInTransit (x).ToSwitch = nodeNumber) AND (CellsInTransit (x).ToPort = nodePort) then
TransitCellToSwitch := x;
NewCell.CellHeader := CellsInTransit (x).CellHeader;
NewCell.CellBody := CellsInTransit (x).CellBody;
NewCell.Port := nodePort;
exit;
end if;
end loop;
if TransitCellToSwitch > 0 then
NetworkNodes (nodeNumber).CellArrival (NewCell);
for x in TransitCellToSwitch .. nextFreeTransit loop
CellsInTransit (x) := CellsInTransit (x + 1);
end loop;
else
NewCell := GenerateNewCell (nodePort);
NetworkNodes (nodeNumber).CellArrival (NewCell);
end if;
end loop;
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, "--------------------------------------------------------------------------------");
end loop;
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, "==================================================================================");
my_io.fileInOut.put_line (fd);
cycleNumber := cycleNumber + 1;
if cycleNumber > NoOfLoops then
exit;
end if;
end loop;
my_io.fileInOut.put_line (fd);
my_io.fileInOut.put_str (fd, "End Of File");
my_io.fileInOut.close (fd);
for count in 1 .. MaxNumberOfNodes loop
NetworkNodes (count).StopNow;
end loop;
exception
when tasking_error => my_io.display.Pause ("Tasking Error in Simulate ", 24, 1);
when program_error => my_io.display.Pause ("Program Error in Simulate ", 24, 1);
when storage_error => my_io.display.Pause ("Storage Error in Simulate ", 24, 1);
when numeric_error => my_io.display.Pause ("Numeric Error in Simulate ", 24, 1);
-- when constraint_error => my_io.display.Pause ("Constraint Error in Simulate ", 24, 1);
when others => my_io.display.Pause ("Other Error in Simulate ", 24, 1);
End simulate;