Ejemplo n.º 1
0
static bool
str_to_ofpact__(char *pos, char *act, char *arg,
                struct ofpbuf *ofpacts, int n_actions)
{
    int code = ofputil_action_code_from_name(act);
    if (code >= 0) {
        parse_named_action(code, arg, ofpacts);
    } else if (!strcasecmp(act, "drop")) {
        if (n_actions) {
            ovs_fatal(0, "Drop actions must not be preceded by other "
                      "actions");
        } else if (ofputil_parse_key_value(&pos, &act, &arg)) {
            ovs_fatal(0, "Drop actions must not be followed by other "
                      "actions");
        }
        return false;
    } else {
        ofp_port_t port;
        if (ofputil_port_from_string(act, &port)) {
            ofpact_put_OUTPUT(ofpacts)->port = port;
        } else {
            ovs_fatal(0, "Unknown action: %s", act);
        }
    }

    return true;
}
Ejemplo n.º 2
0
static void
str_to_action(const struct flow *flow, char *str, struct ofpbuf *b)
{
    char *pos, *act, *arg;
    int n_actions;

    pos = str;
    n_actions = 0;
    while (ofputil_parse_key_value(&pos, &act, &arg)) {
        uint16_t port;
        int code;

        code = ofputil_action_code_from_name(act);
        if (code >= 0) {
            parse_named_action(code, flow, b, arg);
        } else if (!strcasecmp(act, "drop")) {
            /* A drop action in OpenFlow occurs by just not setting
             * an action. */
            if (n_actions) {
                ovs_fatal(0, "Drop actions must not be preceded by other "
                          "actions");
            } else if (ofputil_parse_key_value(&pos, &act, &arg)) {
                ovs_fatal(0, "Drop actions must not be followed by other "
                          "actions");
            }
            break;
        } else if (!strcasecmp(act, "CONTROLLER")) {
            struct ofp_action_output *oao;
            oao = put_output_action(b, OFPP_CONTROLLER);

            /* Unless a numeric argument is specified, we send the whole
             * packet to the controller. */
            if (arg[0] && (strspn(arg, "0123456789") == strlen(arg))) {
               oao->max_len = htons(str_to_u32(arg));
            } else {
                oao->max_len = htons(UINT16_MAX);
            }
        } else if (ofputil_port_from_string(act, &port)) {
            put_output_action(b, port);
        } else {
            ovs_fatal(0, "Unknown action: %s", act);
        }
        n_actions++;
    }
}