Example #1
0
static void
parse_resubmit(struct ofpbuf *b, char *arg)
{
    struct nx_action_resubmit *nar;
    char *in_port_s, *table_s;
    uint16_t in_port;
    uint8_t table;

    in_port_s = strsep(&arg, ",");
    if (in_port_s && in_port_s[0]) {
        if (!ofputil_port_from_string(in_port_s, &in_port)) {
            in_port = str_to_u32(in_port_s);
        }
    } else {
        in_port = OFPP_IN_PORT;
    }

    table_s = strsep(&arg, ",");
    table = table_s && table_s[0] ? str_to_u32(table_s) : 255;

    if (in_port == OFPP_IN_PORT && table == 255) {
        ovs_fatal(0, "at least one \"in_port\" or \"table\" must be specified "
                  " on resubmit");
    }

    if (in_port != OFPP_IN_PORT && table == 255) {
        nar = ofputil_put_NXAST_RESUBMIT(b);
    } else {
        nar = ofputil_put_NXAST_RESUBMIT_TABLE(b);
        nar->table = table;
    }
    nar->in_port = htons(in_port);
}
Example #2
0
static void
parse_sample(struct ofpbuf *b, char *arg)
{
    struct ofpact_sample *os = ofpact_put_SAMPLE(b);
    char *key, *value;

    while (ofputil_parse_key_value(&arg, &key, &value)) {
        if (!strcmp(key, "probability")) {
            os->probability = str_to_u16(value, "probability");
            if (os->probability == 0) {
                ovs_fatal(0, "invalid probability value \"%s\"", value);
            }
        } else if (!strcmp(key, "collector_set_id")) {
            os->collector_set_id = str_to_u32(value);
        } else if (!strcmp(key, "obs_domain_id")) {
            os->obs_domain_id = str_to_u32(value);
        } else if (!strcmp(key, "obs_point_id")) {
            os->obs_point_id = str_to_u32(value);
        } else {
            ovs_fatal(0, "invalid key \"%s\" in \"sample\" argument",
                      key);
        }
    }
    if (os->probability == 0) {
        ovs_fatal(0, "non-zero \"probability\" must be specified on sample");
    }
}
Example #3
0
static void
parse_resubmit(char *arg, struct ofpbuf *ofpacts)
{
    struct ofpact_resubmit *resubmit;
    char *in_port_s, *table_s;

    resubmit = ofpact_put_RESUBMIT(ofpacts);

    in_port_s = strsep(&arg, ",");
    if (in_port_s && in_port_s[0]) {
        if (!ofputil_port_from_string(in_port_s, &resubmit->in_port)) {
            ovs_fatal(0, "%s: resubmit to unknown port", in_port_s);
        }
    } else {
        resubmit->in_port = OFPP_IN_PORT;
    }

    table_s = strsep(&arg, ",");
    resubmit->table_id = table_s && table_s[0] ? str_to_u32(table_s) : 255;

    if (resubmit->in_port == OFPP_IN_PORT && resubmit->table_id == 255) {
        ovs_fatal(0, "at least one \"in_port\" or \"table\" must be specified "
                  " on resubmit");
    }
}
Example #4
0
static void
parse_enqueue(char *arg, struct ofpbuf *ofpacts)
{
    char *sp = NULL;
    char *port = strtok_r(arg, ":q", &sp);
    char *queue = strtok_r(NULL, "", &sp);
    struct ofpact_enqueue *enqueue;

    if (port == NULL || queue == NULL) {
        ovs_fatal(0, "\"enqueue\" syntax is \"enqueue:PORT:QUEUE\"");
    }

    enqueue = ofpact_put_ENQUEUE(ofpacts);
    enqueue->port = u16_to_ofp(str_to_u32(port));
    enqueue->queue = str_to_u32(queue);
}
Example #5
0
static void
parse_enqueue(struct ofpbuf *b, char *arg)
{
    char *sp = NULL;
    char *port = strtok_r(arg, ":q", &sp);
    char *queue = strtok_r(NULL, "", &sp);
    struct ofp_action_enqueue *oae;

    if (port == NULL || queue == NULL) {
        ovs_fatal(0, "\"enqueue\" syntax is \"enqueue:PORT:QUEUE\"");
    }

    oae = ofputil_put_OFPAT_ENQUEUE(b);
    oae->port = htons(str_to_u32(port));
    oae->queue_id = htonl(str_to_u32(queue));
}
Example #6
0
static void
parse_named_instruction(enum ovs_instruction_type type,
                        char *arg, struct ofpbuf *ofpacts)
{
    enum ofperr error;

    switch (type) {
    case OVSINST_OFPIT11_APPLY_ACTIONS:
        NOT_REACHED();  /* This case is handled by str_to_inst_ofpacts() */
        break;

    case OVSINST_OFPIT11_WRITE_ACTIONS:
        /* XXX */
        ovs_fatal(0, "instruction write-actions is not supported yet");
        break;

    case OVSINST_OFPIT11_CLEAR_ACTIONS:
        ofpact_put_CLEAR_ACTIONS(ofpacts);
        break;

    case OVSINST_OFPIT13_METER:
        ofpact_put_METER(ofpacts)->meter_id = str_to_u32(arg);
        break;

    case OVSINST_OFPIT11_WRITE_METADATA:
        parse_metadata(ofpacts, arg);
        break;

    case OVSINST_OFPIT11_GOTO_TABLE: {
        struct ofpact_goto_table *ogt = ofpact_put_GOTO_TABLE(ofpacts);
        char *table_s = strsep(&arg, ",");
        if (!table_s || !table_s[0]) {
            ovs_fatal(0, "instruction goto-table needs table id");
        }
        ogt->table_id = str_to_u8(table_s, "table");
        break;
    }
    }

    /* If write_metadata is specified as an action AND an instruction, ofpacts
       could be invalid. */
    error = ofpacts_verify(ofpacts->data, ofpacts->size);
    if (error) {
        ovs_fatal(0, "Incorrect instruction ordering");
    }
}
Example #7
0
static void
parse_output(char *arg, struct ofpbuf *ofpacts)
{
    if (strchr(arg, '[')) {
        struct ofpact_output_reg *output_reg;

        output_reg = ofpact_put_OUTPUT_REG(ofpacts);
        mf_parse_subfield(&output_reg->src, arg);
        output_reg->max_len = UINT16_MAX;
    } else {
        struct ofpact_output *output;

        output = ofpact_put_OUTPUT(ofpacts);
        output->port = u16_to_ofp(str_to_u32(arg));
        output->max_len = output->port == OFPP_CONTROLLER ? UINT16_MAX : 0;
    }
}
Example #8
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++;
    }
}
Example #9
0
static void
parse_output(struct ofpbuf *b, char *arg)
{
    if (strchr(arg, '[')) {
        struct nx_action_output_reg *naor;
        int ofs, n_bits;
        uint32_t src;

        nxm_parse_field_bits(arg, &src, &ofs, &n_bits);

        naor = ofputil_put_NXAST_OUTPUT_REG(b);
        naor->ofs_nbits = nxm_encode_ofs_nbits(ofs, n_bits);
        naor->src = htonl(src);
        naor->max_len = htons(UINT16_MAX);
    } else {
        put_output_action(b, str_to_u32(arg));
    }
}
Example #10
0
static void
parse_named_action(enum ofputil_action_code code,
                   char *arg, struct ofpbuf *ofpacts)
{
    struct ofpact_tunnel *tunnel;
    uint16_t vid;
    uint16_t ethertype;
    ovs_be32 ip;
    uint8_t pcp;
    uint8_t tos;

    switch (code) {
    case OFPUTIL_ACTION_INVALID:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_OUTPUT:
    case OFPUTIL_OFPAT11_OUTPUT:
        parse_output(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_VID:
    case OFPUTIL_OFPAT11_SET_VLAN_VID:
        vid = str_to_u32(arg);
        if (vid & ~VLAN_VID_MASK) {
            ovs_fatal(0, "%s: not a valid VLAN VID", arg);
        }
        ofpact_put_SET_VLAN_VID(ofpacts)->vlan_vid = vid;
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_PCP:
    case OFPUTIL_OFPAT11_SET_VLAN_PCP:
        pcp = str_to_u32(arg);
        if (pcp & ~7) {
            ovs_fatal(0, "%s: not a valid VLAN PCP", arg);
        }
        ofpact_put_SET_VLAN_PCP(ofpacts)->vlan_pcp = pcp;
        break;

    case OFPUTIL_OFPAT12_SET_FIELD:
        set_field_parse(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_STRIP_VLAN:
    case OFPUTIL_OFPAT11_POP_VLAN:
        ofpact_put_STRIP_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_PUSH_VLAN:
        ethertype = str_to_u16(arg, "ethertype");
        if (ethertype != ETH_TYPE_VLAN_8021Q) {
            /* XXX ETH_TYPE_VLAN_8021AD case isn't supported */
            ovs_fatal(0, "%s: not a valid VLAN ethertype", arg);
        }
        ofpact_put_PUSH_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;


    case OFPUTIL_OFPAT10_SET_DL_SRC:
    case OFPUTIL_OFPAT11_SET_DL_SRC:
        str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_DL_DST:
    case OFPUTIL_OFPAT11_SET_DL_DST:
        str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_NW_SRC:
    case OFPUTIL_OFPAT11_SET_NW_SRC:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_SRC(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_DST:
    case OFPUTIL_OFPAT11_SET_NW_DST:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_DST(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_TOS:
    case OFPUTIL_OFPAT11_SET_NW_TOS:
        tos = str_to_u32(arg);
        if (tos & ~IP_DSCP_MASK) {
            ovs_fatal(0, "%s: not a valid TOS", arg);
        }
        ofpact_put_SET_IPV4_DSCP(ofpacts)->dscp = tos;
        break;

    case OFPUTIL_OFPAT11_DEC_NW_TTL:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_SET_TP_SRC:
    case OFPUTIL_OFPAT11_SET_TP_SRC:
        ofpact_put_SET_L4_SRC_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_SET_TP_DST:
    case OFPUTIL_OFPAT11_SET_TP_DST:
        ofpact_put_SET_L4_DST_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_ENQUEUE:
        parse_enqueue(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
    case OFPUTIL_NXAST_SET_TUNNEL64:
        tunnel = ofpact_put_SET_TUNNEL(ofpacts);
        tunnel->ofpact.compat = code;
        tunnel->tun_id = str_to_u64(arg);
        break;

    case OFPUTIL_NXAST_WRITE_METADATA:
        parse_metadata(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofpact_put_POP_QUEUE(ofpacts);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofpact_put_REG_MOVE(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofpact_put_REG_LOAD(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofpact_put_MULTIPATH(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
    case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofpact_put_EXIT(ofpacts);
        break;

    case OFPUTIL_NXAST_DEC_TTL:
        parse_dec_ttl(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_MPLS_TTL:
    case OFPUTIL_OFPAT11_SET_MPLS_TTL:
        parse_set_mpls_ttl(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
    case OFPUTIL_NXAST_DEC_MPLS_TTL:
        ofpact_put_DEC_MPLS_TTL(ofpacts);
        break;

    case OFPUTIL_NXAST_FIN_TIMEOUT:
        parse_fin_timeout(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_CONTROLLER:
        parse_controller(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_PUSH_MPLS:
    case OFPUTIL_NXAST_PUSH_MPLS:
        ofpact_put_PUSH_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "push_mpls"));
        break;

    case OFPUTIL_OFPAT11_POP_MPLS:
    case OFPUTIL_NXAST_POP_MPLS:
        ofpact_put_POP_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "pop_mpls"));
        break;

    case OFPUTIL_NXAST_STACK_PUSH:
        nxm_parse_stack_action(ofpact_put_STACK_PUSH(ofpacts), arg);
        break;
    case OFPUTIL_NXAST_STACK_POP:
        nxm_parse_stack_action(ofpact_put_STACK_POP(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_SAMPLE:
        parse_sample(ofpacts, arg);
        break;
    }
}
Example #11
0
/* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
 * page) into 'mm' for sending the specified meter_mod 'command' to a switch.
 */
void
parse_ofp_meter_mod_str(struct ofputil_meter_mod *mm, const char *str_,
                        int command, bool verbose)
{
    enum {
        F_METER = 1 << 0,
        F_FLAGS = 1 << 1,
        F_BANDS = 1 << 2,
    } fields;
    char *string = xstrdup(str_);
    char *save_ptr = NULL;
    char *band_str = NULL;
    char *name;

    switch (command) {
    case -1:
        fields = F_METER;
        break;

    case OFPMC13_ADD:
        fields = F_METER | F_FLAGS | F_BANDS;
        break;

    case OFPMC13_DELETE:
        fields = F_METER;
        break;

    case OFPMC13_MODIFY:
        fields = F_METER | F_FLAGS | F_BANDS;
        break;

    default:
        NOT_REACHED();
    }

    mm->command = command;
    mm->meter.meter_id = 0;
    mm->meter.flags = 0;
    if (fields & F_BANDS) {
        band_str = strstr(string, "band");
        if (!band_str) {
            ofp_fatal(str_, verbose, "must specify bands");
        }
        *band_str = '\0';

        band_str = strchr(band_str + 1, '=');
        if (!band_str) {
            ofp_fatal(str_, verbose, "must specify bands");
        }

        band_str++;
    }
    for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
         name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {

        if (fields & F_FLAGS && !strcmp(name, "kbps")) {
            mm->meter.flags |= OFPMF13_KBPS;
        } else if (fields & F_FLAGS && !strcmp(name, "pktps")) {
            mm->meter.flags |= OFPMF13_PKTPS;
        } else if (fields & F_FLAGS && !strcmp(name, "burst")) {
            mm->meter.flags |= OFPMF13_BURST;
        } else if (fields & F_FLAGS && !strcmp(name, "stats")) {
            mm->meter.flags |= OFPMF13_STATS;
        } else {
            char *value;

            value = strtok_r(NULL, ", \t\r\n", &save_ptr);
            if (!value) {
                ofp_fatal(str_, verbose, "field %s missing value", name);
            }

            if (!strcmp(name, "meter")) {
                if (!strcmp(value, "all")) {
                    mm->meter.meter_id = OFPM13_ALL;
                } else if (!strcmp(value, "controller")) {
                    mm->meter.meter_id = OFPM13_CONTROLLER;
                } else if (!strcmp(value, "slowpath")) {
                    mm->meter.meter_id = OFPM13_SLOWPATH;
                } else {
                    mm->meter.meter_id = str_to_u32(value);
                    if (mm->meter.meter_id > OFPM13_MAX) {
                        ofp_fatal(str_, verbose, "invalid value for %s", name);
                    }
                }
            } else {
                ofp_fatal(str_, verbose, "unknown keyword %s", name);
            }
        }
    }
    if (fields & F_METER && !mm->meter.meter_id) {
        ofp_fatal(str_, verbose, "must specify 'meter'");
    }
    if (fields & F_FLAGS && !mm->meter.flags) {
        ofp_fatal(str_, verbose,
                  "meter must specify either 'kbps' or 'pktps'");
    }

    if (fields & F_BANDS) {
        struct ofpbuf bands;
        uint16_t n_bands = 0;
        struct ofputil_meter_band *band = NULL;
        int i;

        ofpbuf_init(&bands, 64);

        for (name = strtok_r(band_str, "=, \t\r\n", &save_ptr); name;
             name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {

            char *value;

            value = strtok_r(NULL, ", \t\r\n", &save_ptr);
            if (!value) {
                ofp_fatal(str_, verbose, "field %s missing value", name);
            }

            if (!strcmp(name, "type")) {
                /* Start a new band */
                band = ofpbuf_put_zeros(&bands, sizeof *band);
                n_bands++;

                if (!strcmp(value, "drop")) {
                    band->type = OFPMBT13_DROP;
                } else if (!strcmp(value, "dscp_remark")) {
                    band->type = OFPMBT13_DSCP_REMARK;
                } else {
                    ofp_fatal(str_, verbose, "field %s unknown value %s", name,
                              value);
                }
            } else if (!band || !band->type) {
                ofp_fatal(str_, verbose,
                          "band must start with the 'type' keyword");
            } else if (!strcmp(name, "rate")) {
                band->rate = str_to_u32(value);
            } else if (!strcmp(name, "burst_size")) {
                band->burst_size = str_to_u32(value);
            } else if (!strcmp(name, "prec_level")) {
                band->prec_level = str_to_u8(value, name);
            } else {
                ofp_fatal(str_, verbose, "unknown keyword %s", name);
            }
        }
        /* validate bands */
        if (!n_bands) {
            ofp_fatal(str_, verbose, "meter must have bands");
        }

        mm->meter.n_bands = n_bands;
        mm->meter.bands = ofpbuf_steal_data(&bands);

        for (i = 0; i < n_bands; ++i) {
            band = &mm->meter.bands[i];

            if (!band->type) {
                ofp_fatal(str_, verbose, "band must have 'type'");
            }
            if (band->type == OFPMBT13_DSCP_REMARK) {
                if (!band->prec_level) {
                    ofp_fatal(str_, verbose, "'dscp_remark' band must have"
                              " 'prec_level'");
                }
            } else {
                if (band->prec_level) {
                    ofp_fatal(str_, verbose, "Only 'dscp_remark' band may have"
                              " 'prec_level'");
                }
            }
            if (!band->rate) {
                ofp_fatal(str_, verbose, "band must have 'rate'");
            }
            if (mm->meter.flags & OFPMF13_BURST) {
                if (!band->burst_size) {
                    ofp_fatal(str_, verbose, "band must have 'burst_size' "
                              "when 'burst' flag is set");
                }
            } else {
                if (band->burst_size) {
                    ofp_fatal(str_, verbose, "band may have 'burst_size' only "
                              "when 'burst' flag is set");
                }
            }
        }
    } else {
        mm->meter.n_bands = 0;
        mm->meter.bands = NULL;
    }

    free(string);
}
Example #12
0
int main(int argc, char *argv[])
{

    u32 sig_id = 0;
    u32 head_len = 0;
    u32 data_len = 0;
    u32 buf_len = 0;
    u32 i = 0;
    u32 tmp_value_a = 0;
    u32 tmp_value_b = 0;

    s8 *data =  NULL;
    s8 *buf =  NULL;
    s8 *prt = NULL;
    u32 *tmp_u32_prt = NULL;
    
    
    s32 rtn_code = 0;
    s32 ret = 0;

    u32 type_count;
    s32 dev_type;

    u32 type_bits;
    u32 slot_max;
    struct ifm_board_info_s * slot_info;

    
    if (argc < 2)
    {
        printf("input parameter error\r\n");
        usage();
        return 0;
    }

    data = (s8 *)argv[1];
    data_len = (u32)strlen(data);
    
    sig_id = str_to_u32((u8 *)data,data_len);    
    
    head_len = sizeof(u32) * 3;
    
    if (2 == argc)
    {
        buf_len = head_len;
        buf = (s8 *)malloc(buf_len);
        if(NULL == buf)
        {
            printf("memory error\r\n");
            return 0;
        }
        memset(buf, 0x0, head_len);

        tmp_u32_prt = (u32 *)buf;

        *tmp_u32_prt = sig_id;
        tmp_u32_prt++; 
        *tmp_u32_prt = 0;
        tmp_u32_prt++;
        *tmp_u32_prt = 0;
    } 
    else
    {
        data = (s8 *)argv[2];
        data_len = (u32)strlen(data);
        if(data_len%2)
        {
            printf("input hex error1\r\n");
            usage();
            return 0;
        }

        buf_len = (data_len/2) + head_len;
        buf = (s8 *)malloc(buf_len);
        if(NULL == buf)
        {
            printf("memory error\r\n");
            return 0;
        }
        memset(buf, 0x0, buf_len);

        tmp_u32_prt = (u32 *)buf;

        *tmp_u32_prt = sig_id;
        tmp_u32_prt++;        
        *tmp_u32_prt = 1;
        tmp_u32_prt++;
        *tmp_u32_prt = data_len/2;

        prt = buf + head_len;

    
        for(i = 0; i < data_len - 1; i += 2, data += 2)
        {
            tmp_value_a = (u32)str_to_hex(*((s8 *)data));
            tmp_value_b = (u32)str_to_hex(*((s8 *)(data + 1)));
            tmp_value_b = tmp_value_a*16 + tmp_value_b;

            *prt =(u8)tmp_value_b;
            prt++;
        }
    }

    type_bits = BIT(UAG_BOARD) | BIT(IPS_BOARD);
    ret = ifm_get_board_count_by_type(type_bits, &type_count);
    if(ret)
    {
        return ret;
    }

    if (type_count == 0)
    {
        rtn_code = conplat_syscall(MODULEID_DCDM,DCDM_CMD_PCRE_TEST,(void *)buf,buf_len,&ret);
    }
    else
    {
        
        ret = ifm_get_slot_status(&slot_max, &slot_info);
        if(ret)
        {
            return ret;
        }

        for (i = 0; i < slot_max; i++)
        {
            dev_type = slot_info[i].slot_type;
            if(slot_info[i].is_available && (type_bits & BIT(dev_type)))
            {
                rtn_code = conplat_syscall(DPI_MODULEID_DCDM | dev_type,DCDM_CMD_PCRE_TEST,(void *)buf,buf_len,&ret);
            }
        }
    }
    
    if( (ERROR_SUCCESS != rtn_code) || (ERROR_SUCCESS != ret) )
    {
        printf("\r\ndcdmd_pcre_test failed!!\r\n");
    }
    else
    {
        printf("\r\ndcdmd_pcre_test succeed\r\n");
    }
    
    free(buf);
    return 0;    
}
Example #13
0
static void
parse_field_value(struct cls_rule *rule, enum field_index index,
                  const char *value)
{
    uint8_t mac[ETH_ADDR_LEN];
    ovs_be64 tun_id, tun_mask;
    ovs_be32 ip, mask;
    struct in6_addr ipv6, ipv6_mask;
    uint16_t port_no;

    switch (index) {
    case F_TUN_ID:
        str_to_tun_id(value, &tun_id, &tun_mask);
        cls_rule_set_tun_id_masked(rule, tun_id, tun_mask);
        break;

    case F_IN_PORT:
        if (!parse_port_name(value, &port_no)) {
            port_no = atoi(value);
        }
        if (port_no == OFPP_LOCAL) {
            port_no = ODPP_LOCAL;
        }
        cls_rule_set_in_port(rule, port_no);
        break;

    case F_DL_VLAN:
        cls_rule_set_dl_vlan(rule, htons(str_to_u32(value)));
        break;

    case F_DL_VLAN_PCP:
        cls_rule_set_dl_vlan_pcp(rule, str_to_u32(value));
        break;

    case F_DL_SRC:
        str_to_mac(value, mac);
        cls_rule_set_dl_src(rule, mac);
        break;

    case F_DL_DST:
        str_to_mac(value, mac);
        cls_rule_set_dl_dst(rule, mac);
        break;

    case F_DL_TYPE:
        cls_rule_set_dl_type(rule, htons(str_to_u32(value)));
        break;

    case F_NW_SRC:
        str_to_ip(value, &ip, &mask);
        cls_rule_set_nw_src_masked(rule, ip, mask);
        break;

    case F_NW_DST:
        str_to_ip(value, &ip, &mask);
        cls_rule_set_nw_dst_masked(rule, ip, mask);
        break;

    case F_NW_PROTO:
        cls_rule_set_nw_proto(rule, str_to_u32(value));
        break;

    case F_NW_TOS:
        cls_rule_set_nw_tos(rule, str_to_u32(value));
        break;

    case F_TP_SRC:
        cls_rule_set_tp_src(rule, htons(str_to_u32(value)));
        break;

    case F_TP_DST:
        cls_rule_set_tp_dst(rule, htons(str_to_u32(value)));
        break;

    case F_ICMP_TYPE:
        cls_rule_set_icmp_type(rule, str_to_u32(value));
        break;

    case F_ICMP_CODE:
        cls_rule_set_icmp_code(rule, str_to_u32(value));
        break;

    case F_ARP_SHA:
        str_to_mac(value, mac);
        cls_rule_set_arp_sha(rule, mac);
        break;

    case F_ARP_THA:
        str_to_mac(value, mac);
        cls_rule_set_arp_tha(rule, mac);
        break;

    case F_IPV6_SRC:
        str_to_ipv6(value, &ipv6, &ipv6_mask);
        cls_rule_set_ipv6_src_masked(rule, &ipv6, &ipv6_mask);
        break;

    case F_IPV6_DST:
        str_to_ipv6(value, &ipv6, &ipv6_mask);
        cls_rule_set_ipv6_dst_masked(rule, &ipv6, &ipv6_mask);
        break;

    case F_ND_TARGET:
        str_to_ipv6(value, &ipv6, NULL);
        cls_rule_set_nd_target(rule, ipv6);
        break;

    case F_ND_SLL:
        str_to_mac(value, mac);
        cls_rule_set_arp_sha(rule, mac);
        break;

    case F_ND_TLL:
        str_to_mac(value, mac);
        cls_rule_set_arp_tha(rule, mac);
        break;

    case N_FIELDS:
        NOT_REACHED();
    }
}
Example #14
0
int main(int argc, char **argv)
{
    int ch, longindex, ret, port = SD_LISTEN_PORT, io_port = SD_LISTEN_PORT;
    int rc = 1;
    const char *dirp = DEFAULT_OBJECT_DIR, *short_options;
    char *dir, *pid_file = NULL, *bindaddr = NULL, log_path[PATH_MAX],
                *argp = NULL;
    bool explicit_addr = false;
    bool daemonize = true;
    int32_t nr_vnodes = -1;
    int64_t zone = -1;
    struct cluster_driver *cdrv;
    struct option *long_options;
#ifdef HAVE_HTTP
    const char *http_options = NULL;
#endif
    static struct logger_user_info sheep_info;
    struct stat logdir_st;
    enum log_dst_type log_dst_type;

    sys->cinfo.flags |= SD_CLUSTER_FLAG_AUTO_VNODES;
    sys->node_status = SD_NODE_STATUS_INITIALIZATION;

    sys->rthrottling.max_exec_count = 0;
    sys->rthrottling.queue_work_interval = 0;
    sys->rthrottling.throttling = false;

    install_crash_handler(crash_handler);
    signal(SIGPIPE, SIG_IGN);

    install_sighandler(SIGHUP, sighup_handler, false);

    long_options = build_long_options(sheep_options);
    short_options = build_short_options(sheep_options);
    while ((ch = getopt_long(argc, argv, short_options, long_options,
                             &longindex)) >= 0) {
        switch (ch) {
        case 'p':
            port = str_to_u16(optarg);
            if (errno != 0 || port < 1) {
                sd_err("Invalid port number '%s'", optarg);
                exit(1);
            }
            break;
        case 'P':
            pid_file = optarg;
            break;
#ifdef HAVE_HTTP
        case 'r':
            http_options = optarg;
            break;
#endif
        case 'l':
            if (option_parse(optarg, ",", log_parsers) < 0)
                exit(1);
            break;
        case 'n':
            sys->nosync = true;
            break;
        case 'y':
            if (!str_to_addr(optarg, sys->this_node.nid.addr)) {
                sd_err("Invalid address: '%s'", optarg);
                exit(1);
            }
            explicit_addr = true;
            break;
        case 'D':
            sys->backend_dio = true;
            break;
        case 'f':
            daemonize = false;
            break;
        case 'g':
            if (nr_vnodes > 0) {
                sd_err("Options '-g' and '-V' can not be both specified");
                exit(1);
            }
            nr_vnodes = 0;
            break;
        case 'z':
            zone = str_to_u32(optarg);
            if (errno != 0) {
                sd_err("Invalid zone id '%s': must be "
                       "an integer between 0 and %u", optarg,
                       UINT32_MAX);
                exit(1);
            }
            sys->this_node.zone = zone;
            break;
        case 'u':
            sys->upgrade = true;
            break;
        case 'c':
            sys->cdrv = find_cdrv(optarg);
            if (!sys->cdrv) {
                sd_err("Invalid cluster driver '%s'", optarg);
                fprintf(stderr, "Supported drivers:");
                FOR_EACH_CLUSTER_DRIVER(cdrv) {
                    fprintf(stderr, " %s", cdrv->name);
                }
                fprintf(stderr, "\n");
                exit(1);
            }

            sys->cdrv_option = get_cdrv_option(sys->cdrv, optarg);
            break;
        case 'i':
            if (option_parse(optarg, ",", ionic_parsers) < 0)
                exit(1);

            if (!str_to_addr(io_addr, sys->this_node.nid.io_addr)) {
                sd_err("Bad addr: '%s'", io_addr);
                exit(1);
            }

            if (io_pt)
                if (sscanf(io_pt, "%u", &io_port) != 1) {
                    sd_err("Bad port '%s'", io_pt);
                    exit(1);
                }
            sys->this_node.nid.io_port = io_port;
#ifdef HAVE_ACCELIO
            if (!strcmp(io_transport, "tcp"))
                sys->this_node.nid.io_transport_type =
                    IO_TRANSPORT_TYPE_TCP;
            else if (!strcmp(io_transport, "rdma"))
                sys->this_node.nid.io_transport_type =
                    IO_TRANSPORT_TYPE_RDMA;
            else {
                sd_err("unknown transport type: %s",
                       io_transport);
                exit(1);
            }
#endif
            break;
        case 'j':
            uatomic_set_true(&sys->use_journal);
            if (option_parse(optarg, ",", journal_parsers) < 0)
                exit(1);
            if (!jsize) {
                sd_err("you must specify size for journal");
                exit(1);
            }
            break;
        case 'b':
            if (!inetaddr_is_valid(optarg))
                exit(1);
            bindaddr = optarg;
            break;
        case 'h':
            usage(0);
            break;
        case 'R':
            if (option_parse(optarg, ",", recovery_parsers) < 0)
                exit(1);
            sys->rthrottling.max_exec_count = max_exec_count;
            sys->rthrottling.queue_work_interval
                = queue_work_interval;
            if (max_exec_count > 0 && queue_work_interval > 0)
                sys->rthrottling.throttling = true;
            break;
        case 'v':
            fprintf(stdout, "Sheepdog daemon version %s\n",
                    PACKAGE_VERSION);
            exit(0);
            break;
        case 'V':
            sys->cinfo.flags &= ~SD_CLUSTER_FLAG_AUTO_VNODES;
            if (nr_vnodes == 0) {
                sd_err("Options '-g' and '-V' can not be both specified");
                exit(1);
            }
            nr_vnodes = str_to_u16(optarg);
            if (errno != 0 || nr_vnodes < 1) {
                sd_err("Invalid number of vnodes '%s': must be "
                       "an integer between 1 and %u",
                       optarg, UINT16_MAX);
                exit(1);
            }
            break;
        case 'W':
            wildcard_recovery = true;
            break;
        case 'w':
            if (option_parse(optarg, ",", wq_parsers) < 0)
                exit(1);
            break;
        default:
            usage(1);
            break;
        }
    }
Example #15
0
static void
parse_named_action(enum ofputil_action_code code, const struct flow *flow,
                   struct ofpbuf *b, char *arg)
{
    struct ofp_action_dl_addr *oada;
    struct ofp_action_vlan_pcp *oavp;
    struct ofp_action_vlan_vid *oavv;
    struct ofp_action_nw_addr *oana;
    struct ofp_action_tp_port *oata;

    switch (code) {
    case OFPUTIL_OFPAT_OUTPUT:
        parse_output(b, arg);
        break;

    case OFPUTIL_OFPAT_SET_VLAN_VID:
        oavv = ofputil_put_OFPAT_SET_VLAN_VID(b);
        oavv->vlan_vid = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_SET_VLAN_PCP:
        oavp = ofputil_put_OFPAT_SET_VLAN_PCP(b);
        oavp->vlan_pcp = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_STRIP_VLAN:
        ofputil_put_OFPAT_STRIP_VLAN(b);
        break;

    case OFPUTIL_OFPAT_SET_DL_SRC:
    case OFPUTIL_OFPAT_SET_DL_DST:
        oada = ofputil_put_action(code, b);
        str_to_mac(arg, oada->dl_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_SRC:
    case OFPUTIL_OFPAT_SET_NW_DST:
        oana = ofputil_put_action(code, b);
        str_to_ip(arg, &oana->nw_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_TOS:
        ofputil_put_OFPAT_SET_NW_TOS(b)->nw_tos = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_SET_TP_SRC:
    case OFPUTIL_OFPAT_SET_TP_DST:
        oata = ofputil_put_action(code, b);
        oata->tp_port = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_ENQUEUE:
        parse_enqueue(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
        parse_set_tunnel(b, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofputil_put_NXAST_SET_QUEUE(b)->queue_id = htonl(str_to_u32(arg));
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofputil_put_NXAST_POP_QUEUE(b);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofputil_put_NXAST_REG_MOVE(b), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofputil_put_NXAST_REG_LOAD(b), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL64:
        ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(str_to_u64(arg));
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofputil_put_NXAST_MULTIPATH(b), arg);
        break;

    case OFPUTIL_NXAST_AUTOPATH:
        autopath_parse(ofputil_put_NXAST_AUTOPATH(b), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(b, arg);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(b, arg, flow);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofputil_put_NXAST_EXIT(b);
        break;
    }
}