'Set a port config bit
This is called in response to port_mods.  It is passed the ofp_phy_port,
the bit/mask, and the value of the bit (i.e., 0 if the flag is to be
unset, or the same value as bit if it is to be set).
The return value is a tuple (handled, msg).
If bit is handled, then handled will be True, else False.
if msg is a string, it will be used as part of a log message.
If msg is None, there will be no log message.
If msg is anything else "truthy", an "enabled" log message is generated.
If msg is anything else "falsy", a "disabled" log message is generated.
msg is only used when handled is True.'

def _set_port_config_bit(self, port, bit, value):

    if (bit == OFPPC_NO_STP):
        if (value == 0):
            self.log.warn("Port    %s:    Can't    enable    802.1D    STP", port.port_no)
        return (True, None)
    if (bit not in (OFPPC_PORT_DOWN, OFPPC_NO_STP, OFPPC_NO_RECV, OFPPC_NO_RECV_STP, OFPPC_NO_FLOOD, OFPPC_NO_FWD, OFPPC_NO_PACKET_IN)):
        return (False, None)
    if port.set_config(value, bit):
        if (bit == OFPPC_PORT_DOWN):
            old_state = (port.state & OFPPS_LINK_DOWN)
            port.state = (port.state & (~ OFPPS_LINK_DOWN))
            if (port.config & OFPPC_PORT_DOWN):
                port.state = (port.state | OFPPS_LINK_DOWN)
            new_state = (port.state & OFPPS_LINK_DOWN)
            if (old_state != new_state):
                self.send_port_status(port, OFPPR_MODIFY)
        return (True, value)
    return (True, None)
