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

MTU support #940

Merged
merged 12 commits into from
Apr 12, 2019
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
5 changes: 5 additions & 0 deletions napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def get_interfaces(self):
* description (string)
* last_flapped (float in seconds)
* speed (int in Mbit)
* MTU (in Bytes)
* mac_address (string)

Example::
Expand All @@ -280,6 +281,7 @@ def get_interfaces(self):
'description': '',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:61',
},
u'Ethernet1':
Expand All @@ -289,6 +291,7 @@ def get_interfaces(self):
'description': 'foo',
'last_flapped': 1429978575.1554043,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:62',
},
u'Ethernet2':
Expand All @@ -298,6 +301,7 @@ def get_interfaces(self):
'description': 'bla',
'last_flapped': 1429978575.1555667,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:63',
},
u'Ethernet3':
Expand All @@ -307,6 +311,7 @@ def get_interfaces(self):
'description': 'bar',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:64',
}
}
Expand Down
1 change: 1 addition & 0 deletions napalm/base/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"is_enabled": bool,
"description": text_type,
"last_flapped": float,
"mtu": int,
"speed": int,
"mac_address": text_type,
}
Expand Down
1 change: 1 addition & 0 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def get_interfaces(self):
"lastStatusChangeTimestamp", -1.0
)

interfaces[interface]["mtu"] = int(values["mtu"])
interfaces[interface]["speed"] = int(values["bandwidth"] * 1e-6)
interfaces[interface]["mac_address"] = napalm.base.helpers.convert(
napalm.base.helpers.mac, values.pop("physicalAddress", "")
Expand Down
8 changes: 5 additions & 3 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,11 +1053,12 @@ def get_interfaces(self):
descr_match = re.search(descr_regex, line)
description = descr_match.groups()[0]

speed_regex = r"^\s+MTU\s+\d+.+BW\s+(\d+)\s+([KMG]?b)"
speed_regex = r"^\s+MTU\s+(\d+).+BW\s+(\d+)\s+([KMG]?b)"
if re.search(speed_regex, line):
speed_match = re.search(speed_regex, line)
speed = speed_match.groups()[0]
speedformat = speed_match.groups()[1]
mtu = int(speed_match.groups()[0])
speed = speed_match.groups()[1]
speedformat = speed_match.groups()[2]
speed = float(speed)
if speedformat.startswith("Kb"):
speed = speed / 1000.0
Expand All @@ -1079,6 +1080,7 @@ def get_interfaces(self):
"description": description,
"mac_address": mac_address,
"last_flapped": last_flapped,
"mtu": mtu,
"speed": speed,
}

Expand Down
2 changes: 2 additions & 0 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ def get_interfaces(self):
)
* 1e-3,
)
mtu = int(napalm.base.helpers.find_txt(interface_tree, "MTU"))
description = napalm.base.helpers.find_txt(interface_tree, "Description")
interfaces[interface_name] = copy.deepcopy(INTERFACE_DEFAULTS)
interfaces[interface_name].update(
{
"is_up": is_up,
"speed": speed,
"mtu": mtu,
"is_enabled": enabled,
"mac_address": mac_address,
"description": description,
Expand Down
4 changes: 4 additions & 0 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ def _convert_to_dict(interfaces):
py23_compat.text_type(iface_data["mac_address"]),
),
"speed": -1,
"mtu": 0,
}
# result[iface]['last_flapped'] = float(result[iface]['last_flapped'])

match_mtu = re.search(r"(\w+)", str(iface_data["mtu"]) or "")
mtu = napalm.base.helpers.convert(int, match_mtu.group(0), 0)
result[iface]["mtu"] = mtu
match = re.search(r"(\d+)(\w*)", iface_data["speed"] or "")
if match is None:
continue
Expand Down
2 changes: 2 additions & 0 deletions napalm/junos/utils/junos_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ junos_iface_view:
last_flapped: { interface-flapped/@seconds: int }
#mode: logical-interface/address-family/address-family-name
speed: speed
mtu: mtu
mac_address: current-physical-address

junos_logical_iface_table:
Expand All @@ -33,6 +34,7 @@ junos_logical_iface_view:
description: { description: unicode }
last_flapped: { ../interface-flapped/@seconds: int }
speed: ../speed
mtu: ../mtu
mac_address: ../current-physical-address

####
Expand Down
3 changes: 3 additions & 0 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ def get_interfaces(self):

for interface_details in interfaces_body:
interface_name = interface_details.get("interface")
interface_mtu = interface_details.get("eth_mtu", 0)
interface_mtu = int(interface_mtu)
# Earlier version of Nexus returned a list for 'eth_bw' (observed on 7.1(0)N1(1a))
interface_speed = interface_details.get("eth_bw", 0)
if isinstance(interface_speed, list):
Expand All @@ -832,6 +834,7 @@ def get_interfaces(self):
interface_details.get("eth_link_flapped", "")
),
"speed": interface_speed,
"mtu": interface_mtu,
"mac_address": napalm.base.helpers.convert(
napalm.base.helpers.mac, interface_details.get("eth_hw_addr")
),
Expand Down
9 changes: 8 additions & 1 deletion napalm/nxos_ssh/nxos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def parse_intf_section(interface):
re_is_enabled_2 = r"^admin state is (?P<is_enabled>\S+), "
re_is_enabled_3 = r"^.* is down.*Administratively down.*$"
re_mac = r"^\s+Hardware:\s+(?P<hardware>.*),\s+address:\s+(?P<mac_address>\S+) "
re_speed = r"\s+MTU .*?,\s+BW\s+(?P<speed>\S+)\s+(?P<speed_unit>\S+).*$"
re_speed = (
r"\s+MTU (?P<mtu>\S+)\s+bytes,\s+BW\s+(?P<speed>\S+)\s+(?P<speed_unit>\S+).*$"
)
re_mtu_nve = r"\s+MTU (?P<mtu_nve>\S+)\s+bytes.*$"
re_description_1 = r"^\s+Description:\s+(?P<description>.*) (?:MTU|Internet)"
re_description_2 = r"^\s+Description:\s+(?P<description>.*)$"
re_hardware = r"^.* Hardware: (?P<hardware>\S+)$"
Expand Down Expand Up @@ -158,11 +161,14 @@ def parse_intf_section(interface):
speed_exist = True
if match:
if match.group("hardware") == "NVE":
match = re.search(re_mtu_nve, interface, flags=re.M)
mtu = int(match.group("mtu_nve"))
speed_exist = False

