-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
release.unlang
68 lines (54 loc) · 1.37 KB
/
release.unlang
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
#
# Test releasing IP addresses in the sqlippool module
#
uint32 expiry
&control.IP-Pool.Name := 'test_release'
#
# Add IP addresses
#
%sql("DELETE FROM fr_ippool WHERE pool_name = '%{control.IP-Pool.Name}'")
%sql("INSERT INTO fr_ippool (pool_name, address, expiry_time) VALUES ('%{control.IP-Pool.Name}', '192.168.0.1', datetime('now', '-00:10'))")
#
# Check allocation
#
sqlippool.allocate
if (!updated) {
test_fail
}
if !(&reply.Framed-IP-Address == 192.168.0.1) {
test_fail
}
#
# Release the IP address
#
&Framed-IP-Address := &reply.Framed-IP-Address
sqlippool.release
if !(updated) {
test_fail
}
#
# Verify the association with the device has been removed
#
if (%sql("SELECT address FROM fr_ippool WHERE pool_name = '%{control.IP-Pool.Name}' AND owner = '%{Calling-Station-Id}'")) {
test_fail
}
# Check the expiry - releasing an address sets the exipry to now
# Allow for some time passing between packet processing and "now"
&expiry := %sql("SELECT strftime('%%s', expiry_time) FROM fr_ippool WHERE pool_name = '%{control.IP-Pool.Name}' AND address = '%{reply.Framed-IP-Address}'")
if (&expiry > (%l + 5)) {
test_fail
}
if ((%l - &expiry) > 5) {
test_fail
}
#
# Release the IP address again
# Will return notfound as address is already released.
#
&Framed-IP-Address := &reply.Framed-IP-Address
sqlippool.release
if (!notfound) {
test_fail
}
&reply := {}
test_pass