For feedback, use the following: |
ipd_online_feedback@alcatel-lucent.com |
Table 21: DHCP Object Members The TLV type provides easy access to the value part of a stream of type-length-value variables, as is the case for the DHCP option field. In example us5.py, the circuit-ID is accessed as alc.dhcp.options[82][1].
• As an example consider script us5.py which sets the sub_ident variable based on the circuit ID of three different DSLAMs:import re
import alc
import struct
# ASAM DSLAM circuit ID comes in three flavours:
# FENT string "TLV1: ATM:3/0:100.33"
# GELT octet-stream 0x01010000A0A0A0A0000000640022
# GENT string "ASAM11 atm 1/1/01:100.35"
#
# Script sets output ('subscriber') to 'sub-vpi.vci', e.g.: 'sub-100.33'.
circuitid = str(alc.dhcp.options[82][1])
m = re.search(r'(\d+\.\d+)$', circuitid)
if m:
# FENT and GENT
alc.dhcp.sub_ident = "sub-" + m.group()
elif len(circuitid) >= 3:
# GELT
# Note: what byte order does GELT use for the VCI?
# Assume network byte (big endian) order for now.
vpi = struct.unpack('B', circuitid[-3:-2])[0]
vci = struct.unpack('>H', circuitid[-2:])[0]
alc.dhcp.sub_ident = "sub-%d.%d" % (vpi, vci)----------------------------------------------
sub-ident-policy "DSLAM" create
description "Parse circuit IDs from different DSLAMs"
primary
script-url "ftp://xxx.xxx.xxx.xx/py/us5.py"
no shutdown
exit
exit
----------------------------------------------A:dut-A>config>service>vpls>sap# info
----------------------------------------------
dhcp
description "client side"
lease-populate 50
no shutdown
exit
anti-spoof ip-mac
sub-sla-mgmt
sub-ident-policy "DSLAM"
no shutdown
exit
----------------------------------------------A:dut-A>config>subscr-mgmt>sub-ident-pol>primary# script-url "ftp://xxx.xxx.xx.xx/py/parsefail1.py"
A:dut-A>config>subscr-mgmt>sub-ident-pol>primary# no shutdown
1 2006/07/30 01:17:33.14 UTC MINOR: DEBUG #2001 - Python Compile Error
"Python Compile Error: parsefail1.py
File "ftp://xxx.xxx.xx.xx/py/parsefail1.py", line 2
def invalid_function():
^
IndentationError: expected an indented block
"
A:dut-A>config>subscr-mgmt>sub-ident-pol>primary# script-url "ftp://xxx.xxx.xx.xx/py/dump.py"
2 2006/07/30 01:24:55.50 UTC MINOR: DEBUG #2001 - Python Output
"Python Output: dump.py
htype = 0
hlen = 0
hops = 0
flags = 0
ciaddr = '0.0.0.0'
yiaddr = '0.0.0.0'
siaddr = '0.0.0.0'
giaddr = '0.0.0.0'
chaddr = ''
sname = ''
file = ''
options = '5\x01\x056\x04\n\x01\x07\n3\x04\x00\x00\x00\xb4\x01\x04\xff\xff\xff
\x00\x1c\x04\n\x02\x02\xffR\x0f\x01\rdut-A|1|1/1/1\xff'
"
3 2006/07/30 01:24:55.50 UTC MINOR: DEBUG #2001 - Python Result
"Python Result: dump.py
"
A:dut-A>config>subscr-mgmt>sub-ident-pol>primary# script-url "ftp://xxx.xxx.xx.xx/py/endless.py"
4 2006/07/30 01:30:17.27 UTC MINOR: DEBUG #2001 - Python Output
"Python Output: endless.py
"
5 2006/07/30 01:30:17.27 UTC MINOR: DEBUG #2001 - Python Error
"Python Error: endless.py
Traceback (most recent call last):
File "ftp://xxx.xxx.xx.xx/py/endless.py", line 2, in ?
FatalError: script interrupted (timeout)
"from alc import dhcp
def print_field(key, value):
print '%-8s = %r' % (key, value)
def ipaddr2a(ipaddr):
return '%d.%d.%d.%d' % (
(ipaddr & 0xFF000000) >> 24,
(ipaddr & 0x00FF0000) >> 16,
(ipaddr & 0x0000FF00) >> 8,
(ipaddr & 0x000000FF))
print_field('htype', dhcp.htype)
print_field('hlen', dhcp.hlen)
print_field('hops', dhcp.hops)
print_field('flags', dhcp.flags)
print_field('ciaddr', ipaddr2a(dhcp.ciaddr))
print_field('yiaddr', ipaddr2a(dhcp.yiaddr))
print_field('siaddr', ipaddr2a(dhcp.siaddr))
print_field('giaddr', ipaddr2a(dhcp.giaddr))
print_field('chaddr', dhcp.chaddr)
print_field('sname', dhcp.sname)
print_field('file', dhcp.file)
print_field('options', str(dhcp.options))import re
import alc
import struct
# ASAM DSLAM circuit ID comes in three flavours:
# FENT string "TLV1: ATM:3/0:100.33"
# GELT octet-stream 0x01010000A0A0A0A0000000640022
# GENT string "ASAM11 atm 1/1/01:100.35"
#
# Script sets output ('subscriber') to 'sub-vpi.vci', e.g.: 'sub-100.33'.
circuitid = str(alc.dhcp.options[82][1])
m = re.search(r'(\d+\.\d+)$', circuitid)
if m:
# FENT and GENT
alc.dhcp.sub_ident = "sub-" + m.group()
elif len(circuitid) >= 3:
# GELT
# Note: what byte order does GELT use for the VCI?
# Assume network byte (big endian) order for now.
vpi = struct.unpack('B', circuitid[-3:-2])[0]
vci = struct.unpack('>H', circuitid[-2:])[0]
alc.dhcp.sub_ident = "sub-%d.%d" % (vpi, vci)The radius-script-policy contains URLs of a primary and optionally a secondary Python script, which could be a local CF file path or a FTP URL. the configured radius-script-policy could be used in different ESM polices like authentication-policy or radius-accounting-policy.# This script takes 2.5 seconds.
s = ""
for c in 'A'*50000:
s += str(ord(c)) + ', '
print '[' + s[:-2] + ']'
# This script takes 0.1 seconds.
print map(ord, 'A'*50000)This script uses the IP address assigned by the DHCP server to derive both sub_ident and sla_profile_string.1. import alc2. yiaddr = alc.dhcp.yiaddr3. # 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 IP8. # address indicates the session Profile ID.9. alc.dhcp.sla_profile_string = 'sp-' + str((yiaddr & 0x0000FF00) >> 8)yiaddr = 10.10.0.2sub_ident: sub-168427522 (hex = A0A00002 = 10.10.0.2)sla_ident: sp-0This script returns the sub_profile_string and sla_profile_string, which are coded directly in the Option 82 string1. import re2. import alc3. # option 82 formatted as follows:4. # "<subscriber Profile>-<sla-profile>”5. ident = str(alc.dhcp.options[82][1])6. alc.dhcp.sub_ident = ident7. tmp = re.match("(?P<sub>.+)-(?P<sla>.+)", str(ident))8. alc.dhcp.sub_profile_string = tmp.group("sub")9. alc.dhcp.sla_profile_string = tmp.group("sla").options = \x52\x0D\x01\0x0Bmydsl-video
sub_ident: mydsl-videosub_profile_string: mydslsla_profile_string: videoThis script parses the option 82 “circuit-id” info inserted in the DHCP packet by a DSLAM, and returns the sub_ident string.1. import re2. import alc3. import struct4. # Alcatel 7300 ASAM circuit ID comes in three flavours:5. # FENT string "TLV1: ATM:3/0:100.33"6. # GELT octet-stream 0x01010000A0A0A0A00000006400227. # GENT string "ASAM11 atm 1/1/01:100.35"8. #9. # Script sets output ('subscriber') to 'sub-vpi.vci',10. # e.g.: 'sub- 100.33'.11. circuitid = str(alc.dhcp.options[82][1])12. m = re.search(r'(\d+\.\d+)$', circuitid)13. if m:14. # FENT and GENT15. alc.dhcp.sub_ident = "sub-" + m.group()16. elif len(circuitid) >= 3:17. # GELT18. # Note: GELT uses network byte (big endian) order for the VCI19. vpi = struct.unpack('B', circuitid[-3:-2])[0]20. vci = struct.unpack('>H', circuitid[-2:])[0]21. alc.dhcp.sub_ident = "sub-%d.%d" % (vpi, vci)options = \x52\x16\x01\x14TLV1: ATM:3/0:100.33sub_ident: sub-100.33options = \x52\x10\x01\x0E\x01\x01\x00\x00\xA0\xA0\xA0\xA0\x00\x00\x00\x64 \x00\x22(in decimal: 82, 16, 1, 15, 1, 1, 0, 0, 160, 160, 160, 160, 0, 0, 0, 100, 0, 34; corresponding to VPI 100, VCI 34)sub_ident: sub-100.34options = \x52\x1A\x01\x18ASAM11 atm 1/1/01:100.35sub_ident: sub-100.35