This script uses the IP address assigned by the DHCP server to derive both sub_ident and sla_profile_string.
Script:
1. import alc
2. yiaddr = alc.dhcp.yiaddr
3. # Subscriber ID equals full client IP address.
4. # Note: IP address 10.10.10.10 yields 'sub-168430090'
5. # and not 'sub-10.10.10.10'
6. alc.dhcp.sub_ident = 'sub-' + str(yiaddr)
7. # DHCP server is configured such that the third byte (field) of the IP
8. # address indicates the session Profile ID.
9. alc.dhcp.sla_profile_string = 'sp-' + str((yiaddr & 0x0000FF00) >> 8)
Explanation:
Line 1 imports the library ‟alc” – Library imports can reside anywhere in the script if the items are imported before they are used.
Line 2 assigns the decimal value of the host’s IP address to a temporary variable ‟yiaddr”. Line 6: The text ‟sub_‟ followed by yiaddr is assigned to ‟sub_ident” string.
Line 9 the text ‟sp-‟ followed with the third byte of the IP address is assigned to the ‟sla- profile” string.
If this script is run, for example, with a DHCP-assigned IP address of:
yiaddr = 10.10.0.2
The following variables are returned:
sub_ident: sub-168427522(hex = A0A00002 = 10.10.0.2)
sla_ident: sp-0