Example #1
0
/* Creates and returns a new learning switch.
 *
 * If 'learn_macs' is true, the new switch will learn the ports on which MAC
 * addresses appear.  Otherwise, the new switch will flood all packets.
 *
 * If 'max_idle' is nonnegative, the new switch will set up flows that expire
 * after the given number of seconds (or never expire, if 'max_idle' is
 * OFP_FLOW_PERMANENT).  Otherwise, the new switch will process every packet.
 *
 * The caller may provide the file stream 'default_flows' that defines
 * default flows that should be pushed when a switch connects.  Each
 * line is a flow entry in the format described for "add-flows" command
 * in the Flow Syntax section of the ovs-ofct(8) man page.  The caller
 * is responsible for closing the stream.
 *
 * 'rconn' is used to send out an OpenFlow features request. */
struct lswitch *
lswitch_create(struct rconn *rconn, bool learn_macs,
               bool exact_flows, int max_idle, bool action_normal,
               FILE *default_flows)
{
    struct lswitch *sw;

    sw = xzalloc(sizeof *sw);
    sw->max_idle = max_idle;
    sw->datapath_id = 0;
    sw->last_features_request = time_now() - 1;
    sw->ml = learn_macs ? mac_learning_create() : NULL;
    sw->action_normal = action_normal;
    if (exact_flows) {
        /* Exact match. */
        sw->wildcards = 0;
    } else {
        /* We cannot wildcard all fields.
         * We need in_port to detect moves.
         * We need both SA and DA to do learning. */
        sw->wildcards = (OFPFW_DL_TYPE | OFPFW_NW_SRC_MASK | OFPFW_NW_DST_MASK
                         | OFPFW_NW_PROTO | OFPFW_TP_SRC | OFPFW_TP_DST);
    }
    sw->queue = UINT32_MAX;
    sw->queued = rconn_packet_counter_create();
    send_features_request(sw, rconn);
    if (default_flows) {
        send_default_flows(sw, rconn, default_flows);
    }
    return sw;
}
Example #2
0
void
ofctrl_init(void)
{
    swconn = rconn_create(5, 0, DSCP_DEFAULT, 1 << OFP13_VERSION);
    tx_counter = rconn_packet_counter_create();
    hmap_init(&installed_flows);
}
Example #3
0
/* Creates and returns a new struct fail_open for 'ofproto' and 'mgr'. */
struct fail_open *
fail_open_create(struct ofproto *ofproto, struct connmgr *mgr)
{
    struct fail_open *fo = xmalloc(sizeof *fo);
    fo->ofproto = ofproto;
    fo->connmgr = mgr;
    fo->last_disconn_secs = 0;
    fo->next_bogus_packet_in = LLONG_MAX;
    fo->bogus_packet_counter = rconn_packet_counter_create();
    return fo;
}
Example #4
0
/* 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;

    sw = xzalloc(sizeof *sw);
    sw->rconn = rconn;
    sw->state = S_CONNECTING;
    sw->max_idle = cfg->max_idle;
    sw->datapath_id = 0;

    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();

    VLOG_INFO("new lswitch in");

    return sw;
}