Пример #1
0
static int
ofl_msg_pack_features_reply(struct ofl_msg_features_reply *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_switch_features *features;
    uint8_t *ptr;
    int i;

    *buf_len = sizeof(struct ofp_switch_features) + msg->ports_num * sizeof(struct ofp_port);
    *buf     = (uint8_t *)malloc(*buf_len);

    features = (struct ofp_switch_features *)(*buf);
    features->datapath_id  = hton64(msg->datapath_id);
    features->n_buffers    = htonl( msg->n_buffers);
    features->n_tables     =        msg->n_tables;
    memset(features->pad, 0x00, 3);
    features->capabilities = htonl( msg->capabilities);
    features->reserved = 0x00000000;

    ptr  = (*buf) + sizeof(struct ofp_switch_features);

    for (i=0; i<msg->ports_num; i++) {
        ptr += ofl_structs_port_pack(msg->ports[i], (struct ofp_port *)ptr);
    }

    return 0;
}
static int
ofl_msg_pack_port_status(struct ofl_msg_port_status *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_port_status *status;

    *buf_len = sizeof(struct ofp_port_status);
    *buf     = (uint8_t *)malloc(*buf_len);

    status = (struct ofp_port_status *)(*buf);
    status->reason = msg->reason;
    memset(status->pad, 0x00, 7);

    ofl_structs_port_pack(msg->desc, &(status->desc));

    return 0;
}