Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1 | """ |
| 2 | IP Routes |
| 3 | |
| 4 | object abstractions for representing IP routes in VPP |
| 5 | """ |
| 6 | |
| 7 | import socket |
| 8 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 9 | # from vnet/vnet/mpls/mpls_types.h |
| 10 | MPLS_IETF_MAX_LABEL = 0xfffff |
| 11 | MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 12 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 13 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 14 | class RoutePath: |
| 15 | |
| 16 | def __init__(self, nh_addr, nh_sw_if_index, nh_table_id=0, labels=[], nh_via_label=MPLS_LABEL_INVALID): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 17 | self.nh_addr = socket.inet_pton(socket.AF_INET, nh_addr) |
| 18 | self.nh_itf = nh_sw_if_index |
| 19 | self.nh_table_id = nh_table_id |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 20 | self.nh_via_label = nh_via_label |
| 21 | self.nh_labels = labels |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class IpRoute: |
| 25 | """ |
| 26 | IP Route |
| 27 | """ |
| 28 | |
| 29 | def __init__(self, test, dest_addr, |
| 30 | dest_addr_len, paths, table_id=0): |
| 31 | self._test = test |
| 32 | self.paths = paths |
| 33 | self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr) |
| 34 | self.dest_addr_len = dest_addr_len |
| 35 | self.table_id = table_id |
| 36 | |
| 37 | def add_vpp_config(self): |
| 38 | for path in self.paths: |
| 39 | self._test.vapi.ip_add_del_route(self.dest_addr, |
| 40 | self.dest_addr_len, |
| 41 | path.nh_addr, |
| 42 | path.nh_itf, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 43 | table_id=self.table_id, |
| 44 | next_hop_out_label_stack=path.nh_labels, |
| 45 | next_hop_n_out_labels=len( |
| 46 | path.nh_labels), |
| 47 | next_hop_via_label=path.nh_via_label) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 48 | |
| 49 | def remove_vpp_config(self): |
| 50 | for path in self.paths: |
| 51 | self._test.vapi.ip_add_del_route(self.dest_addr, |
| 52 | self.dest_addr_len, |
| 53 | path.nh_addr, |
| 54 | path.nh_itf, |
| 55 | table_id=self.table_id, |
| 56 | is_add=0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 57 | |
| 58 | |
| 59 | class MplsIpBind: |
| 60 | """ |
| 61 | MPLS to IP Binding |
| 62 | """ |
| 63 | |
| 64 | def __init__(self, test, local_label, dest_addr, dest_addr_len): |
| 65 | self._test = test |
| 66 | self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr) |
| 67 | self.dest_addr_len = dest_addr_len |
| 68 | self.local_label = local_label |
| 69 | |
| 70 | def add_vpp_config(self): |
| 71 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
| 72 | self.dest_addr, |
| 73 | self.dest_addr_len) |
| 74 | |
| 75 | def remove_vpp_config(self): |
| 76 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
| 77 | self.dest_addr, |
| 78 | self.dest_addr_len, |
| 79 | is_bind=0) |
| 80 | |
| 81 | |
| 82 | class MplsRoute: |
| 83 | """ |
| 84 | MPLS Route |
| 85 | """ |
| 86 | |
| 87 | def __init__(self, test, local_label, eos_bit, paths, table_id=0): |
| 88 | self._test = test |
| 89 | self.paths = paths |
| 90 | self.local_label = local_label |
| 91 | self.eos_bit = eos_bit |
| 92 | self.table_id = table_id |
| 93 | |
| 94 | def add_vpp_config(self): |
| 95 | for path in self.paths: |
| 96 | self._test.vapi.mpls_route_add_del(self.local_label, |
| 97 | self.eos_bit, |
| 98 | 1, |
| 99 | path.nh_addr, |
| 100 | path.nh_itf, |
| 101 | table_id=self.table_id, |
| 102 | next_hop_out_label_stack=path.nh_labels, |
| 103 | next_hop_n_out_labels=len( |
| 104 | path.nh_labels), |
Neale Ranns | cb630ff | 2016-12-14 13:31:29 +0100 | [diff] [blame] | 105 | next_hop_via_label=path.nh_via_label, |
| 106 | next_hop_table_id=path.nh_table_id) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 107 | |
| 108 | def remove_vpp_config(self): |
| 109 | for path in self.paths: |
| 110 | self._test.vapi.mpls_route_add_del(self.local_label, |
| 111 | self.eos_bit, |
| 112 | 1, |
| 113 | path.nh_addr, |
| 114 | path.nh_itf, |
| 115 | table_id=self.table_id, |
| 116 | is_add=0) |