Detection and Mitigation of Cyber Attacks on Time Synchronization Protocols for the Smart Grid