Add a FlowSpec rule to GoBGP and return its UUID.
(stub, params)
| 190 | |
| 191 | |
| 192 | def add_flowspec_rule(stub, params): |
| 193 | """Add a FlowSpec rule to GoBGP and return its UUID.""" |
| 194 | rules = _build_flowspec_rules(params) |
| 195 | if not rules: |
| 196 | raise ValueError("no match criteria specified") |
| 197 | |
| 198 | nlri = nlri_pb2.NLRI( |
| 199 | flow_spec=nlri_pb2.FlowSpecNLRI(rules=rules) |
| 200 | ) |
| 201 | |
| 202 | attributes = [ |
| 203 | attribute_pb2.Attribute( |
| 204 | origin=attribute_pb2.OriginAttribute(origin=0) |
| 205 | ), |
| 206 | ] |
| 207 | |
| 208 | action_community = _build_action(params) |
| 209 | if action_community is not None: |
| 210 | attributes.append( |
| 211 | attribute_pb2.Attribute( |
| 212 | extended_communities=( |
| 213 | attribute_pb2.ExtendedCommunitiesAttribute( |
| 214 | communities=[action_community] |
| 215 | ) |
| 216 | ) |
| 217 | ) |
| 218 | ) |
| 219 | |
| 220 | family = _detect_family(params) |
| 221 | |
| 222 | response = stub.AddPath( |
| 223 | gobgp_pb2.AddPathRequest( |
| 224 | table_type=gobgp_pb2.TABLE_TYPE_GLOBAL, |
| 225 | path=gobgp_pb2.Path( |
| 226 | nlri=nlri, |
| 227 | pattrs=attributes, |
| 228 | family=family, |
| 229 | ), |
| 230 | ), |
| 231 | timeout=_TIMEOUT_SECONDS, |
| 232 | ) |
| 233 | |
| 234 | uuid = response.uuid.hex() |
| 235 | with _lock: |
| 236 | _active_rules[uuid] = params |
| 237 | return uuid |
| 238 | |
| 239 | |
| 240 | def delete_flowspec_rule(stub, uuid): |
no test coverage detected
searching dependent graphs…