From 7888ad9e0bf872ff93f28b9ab87019fb48853edd Mon Sep 17 00:00:00 2001 From: Erik Ruiter Date: Fri, 10 May 2019 13:12:53 +0000 Subject: [PATCH] Add get_arp_table method --- napalm_fortios/fortios.py | 22 +++++++++++ .../normal/expected_result.json | 38 +++++++++++++++++++ .../test_get_arp_table/normal/get_sys_arp.txt | 8 ++++ 3 files changed, 68 insertions(+) create mode 100644 test/unit/mocked_data/test_get_arp_table/normal/expected_result.json create mode 100644 test/unit/mocked_data/test_get_arp_table/normal/get_sys_arp.txt diff --git a/napalm_fortios/fortios.py b/napalm_fortios/fortios.py index 0641290..30113ba 100644 --- a/napalm_fortios/fortios.py +++ b/napalm_fortios/fortios.py @@ -20,6 +20,7 @@ from napalm_base.exceptions import ReplaceConfigException, MergeConfigException from napalm_base.utils.string_parsers import colon_separated_string_to_dict,\ convert_uptime_string_seconds from napalm_base.utils import py23_compat +import napalm_base.helpers try: from napalm.base.base import NetworkDriver @@ -512,3 +513,24 @@ class FortiOSDriver(NetworkDriver): out['power'] = {t: {'status': True, 'capacity': -1.0, 'output': -1.0} for t in psus} return out + + def get_arp_table(self): + + arp_table = [] + command = "get sys arp" + output = self._execute_command_with_vdom(command) + + # Skip the first line which is a header + output = output[1:] + + for line in output: + if len(line) > 0: + address, age, mac, interface = line.split() + entry = { + "interface": interface, + "mac": napalm_base.helpers.mac(mac).rstrip(), + "ip": address, + "age": age.replace("-", "-1"), + } + arp_table.append(entry) + return arp_table diff --git a/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json b/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json new file mode 100644 index 0000000..fc77f11 --- /dev/null +++ b/test/unit/mocked_data/test_get_arp_table/normal/expected_result.json @@ -0,0 +1,38 @@ +[ + { + "interface": "vlan99", + "ip": "192.168.199.43", + "mac": "EC:F4:BB:D6:4B:C8", + "age": 0 + }, + { + "interface": "vlan99", + "ip": "192.168.199.90", + "mac": "00:50:56:88:95:25", + "age": 0 + }, + { + "interface": "vlan99", + "ip": "192.168.199.75", + "mac": "00:0C:29:F0:B6:54", + "age": 0 + }, + { + "interface": "vlan99", + "ip": "192.168.199.44", + "mac": "00:10:18:E6:8F:A7", + "age": 0 + }, + { + "interface": "port4", + "ip": "169.254.0.1", + "mac": "00:50:56:88:B9:98", + "age": -1 + }, + { + "interface": "vlan99", + "ip": "192.168.199.60", + "mac": "00:50:CC:7E:26:40", + "age": 0 + } +] \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_arp_table/normal/get_sys_arp.txt b/test/unit/mocked_data/test_get_arp_table/normal/get_sys_arp.txt new file mode 100644 index 0000000..b56780a --- /dev/null +++ b/test/unit/mocked_data/test_get_arp_table/normal/get_sys_arp.txt @@ -0,0 +1,8 @@ +Address Age(min) Hardware Addr Interface +192.168.199.43 0 ec:f4:bb:d6:4b:c8 vlan99 +192.168.199.90 0 00:50:56:88:95:25 vlan99 +192.168.199.75 0 00:0c:29:f0:b6:54 vlan99 +192.168.199.44 0 00:10:18:e6:8f:a7 vlan99 +169.254.0.1 - 00:50:56:88:b9:98 port4 +192.168.199.60 0 00:50:cc:7e:26:40 vlan99 +