@@ -4838,7 +4838,7 @@ def show_ospf_interfaces(json_data):
48384838 state = target_iface .get ('state' , 'down' )
48394839 cost = target_iface .get ('cost' , 0 )
48404840 priority = target_iface .get ('priority' , 1 )
4841- iface_type = target_iface .get ('interface-type' , 'unknown ' )
4841+ iface_type = target_iface .get ('interface-type' , '' )
48424842 hello_interval = target_iface .get ('hello-interval' , 10 )
48434843 dead_interval = target_iface .get ('dead-interval' , 40 )
48444844 retransmit_interval = target_iface .get ('retransmit-interval' , 5 )
@@ -4914,9 +4914,11 @@ def show_ospf_interfaces(json_data):
49144914 network_type_map = {
49154915 'point-to-point' : 'POINTOPOINT' ,
49164916 'broadcast' : 'BROADCAST' ,
4917- 'non-broadcast' : 'NBMA'
4917+ 'non-broadcast' : 'NBMA' ,
4918+ 'point-to-multipoint' : 'POINTOMULTIPOINT' ,
4919+ 'hybrid' : 'POINTOMULTIPOINT'
49184920 }
4919- network_type = network_type_map .get (iface_type , iface_type .upper ())
4921+ network_type = network_type_map .get (iface_type , iface_type .upper () if iface_type else 'LOOPBACK' )
49204922
49214923 print (f"{ name } is up" )
49224924 if ip_address :
@@ -4956,30 +4958,50 @@ def show_ospf_interfaces(json_data):
49564958 return
49574959
49584960 # Display table view (no specific interface)
4959- hdr = f"{ 'INTERFACE' :<12} { 'AREA' :<12} { 'STATE' :<10} { 'COST' :<6} { 'PRI' :<4} { 'DR' :<15} { 'BDR' :<15} { 'NBRS' :<5} "
4960- print (Decore .invert (hdr ))
4961+ type_display_map = {
4962+ 'point-to-point' : 'P2P' ,
4963+ 'broadcast' : 'Broadcast' ,
4964+ 'non-broadcast' : 'NBMA' ,
4965+ 'point-to-multipoint' : 'P2MP' ,
4966+ 'hybrid' : 'Hybrid'
4967+ }
4968+
4969+ def fmt_state (state ):
4970+ if state in ('dr' , 'bdr' ):
4971+ return state .upper ()
4972+ if state == 'dr-other' :
4973+ return 'DROther'
4974+ return state .capitalize ()
4975+
4976+ table = SimpleTable ([
4977+ Column ('INTERFACE' ),
4978+ Column ('AREA' ),
4979+ Column ('TYPE' ),
4980+ Column ('STATE' ),
4981+ Column ('COST' , 'right' ),
4982+ Column ('PRI' , 'right' ),
4983+ Column ('DR' ),
4984+ Column ('BDR' ),
4985+ Column ('NBRS' , 'right' )
4986+ ])
49614987
49624988 for iface in all_interfaces :
49634989 name = iface .get ('name' , 'unknown' )
49644990 area_id = iface .get ('_area_id' , '0.0.0.0' )
49654991 state = iface .get ('state' , 'down' )
4992+ iface_type = iface .get ('interface-type' , '' )
49664993 cost = iface .get ('cost' , 0 )
49674994 priority = iface .get ('priority' , 1 )
49684995 dr_id = iface .get ('dr-router-id' , '-' )
49694996 bdr_id = iface .get ('bdr-router-id' , '-' )
49704997 neighbors = iface .get ('neighbors' , {}).get ('neighbor' , [])
4971- nbr_count = len (neighbors )
49724998
4973- # Capitalize state nicely
4974- state_display = state .upper () if state in ['dr' , 'bdr' ] else state .capitalize ()
4975- if state == 'dr-other' :
4976- state_display = 'DROther'
4977-
4978- # Shorten router IDs for display
4979- dr_display = dr_id if dr_id != '-' else '-'
4980- bdr_display = bdr_id if bdr_id != '-' else '-'
4999+ table .row (name , area_id ,
5000+ type_display_map .get (iface_type , iface_type .capitalize () if iface_type else '-' ),
5001+ fmt_state (state ),
5002+ cost , priority , dr_id , bdr_id , len (neighbors ))
49815003
4982- print (f" { name :<12 } { area_id :<12 } { state_display :<10 } { cost :<6 } { priority :<4 } { dr_display :<15 } { bdr_display :<15 } { nbr_count :<5 } " )
5004+ table . print ()
49835005
49845006
49855007def show_ospf_neighbor (json_data ):
0 commit comments