lib/learning-switch.c
/* Creates and returns a new learning switch whose configuration is given by
 * 'cfg'.
 *
 * 'rconn' is used to send out an OpenFlow features request. */
Creates and returns a new learning switch whose configuration is given by
'cfg'.

'rconn' is used to send out an OpenFlow features request.
Creates and returns a new learning switch whose configuration is given by ' cfg ' . ' rconn ' is used to send out an OpenFlow features request .
struct lswitch *
lswitch_create(struct rconn *rconn, const struct lswitch_config *cfg)
{
    struct lswitch *sw;
    uint32_t ofpfw;
    sw = xzalloc(sizeof *sw);
    sw->rconn = rconn;
    sw->state = S_CONNECTING;
    sw->max_idle = cfg->max_idle;
    sw->datapath_id = 0;
    sw->ml = (cfg->mode == LSW_LEARN
              ? mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME)
              : NULL);
    sw->action_normal = cfg->mode == LSW_NORMAL;
    switch (cfg->wildcards) {
    case 0:
        ofpfw = 0;
        break;
    case UINT32_MAX:
        ofpfw = (OFPFW10_DL_TYPE | OFPFW10_DL_VLAN_PCP
                 | OFPFW10_NW_SRC_ALL | OFPFW10_NW_DST_ALL
                 | OFPFW10_NW_TOS | OFPFW10_NW_PROTO
                 | OFPFW10_TP_SRC | OFPFW10_TP_DST);
        break;
    default:
        ofpfw = cfg->wildcards;
        break;
    }
    ofputil_wildcard_from_ofpfw10(ofpfw, &sw->wc);
    sw->default_queue = cfg->default_queue;
    hmap_init(&sw->queue_numbers);
    shash_init(&sw->queue_names);
    if (cfg->port_queues) {
        struct simap_node *node;
        SIMAP_FOR_EACH (node, cfg->port_queues) {
            struct lswitch_port *port = xmalloc(sizeof *port);
            hmap_node_nullify(&port->hmap_node);
            port->queue_id = node->data;
            shash_add(&sw->queue_names, node->name, port);
        }
    }
    sw->default_flows = cfg->default_flows;
    sw->n_default_flows = cfg->n_default_flows;
    sw->usable_protocols = cfg->usable_protocols;
    sw->queued = rconn_packet_counter_create();
    return sw;
}
struct lswitch * lswitch_create ( struct rconn * rconn , const struct lswitch_config * cfg ) { struct lswitch * sw ; uint32_t ofpfw ; sw = xzalloc ( sizeof * sw ) ; sw -> rconn = rconn ; sw -> state = S_CONNECTING ; sw -> max_idle = cfg -> max_idle ; sw -> datapath_id = 0 ; sw -> ml = ( cfg -> mode == LSW_LEARN ? mac_learning_create ( MAC_ENTRY_DEFAULT_IDLE_TIME ) : NULL ) ; sw -> action_normal = cfg -> mode == LSW_NORMAL ; switch ( cfg -> wildcards ) { case 0 : ofpfw = 0 ; break ; case UINT32_MAX : ofpfw = ( OFPFW10_DL_TYPE | OFPFW10_DL_VLAN_PCP | OFPFW10_NW_SRC_ALL | OFPFW10_NW_DST_ALL | OFPFW10_NW_TOS | OFPFW10_NW_PROTO | OFPFW10_TP_SRC | OFPFW10_TP_DST ) ; break ; default : ofpfw = cfg -> wildcards ; break ; } ofputil_wildcard_from_ofpfw10 ( ofpfw , & sw -> wc ) ; sw -> default_queue = cfg -> default_queue ; hmap_init ( & sw -> queue_numbers ) ; shash_init ( & sw -> queue_names ) ; if ( cfg -> port_queues ) { struct simap_node * node ; SIMAP_FOR_EACH ( node , cfg -> port_queues ) { struct lswitch_port * port = xmalloc ( sizeof * port ) ; hmap_node_nullify ( & port -> hmap_node ) ; port -> queue_id = node -> data ; shash_add ( & sw -> queue_names , node -> name , port ) ; } } sw -> default_flows = cfg -> default_flows ; sw -> n_default_flows = cfg -> n_default_flows ; sw -> usable_protocols = cfg -> usable_protocols ; sw -> queued = rconn_packet_counter_create ( ) ; return sw ; }
Creates and returns a new learning switch whose configuration is given by
 'cfg'.
Creates and returns a new learning switch whose configuration is given by ' cfg ' .
/* Try to wildcard as many fields as possible, but we cannot
         * wildcard all fields.  We need in_port to detect moves.  We need
         * Ethernet source and dest and VLAN VID to do L2 learning. */