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; }
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; }
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; }