static void send_flow_removed_message(ft_entry_t *entry, indigo_fi_flow_removed_t reason) { of_flow_removed_t *msg; int rv = 0; uint32_t secs; uint32_t nsecs; indigo_time_t current; current = INDIGO_CURRENT_TIME; /* TODO get version from OFConnectionManager */ if ((msg = of_flow_removed_new(entry->match.version)) == NULL) { return; } calc_duration(current, entry->insert_time, &secs, &nsecs); of_flow_removed_xid_set(msg, ind_core_xid_alloc()); of_flow_removed_cookie_set(msg, entry->cookie); of_flow_removed_priority_set(msg, entry->priority); of_flow_removed_idle_timeout_set(msg, entry->idle_timeout); if (msg->version >= OF_VERSION_1_1) { of_flow_removed_table_id_set(msg, entry->table_id); } if (msg->version >= OF_VERSION_1_2) { of_flow_removed_hard_timeout_set(msg, entry->hard_timeout); } if (of_flow_removed_match_set(msg, &entry->match)) { LOG_ERROR("Failed to set match in flow removed message"); of_object_delete(msg); return; } if (reason > INDIGO_FLOW_REMOVED_DELETE) { /* Normalize entry */ reason = INDIGO_FLOW_REMOVED_DELETE; } of_flow_removed_reason_set(msg, reason); of_flow_removed_duration_sec_set(msg, secs); of_flow_removed_duration_nsec_set(msg, nsecs); of_flow_removed_packet_count_set(msg, entry->packets); of_flow_removed_byte_count_set(msg, entry->bytes); /* @fixme hard_timeout and table_id are not in OF 1.0 */ /* @fixme Should a cxn-id be specified? */ rv = indigo_cxn_send_controller_message(INDIGO_CXN_ID_UNSPECIFIED, msg); if (rv != INDIGO_ERROR_NONE) { LOG_ERROR("Error sending flow removed message"); return; } return; }
static int test_removed_setup_from_add(void) { of_flow_removed_t *removed; of_flow_add_t *add; of_match_t m1, m2; TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT((removed = of_flow_removed_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); TEST_ASSERT(of_flow_removed_setup_from_flow_add(removed, add) == 0); TEST_ASSERT(of_flow_removed_match_get(removed, &m2) == 0); TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); of_flow_add_delete(add); of_flow_removed_delete(removed); return TEST_PASS; }