How to only allow communication between certain devices ?

I want to allow from some devices to TV

and allow only some ports between some devices