-
Notifications
You must be signed in to change notification settings - Fork 0
/
checks.jl
58 lines (55 loc) · 1.69 KB
/
checks.jl
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
function check_bounds_are_respected(sn)
used = []
for n in 1:nv(sn)
@assert 0 <= get_prop(sn, n, :cpu_used) <= get_prop(sn, n, :cpu_max)
end
for e in edges(sn)
@assert 0 <= get_prop(sn, e, :BW_used) <= get_prop(sn, e, :BW_max)
end
end
function check_each_vn_uses_different_node(vnr)
used = []
for n in 1:nv(vnr)
host = get_prop(vnr, n, :host_node)
push!(used, host)
end
@assert length(used) == length(unique(used))
end
function check_each_vn_uses_resource_amount(sn, sn_prec, vnr)
for n in 1:nv(vnr)
host = get_prop(vnr, n, :host_node)
cpu = get_prop(vnr, n, :cpu)
@assert cpu == get_prop(sn, host, :cpu_used) - get_prop(sn_prec, host, :cpu_used)
end
end
function check_each_vl_uses_resource_amount(sn, sn_prec, vnr)
vlink_cons = Dict()
for e in edges(vnr)
vlink = get_prop(vnr, e, :vlink)
for (l, bw) in vlink
if l[1] > l[2]
l = (l[2], l[1])
end
if !haskey(vlink_cons, l)
vlink_cons[l] = 0
end
vlink_cons[l] += bw
end
end
for e in edges(sn)
u = e.src
v = e.dst
if u < v
l = (u, v)
else
l = (v, u)
end
if haskey(vlink_cons, (u, v))
@assert vlink_cons[(u, v)] == get_prop(sn, u, v, :BW_used) - get_prop(sn_prec, u, v, :BW_used)
elseif haskey(vlink_cons, (v, u))
@assert vlink_cons[(u, v)] == get_prop(sn, u, v, :BW_used) - get_prop(sn_prec, u, v, :BW_used)
else
@assert 0 == get_prop(sn, u, v, :BW_used) - get_prop(sn_prec, u, v, :BW_used)
end
end
end