'ofp - a FeaturesReply message'

def _setConnection(self, connection, ofp=None):

    if self._connection:
        self._connection.removeListeners(self._listeners)
    self._listeners = []
    self._connection = connection
    if (self._reconnectTimeout is not None):
        self._reconnectTimeout.cancel()
        self._reconnectTimeout = None
    if (connection is None):
        self._reconnectTimeout = Timer(RECONNECT_TIMEOUT, self._timer_ReconnectTimeout)
    if (ofp is not None):
        self.capabilities = ofp.capabilities
        untouched = set(self.ports.keys())
        for p in ofp.ports:
            if (p.port_no in self.ports):
                self.ports[p.port_no]._update(p)
                untouched.remove(p.port_no)
            else:
                self.ports[p.port_no] = OpenFlowPort(p)
        for p in untouched:
            self.ports[p].exists = False
            del self.ports[p]
    if (connection is not None):
        self._listeners = self.listenTo(connection, prefix='con')
        self.raiseEvent(SwitchConnectionUp(switch=self, connection=connection))
    else:
        self.raiseEvent(SwitchConnectionDown(self))
