Physics of optical switching