Network Defense and Countermeasures: Principles and Practices