BGP speaker library API Reference¶
BGPSpeaker class¶
-
class
ryu.services.protocols.bgp.info_base.base.PrefixFilter(prefix, policy, ge=None, le=None)¶ Used to specify a prefix for filter.
We can create PrefixFilter object as follows:
prefix_filter = PrefixFilter('10.5.111.0/24', policy=PrefixFilter.POLICY_PERMIT)
Attribute Description prefix A prefix used for this filter policy One of the following values.
PrefixFilter.POLICY.PERMITPrefixFilter.POLICY_DENYge Prefix length that will be applied to this filter. ge means greater than or equal. le Prefix length that will be applied to this filter. le means less than or equal. For example, when PrefixFilter object is created as follows:
p = PrefixFilter('10.5.111.0/24', policy=PrefixFilter.POLICY_DENY, ge=26, le=28)
Prefixes which match 10.5.111.0/24 and its length matches from 26 to 28 will be filtered. When this filter is used as an out-filter, it will stop sending the path to neighbor because of POLICY_DENY. When this filter is used as in-filter, it will stop importing the path to the global rib because of POLICY_DENY. If you specify POLICY_PERMIT, the path is sent to neighbor or imported to the global rib.
If you don't want to send prefixes 10.5.111.64/26 and 10.5.111.32/27 and 10.5.111.16/28, and allow to send other 10.5.111.0's prefixes, you can do it by specifying as follows:
p = PrefixFilter('10.5.111.0/24', policy=PrefixFilter.POLICY_DENY, ge=26, le=28).
-
clone()¶ This method clones PrefixFilter object.
Returns PrefixFilter object that has the same values with the original one.
-
evaluate(path)¶ This method evaluates the prefix.
Returns this object's policy and the result of matching. If the specified prefix matches this object's prefix and ge and le condition, this method returns True as the matching result.
pathspecifies the path that has prefix.
-
-
class
ryu.services.protocols.bgp.info_base.base.ASPathFilter(as_number, policy)¶ Used to specify a prefix for AS_PATH attribute.
We can create ASPathFilter object as follows:
as_path_filter = ASPathFilter(65000,policy=ASPathFilter.TOP)
Attribute Description as_number A AS number used for this filter policy One of the following values.
ASPathFilter.POLICY_TOPASPathFilter.POLICY_ENDASPathFilter.POLICY_INCLUDEASPathFilter.POLICY_NOT_INCLUDEMeaning of each policy is as follows:
Policy Description POLICY_TOP Filter checks if the specified AS number is at the top of AS_PATH attribute. POLICY_END Filter checks is the specified AS number is at the last of AS_PATH attribute. POLICY_INCLUDE Filter checks if specified AS number exists in AS_PATH attribute. POLICY_NOT_INCLUDE Opposite to POLICY_INCLUDE. -
clone()¶ This method clones ASPathFilter object.
Returns ASPathFilter object that has the same values with the original one.
-
evaluate(path)¶ This method evaluates as_path list.
Returns this object's policy and the result of matching. If the specified AS number matches this object's AS number according to the policy, this method returns True as the matching result.
pathspecifies the path.
-
-
class
ryu.services.protocols.bgp.info_base.base.AttributeMap(filters, attr_type, attr_value)¶ This class is used to specify an attribute to add if the path matches filters. We can create AttributeMap object as follows:
pref_filter = PrefixFilter('192.168.103.0/30', PrefixFilter.POLICY_PERMIT) attribute_map = AttributeMap([pref_filter], AttributeMap.ATTR_LOCAL_PREF, 250) speaker.attribute_map_set('192.168.50.102', [attribute_map])
AttributeMap.ATTR_LOCAL_PREF means that 250 is set as a local preference value if nlri in the path matches pref_filter.
ASPathFilter is also available as a filter. ASPathFilter checks if AS_PATH attribute in the path matches AS number in the filter.
Attribute Description filters A list of filter. Each object should be a Filter class or its sub-class attr_type A type of attribute to map on filters. Currently AttributeMap.ATTR_LOCAL_PREF is available. attr_value A attribute value -
clone()¶ This method clones AttributeMap object.
Returns AttributeMap object that has the same values with the original one.
-
evaluate(path)¶ This method evaluates attributes of the path.
Returns the cause and result of matching. Both cause and result are returned from filters that this object contains.
pathspecifies the path.
-