Sri Lanka opener Tillakaratne Dilshan has announced his retirement from Test cricket with immediate effect.