code: def _set_state(self, new_state, diag=None):
          
          old_state = self._session_state
  
          LOG.info("[BFD][%s][STATE] State changed from %s to %s.",
                   hex(self._local_discr),
                   bfd.BFD_STATE_NAME[old_state],
                   bfd.BFD_STATE_NAME[new_state])
          self._session_state = new_state
  
          if new_state == bfd.BFD_STATE_DOWN:
              if diag is not None:
                  self._local_diag = diag
              self._desired_min_tx_interval = 1000000
              self._is_polling = True
              self._update_xmit_period()
          elif new_state == bfd.BFD_STATE_UP:
              self._desired_min_tx_interval = self._cfg_desired_min_tx_interval
              self._is_polling = True
              self._update_xmit_period()
  
          self.app.send_event_to_observers(
              EventBFDSessionStateChanged(self, old_state, new_state))
docs: Set the state of the BFD session.