"Simile" specifically describes these figures of speech with "like a" or "as ... as a", and it often involves a comparison that is intended to make an interesting or colourful impression on the reader, or a non-literal comparison ("His mind was sharp as a sword"). "Analogy" isn't restricted to this form of words, and it usually involves a comparison that actually aids understanding.