-
Notifications
You must be signed in to change notification settings - Fork 0
/
FTutils.py
30 lines (24 loc) · 917 Bytes
/
FTutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import copy
def ft_entry_init(prefix=None, interface=None):
return {
'Prefix': prefix,
'Interface': interface
}
def ft_build_from_rib(rib, dp, device_dict_cp):
for device in dp['Devices']:
device_name = device['Name']
rib_d = rib[device_name]
# init forwarding table
device['ForwardingTable'] = []
ft = device['ForwardingTable']
# translate static routes into fib entry
for fi in device_dict_cp[device_name]['StaticRoutes']:
ft.append(copy.deepcopy(fi))
# translate rib entry into fib entry
for prefix, entries in rib_d.items():
for entry in entries:
if len(entry['ASPath']) == 0:
# originated locally, added as static route
continue
# translate
ft.append(ft_entry_init(prefix, entry['Interface']))