コード例 #1
0
ファイル: ofl-structs-pack.c プロジェクト: CPqD/nox12oflib
size_t
ofl_structs_flow_stats_pack(struct ofl_flow_stats *src, uint8_t *dst, struct ofl_exp *exp) {
    
    struct ofp_flow_stats *flow_stats;
    size_t total_len;
    uint8_t *data;
    size_t  i;
    
    total_len = ROUND_UP(sizeof(struct ofp_flow_stats) -4 + src->match->length,8) +
                ofl_structs_instructions_ofp_total_len(src->instructions, src->instructions_num, exp);
    
    flow_stats = (struct ofp_flow_stats*) dst;

    flow_stats->length = htons(total_len);
    flow_stats->table_id = src->table_id;
    flow_stats->pad = 0x00;
    flow_stats->duration_sec = htonl(src->duration_sec);
    flow_stats->duration_nsec = htonl(src->duration_nsec);
    flow_stats->priority = htons(src->priority);
    flow_stats->idle_timeout = htons(src->idle_timeout);
    flow_stats->hard_timeout = htons(src->hard_timeout);
    memset(flow_stats->pad2, 0x00, 6);
    flow_stats->cookie = hton64(src->cookie);
    flow_stats->packet_count = hton64(src->packet_count);
    flow_stats->byte_count = hton64(src->byte_count);
    data = (dst) + sizeof(struct ofp_flow_stats) - 4;
    
    ofl_structs_match_pack(src->match, &(flow_stats->match), data, HOST_ORDER, exp);
    data = (dst) + ROUND_UP(sizeof(struct ofp_flow_stats) -4 + src->match->length, 8);  
    
    for (i=0; i < src->instructions_num; i++) {
        data += ofl_structs_instructions_pack(src->instructions[i], (struct ofp_instruction *) data, exp);
    }
    return total_len;
}
コード例 #2
0
static int
ofl_msg_pack_flow_mod(struct ofl_msg_flow_mod *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {
    struct ofp_flow_mod *flow_mod;
    uint8_t *ptr;

    int i;

    *buf_len = ROUND_UP(sizeof(struct ofp_flow_mod)- 4 + msg->match->length,8) +
                ofl_structs_instructions_ofp_total_len(msg->instructions, msg->instructions_num, exp);

    *buf     = (uint8_t *)malloc(*buf_len);
    flow_mod = (struct ofp_flow_mod *)(*buf);
    flow_mod->cookie       = hton64(msg->cookie);
    flow_mod->cookie_mask  = hton64(msg->cookie_mask);
    flow_mod->table_id     =        msg->table_id;
    flow_mod->command      =        msg->command;
    flow_mod->idle_timeout = htons( msg->idle_timeout);
    flow_mod->hard_timeout = htons( msg->hard_timeout);
    flow_mod->priority     = htons( msg->priority);
    flow_mod->buffer_id    = htonl( msg->buffer_id);
    flow_mod->out_port     = htonl( msg->out_port);
    flow_mod->out_group    = htonl( msg->out_group);
    flow_mod->flags        = htons( msg->flags);
    memset(flow_mod->pad, 0x00, 2);

    ptr  = (*buf) + sizeof(struct ofp_flow_mod)- 4;
    ofl_structs_match_pack(msg->match, &(flow_mod->match), ptr, HOST_ORDER, exp);
    /* We advance counting the padded bytes */
    ptr = (*buf) + ROUND_UP(sizeof(struct ofp_flow_mod)- 4 + msg->match->length,8);
    for (i=0; i<msg->instructions_num; i++) {
        ptr += ofl_structs_instructions_pack(msg->instructions[i], (struct ofp_instruction *)ptr, exp);
    }
    return 0;
}
コード例 #3
0
static int
ofl_msg_pack_multipart_request_flow(struct ofl_msg_multipart_request_flow *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {

    struct ofp_multipart_request *req;
    struct ofp_flow_stats_request *stats;
    uint8_t *ptr;

    *buf_len = sizeof(struct ofp_multipart_request) + sizeof(struct ofp_flow_stats_request) + msg->match->length;
    *buf     = (uint8_t *)malloc(*buf_len);

    req = (struct ofp_multipart_request *)(*buf);
    stats = (struct ofp_flow_stats_request *)req->body;
    stats->table_id    =        msg->table_id;
    memset(stats->pad, 0x00, 3);
    stats->out_port    = htonl( msg->out_port);
    stats->out_group   = htonl( msg->out_group);
    memset(stats->pad2, 0x00, 4);
    stats->cookie      = hton64(msg->cookie);
    stats->cookie_mask = hton64(msg->cookie_mask);

    ptr = (*buf) + sizeof(struct ofp_multipart_request) + sizeof(struct ofp_flow_stats_request);
    ofl_structs_match_pack(msg->match, &(stats->match),ptr, HOST_ORDER, exp);

    return 0;
}
コード例 #4
0
static int
ofl_msg_pack_flow_removed(struct ofl_msg_flow_removed *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {
    struct ofp_flow_removed *ofr;

    uint8_t *ptr;
    *buf_len = ROUND_UP((sizeof(struct ofp_flow_removed) -4) + msg->stats->match->length ,8);
    *buf     = (uint8_t *)malloc(*buf_len);

    ofr = (struct ofp_flow_removed *)(*buf);
    ofr->cookie        = hton64(msg->stats->cookie);
    ofr->priority      = htons(msg->stats->priority);
    ofr->reason        =        msg->reason;
    ofr->table_id      =        msg->stats->table_id;
    ofr->duration_sec  = htonl( msg->stats->duration_sec);
    ofr->duration_nsec = htonl( msg->stats->duration_nsec);
    ofr->idle_timeout  = htons( msg->stats->idle_timeout);
    ofr->packet_count  = hton64(msg->stats->packet_count);
    ofr->byte_count    = hton64(msg->stats->byte_count);

    ptr = (*buf) + (sizeof(struct ofp_flow_removed) - 4);

    ofl_structs_match_pack(msg->stats->match, &(ofr->match),ptr, HOST_ORDER, exp);

    return 0;
}
コード例 #5
0
static int
ofl_msg_pack_packet_in(struct ofl_msg_packet_in *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_packet_in *packet_in;
    uint8_t *ptr;

    *buf_len = sizeof(struct ofp_packet_in) + ROUND_UP(msg->match->length - 4 ,8) + msg->data_length + 2;
    *buf     = (uint8_t *)malloc(*buf_len);
    packet_in = (struct ofp_packet_in *)(*buf);
    packet_in->buffer_id   = htonl(msg->buffer_id);
    packet_in->total_len   = htons(msg->total_len);
    packet_in->reason      =       msg->reason;
    packet_in->table_id    =       msg->table_id;
    packet_in->cookie      = hton64(msg->cookie);

    ptr = (*buf) + (sizeof(struct ofp_packet_in) - 4);
    ofl_structs_match_pack(msg->match,&(packet_in->match),ptr, NETWORK_ORDER, NULL);
    ptr = (*buf) + ROUND_UP((sizeof(struct ofp_packet_in)-4) + msg->match->length,8);
    /*padding bytes*/

    memset(ptr,0,2);
    /* Ethernet frame */
    if (msg->data_length > 0) {
        memcpy(ptr + 2 , msg->data, msg->data_length);
    }

    return 0;
}
コード例 #6
0
static int
ofl_msg_pack_packet_in(struct ofl_msg_packet_in *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_packet_in *packet_in;
    uint8_t *ptr;
    size_t match_len;

    
    *buf_len = ROUND_UP(sizeof(struct ofp_packet_in)-4 + msg->match->length,8) + msg->data_length;
    *buf     = (uint8_t *)malloc(*buf_len);
   
    packet_in = (struct ofp_packet_in *)(*buf);
    packet_in->buffer_id   = htonl(msg->buffer_id);
    packet_in->total_len   = htons(msg->total_len);
    packet_in->reason      =       msg->reason;
    packet_in->table_id    =       msg->table_id;

    ptr = (*buf) + sizeof(struct ofp_packet_in) - 4;

    match_len = ofl_structs_match_pack(msg->match,&(packet_in->match),ptr,NULL);
    ptr = (*buf) + ROUND_UP(sizeof(struct ofp_packet_in)-4 + match_len,8) ;
    /*padding bytes*/
    
    memset(ptr,0,2); 
    /* Ethernet frame */
    if (msg->data_length > 0) {
        memcpy(ptr, msg->data, msg->data_length);
    }
   
    return 0;
}
コード例 #7
0
size_t
ofl_structs_flow_stats_pack(struct ofl_flow_stats *src, struct ofp_flow_stats *dst, struct ofl_exp *exp) {
    size_t total_len, len;
    uint8_t *data;
    size_t i;

    total_len = sizeof(struct ofp_flow_stats) +
                ofl_structs_instructions_ofp_total_len(src->instructions, src->instructions_num, exp);

    dst->length = htons(total_len);
    dst->table_id = src->table_id;
    dst->pad = 0x00;
    dst->duration_sec = htonl(src->duration_sec);
    dst->duration_nsec = htonl(src->duration_nsec);
    dst->priority = htons(src->priority);
    dst->idle_timeout = htons(src->idle_timeout);
    dst->hard_timeout = htons(src->hard_timeout);
    memset(dst->pad2, 0x00, 6);
    dst->cookie = hton64(src->cookie);
    dst->packet_count = hton64(src->packet_count);
    dst->byte_count = hton64(src->byte_count);

    ofl_structs_match_pack(src->match, &(dst->match), exp);


    data = (uint8_t *)dst->instructions;

    for (i=0; i<src->instructions_num; i++) {
        len = ofl_structs_instructions_pack(src->instructions[i], (struct ofp_instruction *)data, exp);
        data += len;
    }

    return total_len;
}
コード例 #8
0
static int
ofl_msg_pack_flow_removed(struct ofl_msg_flow_removed *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {
    struct ofp_flow_removed *ofr;

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

    ofr = (struct ofp_flow_removed *)(*buf);
    ofr->cookie        = hton64(msg->stats->cookie);
    ofr->priority      = hton64(msg->stats->priority);
    ofr->reason        =        msg->reason;
    ofr->table_id      =        msg->stats->table_id;
    ofr->duration_sec  = htonl( msg->stats->duration_sec);
    ofr->duration_nsec = htonl( msg->stats->duration_nsec);
    ofr->idle_timeout  = htons( msg->stats->idle_timeout);
    memset(ofr->pad2, 0x00, 2);
    ofr->packet_count  = hton64(msg->stats->packet_count);
    ofr->byte_count    = hton64(msg->stats->byte_count);

    ofl_structs_match_pack(msg->stats->match, &(ofr->match), exp);

    return 0;
}