End-to-end error correction and online diagnosis for on-chip networks