Added PacketCustomizer and State Machine exceptions to 'api' package.

Change-Id: Ifcc98ea0f7e46fb148c2fde60eb2d9b343b5f502
diff --git a/src/main/java/org/opencord/aaa/api/PacketCustomizer.java b/src/main/java/org/opencord/aaa/api/PacketCustomizer.java
new file mode 100644
index 0000000..3dbdb71
--- /dev/null
+++ b/src/main/java/org/opencord/aaa/api/PacketCustomizer.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.aaa.api;
+
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.RADIUS;
+import org.onosproject.net.packet.InboundPacket;
+
+/**
+ * Facilitates the customization of RADIUS packets.
+ * <p>
+ * This default implementation does no customization.
+ * <p>
+ * Subclasses should override the appropriate methods to fill in attributes
+ * according to the specifics of the RADIUS server set up.
+ */
+public class PacketCustomizer {
+
+    /**
+     * Customize the packet as per specific setup or RADIUS server requirements.
+     * <p>
+     * This default implementation returns the packet unaltered.
+     *
+     * @param inPkt     RADIUS packet to be customized
+     * @param eapPacket Incoming packet containing EAP for which this RADIUS
+     *                  message is being created
+     * @return customized RADIUS packet
+     */
+    public RADIUS customizePacket(RADIUS inPkt, InboundPacket eapPacket) {
+        return inPkt;
+    }
+
+    /**
+     * Customize the Ethernet header as per specific setup or RADIUS
+     * server requirements.
+     * <p>
+     * This default implementation returns the packet unaltered.
+     *
+     * @param inPkt     Ethernet packet to be changed
+     * @param eapPacket Incoming packet containing EAP for which this RADIUS
+     *                  message is being created
+     * @return customized Ethernet packet
+     */
+    public Ethernet customizeEthernetIPHeaders(Ethernet inPkt,
+                                               InboundPacket eapPacket) {
+        return inPkt;
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/opencord/aaa/api/StateMachineException.java b/src/main/java/org/opencord/aaa/api/StateMachineException.java
new file mode 100644
index 0000000..7bc5a35
--- /dev/null
+++ b/src/main/java/org/opencord/aaa/api/StateMachineException.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.opencord.aaa.api;
+
+/**
+ * Exception for the AAA State Machine.
+ */
+public class StateMachineException extends Exception {
+    public StateMachineException(String message) {
+        super(message);
+    }
+}
diff --git a/src/main/java/org/opencord/aaa/api/StateMachineInvalidTransitionException.java b/src/main/java/org/opencord/aaa/api/StateMachineInvalidTransitionException.java
new file mode 100644
index 0000000..408a59d
--- /dev/null
+++ b/src/main/java/org/opencord/aaa/api/StateMachineInvalidTransitionException.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.opencord.aaa.api;
+
+/**
+ * Exception raised when the transition from one state to another is invalid.
+ */
+public class StateMachineInvalidTransitionException extends StateMachineException {
+    public StateMachineInvalidTransitionException(String message) {
+        super(message);
+    }
+}
diff --git a/src/test/java/org/opencord/aaa/api/PacketCustomizerTest.java b/src/test/java/org/opencord/aaa/api/PacketCustomizerTest.java
new file mode 100644
index 0000000..d8d9ed8
--- /dev/null
+++ b/src/test/java/org/opencord/aaa/api/PacketCustomizerTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.aaa.api;
+
+import org.junit.Test;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.RADIUS;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+/**
+ * Unit tests for {@link PacketCustomizer}.
+ */
+public class PacketCustomizerTest {
+
+    private static final RADIUS RADIUS_PACKET = new RADIUS();
+    private static final Ethernet ETHERNET_PACKET = new Ethernet();
+
+    private PacketCustomizer customizer;
+
+    @Test
+    public void noChangeToRadius() {
+        customizer = new PacketCustomizer();
+        RADIUS transformed = customizer.customizePacket(RADIUS_PACKET, null);
+        assertSame(RADIUS_PACKET, transformed);
+        assertEquals(RADIUS_PACKET, transformed);
+    }
+
+    @Test
+    public void noChangeToEthernet() {
+        customizer = new PacketCustomizer();
+        Ethernet transformed =
+                customizer.customizeEthernetIPHeaders(ETHERNET_PACKET, null);
+        assertSame(ETHERNET_PACKET, transformed);
+        assertEquals(ETHERNET_PACKET, transformed);
+    }
+}