Characterization of metric spaces whose free space is isometric to $\ell_1$