Gain-switching and mode-locking of quantum cascade lasers