Esempio n. 1
0
    def handle(self):
        # Start by checking the prefix cache
        prefix_cache_age = datetime.now() - self.prefix_cache_update_time
        if prefix_cache_age > self.prefix_cache_max_age:
            yield self._update_prefix_cache()

        self._logger.debug("Collecting IP/MAC mappings")

        # Fetch standard MIBs
        ip_mib = IpMib(self.agent)
        mappings = yield ip_mib.get_ifindex_ip_mac_mappings()
        self._logger.debug("Found %d mappings in IP-MIB", len(mappings))

        # Try IPV6-MIB if no IPv6 results were found in IP-MIB
        if not ipv6_address_in_mappings(mappings):
            ipv6_mib = Ipv6Mib(self.agent)
            ipv6_mappings = yield ipv6_mib.get_ifindex_ip_mac_mappings()
            self._logger.debug("Found %d mappings in IPV6-MIB",
                               len(ipv6_mappings))
            mappings.update(ipv6_mappings)

        # If we got no results, or no IPv6 results, try vendor specific MIBs
        if len(mappings) == 0 or not ipv6_address_in_mappings(mappings):
            cisco_ip_mib = CiscoIetfIpMib(self.agent)
            cisco_ip_mappings = yield cisco_ip_mib.get_ifindex_ip_mac_mappings(
            )
            self._logger.debug("Found %d mappings in CISCO-IETF-IP-MIB",
                               len(cisco_ip_mappings))
            mappings.update(cisco_ip_mappings)

        yield self._process_data(mappings)
Esempio n. 2
0
    def handle(self):
        # Start by checking the prefix cache
        prefix_cache_age = datetime.now() - self.prefix_cache_update_time
        if prefix_cache_age > self.prefix_cache_max_age:
            yield self._update_prefix_cache()

        self._logger.debug("Collecting IP/MAC mappings")

        # Fetch standard MIBs
        ip_mib = IpMib(self.agent)
        mappings = yield ip_mib.get_ifindex_ip_mac_mappings()
        self._logger.debug("Found %d mappings in IP-MIB", len(mappings))

        # Try IPV6-MIB if no IPv6 results were found in IP-MIB
        if not ipv6_address_in_mappings(mappings):
            ipv6_mib = Ipv6Mib(self.agent)
            ipv6_mappings = yield ipv6_mib.get_ifindex_ip_mac_mappings()
            self._logger.debug("Found %d mappings in IPV6-MIB",
                               len(ipv6_mappings))
            mappings.update(ipv6_mappings)

        # If we got no results, or no IPv6 results, try vendor specific MIBs
        if len(mappings) == 0 or not ipv6_address_in_mappings(mappings):
            cisco_ip_mib = CiscoIetfIpMib(self.agent)
            cisco_ip_mappings = yield cisco_ip_mib.get_ifindex_ip_mac_mappings()
            self._logger.debug("Found %d mappings in CISCO-IETF-IP-MIB",
                               len(cisco_ip_mappings))
            mappings.update(cisco_ip_mappings)

        yield self._process_data(mappings)
Esempio n. 3
0
    def _get_stats(self):
        ifmib = IfMib(self.agent)
        ipmib = IpMib(self.agent)
        stats = yield ifmib.retrieve_columns(
            ("ifName", "ifDescr") + USED_COUNTERS).addCallback(reduce_index)
        ipv6stats = yield ipmib.get_ipv6_octet_counters()
        if ipv6stats:
            self._logger.debug("found ipv6 octet counters for %d interfaces",
                               len(ipv6stats))
        for ifindex, (in_octets, out_octets) in ipv6stats.items():
            if ifindex in stats:
                stats[ifindex][IF_IN_OCTETS_IPV6] = in_octets
                stats[ifindex][IF_OUT_OCTETS_IPV6] = out_octets

        defer.returnValue(stats)
Esempio n. 4
0
    def _get_stats(self):
        ifmib = IfMib(self.agent)
        ipmib = IpMib(self.agent)
        stats = yield ifmib.retrieve_columns(
            ("ifName", "ifDescr") + USED_COUNTERS).addCallback(reduce_index)
        ipv6stats = yield ipmib.get_ipv6_octet_counters()
        if ipv6stats:
            self._logger.debug("found ipv6 octet counters for %d interfaces",
                               len(ipv6stats))
        for ifindex, (in_octets, out_octets) in ipv6stats.items():
            if ifindex in stats:
                stats[ifindex][IF_IN_OCTETS_IPV6] = in_octets
                stats[ifindex][IF_OUT_OCTETS_IPV6] = out_octets

        defer.returnValue(stats)
Esempio n. 5
0
 def test_ipv6_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = self._ipAddressPrefixEntry + (
         5,
         11,
         2,
         16,
         32,
         1,
         7,
         0,
         0,
         0,
         5,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         0,
         64,
     )
     expected = IP('2001:700:0:500::/64')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     assert prefix == expected
Esempio n. 6
0
 def test_ipv4_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = self._ipAddressPrefixEntry + (
         5,
         439541760,
         1,
         4,
         192,
         168,
         70,
         0,
         24,
     )
     expected = IP('192.168.70/24')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     assert prefix == expected
