networktocode/ntc-templates

juniper_junos_show_interfaces incorrect parsing of state for irb interfaces

Closed this issue · 7 comments

  • Template Issue with error and raw data
TEMPLATE USING

ntc_templates/templates/juniper_junos_show_interfaces.textfsm

Value Required INTERFACE (\S+)
Value LINK_STATUS (\w+)
Value ADMIN_STATE (\S+)
Value HARDWARE_TYPE (\S+)
Value DESCRIPTION (.*)
Value DESTINATION (\S+)
Value LOCAL (\S+)
Value MTU (\d+|Unlimited)

Start
  ^\s*\S+\s+interface -> Continue.Record
  ^Physical\s+interface:\s+${INTERFACE},\s+${ADMIN_STATE},\s+Physical\s+link\s+is\s+${LINK_STATUS}
  ^.*Description:\s+${DESCRIPTION}
  ^.*ype:\s+${HARDWARE_TYPE},.*MTU:\s+${MTU}.*
  ^\s+Logical\s+interface\s+${INTERFACE}
  ^.*Destination:\s+${DESTINATION},\s+Local:\s+${LOCAL},.*
  ^\s*$$
  ^{master:\d+}

SAMPLE COMMAND OUTPUT
Logical interface irb.6013 (Index 361) (SNMP ifIndex 600)
    Description: Customer-irb-interface11A
    Flags: Down SNMP-Traps 0x4000 Encapsulation: ENET2
    MAC: 0e:00:05:0b:bb:bb
    Bandwidth: 1Gbps
    Routing Instance: DEFAULT-VSWITCH Bridging Domain: BD6013
    Input packets : 0
    Output packets: 0
    Protocol inet, MTU: 1514
    Max nh cache: 100000, New hold nh limit: 100000, Curr nh cnt: 0, Curr new hold cnt: 0, NH drop cnt: 0
      Flags: Sendbcast-pkt-to-re
      Addresses, Flags: Preferred Dest-route-down Is-Preferred Is-Primary
        Destination: x.x.x.x/28, Local: x.x.x.x, Broadcast: x.x.x.x
    Protocol multiservice, MTU: 1514
SUMMARY

Juniper irb interface (Integrated routing and bridging (IRB) interface) does not correctly identify current status, this is because irb reports it in the 'Flags' keyboard rather than 'Physical link'.
So Flags would be:
Flags: Down SNMP-Traps 0x4000 Encapsulation: ENET2
or
Flags: Up SNMP-Traps 0x4000 Encapsulation: ENET2

@andyb2000
It would seem that not only does irb parse this way, but also sub-interfaces.
Check for ge-0/0/0.2036 in the test data below.

❓ Are you suggesting that we should capture the first flag as the link status?

💡 Based on the raw test data, physical interfaces do not have Flags: so it should be safe to capture and should only affect sub-interfaces and irb interfaces. (In theory of course until I go make changes and test!)
https://github.com/networktocode/ntc-templates/blob/master/ntc_templates/templates/juniper_junos_show_interfaces.textfsm

Please respond back.
(I'm holding off working on this until I make sure I understand what is wanted.)

Hi @mjbear sorry for the delay in getting back to you, yes that's interesting then.
I think you're right, capture Flag as link status since on sub and irb/alternative interfaces this is the correct state and won't affect the physicals.
Let me know if you need more test data

Hello @andyb2000 ,
Thank you for responding.

So far I only have the two lines below to work off of. If you find any variations of the formatting on the Flags: line, please post the full output for that interface (just as you did with the first one).

My hope is to make the regex "loose" enough that it works if/when additional characters end up in the middle of the line (ex: between those square brackets in the second example snippet).

yours:
Flags: Down SNMP-Traps 0x4000 Encapsulation: ENET2

previous raw test example:
Flags: Up SNMP-Traps 0x0 VLAN-Tag [ 0x8100.2036 ] Encapsulation: ENET2

Thank you. So far I've not found any other variations on the above in my sample (a few on different sites but all with similar junos versions and models) so I think this looks suitable.

@andyb2000
I pulled together a fix as PR #1593
While I was at it, I made sure it also pulls the Protocol inet MTU as well.

If this works for you, please consider accepting that connection request. 😀 😎

Note: For logical interfaces (such as IRB or VLAN subinterfaces) there isn't any data to capture for admin_state or hardware_type but that doesn't differ from the original template.

Great, thank you!
Testing that PR out just now, looking good:

{'admin_state': '',
  'description': 'Customer: interface:',
  'destination': 'x.x.x.x/29',
  'hardware_type': '',
  'interface': 'irb.6027',
  'link_status': 'Up',
  'local': 'x.x.x.y',
  'mtu': '1514'},

I need to clean up my old branches. Ugh.