sounds like attention seeking and also I think they have trouble containing their testosterone fuelled impulses at this age.
Ds does this quite a bit, and often when he's cuddling you too (he's about the same age). I tend to completely ignore it (unless it really hurts) and also try adn find him some 'violent' activities to do. Not in sense of hitting people but involving jumping up and down and hitting balls and similar. He recently got a plastic tennis set and can hit that hard. Balls he can throw against the outside wall - anything that expends a lot of aggression.