-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_version_simulator.nlogo
5654 lines (4647 loc) · 115 KB
/
old_version_simulator.nlogo
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
breed [routers router]
breed [espioes espiao]
extensions [csv]
routers-own
[
; north-buffer
; east-buffer
; south-buffer
; west-buffer
; PE-buffer
occupancy-rate
buffer-in
buffer-out
temporary-buffer-PE
busy
list-temporario
routing-table
sum-heatmap-occ-i
sum-heatmap-occ-o
sum-heatmap-occ-io
sum-heatmap-max-i
sum-heatmap-max-o
sum-heatmap-max-io
]
globals
[
;temporario
temporario
cheio
execution-time
total-flits-received
total-packets-received
min-latency
min-hops
acc-latency
acc-hops
first-flit-ever
avg-latency
avg-hops
max-latency
max-hops
cycles-left-to-generate
packet-number
file-name
list-orientated-source-id
list-orientated-destination-x
list-orientated-destination-y
stop-simulation
name-of-files
]
to setup
;temporario
set cheio 0
set temporario 0
clear-all
set first-flit-ever true
generate-noc
set cycles-left-to-generate ticks-to-new-traffic-generation
set packet-number 0
; ask routers
; [
; set north-buffer ["N"]
; set east-buffer ["E"]
; set south-buffer ["S"]
; set west-buffer ["W"]
; set PE-buffer ["PE"]
;
; set routing-table []
;
; set list-temporario []
;
; set list-temporario lput north-buffer list-temporario
; set list-temporario lput east-buffer list-temporario
; set list-temporario lput south-buffer list-temporario
; set list-temporario lput west-buffer list-temporario
; set list-temporario lput PE-buffer list-temporario
;
; ]
ask routers
[
set occupancy-rate 0
set routing-table []
set busy [-1 -1 -1 -1 -1]
set buffer-in []
set buffer-out []
set temporary-buffer-PE []
set sum-heatmap-occ-i 0
set sum-heatmap-occ-o 0
set sum-heatmap-occ-io 0
set sum-heatmap-max-i 0
set sum-heatmap-max-o 0
set sum-heatmap-max-io 0
]
; let time (remove-item 6(remove-item 7(remove-item 8 (remove "-"(remove " "(remove "."(remove ":" date-and-time)))))))
; let date (remove "-" (substring date-and-time 16 27))
; let time (remove "." remove ":" remove " " (substring date-and-time 0 15))
let name-of-file date-and-time
set name-of-file (replace-item 2 name-of-file "-")
set name-of-file (replace-item 5 name-of-file "-")
set name-of-file (replace-item 8 name-of-file "-")
set name-of-file (remove-item 7 name-of-file)
set name-of-file (remove-item 7 name-of-file)
set name-of-file (remove-item 7 name-of-file)
set name-of-file (remove-item 7 name-of-file)
set name-of-file (remove-item 8 name-of-file)
set file-name (word name-of-file".csv")
;set file-name 15
;set file-name word file-name ".csv"
; set list-orientated-source-id [1 3 5]
; set list-orientated-destination-x [-49 -49 -49]
; set list-orientated-destination-y [48 48 48]
set list-orientated-source-id []
set list-orientated-destination-x []
set list-orientated-destination-y []
; ask router 0
; [
; ;a
;
; set temporary-buffer-PE [[0 "H" 0 -50 48 0 0] [0 "B" 0 -50 48 0 0] [0 "T" 0 -50 48 0 0]]
; ]
; ask router 2
; [
; set temporary-buffer-PE [[1 "H" 0 -48 48 0 0] [1 "B" 0 -48 48 0 0] [1 "T" 0 -48 48 0 0]]
; ]
reset-ticks
set stop-simulation false
end
to update-arbitrator
ifelse (arbitrator = "Round-Robin")
[
ifelse(ticks = 0)
[
ask routers
[
;; ESSE IF É SÓ PARA TESTES
ifelse (who = 0)
[
set buffer-in []
;set buffer-in lput ["N" [18 "H" 2 -50 49 11 1] [18 "B" 2 -50 49 11 1]] buffer-in
;set buffer-in lput ["N" [18 "H" 2 -50 49 11 1]] buffer-in
set buffer-in lput ["N"] buffer-in
set buffer-in lput ["E"] buffer-in
set buffer-in lput ["S"] buffer-in
; set buffer-in lput ["W" [-2 "H" -1 -50 48 0 -1] [-2 "B" -1 -50 48 0 -1] [-2 "T" -1 -50 48 0 -1]] buffer-in
; set buffer-in lput ["PE" [0 "H" -1 -50 48 0 -1] [0 "B" -1 -50 48 0 -1] [0 "T" -1 -50 48 0 -1]] buffer-in
set buffer-in lput ["W"] buffer-in
set buffer-in lput ["PE"] buffer-in
]
[
set buffer-in []
;set buffer-in lput ["N" [18 "H" 2 -50 49 11 1] [18 "B" 2 -50 49 11 1]] buffer-in
;set buffer-in lput ["N" [18 "H" 2 -50 49 11 1]] buffer-in
set buffer-in lput ["N"] buffer-in
set buffer-in lput ["E"] buffer-in
set buffer-in lput ["S"] buffer-in
set buffer-in lput ["W"] buffer-in
set buffer-in lput ["PE"] buffer-in
]
set buffer-out []
set buffer-out lput ["N"] buffer-out
set buffer-out lput ["E"] buffer-out
set buffer-out lput ["S"] buffer-out
set buffer-out lput ["W"] buffer-out
set buffer-out lput ["PE"] buffer-out
]
]
[
ask routers
[
let temporary-list []
set temporary-list item 0 buffer-in
set buffer-in remove-item 0 buffer-in
set buffer-in lput temporary-list buffer-in
]
]
]
[
;;Para implementar outros árbitros
]
end
to generate-noc
;;Posicionamento dos roteadores
let initial-x -50
let initial-y 50
;let initial-x 0
;let initial-y 0
let lines number_of_lines
let columns number_of_columns
while [lines > 0]
[
while [columns > 0]
[
create-routers 1
[
set shape "square"
set color white
set size 0.5
setxy initial-x initial-y
]
set initial-x initial-x + 1
set columns (columns - 1)
]
set initial-x -50
; set initial-x 0
set initial-y (initial-y - 1)
set columns number_of_columns
set lines (lines - 1)
]
end
to orientated-send
ask router (destination-id)
[
set list-orientated-source-id lput source-id list-orientated-source-id
set list-orientated-destination-x lput xcor list-orientated-destination-x
set list-orientated-destination-y lput ycor list-orientated-destination-y
]
; set list-orientated-source-id lput 1 list-orientated-source-id
; set list-orientated-destination-x lput -49 list-orientated-destination-x
; set list-orientated-destination-y lput 48 list-orientated-destination-y
;
; set list-orientated-source-id lput 3 list-orientated-source-id
; set list-orientated-destination-x lput -49 list-orientated-destination-x
; set list-orientated-destination-y lput 48 list-orientated-destination-y
;
; set list-orientated-source-id lput 5 list-orientated-source-id
; set list-orientated-destination-x lput -49 list-orientated-destination-x
; set list-orientated-destination-y lput 48 list-orientated-destination-y
end
to manual-send
let x-destination 0
let y-destination 0
ask router (destination-id)
[
set x-destination xcor
set y-destination ycor
]
ask router (source-id)
[
ifelse (((length temporary-buffer-PE) + packet-size) <= (temporary-buffer-size))
[
set temporary-buffer-PE lput (list packet-number "H" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
let number-of-bodies (packet-size - 2)
while [number-of-bodies > 0]
[
set temporary-buffer-PE lput (list packet-number "B" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
set number-of-bodies (number-of-bodies - 1)
]
set temporary-buffer-PE lput (list packet-number "T" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
set packet-number (packet-number + 1)
]
[
;
]
]
;orientated-source-id
;orientated-destination-id
end
to generate-new-packets
ifelse (traffic-type = "Random-By-Radius")
[
set temporario (temporario + 1)
;let number-of-bodies (packet-size - 2)
; while [number-of-bodies > 0]
; [
; ask one-of routers
; [
; let x-source xcor
; let y-source ycor
;
; ask one-of other routers in-radius radius
; [
; let x-destination xcor
; let y-destination ycor
;
; ;temporary-buffer-PE
;
; set temporary-buffer-PE lput [packet-number "B" -1 -50 48 0 -1] temporary-buffer-PE
;
; set packet-number (packet-number + 1)
;
;
; ]
; ]
;
; set number-of-bodies (number-of-bodies - 1)
; ]
ask one-of routers
[
ifelse (((length temporary-buffer-PE) + packet-size) <= (temporary-buffer-size))
[
;Esse será o destino
let x-destination xcor
let y-destination ycor
ask one-of other routers in-radius radius
[
;Esse será a origem (onda a mensagem será gerada)
;let x-source xcor
;let y-source ycor
;temporary-buffer-PE
;[-2 "H" -1 -50 48 0 -1]
set temporary-buffer-PE lput (list packet-number "H" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
let number-of-bodies (packet-size - 2)
while [number-of-bodies > 0]
[
set temporary-buffer-PE lput (list packet-number "B" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
set number-of-bodies (number-of-bodies - 1)
]
set temporary-buffer-PE lput (list packet-number "T" ticks x-destination y-destination 0 ticks) temporary-buffer-PE
set packet-number (packet-number + 1)
]
]
[
set cheio (cheio + 1)
]
]
]
[
ifelse (traffic-type = "Orientated")
[
set temporario (temporario + 1)
if (length list-orientated-source-id > 0)
[
;
;list-orientated-source-id
;list-orientated-destination-x
;list-orientated-destination-y
let i random (length list-orientated-source-id)
;
; print (item i list-orientated-source-id)
; print (item i list-orientated-destination-x)
; print (item i list-orientated-destination-y)
ask router (item i list-orientated-source-id)
[
ifelse (((length temporary-buffer-PE) + packet-size) <= (temporary-buffer-size))
[
set temporary-buffer-PE lput (list packet-number "H" ticks (item i list-orientated-destination-x) (item i list-orientated-destination-y) 0 ticks) temporary-buffer-PE
let number-of-bodies (packet-size - 2)
while [number-of-bodies > 0]
[
set temporary-buffer-PE lput (list packet-number "B" ticks (item i list-orientated-destination-x) (item i list-orientated-destination-y) 0 ticks) temporary-buffer-PE
set number-of-bodies (number-of-bodies - 1)
]
set temporary-buffer-PE lput (list packet-number "T" ticks (item i list-orientated-destination-x) (item i list-orientated-destination-y) 0 ticks) temporary-buffer-PE
; print "roteador"
; print who
; print temporary-buffer-PE
set packet-number (packet-number + 1)
]
[
set cheio (cheio + 1)
]
]
;print "--"
]
]
[
; Para implementar novos tipos de tráfego
]
]
end
to go
; ask router 7
; [
; print buffer-in
; ]
if (number_of_lines * number_of_columns < 2)
[
user-message (word "The simulation must have at least two routers")
set stop-simulation true
stop
]
if (ticks = simulation-length)
[
file-close
;user-message (temporario)
;user-message (cheio)
;print-heatmap
set stop-simulation true
stop
]
;Gerar Tráfego
if (generate-traffic)
[
ifelse (cycles-left-to-generate = 1)
[
let number-of-new-packets packets-per-generation
while [number-of-new-packets > 0]
[
generate-new-packets
set number-of-new-packets (number-of-new-packets - 1)
]
set cycles-left-to-generate ticks-to-new-traffic-generation
]
[
set cycles-left-to-generate (cycles-left-to-generate - 1)
]
]
; print "***"
; print "inicio do ciclo"
; print ticks
; ask routers
; [
; print "--"
; print who
; print "bin"
; print buffer-in
; print "bout"
; print buffer-out
; print "temporary"
; print temporary-buffer-PE
; print "--"
; ]
; print "***"
if (ticks = 0)
[
reset-timer
]
;print "--------------------------------------------------------------"
;print "No tick"
;print ticks
; ask routers
; [
; ;print "-------------------------------"
; ;print "roteador"
; ;print who
; ;print "Inicio"
; ;print "buffer-in"
; ;print buffer-in
; ;print "buffer-out"
; ;print buffer-out
; ;print "busy"
; ;print busy
; ;print "tabela de roteamento"
; ;print routing-table
; ;print "-------------------------------"
; ]
; ;print "-------------------------------"
;;print "---"
;;print "diminuindo ciclos"
;Diminuir ciclos - tabela de roteamento, buffer de saida
;ask router 0
ask routers
[
update-arbitrator
if (ticks > 0)
[
;Passar flits do buffer temporário do PE para o PE real (entrada)
if (length temporary-buffer-PE > 0)
[
let aa 0
while [aa < length buffer-in]
[
;;print item 0 (item aa buffer-in)
if (item 0 (item aa buffer-in) = "PE")
[
; if (length item aa buffer-in <= buffer-in-size)
; [
;
; ]
; ;print "**"
; ;print length item aa buffer-in
; ;print buffer-in-size
; ;print "**"
;print "b-in antes de mexer"
;print buffer-in
;print "temporary-buffer-PE antes de mexer"
;print temporary-buffer-PE
while [length item aa buffer-in <= buffer-in-size AND length temporary-buffer-PE > 0]
[
; print "aehoo"
; print who
; ;print "**"
; ;print length item aa buffer-in
; ;print buffer-in-size
; ;print "**"
let aaa item 0 temporary-buffer-PE
; print "---"
; print "aaa"
; print aaa
set aaa (replace-item 2 aaa ticks)
set aaa (replace-item 6 aaa ticks)
; print "aaa novo"
; print aaa
;
; print "---"
let bbb item aa buffer-in
set bbb (lput aaa bbb)
; ;print "bbb:"
; ;print bbb
; set buffer-in (replace-item c1 buffer-in (remove-item 1 (item c1 buffer-in)))
set buffer-in (replace-item aa buffer-in bbb)
; print buffer-in
; set buffer-in replace-item aa bbb buffer-in
set temporary-buffer-PE but-first temporary-buffer-PE
]
; print "temporario e bin depois de mover"
; print temporary-buffer-PE
; print buffer-in
;print "b-in depois de mexer"
;print buffer-in
;print "temporary-buffer-PE depois de mexer"
;print temporary-buffer-PE
]
set aa (aa + 1)
]
]
; if (who = 0)
; [
; print "temporario e bin depois de mover"
; print temporary-buffer-PE
; print buffer-in
; ]
;Pra testes
; set routing-table fput [20 "PE" 1] routing-table
; set routing-table fput [50 "PE" 1] routing-table
let num-cycles ""
let c1 0
;;print "tabela de roteamento antes"
;;print routing-table
while [c1 < length routing-table]
[
;;;print "-"
;;;print item c1 routing-table
if ((item 2 (item c1 routing-table)) > 0)
[
set num-cycles (item 2 (item c1 routing-table)) - 1
;;;print num-cycles
set routing-table (replace-item c1 routing-table (replace-item 2 (item c1 routing-table) num-cycles))
]
;set buffer-in (replace-item c1 buffer-in (remove-item 1 (item c1 buffer-in)))
;;;print routing-table
set c1 (c1 + 1)
;;;print "-"
]
;;print "tabela de roteamento depois"
;;print routing-table
set num-cycles ""
set c1 0
;set buffer-out [["N" [18 "H" 2 -50 49 11 1 10]] ["E"] ["S" [18 "H" 2 -50 49 11 1 15] [18 "H" 2 -50 49 11 1 20]] ["W"] ["PE"]]
;;print "buffer-out antes"
;;print buffer-out
;;print "começando a processar buffer-out"
;;print "c1"
;;print c1
while [c1 < length buffer-out]
[
;;;print "-"
;set num-cycles (item 2 (item c1 routing-table)) - 1
;;;print num-cycles
;set routing-table (replace-item c1 routing-table (replace-item 2 (item c1 routing-table) num-cycles))
;;;print routing-table
;;print "processando a porta"
;;print item 0 (item c1 buffer-out)
if (length item c1 buffer-out > 1)
[
;;print "na porta"
;;print item 0 (item c1 buffer-out)
;;print "tem X mensagens"
;;print length item c1 buffer-out
let c2 1
while [c2 < (length item c1 buffer-out)]
[
;;print "imprimindo as mensagens individualmente"
;;print item c2 (item c1 buffer-out)
if ((item 7 (item c2 (item c1 buffer-out))) > 0)
[
set num-cycles (item 7 (item c2 (item c1 buffer-out))) - 1
;;print "num-cycles"
;;print num-cycles
; ;set routing-table (replace-item c1 routing-table (replace-item 2 (item c1 routing-table) num-cycles))
;
; ;fez alguma diferença, mas ainda não funciona
; ;set buffer-out (replace-item c1 buffer-out (replace-item c2 (item c1 buffer-out) num-cycles) )
;
;
let kk []
set kk item c2 (item c1 buffer-out)
;;print "kk"
set kk (replace-item 7 (item c2 (item c1 buffer-out)) num-cycles)
;;print kk
;
;;print "aaa"
;;print item c2 (item c1 buffer-out)
;set buffer-out (replace-item c1 (item c1 buffer-out) kk)
set buffer-out (replace-item c1 buffer-out (replace-item c2 (item c1 buffer-out) kk))
;set routing-table (replace-item c1 routing-table (replace-item 2 (item c1 routing-table) num-cycles))
;;print "bo"
;;print buffer-out
;
; ;set buffer-out (replace-item c1 buffer-out (replace-item c2 (replace-item c1 (item 7 (item c2 (item c1 buffer-out))) num-cycles) item c1 buffer-out) )
;
; ;;print "bo"
; ;;print buffer-out
;
;
;
; ;set buffer-out (replace-item c1 buffer-out (replace-item c2 (replace-item 7 (item c2 (item c1 buffer-out)) num-cycles) (item c2 (item c1 buffer-out) ) ))
]
set c2 (c2 + 1)
]
]
set c1 (c1 + 1)
]
;;print "buffer-out depois"
;;print buffer-out
]
]
; ask router 0
; [
; print "temporario e bin depois de mover, final da transferência"
; print temporary-buffer-PE
; print buffer-in
; ]
;;print "---"
; let segura-lista []
;
; ask routers
; [
;
; ;let primeiro remainder ticks 5
; ;;;;print "---"
; ;;;;print "no ciclo"
; ;;;;print ticks
; ;;;;print list-temporario
;
; set segura-lista item 0 list-temporario
; set list-temporario remove-item 0 list-temporario
; set list-temporario lput segura-lista list-temporario
;
;; ;;;;print "depois de mexer ficou"
;; ;;;;print list-temporario
;
; ;;;;print "---"
; ]
;ask router 0
ask routers
[
;;;;print who
;;;;print "---"
;;;;print "no tick"
;;;;print ticks
;;;;print buffer-in
;;;;print "---"
;;Executando cada porta, segundo a ordem do árbitro
let processed-port ""
let c1 0
let n []
while [c1 < length buffer-in]
[
set n item c1 buffer-in
set processed-port item 0 n
;;;;;print "porta"
;;;;;print processed-port
;;;;;print length n
;;Tem mensagem no buffer?
if (length n > 1)
[
let flit item 0 (sublist n 1 2)
;;;;;print flit
;;;;;print item 2 flit
if (ticks != item 2 flit)
[
; ;;;;print "pode processar, mensagem chegou no ciclo"
; ;;;;print item 2 flit
; ;;;;print "ciclo atual"
; ;;;;print ticks
let a1 0
let not-in-routing-table true
while [a1 < length routing-table]
[
;print item a1 routing-table
if (item 0 (item a1 routing-table) = item 0 flit)
[
set not-in-routing-table false
]
set a1 (a1 + 1)
]
;set routing-table lput (list ID destination-port routing-cost) routing-table
;;Flit é header? Ainda não está na tabela de roteamento?
if (item 1 flit = "H" and not-in-routing-table)
[
;;Se sim, calcula e escreve na tabela de roteamento
update-routing-table (item 0 flit) (item 3 flit) (item 4 flit)
; let id-flit 0
; set id-flit item 0 flit
; set routing-table lput (list id-flit "S" 2) routing-table
;;;;print "tabela de roteamento"
;;;;print routing-table
]
;;Consultar tabela de roteamento para ver se o custo já está 0 e, se sim, por qual porta o flit sai
let port-to-send 0
let routing-done false
foreach routing-table
[
a ->
;;ID flit = ID registro da tabela de roteamento E custo da tabela de roteamento = 0?
if (item 0 flit = item 0 a AND item 2 a = 0)
[
set port-to-send item 1 a
set routing-done true
]
]
if (routing-done)
[
;;;;;print "acessando o indice"
;;;;;print port-to-send
;;;;;print item port-to-send busy
;;;;print "antes do if"
;;;;print busy
if (item port-to-send busy = -1)
[
set busy replace-item port-to-send busy item 0 flit
]
;;;;print "lista busy"
;;;;print busy
if (item port-to-send busy = item 0 flit)
[
;set busy replace-item port-to-send busy item 0 flit
;;;;print "entrou aqui"
;;;;;print buffer-out
;;;;;print length buffer-out
;;;;print length (item port-to-send buffer-out)
if (length (item port-to-send buffer-out) <= buffer-out-size)
[
;;print "---"
;;print "flit sendo processado:"
;;print flit
;;print "---"
; ;;;;print "tem espaço no buffer"
; ;;;;print "n:"
; ;;;;print n
;; ;;;;print "item 1 n"
;; ;;;;print item 1 n
;;;;print item port-to-send buffer-out
;;;;print buffer-out
;set buffer-out replace-item port-to-send buffer-out (sentence item 1 n router-to-router-cost)
; let temporary-direction ""
; set temporary-direction item 0 (item port-to-send buffer-out)
;;print "*** buffer out antes de tirar do in e por no out ***"
;;print buffer-out
let temporary-direction item port-to-send buffer-out
;;print "***********************"
;;print "temporary sem o custo"
;;print temporary-direction
;;print "temporary com o custo"
set temporary-direction lput (sentence flit router-to-router-cost) temporary-direction
;;print temporary-direction
;set buffer-out replace-item port-to-send buffer-out (list temporary-direction (sentence item 1 n router-to-router-cost))
set buffer-out replace-item port-to-send buffer-out temporary-direction
;set temporary-direction lput () temporary-direction
;set buffer-in (replace-item port-to-send buffer-in (lput temporary item indice buffer-in))
;;;;print temporary-direction
;;;;;print "ta indo longe"
;;print "*** buffer out depois de tirar do in e por no out ***"
;;print buffer-out
;;;;print buffer-out
set buffer-in remove (sublist n 1 2) buffer-in
; ;;print "n:"
; ;;print n
; ;;print item c1 buffer-in
;;print "antes de tirar"
;;print buffer-in
set buffer-in (replace-item c1 buffer-in (remove-item 1 (item c1 buffer-in)))
;;print "sera que foi?"
;;print buffer-in
;set buffer-in (replace-item indice buffer-in (lput temporary item indice buffer-in))
;set mylist (replace-item 3 mylist (remove-item 2 (item 3 mylist)))
;set buffer-in (replace-item 3 mylist (remove-item 2 (item 3 buffer-in)))
;set item port-to-send buffer-out lput 0 item port-to-send buffer-out
;set buffer-out
;set n remove-item 1 n
; ;;;;print "n = "
; ;;;;print n