+ uint32_t ii = 0;
+ payload.contract.n_rules = n_rules;
+
+ for (auto rule : m_gbp_rules) {
+ if (rule.action() == gbp_rule::action_t::REDIRECT)
+ payload.contract.rules[ii].action = GBP_API_RULE_REDIRECT;
+ else if (rule.action() == gbp_rule::action_t::PERMIT)
+ payload.contract.rules[ii].action = GBP_API_RULE_PERMIT;
+ else
+ payload.contract.rules[ii].action = GBP_API_RULE_DENY;
+
+ if (rule.nhs().hash_mode() == gbp_rule::hash_mode_t::SYMMETRIC)
+ payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_SYMMETRIC;
+ else if (rule.nhs().hash_mode() == gbp_rule::hash_mode_t::SRC_IP)
+ payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_SRC_IP;
+ else
+ payload.contract.rules[ii].nh_set.hash_mode = GBP_API_HASH_MODE_DST_IP;
+
+ const gbp_rule::next_hops_t& next_hops = rule.nhs().next_hops();
+ uint8_t jj = 0, nh_size = (next_hops.size() > 8) ? 8 : next_hops.size();
+
+ payload.contract.rules[ii].nh_set.n_nhs = nh_size;
+ for (auto nh : next_hops) {
+ to_api(nh.getIp(), payload.contract.rules[ii].nh_set.nhs[jj].ip);
+ to_api(nh.getMac(), payload.contract.rules[ii].nh_set.nhs[jj].mac);
+ payload.contract.rules[ii].nh_set.nhs[jj].bd_id = nh.getBdId();
+ payload.contract.rules[ii].nh_set.nhs[jj].rd_id = nh.getRdId();
+ jj++;
+ }
+ ++ii;
+ }
+
+ u8* data;
+ u16* et;
+
+ data = (((u8*)&payload.contract.n_ether_types) +
+ (sizeof(payload.contract.rules[0]) * payload.contract.n_rules));
+ *data = m_allowed_ethertypes.size();
+ et = (u16*)(++data);
+ ii = 0;
+ for (auto tt : m_allowed_ethertypes) {
+ et[ii] = tt.value();
+ ii++;
+ }
+