if speed_exist:
match = re.search(re_speed, interface, flags=re.M)
speed = int(match.group("speed"))
mtu = int(match.group("mtu"))
speed_unit = match.group("speed_unit")
speed_unit = speed_unit.rstrip(",")
# This was alway in Kbit (in the data I saw)
Expand All @@ -189,6 +195,7 @@ def parse_intf_section(interface):
"is_up": is_up,
"last_flapped": -1.0,
"mac_address": mac_address,
"mtu": mtu,
"speed": speed,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"last_flapped": 1474274582.7947989,
"is_up": true,
"mac_address": "",
"mtu": 65535,
"speed": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"last_flapped": 1466586841.4151127,
"is_up": true,
"mac_address": "08:00:27:10:C4:8F",
"mtu": 9214,
"speed": 0
},
"Management1": {
Expand All @@ -13,6 +14,7 @@
"last_flapped": 1466586841.4284112,
"is_up": true,
"mac_address": "08:00:27:20:B9:04",
"mtu": 1500,
"speed": 1000
},
"Ethernet1": {
Expand All @@ -21,6 +23,7 @@
"last_flapped": 1466586841.4148579,
"is_up": true,
"mac_address": "08:00:27:C6:00:F0",
"mtu": 9214,
"speed": 0
},
"Ethernet4": {
Expand All @@ -29,6 +32,7 @@
"last_flapped": 1466586841.415464,
"is_up": true,
"mac_address": "08:00:27:E0:12:D2",
"mtu": 9214,
"speed": 0
},
"Ethernet3": {
Expand All @@ -37,6 +41,7 @@
"last_flapped": 1466586841.4152465,
"is_up": true,
"mac_address": "08:00:27:1F:60:43",
"mtu": 9214,
"speed": 0
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,74 @@
{
"GigabitEthernet0/0": {
"last_flapped": -1,
"description": "",
"is_enabled": true,
"is_up": false,
"speed": 1000,
"last_flapped": -1,
"mac_address": "FA:16:3E:57:33:6F",
"description": ""
"mtu": 1500,
"speed": 1000
},
"GigabitEthernet0/1": {
"last_flapped": -1,
"description": "to iosvl2-2",
"is_enabled": true,
"is_up": true,
"speed": 1000,
"mac_address": "FA:16:3E:4F:41:CC",
"description": "to iosvl2-2"
},
"Port-channel1": {
"last_flapped": -1,
"is_enabled": true,
"is_up": false,
"speed": 100,
"mac_address": "FA:16:3E:4F:41:CC",
"description": ""
"mtu": 1500,
"speed": 1000
},
"GigabitEthernet0/3": {
"last_flapped": -1,
"GigabitEthernet0/2": {
"description": "to iosvl2-4",
"is_enabled": true,
"is_up": true,
"speed": 1000,
"mac_address": "FA:16:3E:31:2C:47",
"description": "to iosvl2-3"
},
"Loopback0": {
"last_flapped": -1,
"mac_address": "FA:16:3E:A3:3E:49",
"mtu": 1500,
"speed": 1000
},
"GigabitEthernet0/3": {
"description": "to iosvl2-3",
"is_enabled": true,
"is_up": true,
"speed": 8000,
"mac_address": "",
"description": "Loopback"
"last_flapped": -1,
"mac_address": "FA:16:3E:31:2C:47",
"mtu": 1500,
"speed": 1000
},
"GigabitEthernet1/0": {
"last_flapped": -1,
"description": "to iosvl2-3",
"is_enabled": true,
"is_up": true,
"speed": 1000,
"last_flapped": -1,
"mac_address": "FA:16:3E:C8:50:AB",
"description": "to iosvl2-3"
"mtu": 1500,
"speed": 1000
},
"Vlan1": {
"last_flapped": -1,
"Loopback0": {
"description": "Loopback",
"is_enabled": true,
"is_up": true,
"speed": 1000,
"mac_address": "FA:16:3E:57:80:01",
"description": "OOB Management"
"last_flapped": -1,
"mac_address": "",
"mtu": 1514,
"speed": 8000
},
"GigabitEthernet0/2": {
"Port-channel1": {
"description": "",
"is_enabled": true,
"is_up": false,
"last_flapped": -1,
"mac_address": "FA:16:3E:4F:41:CC",
"mtu": 1500,
"speed": 100
},
"Vlan1": {
"description": "OOB Management",
"is_enabled": true,
"is_up": true,
"speed": 1000,
"mac_address": "FA:16:3E:A3:3E:49",
"description": "to iosvl2-4"
"last_flapped": -1,
"mac_address": "FA:16:3E:57:80:01",
"mtu": 1500,
"speed": 1000
}
}
Loading