Understanding of NiO-based unipolar resistive switching from first principle simulations to macroscopic models