An attack by a renegade Afghan soldier has claimed the lives of three British troops and left four others wounded.