*/
int waiting_threads;
/**
- * is this SA flagged for deleting ?
+ * condvar where threads can wait until it's free again
*/
pthread_cond_t condvar;
/**
*
* This constructor additionaly creates a new and empty SA
*
- * @param ike_sa_id the associated ike_sa_id_t, cloned
+ * @param ike_sa_id the associated ike_sa_id_t, will be cloned
* @return created entry, with ike_sa and ike_sa_id
*/
static ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
this->checked_out = FALSE;
this->driveout_new_threads = FALSE;
this->driveout_waiting_threads = FALSE;
- this->ike_sa_id = ike_sa_id;
+ ike_sa_id->clone(ike_sa_id, &(this->ike_sa_id));
this->ike_sa = ike_sa_create(ike_sa_id);
return this;
}
* IKE_SA. This could be improved...
*/
spi_t responder_spi;
- ike_sa_id_t *new_ike_sa_id;
ike_sa_entry_t *new_ike_sa_entry;
/* set SPIs, we are the responder */
- ike_sa_id->clone(ike_sa_id, &new_ike_sa_id);
this->get_next_spi(this, &responder_spi);
- new_ike_sa_id->set_responder_spi(new_ike_sa_id, responder_spi);
/* we also set arguments spi, so its still valid */
ike_sa_id->set_responder_spi(ike_sa_id, responder_spi);
/* create entry */
- new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
+ new_ike_sa_entry = ike_sa_entry_create(ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
/* check ike_sa out */
/* creation of an IKE_SA from local site,
* we are the initiator!
*/
- spi_t initiator_spi, responder_spi;
- ike_sa_id_t *new_ike_sa_id;
+ spi_t initiator_spi;
ike_sa_entry_t *new_ike_sa_entry;
-
- /* set SPIs */
- memset(&responder_spi, 0, sizeof(spi_t));
this->get_next_spi(this, &initiator_spi);
ike_sa_id->set_initiator_spi(ike_sa_id, initiator_spi);
/* create entry */
- new_ike_sa_id = ike_sa_id_create(initiator_spi, responder_spi, INITIATOR);
- new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
+ new_ike_sa_entry = ike_sa_entry_create(ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
/* check ike_sa out */
ike_sa_manager_t *isam;
} td;
-static void successful_thread(ike_sa_id_t *ike_sa_id)
+static void test1_thread(ike_sa_id_t *ike_sa_id)
{
ike_sa_t *ike_sa;
status_t status;
td.tester->assert_true(td.tester, (status == SUCCESS), "checkin of a requested ike_sa");
}
-static void failed_thread(ike_sa_id_t *ike_sa_id)
+
+static void test2_thread(ike_sa_id_t *ike_sa_id)
+{
+ ike_sa_t *ike_sa;
+ status_t status;
+
+ status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
+ td.tester->assert_true(td.tester, (status == NOT_FOUND), "IKE_SA already deleted");
+}
+
+static void test3_thread(ike_sa_id_t *ike_sa_id)
{
ike_sa_t *ike_sa;
status_t status;
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
td.tester->assert_true(td.tester, (status == NOT_FOUND), "IKE_SA already deleted");
+
+ ike_sa_id->destroy(ike_sa_id);
}
+
+
+
void test_ike_sa_manager(tester_t *tester)
{
status_t status;
spi_t initiator, responder;
- ike_sa_id_t *ike_sa_id;
+ ike_sa_id_t *ike_sa_id, *sa_id;
ike_sa_t *ike_sa;
int thread_count = 200;
- int sa_count = 50;
+ int sa_count = 100;
int i;
pthread_t threads[thread_count];
-
/* First Test:
* we play initiator for IKE_SA_INIT first
* create an IKE_SA,
* this is usually done be the response from the communication partner,
* but we don't have one...
*/
- ike_sa_id->destroy(ike_sa_id);
- ike_sa_id = ike_sa->get_id(ike_sa);
responder.low = 123;
- ike_sa_id->set_responder_spi(ike_sa_id, responder);
+
+ sa_id = ike_sa->get_id(ike_sa);
+ sa_id->set_responder_spi(sa_id, responder);
/* check in, so we should have a "completed" sa, specified by ike_sa_id */
status = td.isam->checkin(td.isam, ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkin modified IKE_SA");
/* now we check it out and start some other threads */
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkout existing IKE_SA 1");
-
-
-
+
for (i = 0; i < thread_count; i++)
{
- if (pthread_create(&threads[i], NULL, (void*(*)(void*))successful_thread, (void*)ike_sa_id))
+ if (pthread_create(&threads[i], NULL, (void*(*)(void*))test1_thread, (void*)ike_sa_id))
{
/* failed, decrease list */
thread_count--;
pthread_join(threads[i], NULL);
}
- //ike_sa_id->destroy(ike_sa_id);
-
-
-
+ ike_sa_id->destroy(ike_sa_id);
/* Second Test:
* so we are the responder.
*
*/
-
memset(&initiator, 0, sizeof(initiator));
memset(&responder, 0, sizeof(responder));
tester->assert_true(tester, (status == SUCCESS), "checkout unexisting IKE_SA 2");
for (i = 0; i < thread_count; i++)
{
- if (pthread_create(&threads[i], NULL, (void*(*)(void*))failed_thread, (void*)ike_sa_id))
+ if (pthread_create(&threads[i], NULL, (void*(*)(void*))test2_thread, (void*)ike_sa_id))
{
/* failed, decrease list */
thread_count--;
pthread_join(threads[i], NULL);
}
- //ike_sa_id->destroy(ike_sa_id);
+ ike_sa_id->destroy(ike_sa_id);
/* Third Test:
* put in a lot of IKE_SAs, check it out, set a thread waiting
* and destroy the manager...
*/
-
+
memset(&initiator, 0, sizeof(initiator));
memset(&responder, 0, sizeof(responder));
status = td.isam->checkout(td.isam, ike_sa_id, &ike_sa);
tester->assert_true(tester, (status == SUCCESS), "checkout unexisting IKE_SA 3");
- if (pthread_create(&threads[i], NULL, (void*(*)(void*))failed_thread, (void*)ike_sa_id))
+ if (pthread_create(&threads[i], NULL, (void*(*)(void*))test3_thread, (void*)ike_sa_id))
{
/* failed, decrease list */
thread_count--;
}
- //ike_sa_id->destroy(ike_sa_id);
}
/* let them go acquiring */
pthread_join(threads[i], NULL);
}
+
}