def new(self, neighbor, restarted): graceful = neighbor.graceful_restart families = neighbor.families() mp = MultiProtocol() mp.extend(families) self[Capability.CODE.MULTIPROTOCOL] = mp if neighbor.asn4: self[Capability.CODE.FOUR_BYTES_ASN] = ASN4(neighbor.local_as) if neighbor.add_path: ap_families = [] if (AFI(AFI.ipv4), SAFI(SAFI.unicast)) in families: ap_families.append((AFI(AFI.ipv4), SAFI(SAFI.unicast))) if (AFI(AFI.ipv6), SAFI(SAFI.unicast)) in families: ap_families.append((AFI(AFI.ipv6), SAFI(SAFI.unicast))) if (AFI(AFI.ipv4), SAFI(SAFI.nlri_mpls)) in families: ap_families.append((AFI(AFI.ipv4), SAFI(SAFI.nlri_mpls))) if (AFI(AFI.ipv6), SAFI(SAFI.unicast)) in families: ap_families.append((AFI(AFI.ipv6), SAFI(SAFI.unicast))) self[Capability.CODE.ADD_PATH] = AddPath(ap_families, neighbor.add_path) if graceful: if restarted: self[Capability.CODE.GRACEFUL_RESTART] = Graceful().set( Graceful.RESTART_STATE, graceful, [(afi, safi, Graceful.FORWARDING_STATE) for (afi, safi) in families]) else: self[Capability.CODE.GRACEFUL_RESTART] = Graceful().set( 0x0, graceful, [(afi, safi, Graceful.FORWARDING_STATE) for (afi, safi) in families]) if neighbor.route_refresh: self[Capability.CODE.ROUTE_REFRESH] = RouteRefresh() self[Capability.CODE. ENHANCED_ROUTE_REFRESH] = EnhancedRouteRefresh() # MUST be the last key added if neighbor.multisession: # XXX: FIXME: should it not be the RFC version ? self[Capability.CODE.MULTISESSION] = MultiSession().set( [Capability.CODE.MULTIPROTOCOL]) return self
def new(self, neighbor, restarted): graceful = neighbor.graceful_restart families = neighbor.families() mp = MultiProtocol() mp.extend(families) self[CapabilityID.MULTIPROTOCOL_EXTENSIONS] = mp if neighbor.asn4: self[CapabilityID.FOUR_BYTES_ASN] = neighbor.local_as if neighbor.add_path: ap_families = [] if (AFI(AFI.ipv4), SAFI(SAFI.unicast)) in families: ap_families.append((AFI(AFI.ipv4), SAFI(SAFI.unicast))) if (AFI(AFI.ipv6), SAFI(SAFI.unicast)) in families: ap_families.append((AFI(AFI.ipv4), SAFI(SAFI.unicast))) if (AFI(AFI.ipv4), SAFI(SAFI.nlri_mpls)) in families: ap_families.append((AFI(AFI.ipv4), SAFI(SAFI.nlri_mpls))) #if (AFI(AFI.ipv6),SAFI(SAFI.unicast)) in families: # ap_families.append((AFI(AFI.ipv6),SAFI(SAFI.unicast))) self[CapabilityID.ADD_PATH] = AddPath(ap_families, neighbor.add_path) if graceful: if restarted: self[CapabilityID.GRACEFUL_RESTART] = Graceful( Graceful.RESTART_STATE, graceful, [(afi, safi, Graceful.FORWARDING_STATE) for (afi, safi) in families]) else: self[CapabilityID.GRACEFUL_RESTART] = Graceful( 0x0, graceful, [(afi, safi, Graceful.FORWARDING_STATE) for (afi, safi) in families]) if neighbor.route_refresh: self[CapabilityID.ROUTE_REFRESH] = RouteRefresh(families) # MUST be the last key added if neighbor.multisession: self[CapabilityID.MULTISESSION_BGP] = MultiSession( [CapabilityID.MULTIPROTOCOL_EXTENSIONS]) return self
def _session(self, neighbor): if not neighbor.multisession: return # XXX: FIXME: should it not be the RFC version ? self[Capability.CODE.MULTISESSION] = MultiSession().set( [Capability.CODE.MULTIPROTOCOL])
def CapabilitiesFactory(data): capabilities = Capabilities() option_len = ord(data[0]) if option_len: data = data[1:] while data: key, value, data = _key_values('parameter', data) # Paramaters must only be sent once. if key == Parameter.AUTHENTIFICATION_INFORMATION: raise Notify(2, 5) if key == Parameter.CAPABILITIES: while value: k, capv, value = _key_values('capability', value) # Multiple Capabilities can be present in a single attribute #if r: # raise Notify(2,0,"Bad length for OPEN %s (size mismatch) %s" % ('capability',hexa(value))) if k == CapabilityID.MULTIPROTOCOL_EXTENSIONS: if k not in capabilities: capabilities[k] = MultiProtocol() afi = AFI(unpack('!H', capv[:2])[0]) safi = SAFI(ord(capv[3])) capabilities[k].append((afi, safi)) continue if k == CapabilityID.GRACEFUL_RESTART: restart = unpack('!H', capv[:2])[0] restart_flag = restart >> 12 restart_time = restart & Graceful.TIME_MASK value_gr = capv[2:] families = [] while value_gr: afi = AFI(unpack('!H', value_gr[:2])[0]) safi = SAFI(ord(value_gr[2])) flag_family = ord(value_gr[0]) families.append((afi, safi, flag_family)) value_gr = value_gr[4:] capabilities[k] = Graceful(restart_flag, restart_time, families) continue if k == CapabilityID.FOUR_BYTES_ASN: capabilities[k] = ASN(unpack('!L', capv[:4])[0]) continue if k == CapabilityID.CISCO_ROUTE_REFRESH: capabilities[k] = RouteRefresh() continue if k == CapabilityID.ROUTE_REFRESH: capabilities[k] = RouteRefresh() continue if k == CapabilityID.ENHANCED_ROUTE_REFRESH: capabilities[k] = EnhancedRouteRefresh() continue if k == CapabilityID.MULTISESSION_BGP: capabilities[k] = MultiSession() continue if k == CapabilityID.MULTISESSION_BGP_RFC: capabilities[k] = MultiSession() continue if k == CapabilityID.ADD_PATH: if k not in capabilities: capabilities[k] = AddPath() value_ad = capv while value_ad: afi = AFI(unpack('!H', value_ad[:2])[0]) safi = SAFI(ord(value_ad[2])) sr = ord(value_ad[3]) capabilities[k].add_path(afi, safi, sr) value_ad = value_ad[4:] if k == CapabilityID.OPERATIONAL: capabilities[k] = Operational() continue if k not in capabilities: capabilities[k] = UnknownCapability( k, [ord(_) for _ in capv]) else: raise Notify(2, 0, 'Unknow OPEN parameter %s' % hex(key)) return capabilities