@@ -4923,7 +4923,7 @@ def show_ospf_interfaces(json_data):
49234923 state = target_iface .get ('state' , 'down' )
49244924 cost = target_iface .get ('cost' , 0 )
49254925 priority = target_iface .get ('priority' , 1 )
4926- iface_type = target_iface .get ('interface-type' , 'unknown ' )
4926+ iface_type = target_iface .get ('interface-type' , '' )
49274927 hello_interval = target_iface .get ('hello-interval' , 10 )
49284928 dead_interval = target_iface .get ('dead-interval' , 40 )
49294929 retransmit_interval = target_iface .get ('retransmit-interval' , 5 )
@@ -4999,9 +4999,11 @@ def show_ospf_interfaces(json_data):
49994999 network_type_map = {
50005000 'point-to-point' : 'POINTOPOINT' ,
50015001 'broadcast' : 'BROADCAST' ,
5002- 'non-broadcast' : 'NBMA'
5002+ 'non-broadcast' : 'NBMA' ,
5003+ 'point-to-multipoint' : 'POINTOMULTIPOINT' ,
5004+ 'hybrid' : 'POINTOMULTIPOINT'
50035005 }
5004- network_type = network_type_map .get (iface_type , iface_type .upper ())
5006+ network_type = network_type_map .get (iface_type , iface_type .upper () if iface_type else 'LOOPBACK' )
50055007
50065008 print (f"{ name } is up" )
50075009 if ip_address :
@@ -5041,30 +5043,50 @@ def show_ospf_interfaces(json_data):
50415043 return
50425044
50435045 # Display table view (no specific interface)
5044- hdr = f"{ 'INTERFACE' :<12} { 'AREA' :<12} { 'STATE' :<10} { 'COST' :<6} { 'PRI' :<4} { 'DR' :<15} { 'BDR' :<15} { 'NBRS' :<5} "
5045- print (Decore .invert (hdr ))
5046+ type_display_map = {
5047+ 'point-to-point' : 'P2P' ,
5048+ 'broadcast' : 'Broadcast' ,
5049+ 'non-broadcast' : 'NBMA' ,
5050+ 'point-to-multipoint' : 'P2MP' ,
5051+ 'hybrid' : 'Hybrid'
5052+ }
5053+
5054+ def fmt_state (state ):
5055+ if state in ('dr' , 'bdr' ):
5056+ return state .upper ()
5057+ if state == 'dr-other' :
5058+ return 'DROther'
5059+ return state .capitalize ()
5060+
5061+ table = SimpleTable ([
5062+ Column ('INTERFACE' ),
5063+ Column ('AREA' ),
5064+ Column ('TYPE' ),
5065+ Column ('STATE' ),
5066+ Column ('COST' , 'right' ),
5067+ Column ('PRI' , 'right' ),
5068+ Column ('DR' ),
5069+ Column ('BDR' ),
5070+ Column ('NBRS' , 'right' )
5071+ ])
50465072
50475073 for iface in all_interfaces :
50485074 name = iface .get ('name' , 'unknown' )
50495075 area_id = iface .get ('_area_id' , '0.0.0.0' )
50505076 state = iface .get ('state' , 'down' )
5077+ iface_type = iface .get ('interface-type' , '' )
50515078 cost = iface .get ('cost' , 0 )
50525079 priority = iface .get ('priority' , 1 )
50535080 dr_id = iface .get ('dr-router-id' , '-' )
50545081 bdr_id = iface .get ('bdr-router-id' , '-' )
50555082 neighbors = iface .get ('neighbors' , {}).get ('neighbor' , [])
5056- nbr_count = len (neighbors )
50575083
5058- # Capitalize state nicely
5059- state_display = state .upper () if state in ['dr' , 'bdr' ] else state .capitalize ()
5060- if state == 'dr-other' :
5061- state_display = 'DROther'
5062-
5063- # Shorten router IDs for display
5064- dr_display = dr_id if dr_id != '-' else '-'
5065- bdr_display = bdr_id if bdr_id != '-' else '-'
5084+ table .row (name , area_id ,
5085+ type_display_map .get (iface_type , iface_type .capitalize () if iface_type else '-' ),
5086+ fmt_state (state ),
5087+ cost , priority , dr_id , bdr_id , len (neighbors ))
50665088
5067- print (f" { name :<12 } { area_id :<12 } { state_display :<10 } { cost :<6 } { priority :<4 } { dr_display :<15 } { bdr_display :<15 } { nbr_count :<5 } " )
5089+ table . print ()
50685090
50695091
50705092def show_ospf_neighbor (json_data ):
0 commit comments