def get_details_ports(self, page=1, order="-links"):
        sort_options = ['links', 'port']
        first_result = (page - 1) * self.page_size

        qvars = {
            'links_table': self.table_links,
            'start': self.ip_start,
            'end': self.ip_end,
            'first': first_result,
            'size': self.page_size,
            'WHERE': self.build_where_clause(self.time_range, self.port),
        }

        if order and order[0] == '-':
            sort_dir = "DESC"
        else:
            sort_dir = "ASC"
        if order and order[1:] in sort_options:
            sort_by = order[1:]
        else:
            sort_by = sort_options[0]
        qvars['order'] = "{0} {1}".format(sort_by, sort_dir)

        query = """
            SELECT port AS 'port', sum(links) AS 'links'
            FROM {links_table}
            WHERE dst BETWEEN $start AND $end
             {WHERE}
            GROUP BY port
            ORDER BY {order}
            LIMIT $first, $size;
        """.format(**qvars)
        return list(sam.common.db.query(query, vars=qvars))