Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update get probe code to make it work it IOS XE 16.12.x #1285

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,18 +2697,22 @@ def process_mac_fields(vlan, mac, mac_type, interface):

def get_probes_config(self):
probes = {}

probes_regex = (
r"ip\s+sla\s+(?P<id>\d+)\n"
r"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*\n).*"
r"\s+tag\s+(?P<name>\S+)\n.*"
r"\s+history\s+buckets-kept\s+(?P<probe_count>\d+)\n.*"
r"\s+frequency\s+(?P<interval>\d+)$"
r"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*)\n"
r"\s+tag\s+(?P<name>[\S ]+)\n"
r"(\s+.*\n)*"
r"((\s+frequency\s+(?P<interval0>\d+)\n(\s+.*\n)*\s+history"
r"\s+buckets-kept\s+(?P<probe_count0>\d+))|(\s+history\s+buckets-kept"
r"\s+(?P<probe_count1>\d+)\n.*\s+frequency\s+(?P<interval1>\d+)))"
)

probe_args = {
"icmp-echo": r"^(?P<target>\S+)\s+source-(?:ip|interface)\s+(?P<source>\S+)$"
}
probe_type_map = {"icmp-echo": "icmp-ping"}
command = "show run | include ip sla [0-9]"
command = "show run | section ip sla [0-9]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a lot of experience on IOS platforms, but my understanding from past PRs / conversations is that older versions may not support | section (while | include should always be there). Could you clarify what's the advantage or why you chose to switch @javcasalc?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Cisco doc, the right flag is section: https://www.cisco.com/c/en/us/td/docs/ios/fundamentals/command/reference/cf_book/cf_s1.html

Examples

The following examples compare the filtering characteristics of the show running-config | include command with the show running-config | section command. The first example gathers just the lines from the configuration file with "interface" in them.

Router# show running-config | include interface


interface Ethernet0/0 
interface Ethernet1/0 
interface Serial2/0 
interface Serial3/0


The next example uses the show command section command to gather the lines in the configuration file with "interface" in them as well as any lines associated with those entries. In this example, interface configuration information is captured.

Router# show running-config | section include interface


interface Ethernet0/0 
 shutdown 
 no cdp enable

interface Ethernet1/0 
 shutdown 
 no cdp enable 
interface Serial2/0 
 shutdown 
 no cdp enable 
interface Serial3/0 
 shutdown 
 no cdp enable

I did some tests in GNS3 with some old cisco routers (cisco 3640 with IOS 12.4; cisco 7200 with IOS 15.2) and I do confirm that section is the right choice:
imagen

Regarding the test case, I've included an extra "ip sla 3" entry, formatted with the new ios format, in order to test the correct parsing of both styles (old and new styles). Is this ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough... any thoughts on this @ktbyers ?

output = self._send_command(command)
for match in re.finditer(probes_regex, output, re.M):
probe = match.groupdict()
Expand All @@ -2724,8 +2728,8 @@ def get_probes_config(self):
"probe_type": probe_type_map[probe["probe_type"]],
"target": probe_data["target"],
"source": probe_data["source"],
"probe_count": int(probe["probe_count"]),
"test_interval": int(probe["interval"]),
"probe_count": int(probe["probe_count0"] or probe["probe_count1"]),
"test_interval": int(probe["interval0"] or probe["interval1"]),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@
"test_interval": 3,
"probe_count": 20
}
},
"3": {
"quad9": {
"source": "GigabitEthernet11",
"probe_type": "icmp-ping",
"target": "9.9.9.9",
"test_interval": 15,
"probe_count": 60
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ ip sla 2
history lives-kept 1
history buckets-kept 20
timeout 2000
frequency 3
frequency 3
ip sla 3
icmp-echo 9.9.9.9 source-interface GigabitEthernet11
tag quad9
frequency 15
history lives-kept 1
history buckets-kept 60