@@ -28,8 +28,10 @@ class Level(Enum):
28
28
def __str__ (self ):
29
29
return self .value
30
30
31
+
31
32
report_level = syslog .LOG_ERR
32
33
34
+
33
35
def set_level (lvl ):
34
36
global report_level
35
37
@@ -48,27 +50,37 @@ def print_message(lvl, *args):
48
50
print (msg )
49
51
syslog .syslog (lvl , msg )
50
52
53
+
51
54
def add_prefix (ip ):
52
55
if ip .find (IPV6_SEPARATOR ) == - 1 :
53
56
ip = ip + PREFIX_SEPARATOR + "32"
54
57
else :
55
58
ip = ip + PREFIX_SEPARATOR + "128"
56
59
return ip
57
60
61
+
58
62
def add_prefix_ifnot (ip ):
59
63
return ip if ip .find (PREFIX_SEPARATOR ) != - 1 else add_prefix (ip )
60
64
65
+
61
66
def is_local (ip ):
62
67
t = ipaddress .ip_address (ip .split ("/" )[0 ].decode ('utf-8' ))
63
68
return t .is_link_local
64
69
70
+
71
+ def is_default_route (ip ):
72
+ t = ipaddress .ip_address (ip .split ("/" )[0 ].decode ('utf-8' ))
73
+ return t .is_unspecified and ip .split ("/" )[1 ] == "0"
74
+
75
+
65
76
def cmps (s1 , s2 ):
66
77
if (s1 == s2 ):
67
78
return 0
68
79
if (s1 < s2 ):
69
80
return - 1
70
81
return 1
71
82
83
+
72
84
def do_diff (t1 , t2 ):
73
85
t1_x = t2_x = 0
74
86
t1_miss = []
@@ -111,6 +123,7 @@ def get_routes():
111
123
print_message (syslog .LOG_DEBUG , json .dumps ({"ROUTE_TABLE" : sorted (valid_rt )}, indent = 4 ))
112
124
return sorted (valid_rt )
113
125
126
+
114
127
def get_route_entries ():
115
128
db = ConfigDBConnector ()
116
129
db .db_connect ('ASIC_DB' )
@@ -147,6 +160,7 @@ def get_interfaces():
147
160
print_message (syslog .LOG_DEBUG , json .dumps ({"APPL_DB_INTF" : sorted (intf )}, indent = 4 ))
148
161
return sorted (intf )
149
162
163
+
150
164
def filter_out_local_interfaces (keys ):
151
165
rt = []
152
166
local_if = set (['eth0' , 'lo' , 'docker0' ])
@@ -164,6 +178,17 @@ def filter_out_local_interfaces(keys):
164
178
165
179
return rt
166
180
181
+
182
+ def filter_out_default_routes (lst ):
183
+ upd = []
184
+
185
+ for rt in lst :
186
+ if not is_default_route (rt ):
187
+ upd .append (rt )
188
+
189
+ return upd
190
+
191
+
167
192
def check_routes ():
168
193
intf_appl_miss = []
169
194
rt_appl_miss = []
@@ -181,6 +206,7 @@ def check_routes():
181
206
182
207
# Check missed ASIC routes against APPL-DB INTF_TABLE
183
208
_ , rt_asic_miss = do_diff (intf_appl , rt_asic_miss )
209
+ rt_asic_miss = filter_out_default_routes (rt_asic_miss )
184
210
185
211
# Check APPL-DB INTF_TABLE with ASIC table route entries
186
212
intf_appl_miss , _ = do_diff (intf_appl , rt_asic )
@@ -208,6 +234,7 @@ def check_routes():
208
234
print_message (syslog .LOG_INFO , "All good!" )
209
235
return 0
210
236
237
+
211
238
def main (argv ):
212
239
interval = 0
213
240
parser = argparse .ArgumentParser (description = "Verify routes between APPL-DB & ASIC-DB are in sync" )
0 commit comments