adopted to git (cygwin)
[luayats.git] / apps / tn / test-base-8-vcg.lua
blob09db4808897fa8b527a8c0128588431e170d2dee
1 require "yats.stdlib"
2 require "yats.core"
3 require "yats.n23"
4 require "yats.graphics"
5 require "yats.user"
6 local fmt = string.format
8 -- Helper: units
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
16 yats.sim:setRand(1)
17 yats.sim:SetSlotLength(1*ns)
19 -- Logging Setup
20 yats.log:setLevel("INFO")
21 yats.kernel_log:setLevel("INFO")
22 local log = yats.log
24 -- Simulation Config
25 local N = 8
26 local SOURCETYPE="cbr"
27 local RTT = 16*us -- expected RTT
28 local TLINEUP = 2*us
29 local TLINEDN = 2*us
30 local SEGSIZE = 64
31 local CHUNKSIZE = 16
32 --local FLEN = 1518
33 local N2 = SEGSIZE
34 local SRATE = 4 * Gbps
35 local rates = {
36 3*149*Mbps,
37 100*Mbps,
38 100*Mbps,
39 90*Mbps,
40 145*Mbps,
41 20*Mbps,
42 90*Mbps,
43 2*Mbps
46 local loads = {
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
52 local flens = {
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)
59 local t = {}
60 for k,v in pairs(defattrib) do
61 t[k] = v
62 end
63 t[key] = val
64 return t
65 end
67 local TDELTA=1*us
68 local ddelta = t2s(TDELTA)
69 --local ddelta = 1000
70 local dupdate = ddelta/100
71 local dmaxval = 10
72 local senders = {}
73 local receivers = {}
74 local uplines = {}
76 ----------------------------------------------------------------
77 -- Network
78 ----------------------------------------------------------------
79 -- Demux PtP to receivers
80 local dout = {}
81 for i = 1, N do
82 dout[i] = {"receiver-"..i, "in"}
83 end
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"}}
89 -- Mux
90 local mux = yats.mux{"mux", ninp = N, buff = 100, out = {"tcptp", "in"}}
92 -- PTP TC Layer
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 = {},{}
101 for i = 1, N do
103 -- Sources
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"}
109 else
110 src[i] = yats.geosrc{"src-"..i, ed = r2s(rates[i]*loads[i], flens[i]), vci = i,
111 out = {"d2f-"..i, "dat2fram"}}
113 -- Frame generator
114 d2f[i] = yats.dat2fram{"d2f-"..i, flen = flens[i], connid = i,
115 out = {"scheduler-"..i, "in"}}
116 -- Sink
117 snk[i] = yats.sink{"snk-"..i}
119 local n2 = 10*us * rates[i] / 8
120 -- local n2 = N2
122 -- Sender/Scheduler
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}}
126 -- Receivers
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"}}}
131 --- Source rate
132 msrc[i] = yats.meter{
133 "msrc-"..i, title = "SRCRATE-"..i,
134 val = {senders[i], "Count"},
135 win = {x,y,dx,dy},
136 mode = yats.DiffMode,
137 nvals = 100,
138 maxval = 2,
139 delta = ddelta,
140 update = dupdate,
141 display = false
143 -- Credit update rate
144 mcup[i] = yats.meter{
145 "cup-"..i, title = "CUPRATE-"..i,
146 val = {senders[i], "ival1"},
147 win = {x,y,dx,dy},
148 mode = yats.DiffMode,
149 nvals = 100,
150 maxval = 2,
151 delta = ddelta,
152 update = dupdate,
153 display = false
155 -- Receive rate
156 mrx[i] = yats.meter{
157 "mrx-"..i, title = "CHNRATE-"..i,
158 val = {receivers[i], "Count"},
159 win = {x,y,dx,dy},
160 mode = yats.DiffMode,
161 nvals = 100,
162 maxval = TDELTA*rates[i]/SEGSIZE,
163 delta = ddelta,
164 update = dupdate,
165 display = false
167 -- Channel mean rate
168 mrxmean[i] = yats.meter{
169 "mrxmean-"..i, title = "MEANRATE-"..i,
170 val = {receivers[i], "ival4"},
171 mode = yats.AbsMode,
172 win = {x,y,dx,dy},
173 nvals = 100,
174 maxval = 1 * Gbps,
175 delta = ddelta,
176 update = dupdate,
177 display = false
180 -- Line rate
181 mln[i] = yats.meter{
182 "mln-"..i, title = "LINRATE-"..i,
183 val = {snk[i], "Count"},
184 win = {x,y,dx,dy},
185 mode = yats.DiffMode,
186 nvals = 100,
187 maxval = TDELTA*rates[i]/CHUNKSIZE+1,
188 delta = ddelta,
189 update = dupdate,
190 display = false
193 mbf[i] = yats.meter{
194 "mbf-"..i, title = "BF-"..i,
195 val = {receivers[i], "ival0"},
196 mode = yats.AbsMode,
197 win = {x,y,dx,dy},
198 nvals = 100,
199 maxval = 2000,
200 -- maxval = N2 + RTT * 800*Mbps / 8,
201 delta = ddelta, update = dupdate,
202 display = false
204 -- PtP PHY => LINK(sender)
205 uplines[i] = yats.line{
206 "upline-"..i,
207 delay = t2s(TLINEUP),
208 out = {"scheduler-"..i, "credit"}
210 -- Configure demux
211 demux:signal{i,i,i}
214 ----------------------------------------------------------
215 -- Display
216 ----------------------------------------------------------
217 local instr = {}
218 for j,inst in ipairs{msrc, mrxmean, mbf, mcup, mln} do
219 instr[j] = {}
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,
228 instruments = instr,
230 disp:show()
232 ----------------------------------------------------------
233 -- Run
234 ----------------------------------------------------------
235 printf("Connecting ...\n")
236 yats.sim:connect()
238 local T1 = 15000*us
240 yats.sim:run(t2s(T1))
242 ----------------------------------------------------------
243 -- Result output
244 ----------------------------------------------------------
245 local sumrate = 0
246 for i = 1, N do
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)