Self-Aware Networks that Optimize Security, QoS and Energy