CORD-1615 add CLI command to support the removal of state machines
Change-Id: I428bff2a8e502cc7b1c73f804792c36a8f847b57
diff --git a/src/test/java/org/opencord/aaa/StateMachineTest.java b/src/test/java/org/opencord/aaa/StateMachineTest.java
index 3f95134..3d4ea27 100644
--- a/src/test/java/org/opencord/aaa/StateMachineTest.java
+++ b/src/test/java/org/opencord/aaa/StateMachineTest.java
@@ -20,8 +20,11 @@
import org.junit.Before;
import org.junit.Test;
+import org.onlab.packet.MacAddress;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
import org.onlab.packet.VlanId;
@@ -258,4 +261,42 @@
assertEquals(stateMachine2,
StateMachine.lookupStateMachineById(stateMachine2.identifier()));
}
+
+ @Test
+ /**
+ * Test state machine deletes
+ */
+ public void testStateMachineReset() throws StateMachineException {
+
+ int count = 256;
+
+ //StateMachine.initializeMaps();
+ StateMachine.lookupStateMachineById((byte) 1);
+
+ // Instantiate a bunch of state machines
+ for (int i = 0; i < count; i += 1) {
+ String mac = String.format("00:00:00:00:00:%02x", i);
+ StateMachine sm = new StateMachine(mac, VlanId.vlanId((short) i));
+ sm.start();
+ sm.setSupplicantAddress(MacAddress.valueOf(mac));
+ }
+
+ // Verify all state machines with a "even" MAC exist
+ for (int i = 0; i < count; i += 2) {
+ String mac = String.format("00:00:00:00:00:%02x", i);
+ assertNotNull(StateMachine.lookupStateMachineBySessionId(mac));
+ }
+
+ // Delete all state machines with a "even" MAC
+ for (int i = 0; i < count; i += 2) {
+ String mac = String.format("00:00:00:00:00:%02x", i);
+ StateMachine.deleteByMac(MacAddress.valueOf(mac));
+ }
+
+ // Verify all the delete state machines no long exist
+ for (int i = 0; i < count; i += 2) {
+ String mac = String.format("00:00:00:00:00:%02x", i);
+ assertNull(StateMachine.lookupStateMachineBySessionId(mac));
+ }
+ }
}