Analyzing cascading failures in smart grids under random and targeted attacks