def encode_attr_mp_nexthop(nexthop):
""" Encode string nexthop into a BGP MP_REACH attribute TLV
A modified MP_REACH attribute that includes only the next hop info (per MRT RFC6396)
This includes only the next hop address lenght (1 octet) and the next-hop
:param nexthop: String value for the next-hop
:return: BGP attribute TLV ready to be written
"""
# Set afi and length based on nexthop address
if ':' in nexthop:
nh_len = 16
afi = socket.AF_INET6
else:
nh_len = 4
afi = socket.AF_INET
return ATTR_TYPE_MP_REACH + pack('!BB', nh_len + 1, nh_len) + socket.inet_pton(afi, nexthop)
评论列表
文章目录