8
8
from swsssdk import port_util
9
9
from sonic_ax_impl import mibs , logger
10
10
from sonic_ax_impl .mibs import Namespace
11
+ from ax_interface .util import ip2byte_tuple
11
12
from ax_interface import MIBMeta , SubtreeMIBEntry , MIBEntry , MIBUpdater , ValueType
12
13
13
14
@@ -317,7 +318,8 @@ def reinit_data(self):
317
318
mgmt_ip_sub_oid = None
318
319
for mgmt_ip in self .mgmt_ip_str .split (',' ):
319
320
if '.' in mgmt_ip :
320
- mgmt_ip_sub_oid = (addr_subtype_sub_oid , * [int (i ) for i in mgmt_ip .split ('.' )])
321
+ mgmt_ip_tuple = ip2byte_tuple (mgmt_ip )
322
+ mgmt_ip_sub_oid = (addr_subtype_sub_oid , * mgmt_ip_tuple )
321
323
break
322
324
else :
323
325
logger .error ("Could not find IPv4 address in lldp_loc_man_addr" )
@@ -494,10 +496,8 @@ def __init__(self):
494
496
# establish connection to application database.
495
497
Namespace .connect_all_dbs (self .db_conn , mibs .APPL_DB )
496
498
self .if_range = []
497
- self .mgmt_ips = {}
498
499
self .oid_name_map = {}
499
500
self .mgmt_oid_name_map = {}
500
- self .mgmt_ip_str = None
501
501
self .pubsub = [None ] * len (self .db_conn )
502
502
503
503
def update_rem_if_mgmt (self , if_oid , if_name ):
@@ -511,28 +511,28 @@ def update_rem_if_mgmt(self, if_oid, if_name):
511
511
if len (mgmt_ip_str ) == 0 :
512
512
# the peer advertise an emtpy mgmt address
513
513
return
514
- time_mark = int ( lldp_kvs [ 'lldp_rem_time_mark' ] )
515
- remote_index = int ( lldp_kvs [ 'lldp_rem_index' ])
516
- subtype = self . get_subtype ( mgmt_ip_str )
517
- ip_hex = self . get_ip_hex ( mgmt_ip_str , subtype )
518
- if subtype == ManAddrConst . man_addr_subtype_ipv4 :
519
- addr_subtype_sub_oid = 4
520
- mgmt_ip_sub_oid = ( addr_subtype_sub_oid , * [ int ( i ) for i in mgmt_ip_str . split ( '.' )] )
521
- elif subtype == ManAddrConst . man_addr_subtype_ipv6 :
522
- addr_subtype_sub_oid = 6
523
- mgmt_ip_sub_oid = ( addr_subtype_sub_oid , * [ int ( i , 16 ) if i else 0 for i in mgmt_ip_str . split ( ':' )])
524
- else :
525
- logger . warning ( "Invalid management IP {}" . format ( mgmt_ip_str ))
526
- return
527
- self . if_range . append (( time_mark ,
528
- if_oid ,
529
- remote_index ,
530
- subtype ,
531
- * mgmt_ip_sub_oid ))
532
-
533
- self . mgmt_ips . update ({ if_name : { "ip_str" : mgmt_ip_str ,
534
- "addr_subtype" : subtype ,
535
- "addr_hex" : ip_hex }} )
514
+ mgmt_ip_set = set ( )
515
+ for mgmt_ip in mgmt_ip_str . split ( ',' ):
516
+ time_mark = int ( lldp_kvs [ 'lldp_rem_time_mark' ] )
517
+ remote_index = int ( lldp_kvs [ 'lldp_rem_index' ] )
518
+ subtype = self . get_subtype ( mgmt_ip )
519
+ if not subtype :
520
+ logger . warning ( "Invalid management IP {}" . format ( mgmt_ip ) )
521
+ continue
522
+ mgmt_ip_tuple = ip2byte_tuple ( mgmt_ip )
523
+ if mgmt_ip_tuple in mgmt_ip_set :
524
+ continue
525
+ elif subtype == ManAddrConst . man_addr_subtype_ipv4 :
526
+ addr_subtype_sub_oid = 4
527
+ else :
528
+ addr_subtype_sub_oid = 16
529
+ mgmt_ip_set . add ( mgmt_ip_tuple )
530
+ mgmt_ip_sub_oid = ( addr_subtype_sub_oid , * mgmt_ip_tuple )
531
+ self . if_range . append (( time_mark ,
532
+ if_oid ,
533
+ remote_index ,
534
+ subtype ,
535
+ * mgmt_ip_sub_oid ) )
536
536
except (KeyError , AttributeError ) as e :
537
537
logger .warning ("Error updating remote mgmt addr: {}" .format (e ))
538
538
return
@@ -562,7 +562,6 @@ def update_data(self):
562
562
self .pubsub [i ] = mibs .get_redis_pubsub (self .db_conn [i ], self .db_conn [i ].APPL_DB , pattern )
563
563
self ._update_per_namespace_data (self .pubsub [i ])
564
564
565
-
566
565
def reinit_data (self ):
567
566
"""
568
567
Subclass reinit data routine.
@@ -577,7 +576,6 @@ def reinit_data(self):
577
576
Namespace .connect_all_dbs (self .db_conn , mibs .APPL_DB )
578
577
579
578
self .if_range = []
580
- self .mgmt_ips = {}
581
579
for if_oid , if_name in self .oid_name_map .items ():
582
580
self .update_rem_if_mgmt (if_oid , if_name )
583
581
@@ -588,25 +586,9 @@ def get_next(self, sub_id):
588
586
return self .if_range [right ]
589
587
590
588
def lookup (self , sub_id , callable ):
591
- if len (sub_id ) == 0 :
592
- return None
593
- sub_id = sub_id [1 ]
594
- if sub_id not in self .oid_name_map :
595
- return None
596
- if_name = self .oid_name_map [sub_id ]
597
- if if_name not in self .mgmt_ips :
598
- # no data for this interface
589
+ if sub_id not in self .if_range :
599
590
return None
600
- return callable (sub_id , if_name )
601
-
602
- def get_ip_hex (self , mgmt_ip_str , subtype ):
603
- if subtype == ManAddrConst .man_addr_subtype_ipv4 :
604
- hex_ip = " " .join ([format (int (i ), '02X' ) for i in mgmt_ip_str .split ('.' )])
605
- elif subtype == ManAddrConst .man_addr_subtype_ipv6 :
606
- hex_ip = " " .join ([format (int (i , 16 ), 'x' ) if i else "0" for i in mgmt_ip_str .split (':' )])
607
- else :
608
- hex_ip = None
609
- return hex_ip
591
+ return callable (sub_id )
610
592
611
593
def get_subtype (self , ip_str ):
612
594
try :
@@ -623,24 +605,14 @@ def get_subtype(self, ip_str):
623
605
logger .warning ("Invalid mgmt IP {}" .format (ip_str ))
624
606
return None
625
607
626
- def man_addr_subtype (self , sub_id , if_name ):
627
- return self .mgmt_ips [if_name ]['addr_subtype' ]
628
-
629
- def man_addr (self , sub_id , if_name ):
630
- """
631
- :param sub_id:
632
- :return: MGMT IP in HEX
633
- """
634
- return self .mgmt_ips [if_name ]['addr_hex' ]
635
-
636
608
@staticmethod
637
- def man_addr_if_subtype (sub_id , _ ): return ManAddrConst .man_addr_if_subtype
609
+ def man_addr_if_subtype (sub_id ): return ManAddrConst .man_addr_if_subtype
638
610
639
611
@staticmethod
640
- def man_addr_if_id (sub_id , _ ): return ManAddrConst .man_addr_if_id
612
+ def man_addr_if_id (sub_id ): return ManAddrConst .man_addr_if_id
641
613
642
614
@staticmethod
643
- def man_addr_OID (sub_id , _ ): return ManAddrConst .man_addr_oid
615
+ def man_addr_OID (sub_id ): return ManAddrConst .man_addr_oid
644
616
645
617
646
618
class LLDPLocalSystemData (metaclass = MIBMeta , prefix = '.1.0.8802.1.1.2.1.3' ):
0 commit comments