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 | |
| 9 | |
| 10 | class IpPath: |
| 11 | |
| 12 | def __init__(self, nh_addr, nh_sw_if_index, nh_table_id=0): |
| 13 | self.nh_addr = socket.inet_pton(socket.AF_INET, nh_addr) |
| 14 | self.nh_itf = nh_sw_if_index |
| 15 | self.nh_table_id = nh_table_id |
| 16 | |
| 17 | |
| 18 | class IpRoute: |
| 19 | """ |
| 20 | IP Route |
| 21 | """ |
| 22 | |
| 23 | def __init__(self, test, dest_addr, |
| 24 | dest_addr_len, paths, table_id=0): |
| 25 | self._test = test |
| 26 | self.paths = paths |
| 27 | self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr) |
| 28 | self.dest_addr_len = dest_addr_len |
| 29 | self.table_id = table_id |
| 30 | |
| 31 | def add_vpp_config(self): |
| 32 | for path in self.paths: |
| 33 | self._test.vapi.ip_add_del_route(self.dest_addr, |
| 34 | self.dest_addr_len, |
| 35 | path.nh_addr, |
| 36 | path.nh_itf, |
| 37 | table_id=self.table_id) |
| 38 | |
| 39 | def remove_vpp_config(self): |
| 40 | for path in self.paths: |
| 41 | self._test.vapi.ip_add_del_route(self.dest_addr, |
| 42 | self.dest_addr_len, |
| 43 | path.nh_addr, |
| 44 | path.nh_itf, |
| 45 | table_id=self.table_id, |
| 46 | is_add=0) |