本文整理汇总了Python中exabgp.bgp.message.update.nlri.nlri.NLRI._nlri方法的典型用法代码示例。如果您正苦于以下问题:Python NLRI._nlri方法的具体用法?Python NLRI._nlri怎么用?Python NLRI._nlri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exabgp.bgp.message.update.nlri.nlri.NLRI
的用法示例。
在下文中一共展示了NLRI._nlri方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpack
# 需要导入模块: from exabgp.bgp.message.update.nlri.nlri import NLRI [as 别名]
# 或者: from exabgp.bgp.message.update.nlri.nlri.NLRI import _nlri [as 别名]
def unpack (cls,afi,safi,bgp,addpath,nexthop,action):
labels,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action)
nlri = cls(afi,safi,prefix,mask,nexthop,action)
if labels: nlri.labels = Labels(labels)
if rd: nlri.rd = RouteDistinguisher(rd)
return len(bgp) - len(left),nlri
示例2: unpack
# 需要导入模块: from exabgp.bgp.message.update.nlri.nlri import NLRI [as 别名]
# 或者: from exabgp.bgp.message.update.nlri.nlri.NLRI import _nlri [as 别名]
def unpack (cls,afi,safi,bgp,addpath,nexthop,action):
labels,rd,path_identifier,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action,addpath)
nlri = cls(afi,safi,prefix,mask,nexthop,action)
if labels: nlri.labels = Labels(labels)
if rd: nlri.rd = RouteDistinguisher(rd)
if path_identifier: nlri.path_info = PathInfo(None,None,path_identifier)
return len(bgp) - len(left),nlri
示例3: unpack
# 需要导入模块: from exabgp.bgp.message.update.nlri.nlri import NLRI [as 别名]
# 或者: from exabgp.bgp.message.update.nlri.nlri.NLRI import _nlri [as 别名]
def unpack (cls,afi,safi,data,addpath,nexthop,action):
if addpath:
path_identifier = PathInfo(None,None,data[:4])
data = data[4:]
length = 4
else:
path_identifier = None
length = 0
labels,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,data,action)
nlri = cls(afi,safi,prefix,mask,nexthop,action)
if addpath:
nlri.path_info = path_identifier
return length + len(data) - len(left),nlri
示例4: unpack
# 需要导入模块: from exabgp.bgp.message.update.nlri.nlri import NLRI [as 别名]
# 或者: from exabgp.bgp.message.update.nlri.nlri.NLRI import _nlri [as 别名]
def unpack (cls,afi,safi,bgp,has_multiple_path,nexthop,action):
total = len(bgp)
length,bgp = ord(bgp[0]),bgp[1:]
if length & 0xF0 == 0xF0: # bigger than 240
extra,bgp = ord(bgp[0]),bgp[1:]
length = ((length & 0x0F) << 16) + extra
if length > len(bgp):
raise Notify(3,10,'invalid length at the start of the the flow')
bgp = bgp[:length]
nlri = Flow(afi,safi,nexthop)
nlri.action = action
if safi == SAFI.flow_vpn:
nlri.rd = RouteDistinguisher(bgp[:8])
bgp = bgp[8:]
seen = []
while bgp:
what,bgp = ord(bgp[0]),bgp[1:]
if what not in decode.get(afi,{}):
raise Notify(3,10,'unknown flowspec component received for address family %d' % what)
seen.append(what)
if sorted(seen) != seen:
raise Notify(3,10,'components are not sent in the right order %s' % seen)
decoder = decode[afi][what]
klass = factory[afi][what]
if decoder == 'prefix':
if afi == AFI.ipv4:
_,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action)
adding = klass(prefix,mask)
if not nlri.add(adding):
raise Notify(3,10,'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen)
# logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),od,bgp[:-len(left)]))
bgp = left
else:
byte,bgp = bgp[1],bgp[0]+bgp[2:]
offset = ord(byte)
_,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action)
adding = klass(prefix,mask,offset)
if not nlri.add(adding):
raise Notify(3,10,'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen)
# logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),od,bgp[:-len(left)]))
bgp = left
else:
end = False
while not end:
byte,bgp = ord(bgp[0]),bgp[1:]
end = CommonOperator.eol(byte)
operator = CommonOperator.operator(byte)
length = CommonOperator.length(byte)
value,bgp = bgp[:length],bgp[length:]
adding = klass.decoder(value)
nlri.add(klass(operator,adding))
# logger.parser(LazyFormat("added flow %s (%s) operator %d len %d payload " % (klass.NAME,adding,byte,length),od,value))
return total-len(bgp),nlri
示例5: unpack
# 需要导入模块: from exabgp.bgp.message.update.nlri.nlri import NLRI [as 别名]
# 或者: from exabgp.bgp.message.update.nlri.nlri.NLRI import _nlri [as 别名]
def unpack (cls, afi, safi, data, addpath, nexthop, action):
labels,rd,path_identifier,mask,size,prefix,left = NLRI._nlri(afi,safi,data,action,addpath)
nlri = cls(afi,safi,prefix,mask,nexthop,action)
if path_identifier:
nlri.path_info = PathInfo(None,None,path_identifier)
return len(data) - len(left),nlri