Nonlinear Carrier Waves and Gain Oscillations in Infrared and Terahertz Quantum Cascade Lasers