Example #1
0
 def __init__(self, start_net, show_unused_addresses, end_net=None,
              bits_in_matrix=3):
     Matrix.__init__(self, start_net, end_net=end_net,
                     bits_in_matrix=bits_in_matrix)
     self.column_headings = self._get_column_headers()
     self.visible_column_headings = self.column_headings[::4]
     self.num_columns = len(self.column_headings)
     self.show_unused_addresses = show_unused_addresses
     self.heading_colspan = 4
Example #2
0
 def __init__(self, start_net, show_unused_addresses, end_net=None,
              bits_in_matrix=3):
     Matrix.__init__(self, start_net, end_net=end_net,
                     bits_in_matrix=bits_in_matrix)
     self.column_headings = self._get_column_headers()
     self.visible_column_headings = self.column_headings[::4]
     self.num_columns = len(self.column_headings)
     self.show_unused_addresses = show_unused_addresses
     self.color_configuration = ColorConfig(configfile)
     self.heading_colspan = 4
Example #3
0
    def _remaining_blank_nets(self, ip, depth):
        if not self.show_unused_addresses:
            return []

        rows = []
        tTree = self.tree
        subtree = IPtree.getSubtree(tTree, ip)
        nets = self.generate_matrix_nets(ip)

        for net in nets:
            overlap = False
            for subnet in subtree.keys():
                if subnet.overlaps(net) == 1:
                    overlap = True
                    break

            if overlap or IPtree.search(subtree, net):
                continue
            else:
                rows.append([
                    self.Cell(
                        colspan=1,
                        color=None,
                        content='{0} {1}'.format(
                            Matrix.print_depth(depth),
                            _netlink(net))),
                    self.Cell(
                        colspan=self.num_columns,
                        color=None,
                        content=' ')
                ])
        return rows
Example #4
0
    def _remaining_blank_nets(self, ip, depth):
        if not self.show_unused_addresses:
            return []

        rows = []
        tTree = self.tree
        subtree = IPtree.getSubtree(tTree, ip)
        nets = self.generate_matrix_nets(ip)

        for net in nets:
            overlap = False
            for subnet in subtree.keys():
                if subnet.overlaps(net) == 1:
                    overlap = True
                    break

            if overlap or IPtree.search(subtree, net):
                continue
            else:
                rows.append([
                    self.Cell(colspan=1,
                              color=None,
                              content='{0} {1}'.format(
                                  Matrix.print_depth(depth), _netlink(net))),
                    self.Cell(colspan=self.num_columns,
                              color=None,
                              content=' ')
                ])
        return rows
Example #5
0
 def _nets_in_range(self, net1, net2, depth):
     rows = []
     if net1.prefixlen() == net2.prefixlen():
         diff = netDiff(net1, net2)
         if len(diff) > 1:
             for net in diff[1:]:
                 rows.append([
                     self.Cell(colspan=1,
                               color=None,
                               content='{0} {1}'.format(
                                   Matrix.print_depth(depth),
                                   _netlink(net))),
                     self.Cell(colspan=self.num_columns,
                               color=None,
                               content=' ')
                 ])
     return rows
Example #6
0
 def _nets_in_range(self, net1, net2, depth):
     rows = []
     if net1.prefixlen() == net2.prefixlen():
         diff = netDiff(net1, net2)
         if len(diff) > 1:
             for net in diff[1:]:
                 rows.append([
                     self.Cell(
                         colspan=1,
                         color=None,
                         content='{0} {1}'.format(
                             Matrix.print_depth(depth),
                             _netlink(net))),
                     self.Cell(
                         colspan=self.num_columns,
                         color=None,
                         content=' ')
                 ])
     return rows
Example #7
0
 def __init__(self, start_net, end_net=None):
     Matrix.__init__(self, start_net, end_net=end_net, bits_in_matrix=4)
     self.column_headings = ["%X" % i for i in range(0, 16)]
     self.visible_column_headings = self.column_headings
     self.num_columns = len(self.column_headings)
