本文整理汇总了Python中exabgp.protocol.family.AFI类的典型用法代码示例。如果您正苦于以下问题:Python AFI类的具体用法?Python AFI怎么用?Python AFI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AFI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unpack_capability
def unpack_capability (instance, data, capability=None): # pylint: disable=W0613
# XXX: FIXME: we should complain if we have twice the same AFI/SAFI
# XXX: FIXME: should check that we have not yet seen the capability
while data:
afi = AFI.unpack(data[:2])
safi = SAFI.unpack(data[3])
nexthop = AFI.unpack(data[4:6])
instance.add_nexthop(afi, safi, nexthop)
data = data[6:]
return instance
示例2: _add
def _add (self,tokeniser,afi_name,safi_names):
self._check_duplicate(tokeniser,RaisedFamily)
known = self.content.setdefault(AFI(AFI.value(afi_name)),[])
for (idx_line,idx_column,line,safi_name) in safi_names:
if safi_name not in AFI.implemented_safi(afi_name):
raise RaisedFamily(Location(idx_line,idx_column,line),'the family pair afi/safi %s/%s is unimplemented' % (afi_name,safi_name))
safi = SAFI(SAFI.value(safi_name))
if safi in known:
raise RaisedFamily(Location(idx_line,idx_column,line),'afi/safi pair already defined in this family')
known.append(safi)
示例3: _family
def _family (self, tokeniser, afi, safis, nhafis):
safi = tokeniser().lower()
if safi not in safis:
raise ValueError('invalid afi/safi pair %s/%s' % (afi, safi))
nhafi = tokeniser().lower()
if nhafi not in nhafis:
raise ValueError('invalid nexthop afi %s' % nhafi)
seen = (AFI.fromString(afi), SAFI.fromString(safi), AFI.fromString(nhafi))
self._seen.append(seen)
return seen
示例4: RouteRefresh
class RouteRefresh (Message):
ID = Message.ID.ROUTE_REFRESH
TYPE = chr(Message.ID.ROUTE_REFRESH)
request = 0
start = 1
end = 2
def __init__ (self,afi,safi,reserved=0):
self.afi = AFI(afi)
self.safi = SAFI(safi)
self.reserved = Reserved(reserved)
def messages (self,negotitated):
return [self._message('%s%s%s' % (self.afi.pack(),chr(self.reserved),self.safi.pack())),]
def __str__ (self):
return "REFRESH"
def extensive (self):
return 'route refresh %s/%d/%s' % (self.afi,self.reserved,self.safi)
def families (self):
return self._families[:]
@classmethod
def unpack_message (cls,data,negotitated):
try:
afi,reserved,safi = unpack('!HBB',data)
except error:
raise Notify(7,1,'invalid route-refresh message')
if reserved not in (0,1,2):
raise Notify(7,2,'invalid route-refresh message subtype')
return RouteRefresh(afi,safi,reserved)
示例5: __init__
def __init__ (self,what,afi,safi,data=''):
self.afi = AFI(afi)
self.safi = SAFI(afi)
Operational.__init__(
self,what,
'%s%s%s' % (self.afi.pack(),self.safi.pack(),data)
)
示例6: unpack
def unpack (capability,instance,data):
# XXX: FIXME: should check that we have not yet seen the capability
while data:
afi = AFI.unpack(data[:2])
safi = SAFI.unpack(data[2])
sr = ord(data[3])
instance.add_path(afi,safi,sr)
data = data[4:]
return instance
示例7: unpack_capability
def unpack_capability (instance, data, capability=None): # pylint: disable=W0613
# XXX: FIXME: should check that we have not yet seen the capability
while data:
afi = AFI.unpack(data[:2])
safi = SAFI.unpack(data[2])
sr = ord(data[3])
instance.add_path(afi,safi,sr)
data = data[4:]
return instance
示例8: parse_api_refresh
def parse_api_refresh (self,command):
tokens = formated(command).split(' ')[2:]
if len(tokens) != 2:
return False
afi = AFI.value(tokens.pop(0))
safi = SAFI.value(tokens.pop(0))
if afi is None or safi is None:
return False
return RouteRefresh(afi,safi)
示例9: OperationalFamily
class OperationalFamily (Operational):
def __init__ (self,what,afi,safi,data=''):
self.afi = AFI(afi)
self.safi = SAFI(afi)
Operational.__init__(
self,what,
'%s%s%s' % (self.afi.pack(),self.safi.pack(),data)
)
def family (self):
return (self.afi,self.safi)
示例10: unpack_nlri
def unpack_nlri (cls, afi, safi, data, action, addpath):
if not cls.logger:
cls.logger = Logger()
a,s = AFI.create(afi),SAFI.create(safi)
cls.logger.debug(LazyNLRI(a,s,addpath,data),'parser')
key = '%s/%s' % (a, s)
if key in cls.registered_nlri:
return cls.registered_nlri[key].unpack_nlri(a,s,data,action,addpath)
raise Notify(3,0,'trying to decode unknown family %s/%s' % (a,s))
示例11: register_nlri
def register_nlri (klass):
new = (AFI.create(afi),SAFI.create(safi))
if new in cls.registered_nlri:
if force:
# python has a bug and does not allow %ld/%ld (pypy does)
cls.registered_nlri['%s/%s' % new] = klass
else:
raise RuntimeError('Tried to register %s/%s twice' % new)
else:
# python has a bug and does not allow %ld/%ld (pypy does)
cls.registered_nlri['%s/%s' % new] = klass
cls.registered_families.append(new)
return klass
示例12: unpack_capability
def unpack_capability (instance, data, capability=None): # pylint: disable=W0613
# XXX: FIXME: should raise if instance was already setup
restart = unpack('!H',data[:2])[0]
restart_flag = restart >> 12
restart_time = restart & Graceful.TIME_MASK
data = data[2:]
families = []
while data:
afi = AFI.unpack(data[:2])
safi = SAFI.unpack(data[2])
flag_family = ord(data[3])
families.append((afi,safi,flag_family))
data = data[4:]
return instance.set(restart_flag,restart_time,families)
示例13: unpack
def unpack (what,instance,data):
# XXX: FIXME: should raise if instance was already setup
restart = unpack('!H',data[:2])[0]
restart_flag = restart >> 12
restart_time = restart & Graceful.TIME_MASK
data = data[2:]
families = []
while data:
afi = AFI.unpack(data[:2])
safi = SAFI.unpack(data[2])
flag_family = ord(data[0])
families.append((afi,safi,flag_family))
data = data[4:]
return instance.set(restart_flag,restart_time,families)
示例14: RouteRefresh
class RouteRefresh (Message):
ID = Message.CODE.ROUTE_REFRESH
TYPE = chr(Message.CODE.ROUTE_REFRESH)
request = 0
start = 1
end = 2
def __init__ (self, afi, safi, reserved=0):
self.afi = AFI(afi)
self.safi = SAFI(safi)
self.reserved = Reserved(reserved)
def message (self,negotiated=None):
return self._message('%s%s%s' % (self.afi.pack(),chr(self.reserved),self.safi.pack()))
def __str__ (self):
return "REFRESH"
def extensive (self):
return 'route refresh %s/%d/%s' % (self.afi,self.reserved,self.safi)
def families (self):
return self._families[:]
@classmethod
def unpack_message (cls, data, _):
try:
afi,reserved,safi = unpack('!HBB',data)
except error:
raise Notify(7,1,'invalid route-refresh message')
if reserved not in (0,1,2):
raise Notify(7,2,'invalid route-refresh message subtype')
return RouteRefresh(afi,safi,reserved)
def __eq__ (self, other):
if not isinstance(other, RouteRefresh):
return False
if self.afi != other.afi:
return False
if self.safi != other.safi:
return False
if self.reserved != other.reserved:
return False
return True
def __ne__ (self, other):
return not self.__eq__(other)
示例15: parse_api_eor
def parse_api_eor (self,command):
tokens = formated(command).split(' ')[2:]
lt = len(tokens)
if not lt:
return Family(1,1)
if lt !=2:
return False
afi = AFI.fromString(tokens[0])
if afi == AFI.undefined:
return False
safi = SAFI.fromString(tokens[1])
if safi == SAFI.undefined:
return False
return Family(afi,safi)