Ejemplo n.º 1
0
size_t
ofl_structs_meter_conf_pack(struct ofl_meter_config *src, struct ofp_meter_config *dst, uint8_t* data){
    size_t total_len, len;
    int i;

    total_len = sizeof(struct ofp_meter_config) +
        ofl_structs_meter_bands_ofp_total_len(src->bands, src->meter_bands_num);

    dst->length = ntohs(total_len);
    dst->flags = ntohs(src->flags);
    dst->meter_id = ntohl(src->meter_id);

    data = (uint8_t *)dst->bands;

    for (i=0; i<src->meter_bands_num; i++) {
        len = ofl_structs_meter_band_pack(src->bands[i], (struct ofp_meter_band_header *)data);
        data += len;
    }
    return total_len;
}
static int
ofl_msg_pack_meter_mod(struct ofl_msg_meter_mod *msg, uint8_t ** buf, size_t *buf_len){
    struct ofp_meter_mod *meter_mod;
    uint8_t *ptr;
    int i;

    *buf_len =  sizeof(struct ofp_meter_mod) + ofl_structs_meter_bands_ofp_total_len(msg->bands, msg->meter_bands_num);
    *buf = malloc(*buf_len);

    meter_mod = (struct ofp_meter_mod*) (*buf);
    meter_mod->command = htons(msg->command);
    meter_mod->flags = htons(msg->flags);
    meter_mod->meter_id = ntohl(msg->meter_id);

    ptr = (*buf) + sizeof(struct ofp_meter_mod);
    for (i=0; i < msg->meter_bands_num; i++) {
        ptr += ofl_structs_meter_band_pack(msg->bands[i], (struct ofp_meter_band_header *) ptr);
    }
    return 0;
}