Example #8
0
    def _write_subnets(self, net, depth):

        nodes = IPtools.sort_nets_by_address(net.keys())
        lastnet = None
        subnet_matrix = []

        for subnet in nodes:
            if lastnet is None:
                lastnet = subnet

            if subnet in self.matrix_nets:
                if self.show_unused_addresses:
                    subnet_matrix.extend(
                        self._nets_in_range(
                            lastnet,
                            subnet,
                            depth))

                lastnet = subnet
                matrix_row = [
                    self.Cell(
                        colspan=1,
                        color=None,
                        content='{0} {1}'.format(
                            Matrix.print_depth(depth),
                            _netlink(subnet)))
                ]

                host_nybbles_map = IPtools.getLastbitsIpMap(
                    self.matrix_nets[subnet].keys())
                next_header_idx = -1

                if self.has_too_small_nets(subnet):
                    matrix_row.append(
                        self.Cell(
                            colspan=self.num_columns,
                            color=self._load_color(0, 'large'),
                            content='Too many small nets')
                    )

                elif host_nybbles_map is None:
                # i.e. there exist a net with no
                # subnets <==> net spans whole row
                    ip = IPy.IP(subnet)
                    meta = metaIP.MetaIP(ip)
                    matrix_row.append(
                        self.Cell(
                            colspan=self.num_columns,
                            color=self._load_color(
                                meta.usage_percent,
                                meta.nettype),
                            content=_matrixlink(0, ip))
                    )

                else:
                # The net exists and have subnets
                    for i in self.column_headings:
                        if self.column_headings.index(i) < next_header_idx:
                            continue

                        key = i.lower()
                        if key in host_nybbles_map:
                            ip = host_nybbles_map[key]
                            meta = metaIP.MetaIP(ip)
                            matrix_cell = self.Cell(
                                colspan=self._colspan(ip),
                                color=self._load_color(
                                    meta.usage_percent,
                                    meta.nettype),
                                content=_matrixlink(key, ip))
                            next_header_idx = (self.column_headings.index(i)
                                               + int(self._colspan(ip)))
                        else:
                            matrix_cell = self.Cell(
                                colspan=1,
                                color=None,
                                content='&nbsp;')
                        matrix_row.append(matrix_cell)
                subnet_matrix.append(matrix_row)
            else:
                if (self.matrix_nets
                    and lastnet.prefixlen() <
                        self.matrix_nets.keys()[0].prefixlen()):
                    mnets = self.generate_matrix_nets(lastnet)
                    subnet_extended = IPy.IP(
                        '/'.join([
                            subnet.net().strNormal(),
                            str(self.matrix_nets.keys()[0].prefixlen())
                        ]))
                    subnet_matrix.extend(
                        self._nets_in_range(
                            mnets[-1],
                            subnet_extended,
                            depth))
                lastnet = subnet
                meta = metaIP.MetaIP(subnet)
                matrix_row = [
                    self.Cell(
                        colspan=1,
                        color=None,
                        content='{0} {1}'.format(
                            Matrix.print_depth(depth),
                            _netlink(subnet, True))),
                    self.Cell(
                        colspan=self.num_columns,
                        color=self._load_color(
                            meta.usage_percent,
                            meta.nettype),
                        content=_supernet_matrixlink(subnet))
                ]
                subnet_matrix.append(matrix_row)
                subnet_matrix.extend(
                    self._write_subnets(net[subnet], depth + 1))
                subnet_matrix.extend(
                    self._remaining_blank_nets(subnet, depth + 1))
        return subnet_matrix
Example #9
0
    def _write_subnets(self, net, depth):

        nodes = IPtools.sort_nets_by_address(net.keys())
        lastnet = None
        subnet_matrix = []

        for subnet in nodes:
            if lastnet is None:
                lastnet = subnet

            if subnet in self.matrix_nets:
                if IPtools.isIntermediateNets(lastnet, subnet):
                    subnet_matrix.append(None)

                lastnet = subnet

                matrix_row = [
                    self.Cell(
                        colspan=1,
                        color=None,
                        content='{0}{1}'.format(
                            Matrix.print_depth(depth),
                            _netlink(subnet)))
                ]

                host_nybbles_map = IPtools.getLastbitsIpMap(
                    self.matrix_nets[subnet].keys())
                next_header_idx = -1
                for i in self.column_headings:
                    if self.column_headings.index(i) < next_header_idx:
                        continue

                    key = i.lower()
                    if key in host_nybbles_map:
                        meta = metaIP.MetaIP(host_nybbles_map[key])
                        ip = host_nybbles_map[key]
                        matrix_cell = self.Cell(
                            colspan=self._colspan(ip),
                            color=meta.ipv6_color,
                            content=_matrixlink(key, ip))
                        next_header_idx = self.column_headings.index(
                            i) + int(self._colspan(ip))
                    else:
                        matrix_cell = self.Cell(
                            colspan=1,
                            color=None,
                            content='&nbsp;')
                    matrix_row.append(matrix_cell)
                subnet_matrix.append(matrix_row)
            else:
                subnet_matrix.append(None)
                lastnet = subnet
                matrix_row = [
                    self.Cell(
                        colspan=1,
                        color=None,
                        content='{0}{1}'.format(
                            Matrix.print_depth(depth),
                            _netlink(subnet, True))),
                    self.Cell(
                        colspan=self.num_columns,
                        color=None,
                        content='&nbsp;')
                ]
                subnet_matrix.append(matrix_row)
                subnet_matrix.extend(
                    self._write_subnets(net[subnet], depth + 1))
        return subnet_matrix
