'Initialize switch
- ports is a list of ofp_phy_ports or a number of ports
- miss_send_len is number of bytes to send to controller on table miss
- max_buffers is number of buffered packets to store
- max_entries is max flows entries per table'

def __init__(self, dpid, name=None, ports=4, miss_send_len=128, max_buffers=100, max_entries=2147483647, features=None):

    if (name is None):
        name = dpid_to_str(dpid)
    self.name = name
    self.dpid = dpid
    if isinstance(ports, int):
        ports = [self.generate_port(i) for i in range(1, (ports + 1))]
    self.max_buffers = max_buffers
    self.max_entries = max_entries
    self.miss_send_len = miss_send_len
    self.config_flags = 0
    self._has_sent_hello = False
    self.table = FlowTable()
    self.table.addListeners(self)
    self._lookup_count = 0
    self._matched_count = 0
    self.log = logging.getLogger(self.name)
    self._connection = None
    self._packet_buffer = []
    self.ports = {}
    self.port_stats = {}
    for port in ports:
        self.add_port(port)
    if (features is not None):
        self.features = features
    else:
        self.features = SwitchFeatures()
        self.features.cap_flow_stats = True
        self.features.cap_table_stats = True
        self.features.cap_port_stats = True
        self.features.act_output = True
        self.features.act_enqueue = True
        self.features.act_strip_vlan = True
        self.features.act_set_vlan_vid = True
        self.features.act_set_vlan_pcp = True
        self.features.act_set_dl_dst = True
        self.features.act_set_dl_src = True
        self.features.act_set_nw_dst = True
        self.features.act_set_nw_src = True
        self.features.act_set_nw_tos = True
        self.features.act_set_tp_dst = True
        self.features.act_set_tp_src = True
    self.ofp_handlers = {}
    for (value, name) in ofp_type_map.iteritems():
        name = name.split('OFPT_', 1)[(-1)].lower()
        h = getattr(self, ('_rx_' + name), None)
        if (not h):
            continue
        assert of._message_type_to_class[value]._from_controller, name
        self.ofp_handlers[value] = h
    self.action_handlers = {}
    for (value, name) in ofp_action_type_map.iteritems():
        name = name.split('OFPAT_', 1)[(-1)].lower()
        h = getattr(self, ('_action_' + name), None)
        if (not h):
            continue
        if (getattr(self.features, ('act_' + name)) is False):
            continue
        self.action_handlers[value] = h
    self.stats_handlers = {}
    for (value, name) in ofp_stats_type_map.iteritems():
        name = name.split('OFPST_', 1)[(-1)].lower()
        h = getattr(self, ('_stats_' + name), None)
        if (not h):
            continue
        self.stats_handlers[value] = h
    self.flow_mod_handlers = {}
    for (name, value) in ofp_flow_mod_command_rev_map.iteritems():
        name = name.split('OFPFC_', 1)[(-1)].lower()
        h = getattr(self, ('_flow_mod_' + name), None)
        if (not h):
            continue
        self.flow_mod_handlers[value] = h
