| 428 | |
| 429 | |
| 430 | class VppRoutePath: |
| 431 | def __init__( |
| 432 | self, |
| 433 | nh_addr, |
| 434 | nh_sw_if_index, |
| 435 | nh_table_id=0, |
| 436 | labels=[], |
| 437 | nh_via_label=MPLS_LABEL_INVALID, |
| 438 | rpf_id=0, |
| 439 | next_hop_id=INVALID_INDEX, |
| 440 | proto=None, |
| 441 | flags=FibPathFlags.FIB_PATH_FLAG_NONE, |
| 442 | type=FibPathType.FIB_PATH_TYPE_NORMAL, |
| 443 | ): |
| 444 | self.nh_itf = nh_sw_if_index |
| 445 | self.nh_table_id = nh_table_id |
| 446 | self.nh_labels = labels |
| 447 | self.weight = 1 |
| 448 | self.rpf_id = rpf_id |
| 449 | self.proto = proto |
| 450 | self.flags = flags |
| 451 | self.type = type |
| 452 | self.nh = VppFibPathNextHop(nh_addr, nh_via_label, next_hop_id) |
| 453 | if proto is None: |
| 454 | self.proto = self.nh.proto() |
| 455 | else: |
| 456 | self.proto = proto |
| 457 | self.next_hop_id = next_hop_id |
| 458 | |
| 459 | def encode_labels(self): |
| 460 | lstack = [] |
| 461 | for l in self.nh_labels: |
| 462 | if type(l) == VppMplsLabel: |
| 463 | lstack.append(l.encode()) |
| 464 | else: |
| 465 | lstack.append({"label": l, "ttl": 255}) |
| 466 | while len(lstack) < 16: |
| 467 | lstack.append({}) |
| 468 | |
| 469 | return lstack |
| 470 | |
| 471 | def encode(self): |
| 472 | return { |
| 473 | "weight": 1, |
| 474 | "preference": 0, |
| 475 | "table_id": self.nh_table_id, |
| 476 | "nh": self.nh.encode(), |
| 477 | "next_hop_id": self.next_hop_id, |
| 478 | "sw_if_index": self.nh_itf, |
| 479 | "rpf_id": self.rpf_id, |
| 480 | "proto": self.proto, |
| 481 | "type": self.type, |
| 482 | "flags": self.flags, |
| 483 | "n_labels": len(self.nh_labels), |
| 484 | "label_stack": self.encode_labels(), |
| 485 | } |
| 486 | |
| 487 | def __eq__(self, other): |
no outgoing calls