Example #10
0
 def __init__(self, start_net, end_net=None):
     Matrix.__init__(self, start_net, end_net=end_net, bits_in_matrix=4)
     self.column_headings = ["%X" % i for i in range(0, 16)]
     self.visible_column_headings = self.column_headings
     self.num_columns = len(self.column_headings)
     self.color_configuration = ColorConfig(configfile)
Example #11
0
    def _write_subnets(self, net, depth):

        nodes = IPtools.sort_nets_by_address(net.keys())
        lastnet = None
        subnet_matrix = []

        for subnet in nodes:
            if lastnet is None:
                lastnet = subnet

            if subnet in self.matrix_nets:
                if self.show_unused_addresses:
                    subnet_matrix.extend(
                        self._nets_in_range(lastnet, subnet, depth))

                lastnet = subnet
                matrix_row = [
                    self.Cell(colspan=1,
                              color=None,
                              content='{0} {1}'.format(
                                  Matrix.print_depth(depth), _netlink(subnet)))
                ]

                host_nybbles_map = IPtools.getLastbitsIpMap(
                    self.matrix_nets[subnet].keys())
                next_header_idx = -1

                if self.has_too_small_nets(subnet):
                    matrix_row.append(
                        self.Cell(colspan=self.num_columns,
                                  color=self._load_color(0, 'large'),
                                  content='Too many small nets'))

                elif host_nybbles_map is None:
                    # i.e. there exist a net with no
                    # subnets <==> net spans whole row
                    ip = IPy.IP(subnet)
                    meta = metaIP.MetaIP(ip)
                    matrix_row.append(
                        self.Cell(colspan=self.num_columns,
                                  color=self._load_color(
                                      meta.usage_percent, meta.nettype),
                                  content=_matrixlink(0, ip)))

                else:
                    # The net exists and have subnets
                    for i in self.column_headings:
                        if self.column_headings.index(i) < next_header_idx:
                            continue

                        key = i.lower()
                        if key in host_nybbles_map:
                            ip = host_nybbles_map[key]
                            meta = metaIP.MetaIP(ip)
                            matrix_cell = self.Cell(
                                colspan=self._colspan(ip),
                                color=self._load_color(meta.usage_percent,
                                                       meta.nettype),
                                content=_matrixlink(key, ip))
                            next_header_idx = (self.column_headings.index(i) +
                                               int(self._colspan(ip)))
                        else:
                            matrix_cell = self.Cell(colspan=1,
                                                    color=None,
                                                    content='&nbsp;')
                        matrix_row.append(matrix_cell)
                subnet_matrix.append(matrix_row)
            else:
                if (self.matrix_nets and lastnet.prefixlen() <
                        self.matrix_nets.keys()[0].prefixlen()):
                    mnets = self.generate_matrix_nets(lastnet)
                    subnet_extended = IPy.IP('/'.join([
                        subnet.net().strNormal(),
                        str(self.matrix_nets.keys()[0].prefixlen())
                    ]))
                    subnet_matrix.extend(
                        self._nets_in_range(mnets[-1], subnet_extended, depth))
                lastnet = subnet
                meta = metaIP.MetaIP(subnet)
                matrix_row = [
                    self.Cell(colspan=1,
                              color=None,
                              content='{0} {1}'.format(
                                  Matrix.print_depth(depth),
                                  _netlink(subnet, True))),
                    self.Cell(colspan=self.num_columns,
                              color=self._load_color(meta.usage_percent,
                                                     meta.nettype),
                              content=_supernet_matrixlink(subnet))
                ]
                subnet_matrix.append(matrix_row)
                subnet_matrix.extend(
                    self._write_subnets(net[subnet], depth + 1))
                subnet_matrix.extend(
                    self._remaining_blank_nets(subnet, depth + 1))
        return subnet_matrix