Tennis is not a contact sport, but there is a mano-a-mano aspect to it. There is one basic rule for dealing with jerks in any sport, whether they be someone trashtalking or some cheap shot artist. You can never show any reaction. I have been elbowed in the gut so hard playing basketball I thought I would puke, but I never gave off any indication I felt it. I have had the crap knocked out of me on late, blindside hits in football. You get up and make sure you still have your mouthpiece. The alternative is to fight, but that means getting kicked out of the game, which may be what the cheap shot artist is looking for. And it's always the guy who retaliates who gets caught, never the instigator.
I have never encountered anyone trashtalking at tennis, but if I did, I would ignore them or maybe give them an F-you. Don't let them take you out of your game, which is of course their objective.
Beyond a certain level, maybe 3.0, if you get hit it's your fault or your partner's fault. Going at an opponent is a legitimate play. If it bothers you, find another sport or stay at the baseline. If you're at the net, you can expect to be tested.
Now if an opponent turns their back, it's not cool to drill them, and if you do, you can definitely expect attempts at payback.