4 require
"yats.graphics"
6 local fmt
= string.format
9 local ms
, us
, ns
= 1e-3, 1e-6, 1e-9
10 local Gbps
, Mbps
, kbps
= 1e9
, 1e6
, 1e3
12 -- Fequently used functions
13 local t2s
, r2s
, s2t
= yats
.t2s
, yats
.r2s
, yats
.s2t
15 -- Init Simulation time
17 yats
.sim
:SetSlotLength(1*ns
)
20 yats
.log:setLevel("INFO")
21 yats
.kernel_log
:setLevel("INFO")
26 local SOURCETYPE
="cbr"
27 local RTT
= 16*us
-- expected RTT
34 local SRATE
= 4 * Gbps
47 -- 0.5, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95
48 0.5, 1, 1, 1, 1, 1, 1, 1
49 -- 1.1, 1,1, 1,1, 1,1, 1, 1, 1, 1
53 1518, 512, 64, 1518, 1518, 1518, 1518, 1518
55 -- Graphic output configuration
56 local x
,y
,dx
,dy
= 0,0,200,100
58 local function gattr(key
, val
)
60 for k
,v
in pairs(defattrib
) do
68 local ddelta
= t2s(TDELTA
)
70 local dupdate
= ddelta
/100
76 ----------------------------------------------------------------
78 ----------------------------------------------------------------
79 -- Demux PtP to receivers
82 dout
[i
] = {"receiver-"..i
, "in"}
84 local demux
= yats
.demux
{"demux", maxvci
= N
, nout
= N
, out
= dout
}
86 -- PtP LINK => PHY(demux)
87 dnline
= yats
.line
{"dnline",delay
= t2s(TLINEDN
), out
= {"demux", "demux"}}
90 local mux
= yats
.mux
{"mux", ninp
= N
, buff
= 100, out
= {"tcptp", "in"}}
93 local tc
= yats
.tcptp
{
94 "tcptp", rate
= 1.2 * Gbps
, segsize
= SEGSIZE
,
95 out
= {"dnline", "line"}
97 -- Sources, Senders, Receivers
98 local src
, d2f
, msrc
, mrx
, mbf
, snk
, mln
= {}, {}, {}, {}, {}, {}, {}
99 local mrxmean
, mcup
= {},{}
104 if SOURCETYPE
== "cbr" then
105 src
[i
] = yats
.cbrsrc
{
106 "src-"..i
, delta
= r2s(rates
[i
]*loads
[i
], flens
[i
]), vci
=i
,
107 out
= {"d2f-"..i
, "dat2fram"}
110 src
[i
] = yats
.geosrc
{"src-"..i
, ed
= r2s(rates
[i
]*loads
[i
], flens
[i
]), vci
= i
,
111 out
= {"d2f-"..i
, "dat2fram"}}
114 d2f
[i
] = yats
.dat2fram
{"d2f-"..i
, flen
= flens
[i
], connid
= i
,
115 out
= {"scheduler-"..i
, "in"}}
117 snk
[i
] = yats
.sink
{"snk-"..i
}
119 local n2
= 10*us
* rates
[i
] / 8
123 senders
[i
] = yats
.scheduler
{"scheduler-"..i
, cycle
= r2s(SRATE
, SEGSIZE
),
124 n2
= n2
, n3
= RTT
* rates
[i
] / 8, segsize
= SEGSIZE
, out
= {"mux", "in"..i
}}
127 receivers
[i
] = yats
.receiver
{"receiver-"..i
, rtt
= RTT
, rate
= rates
[i
], n2
= n2
,
128 meantime
= 100*us
, watermark
= SEGSIZE
*1,
129 chunksize
= CHUNKSIZE
, out
= {{"upline-"..i
, "line"}, {"snk-"..i
, "sink"}}}
132 msrc
[i
] = yats
.meter
{
133 "msrc-"..i
, title
= "SRCRATE-"..i
,
134 val
= {senders
[i
], "Count"},
136 mode
= yats
.DiffMode
,
143 -- Credit update rate
144 mcup
[i
] = yats
.meter
{
145 "cup-"..i
, title
= "CUPRATE-"..i
,
146 val
= {senders
[i
], "ival1"},
148 mode
= yats
.DiffMode
,
157 "mrx-"..i
, title
= "CHNRATE-"..i
,
158 val
= {receivers
[i
], "Count"},
160 mode
= yats
.DiffMode
,
162 maxval
= TDELTA
*rates
[i
]/SEGSIZE
,
168 mrxmean
[i
] = yats
.meter
{
169 "mrxmean-"..i
, title
= "MEANRATE-"..i
,
170 val
= {receivers
[i
], "ival4"},
182 "mln-"..i
, title
= "LINRATE-"..i
,
183 val
= {snk
[i
], "Count"},
185 mode
= yats
.DiffMode
,
187 maxval
= TDELTA
*rates
[i
]/CHUNKSIZE
+1,
194 "mbf-"..i
, title
= "BF-"..i
,
195 val
= {receivers
[i
], "ival0"},
200 -- maxval = N2 + RTT * 800*Mbps / 8,
201 delta
= ddelta
, update
= dupdate
,
204 -- PtP PHY => LINK(sender)
205 uplines
[i
] = yats
.line
{
207 delay
= t2s(TLINEUP
),
208 out
= {"scheduler-"..i
, "credit"}
214 ----------------------------------------------------------
216 ----------------------------------------------------------
218 for j
,inst
in ipairs
{msrc
, mrxmean
, mbf
, mcup
, mln
} do
220 for i
,v
in ipairs
{1,2,3,8} do
221 -- table.insert(instr, {msrc[i], mrx[i], mrxmean[i], mbf[i], mln[i]})
222 -- table.insert(instr, {msrc[i], mrxmean[i], mbf[i], mln[i]})
223 instr
[j
][i
] = inst
[v
]
226 local disp
= yats
.bigdisplay
{
227 "disp", title
="TN PtP", nrow
= 5, ncol
= table.getn(instr
[1]), width
= 200, height
= 100,
232 ----------------------------------------------------------
234 ----------------------------------------------------------
235 printf("Connecting ...\n")
240 yats
.sim
:run(t2s(T1
))
242 ----------------------------------------------------------
244 ----------------------------------------------------------
247 local src
, rx
, tx
, snk
= src
[i
], receivers
[i
], senders
[i
], snk
[i
]
248 local cr
= tx
:getcreditcount()*(4+2+1)*8/yats
.SimTimeReal
249 printf("ch-%d: src=%d rx=%d rx-loss=%d ur=%s sk=%d ra=%.1f Mbps cc=%d cr=%.1g Mbps %.1f %% maxbuf=%d\n",
250 i
, src
.counter
, rx
.counter
, rx
.lost
, rx
.underrun
, snk
.counter
, rates
[i
]/Mbps
, tx
:getcreditcount(),
251 cr
/Mbps
, cr
/rates
[i
]*100, rx
.maxbuf
)
252 printf("mux: losstotal=%d loss[%d]=%d\n", mux
:getLossTot(), i
, mux
:getLoss(i
))
253 sumrate
= sumrate
+ rates
[i
]
255 printf("Sum of linerate=%.4E\n", sumrate
/Mbps
)