From ce80625f1dc50e2a886ef957e62673dc85b43c30 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:52:56 +0300 Subject: [PATCH] Aggregate L3 errors with L2 discards for interfaces with RIF (#325) Signed-off-by: Stepan Blyschak --- src/sonic_ax_impl/mibs/__init__.py | 12 +- tests/mock_tables/asic0/counters_db.json | 4 +- tests/mock_tables/asic1/counters_db.json | 4 +- tests/mock_tables/counters_db.json | 12 +- tests/namespace/test_interfaces.py | 144 +++++++++++++++++--- tests/test_interfaces.py | 162 +++++++++++++++++++---- 6 files changed, 276 insertions(+), 62 deletions(-) diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index 35e093ac3..38c70b113 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -33,15 +33,15 @@ RIF_COUNTERS_AGGR_MAP = { "SAI_PORT_STAT_IF_IN_OCTETS": "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS", "SAI_PORT_STAT_IF_IN_UCAST_PKTS": "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS", - "SAI_PORT_STAT_IF_IN_ERRORS": "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS", + "SAI_PORT_STAT_IF_IN_DISCARDS": "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS", "SAI_PORT_STAT_IF_OUT_OCTETS": "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS", "SAI_PORT_STAT_IF_OUT_UCAST_PKTS": "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS", - "SAI_PORT_STAT_IF_OUT_ERRORS": "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS" + "SAI_PORT_STAT_IF_OUT_DISCARDS": "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS" } RIF_DROPS_AGGR_MAP = { - "SAI_PORT_STAT_IF_IN_ERRORS": "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS", - "SAI_PORT_STAT_IF_OUT_ERRORS": "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS" + "SAI_PORT_STAT_IF_IN_DISCARDS": "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS" } redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'} @@ -231,7 +231,7 @@ def init_db(): :return: db_conn """ Namespace.init_sonic_db_config() - + # SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS. # Redis PubSub objects (such as those within swsscommon) are NOT thread-safe. db_conn = SonicV2Connector(**redis_kwargs) @@ -575,7 +575,7 @@ def init_namespace_dbs(): db_conn = [] Namespace.init_sonic_db_config() host_namespace_idx = 0 - for idx, namespace in enumerate(SonicDBConfig.get_ns_list()): + for idx, namespace in enumerate(SonicDBConfig.get_ns_list()): if namespace == multi_asic.DEFAULT_NAMESPACE: host_namespace_idx = idx db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace) diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index f7222c13d..3192cb355 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -216,7 +216,7 @@ "SAI_PORT_STAT_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", - "SAI_PORT_STAT_IF_IN_DISCARDS": "0", + "SAI_PORT_STAT_IF_IN_DISCARDS": "8", "SAI_PORT_STAT_IP_OUT_DISCARDS": "0", "SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0", "SAI_PORT_STAT_IPV6_IN_DISCARDS": "0", @@ -241,7 +241,7 @@ "SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0", "SAI_PORT_STAT_IPV6_IN_RECEIVES": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0", - "SAI_PORT_STAT_IF_OUT_DISCARDS": "0", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "14", "SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0", "SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0", "SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0", diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 4e7511f48..ef26c9d42 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -577,7 +577,7 @@ "SAI_PORT_STAT_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", - "SAI_PORT_STAT_IF_IN_DISCARDS": "0", + "SAI_PORT_STAT_IF_IN_DISCARDS": "13", "SAI_PORT_STAT_IP_OUT_DISCARDS": "0", "SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0", "SAI_PORT_STAT_IPV6_IN_DISCARDS": "0", @@ -602,7 +602,7 @@ "SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0", "SAI_PORT_STAT_IPV6_IN_RECEIVES": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0", - "SAI_PORT_STAT_IF_OUT_DISCARDS": "0", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "15", "SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0", "SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0", "SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0", diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index fdd76e764..6d22635d1 100755 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -12,7 +12,7 @@ "SAI_PORT_STAT_IF_IN_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", - "SAI_PORT_STAT_IF_IN_DISCARDS": "0", + "SAI_PORT_STAT_IF_IN_DISCARDS": "5", "SAI_PORT_STAT_IP_OUT_DISCARDS": "0", "SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0", "SAI_PORT_STAT_IPV6_IN_DISCARDS": "0", @@ -37,7 +37,7 @@ "SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0", "SAI_PORT_STAT_IPV6_IN_RECEIVES": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0", - "SAI_PORT_STAT_IF_OUT_DISCARDS": "0", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "10", "SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0", "SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0", "SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0", @@ -828,7 +828,7 @@ "SAI_PORT_STAT_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", - "SAI_PORT_STAT_IF_IN_DISCARDS": "0", + "SAI_PORT_STAT_IF_IN_DISCARDS": "7", "SAI_PORT_STAT_IP_OUT_DISCARDS": "0", "SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0", "SAI_PORT_STAT_IPV6_IN_DISCARDS": "0", @@ -853,7 +853,7 @@ "SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0", "SAI_PORT_STAT_IPV6_IN_RECEIVES": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0", - "SAI_PORT_STAT_IF_OUT_DISCARDS": "0", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "11", "SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0", "SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0", "SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0", @@ -3112,7 +3112,7 @@ "SAI_PORT_STAT_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", - "SAI_PORT_STAT_IF_IN_DISCARDS": "0", + "SAI_PORT_STAT_IF_IN_DISCARDS": "110", "SAI_PORT_STAT_IP_OUT_DISCARDS": "0", "SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0", "SAI_PORT_STAT_IPV6_IN_DISCARDS": "0", @@ -3137,7 +3137,7 @@ "SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0", "SAI_PORT_STAT_IPV6_IN_RECEIVES": "0", "SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0", - "SAI_PORT_STAT_IF_OUT_DISCARDS": "0", + "SAI_PORT_STAT_IF_OUT_DISCARDS": "120", "SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0", "SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0", "SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0", diff --git a/tests/namespace/test_interfaces.py b/tests/namespace/test_interfaces.py index 4ee723b20..56b1a295e 100644 --- a/tests/namespace/test_interfaces.py +++ b/tests/namespace/test_interfaces.py @@ -5,7 +5,7 @@ # 3 directory levels above sonic-snmpagent/tests/namespace/test_interfaces.py = sonic-snmpagent modules_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -# Insert sonic-snmpagent and sonic-snmpagent/src to path +# Insert sonic-snmpagent and sonic-snmpagent/src to path sys.path.insert(0, modules_path) sys.path.insert(0, os.path.join(modules_path, 'src')) @@ -466,7 +466,7 @@ def test_in_ucast_rif(self): def test_in_errors_rif(self): """ - For a port with RIF the counter values are aggregated + For a port with RIF the error counter values are not aggregated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)) get_pdu = GetPDU( @@ -480,7 +480,25 @@ def test_in_errors_rif(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)))) - self.assertEqual(value0.data, 101) + self.assertEqual(value0.data, 100) + + def test_in_discards_rif(self): + """ + For a port with RIF the discard counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 9)))) + self.assertEqual(value0.data, 14) def test_out_octets_rif(self): """ @@ -520,7 +538,7 @@ def test_out_ucast_rif(self): def test_out_errors_rif(self): """ - For a port with RIF the counter values are aggregated + For a port with RIF the error counter values are not aggregated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)) get_pdu = GetPDU( @@ -534,7 +552,25 @@ def test_out_errors_rif(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)))) - self.assertEqual(value0.data, 102) + self.assertEqual(value0.data, 100) + + def test_out_discards_rif(self): + """ + For a port with RIF the discard counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 9)))) + self.assertEqual(value0.data, 17) def test_in_octets_vlan(self): """ @@ -572,11 +608,11 @@ def test_in_ucast_vlan(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)))) self.assertEqual(value0.data, 10) - def test_in_errors_vlan(self): + def test_in_discards_vlan(self): """ For a l3 Vlan values are mapped from RIF stats """ - oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)) + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 3000)) get_pdu = GetPDU( header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid] @@ -587,7 +623,7 @@ def test_in_errors_vlan(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) - self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)))) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 3000)))) self.assertEqual(value0.data, 1) def test_out_octets_vlan(self): @@ -626,11 +662,11 @@ def test_out_ucast_vlan(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)))) self.assertEqual(value0.data, 20) - def test_out_errors_vlan(self): + def test_out_discards_vlan(self): """ For a l3 Vlan values are mapped from RIF stats """ - oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)) + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 3000)) get_pdu = GetPDU( header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid] @@ -641,7 +677,7 @@ def test_out_errors_vlan(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) - self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)))) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 3000)))) self.assertEqual(value0.data, 2) def test_in_octets_vlan_subinterface(self): @@ -682,7 +718,7 @@ def test_in_ucast_vlan_subinterface(self): def test_in_errors_vlan_subinterface(self): """ - For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + For a port with multiple vlan subinterfaces (RIF) all RIF errors are not accumulated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 17)) get_pdu = GetPDU( @@ -696,6 +732,24 @@ def test_in_errors_vlan_subinterface(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 17)))) + self.assertEqual(value0.data, 0) + + def test_in_discards_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 17)))) self.assertEqual(value0.data, 203) def test_out_octets_vlan_subinterface(self): @@ -736,7 +790,7 @@ def test_out_ucast_vlan_subinterface(self): def test_out_errors_vlan_subinterface(self): """ - For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + For a port with multiple vlan subinterfaces (RIF) all RIF errors are not accumulated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 17)) get_pdu = GetPDU( @@ -750,6 +804,24 @@ def test_out_errors_vlan_subinterface(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 17)))) + self.assertEqual(value0.data, 0) + + def test_out_discards_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 17)))) self.assertEqual(value0.data, 203) def test_in_octets_portchannel(self): @@ -790,7 +862,7 @@ def test_in_ucast_portchannel(self): def test_in_errors_portchannel(self): """ - For a l3 portchannel interface value is accumulated on members plus added Rif counters + For a l3 portchannel interface error value is accumulated on members """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)) get_pdu = GetPDU( @@ -804,7 +876,25 @@ def test_in_errors_portchannel(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)))) - self.assertEqual(value0.data, 106) + self.assertEqual(value0.data, 100) + + def test_in_discards_portchannel(self): + """ + For a l3 portchannel interface discard value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 1001)))) + self.assertEqual(value0.data, 14) def test_out_octets_portchannel(self): """ @@ -844,7 +934,7 @@ def test_out_ucast_portchannel(self): def test_out_errors_portchannel(self): """ - For a l3 portchannel interface value is accumulated on members plus added Rif counters + For a l3 portchannel interface error value is accumulated on members plus """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)) get_pdu = GetPDU( @@ -858,7 +948,25 @@ def test_out_errors_portchannel(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)))) - self.assertEqual(value0.data, 106) + self.assertEqual(value0.data, 100) + + def test_out_discards_portchannel(self): + """ + For a l3 portchannel interface discard value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 1001)))) + self.assertEqual(value0.data, 20) class TestGetNextPDU_2863(TestCase): @classmethod @@ -948,5 +1056,3 @@ def test_vlan_iface_description_ifMIB(self): self.assertEqual(value0.type_, ValueType.OCTET_STRING) self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)))) self.assertEqual(str(value0.data), '') - - diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py index 581cc2fb2..67676aa1c 100755 --- a/tests/test_interfaces.py +++ b/tests/test_interfaces.py @@ -461,7 +461,7 @@ def test_in_ucast_rif(self): def test_in_errors_rif(self): """ - For a port with RIF the counter values are aggregated + For a port with RIF the error counter values are not aggregated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 21)) get_pdu = GetPDU( @@ -475,7 +475,25 @@ def test_in_errors_rif(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 21)))) - self.assertEqual(value0.data, 101) + self.assertEqual(value0.data, 100) + + def test_in_discards_rif(self): + """ + For a port with RIF the discard counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 21)))) + self.assertEqual(value0.data, 111) def test_out_octets_rif(self): """ @@ -515,7 +533,7 @@ def test_out_ucast_rif(self): def test_out_errors_rif(self): """ - For a port with RIF the counter values are aggregated + For a port with RIF the error counter values are not aggregated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 21)) get_pdu = GetPDU( @@ -529,7 +547,25 @@ def test_out_errors_rif(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 21)))) - self.assertEqual(value0.data, 102) + self.assertEqual(value0.data, 100) + + def test_out_discards_rif(self): + """ + For a port with RIF the discard counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 21)))) + self.assertEqual(value0.data, 122) def test_in_octets_vlan(self): """ @@ -567,11 +603,11 @@ def test_in_ucast_vlan(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)))) self.assertEqual(value0.data, 10) - def test_in_errors_vlan(self): + def test_in_discards_vlan(self): """ For a l3 Vlan values are mapped from RIF stats """ - oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)) + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 3000)) get_pdu = GetPDU( header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid] @@ -582,7 +618,7 @@ def test_in_errors_vlan(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) - self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)))) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 3000)))) self.assertEqual(value0.data, 1) def test_out_octets_vlan(self): @@ -621,11 +657,11 @@ def test_out_ucast_vlan(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)))) self.assertEqual(value0.data, 20) - def test_out_errors_vlan(self): + def test_out_discards_vlan(self): """ For a l3 Vlan values are mapped from RIF stats """ - oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)) + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 3000)) get_pdu = GetPDU( header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid] @@ -636,7 +672,7 @@ def test_out_errors_vlan(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) - self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)))) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 3000)))) self.assertEqual(value0.data, 2) def test_in_octets_vlan_subinterface(self): @@ -677,7 +713,7 @@ def test_in_ucast_vlan_subinterface(self): def test_in_errors_vlan_subinterface(self): """ - For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + For a port with multiple vlan subinterfaces (RIF) errors are not accumulated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)) get_pdu = GetPDU( @@ -691,6 +727,24 @@ def test_in_errors_vlan_subinterface(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)))) + self.assertEqual(value0.data, 0) + + def test_in_discards_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) discards are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 9)))) self.assertEqual(value0.data, 203) def test_out_octets_vlan_subinterface(self): @@ -731,7 +785,7 @@ def test_out_ucast_vlan_subinterface(self): def test_out_errors_vlan_subinterface(self): """ - For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + For a port with multiple vlan subinterfaces (RIF) RIF errors are not accumulated """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)) get_pdu = GetPDU( @@ -745,6 +799,24 @@ def test_out_errors_vlan_subinterface(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)))) + self.assertEqual(value0.data, 0) + + def test_out_discards_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF discards are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 9)))) self.assertEqual(value0.data, 203) def test_in_octets_portchannel(self): @@ -785,7 +857,7 @@ def test_in_ucast_portchannel(self): def test_in_errors_portchannel(self): """ - For a l3 portchannel interface value is accumulated on members plus added Rif counters + For a l3 portchannel interface error is accumulated on members plus """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)) get_pdu = GetPDU( @@ -799,7 +871,25 @@ def test_in_errors_portchannel(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)))) - self.assertEqual(value0.data, 106) + self.assertEqual(value0.data, 100) + + def test_in_discards_portchannel(self): + """ + For a l3 portchannel interface discard is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 13, 1001)))) + self.assertEqual(value0.data, 18) def test_out_octets_portchannel(self): """ @@ -839,7 +929,7 @@ def test_out_ucast_portchannel(self): def test_out_errors_portchannel(self): """ - For a l3 portchannel interface value is accumulated on members plus added Rif counters + For a l3 portchannel interface error is accumulated on members """ oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)) get_pdu = GetPDU( @@ -853,7 +943,25 @@ def test_out_errors_portchannel(self): value0 = response.values[0] self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)))) - self.assertEqual(value0.data, 106) + self.assertEqual(value0.data, 100) + + def test_out_discards_portchannel(self): + """ + For a l3 portchannel interface discard is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 19, 1001)))) + self.assertEqual(value0.data, 27) class TestGetNextPDU_2863(TestCase): @classmethod @@ -865,7 +973,7 @@ def setUpClass(cls): updater.update_data() updater.reinit_data() updater.update_data() - + # Also load the data for RFC1213 which we will need to check consistency importlib.reload(rfc1213) cls.lut_1213 = MIBTable(rfc1213.InterfacesMIB) @@ -955,9 +1063,9 @@ def test_vlan_iface_description_ifMIB(self): def test_vlan_iface_1213_2863_consistent(self): """ Test that the interface paths in RFC1213 and RFC2863 have the same leaf values. - """ - - # Build prefixes for vlan interface descriptions in RFC1213 and RFC2863 tables + """ + + # Build prefixes for vlan interface descriptions in RFC1213 and RFC2863 tables pfx_1213 = [1, 3, 6, 1, 2, 1, 2, 2, 1, 2] pfx_2863 = [1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18] @@ -968,10 +1076,10 @@ def test_vlan_iface_1213_2863_consistent(self): raw_oid_2863.append(1) incl = 1 done = False - + # Compare actual OIDs found for the two RFCs with the relevant prefix while not done: - + # Get next OID for each table oid_1213 = ObjectIdentifier(11, 0, incl, 0, tuple(raw_oid_1213)) get_pdu_1213 = GetNextPDU( @@ -983,7 +1091,7 @@ def test_vlan_iface_1213_2863_consistent(self): header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid_2863] ) - + # Decode the OIDs found encoded_1213 = get_pdu_1213.encode() response_1213 = get_pdu_1213.make_response(self.lut_1213) @@ -991,13 +1099,13 @@ def test_vlan_iface_1213_2863_consistent(self): response_2863 = get_pdu_2863.make_response(self.lut) value0_1213 = response_1213.values[0] value0_2863 = response_2863.values[0] - + # Convert returned OIDs to lists, and extract prefixes by removing last element cur_pfx_1213 = list(value0_1213.name.subids) cur_pfx_2863 = list(value0_2863.name.subids) cur_pfx_1213.pop() cur_pfx_2863.pop() - + # Check if the returned OID have the same prefix we started with # It may be abbreviated so only check the end match_1213 = (cur_pfx_1213 == pfx_1213[-len(cur_pfx_1213):]) and (value0_1213.type_ == ValueType.OCTET_STRING) @@ -1005,7 +1113,7 @@ def test_vlan_iface_1213_2863_consistent(self): # We expect both tables to have equal numbers of OIDs self.assertEqual(match_1213, match_2863) - + # Check contents if both OIDs still match the original prefix if match_1213 and match_2863: last_1213 = value0_1213.name.subids[-1] @@ -1019,7 +1127,7 @@ def test_vlan_iface_1213_2863_consistent(self): raw_oid_2863 = pfx_2863.copy() raw_oid_2863.append(last_2863) incl = 0 - + # Otherwise we exhausted the values with this OID prefix else: done = True