Plants release hundreds of volatile chemicals ( scents ) to both attract and repel insects.
Cabbage butterflies lay their eggs in cabbage. In response the cabbage plants release a scent that attracts two species of moths that feed on cabbage butterflies.
When insects lay eggs in the plant they damage the plant, this damage triggers the plant to release chemicals to protect it from the insects about to hatch and feed on the plant. Some chemicals kill the plant tissue around the egg causing the egg to fall off the plant. Other chemicals attract predators of the insect eggs.
Cabbage family plants make glucosinolate from sugar giving them their well known bitter flavor. This is what acts to fight cancer in people who eat these plants.
Plants containing glucosinolate can be used keep pests away from other crops.Some insects have adapted to be able to deflect the toxins and use these plants for feeding and egg laying.