Esempio n. 7
0
    def handle(self):
        self._logger.debug("Collecting prefixes")
        netbox = self.containers.factory(None, shadows.Netbox)

        ipmib = IpMib(self.agent)
        ciscoip = CiscoIetfIpMib(self.agent)
        ipv6mib = Ipv6Mib(self.agent)

        # Retrieve interface names and keep those who match a VLAN
        # naming pattern
        vlan_interfaces = yield self.get_vlan_interfaces()
        ifc_aliases = yield self._get_ifc_aliases()

        # Traverse address tables from IP-MIB, IPV6-MIB and
        # CISCO-IETF-IP-MIB in that order.
        addresses = set()
        for mib in ipmib, ipv6mib, ciscoip:
            self._logger.debug("Trying address tables from %s",
                               mib.mib['moduleName'])
            df = mib.get_interface_addresses()
            # Special case; some devices will time out while building a bulk
            # response outside our scope when it has no proprietary MIB support
            if mib != ipmib:
                df.addErrback(self._ignore_timeout, set())
            df.addErrback(self._ignore_index_exceptions, mib)
            new_addresses = yield df
            self._logger.debug(
                "Found %d addresses in %s: %r",
                len(new_addresses),
                mib.mib['moduleName'],
                new_addresses,
            )
            addresses.update(new_addresses)

        adminup_ifcs = yield self._get_adminup_ifcs()
        for ifindex, ip, prefix in addresses:
            if ifindex not in adminup_ifcs:
                self._logger.debug(
                    "ignoring collected address %s on admDown ifindex %s", ip,
                    ifindex)
                continue
            if self._prefix_should_be_ignored(prefix):
                self._logger.debug("ignoring prefix %s as configured", prefix)
                continue
            self.create_containers(netbox, ifindex, prefix, ip,
                                   vlan_interfaces, ifc_aliases)
Esempio n. 8
0
 def test_ipv6_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (2, 16, 32, 1, 13, 184, 18, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
     expected = IP('2001:db8:1234::1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     assert ip == expected
Esempio n. 9
0
 def test_too_long_ipv6_address_should_raise_exception(self):
     ip_tuple = (2, 16, 32, 1, 13, 184, 18, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
     with pytest.raises(IndexToIpException):
         IpMib.inetaddress_to_ip(ip_tuple)
Esempio n. 10
0
 def test_ipv4_syntax_not_annotated_with_size_should_parse_ok(self):
     ip_tuple = (1, 192, 0, 2, 1)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     assert ip == expected
Esempio n. 11
0
 def test_nxos_ipv4_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = self._ipAddressPrefixEntry + (
         439541760, 1, 4, 192, 168, 70, 0, 24)
     expected = IP('192.168.70/24')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     self.assertEquals(prefix, expected)
Esempio n. 12
0
 def test_ipv4_syntax_not_annotated_with_size_should_parse_ok(self):
     ip_tuple = (1, 192, 0L, 2L, 1L)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 13
0
 def test_ipv6_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = (1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 11, 2, 16, 32, 1, 7, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64)
     expected = IP('2001:700:0:500::/64')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     self.assertEquals(prefix, expected)
Esempio n. 14
0
 def test_ipv4_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = (1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 439541760, 1, 4, 192, 168, 70, 0, 24)
     expected = IP('192.168.70/24')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     self.assertEquals(prefix, expected)
Esempio n. 15
0
 def test_ipv6_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (2, 16, 32L, 1L, 13L, 184L, 18L, 52L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)
     expected = IP('2001:db8:1234::1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 16
0
 def test_ipv4_syntax_not_annotated_with_size_should_parse_ok(self):
     ip_tuple = (1, 192, 0L, 2L, 1L)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 17
0
 def test_ipv4_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (1, 4, 192, 0L, 2L, 1L)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 18
0
 def test_ipv4_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (1, 4, 192, 0L, 2L, 1L)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 19
0
 def test_ipv4_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (1, 4, 192, 0, 2, 1)
     expected = IP('192.0.2.1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     assert ip == expected
Esempio n. 20
0
 def test_ipv6_syntax_with_length_should_be_parsed_correctly(self):
     ip_tuple = (2, 16, 32L, 1L, 13L, 184L, 18L, 52L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)
     expected = IP('2001:db8:1234::1')
     ip = IpMib.inetaddress_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Esempio n. 21
0
 def test_invalid_ipv4_syntax_should_raise_error(self):
     ip_tuple = (1, 4, 300, 300, 300, 300)
     with pytest.raises(ValueError):
         IpMib.inetaddress_to_ip(ip_tuple)
Esempio n. 22
0
 def test_nxos_ipv6_prefix_rowpointer_should_be_parsed_correctly(self):
     rowpointer = self._ipAddressPrefixEntry + (
         11, 2, 16, 32, 1, 7, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64)
     expected = IP('2001:700:0:500::/64')
     prefix = IpMib.prefix_index_to_ip(rowpointer)
     self.assertEquals(prefix, expected)
Esempio n. 23
0
 def test_too_short_ipv4_address_should_raise_exception(self):
     ip_tuple = (1, 4, 1, 2)
     with pytest.raises(IndexToIpException):
         IpMib.inetaddress_to_ip(ip_tuple)