SEBA-73: Decouple AAA auth from subscriber provisioning

Change-Id: Iaeac39e103b0ff1f15ce0cfef0dff49017c98e25
diff --git a/pom.xml b/pom.xml
index 30c1832..2c4c7c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
 
     <groupId>org.opencord</groupId>
     <artifactId>aaa</artifactId>
-    <version>1.7.0-SNAPSHOT</version>
+    <version>1.8.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <description>ONOS authentication application</description>
@@ -41,11 +41,9 @@
         <onos.app.url>http://opencord.org</onos.app.url>
         <onos.app.readme>802.1x authentication service.</onos.app.readme>
         <onos.app.requires>
-              org.opencord.olt,
               org.opencord.sadis
         </onos.app.requires>
         <sadis.api.version>2.1.0</sadis.api.version>
-        <olt.api.version>1.4.0</olt.api.version>
     </properties>
 
     <dependencies>
@@ -62,12 +60,6 @@
         </dependency>
 
         <dependency>
-             <groupId>org.opencord</groupId>
-             <artifactId>olt-api</artifactId>
-	     <version>${olt.api.version}</version>
-         </dependency>
-
-        <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-api</artifactId>
             <version>${onos.version}</version>
diff --git a/src/main/java/org/opencord/aaa/AaaManager.java b/src/main/java/org/opencord/aaa/AaaManager.java
index c920864..c9fddc0 100755
--- a/src/main/java/org/opencord/aaa/AaaManager.java
+++ b/src/main/java/org/opencord/aaa/AaaManager.java
@@ -15,11 +15,11 @@
  */
 package org.opencord.aaa;
 
+import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.onlab.packet.DeserializationException;
 import org.onlab.packet.EAP;
 import org.onlab.packet.EAPOL;
@@ -28,11 +28,9 @@
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.RADIUS;
 import org.onlab.packet.RADIUSAttribute;
-import org.onlab.packet.VlanId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
 import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.PortNumber;
@@ -51,8 +49,6 @@
 import org.onosproject.net.packet.PacketContext;
 import org.onosproject.net.packet.PacketProcessor;
 import org.onosproject.net.packet.PacketService;
-import org.opencord.olt.AccessDeviceService;
-import org.opencord.sadis.SubscriberAndDeviceInformation;
 import org.opencord.sadis.SubscriberAndDeviceInformationService;
 import org.osgi.service.component.annotations.Activate;
 import org.slf4j.Logger;
@@ -96,9 +92,6 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected MastershipService mastershipService;
 
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected AccessDeviceService accessDeviceService;
-
     private final DeviceListener deviceListener = new InternalDeviceListener();
 
     // NAS IP address
@@ -209,7 +202,6 @@
 
 
         StateMachine.initializeMaps();
-        StateMachine.setAccessDeviceService(accessDeviceService);
 
         impl.initializeLocalState(newCfg);
 
@@ -441,21 +433,7 @@
             String sessionId = deviceId.toString() + portNumber.toString();
             StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
             if (stateMachine == null) {
-                if (deviceService != null) {
-                    String nasPortId = deviceService.getPort(inPacket.receivedFrom()).
-                            annotations().value(AnnotationKeys.PORT_NAME);
-
-                    SubscriberAndDeviceInformation subscriber =
-                            subsService.get(nasPortId);
-                    if (subscriber != null) {
-                        stateMachine = new StateMachine(sessionId, subscriber.cTag());
-                    } else {
-                        log.error("Could not create new state machine for {}", nasPortId);
-                        return;
-                    }
-                } else {
-                    stateMachine = new StateMachine(sessionId, VlanId.vlanId((short) 0));
-                }
+                stateMachine = new StateMachine(sessionId);
             }
 
             EAPOL eapol = (EAPOL) ethPkt.getPayload();
diff --git a/src/main/java/org/opencord/aaa/StateMachine.java b/src/main/java/org/opencord/aaa/StateMachine.java
index a4b46aa..e2a24bc 100644
--- a/src/main/java/org/opencord/aaa/StateMachine.java
+++ b/src/main/java/org/opencord/aaa/StateMachine.java
@@ -19,9 +19,7 @@
 
 import com.google.common.collect.Maps;
 import org.onlab.packet.MacAddress;
-import org.onlab.packet.VlanId;
 import org.onosproject.net.ConnectPoint;
-import org.opencord.olt.AccessDeviceService;
 import org.slf4j.Logger;
 
 import java.util.Map;
@@ -47,8 +45,6 @@
     static final int TRANSITION_DENY_ACCESS = 3;
     static final int TRANSITION_LOGOFF = 4;
 
-    private static AccessDeviceService accessDeviceService;
-
     private static int identifier = -1;
     private byte challengeIdentifier;
     private byte[] challengeState;
@@ -59,7 +55,6 @@
     private ConnectPoint supplicantConnectpoint;
     private MacAddress supplicantAddress;
     private short vlanId;
-    private VlanId ctag;
     private byte priorityCode;
 
     private String sessionId = null;
@@ -125,10 +120,6 @@
         identifierMap = null;
     }
 
-    public static void setAccessDeviceService(AccessDeviceService service) {
-        accessDeviceService = service;
-    }
-
     public static Map<String, StateMachine> sessionIdMap() {
         return sessionIdMap;
     }
@@ -169,17 +160,14 @@
     }
 
     /**
-     * State Machine Constructor.
+     * Creates a new StateMachine with the given session ID.
      *
-     * @param sessionId   session Id represented by the switch dpid +  port number
-     * @param ctag        C-TAG for this subscriber
+     * @param sessionId session Id represented by the switch dpid +  port number
      */
-    public StateMachine(String sessionId, VlanId ctag) {
-        log.info("Creating a new state machine for {} C-TAG {}", sessionId,
-                ctag);
+    public StateMachine(String sessionId) {
+        log.info("Creating a new state machine for {}", sessionId);
         this.sessionId = sessionId;
         sessionIdMap.put(sessionId, this);
-        this.ctag = ctag;
     }
 
     /**
@@ -406,12 +394,7 @@
         //move to the next state
         next(TRANSITION_AUTHORIZE_ACCESS);
 
-        if (accessDeviceService != null) {
-            log.info("Provisioning subscriber at {} with C-TAG {}",
-                    supplicantConnectpoint(), ctag);
-            accessDeviceService.provisionSubscriber(supplicantConnectpoint(),
-                                                    ctag);
-        }
+        // TODO send state machine change event
 
         // Clear mapping
         deleteStateMachineMapping(this);
diff --git a/src/test/java/org/opencord/aaa/StateMachineTest.java b/src/test/java/org/opencord/aaa/StateMachineTest.java
index 3d4ea27..f12a95f 100644
--- a/src/test/java/org/opencord/aaa/StateMachineTest.java
+++ b/src/test/java/org/opencord/aaa/StateMachineTest.java
@@ -19,14 +19,11 @@
 import org.junit.After;
 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;
+import static org.junit.Assert.assertNull;
 
 public class StateMachineTest {
     StateMachine stateMachine = null;
@@ -35,7 +32,7 @@
     public void setUp() {
         System.out.println("Set Up.");
         StateMachine.initializeMaps();
-        stateMachine = new StateMachine("session0", VlanId.vlanId((short) 2));
+        stateMachine = new StateMachine("session0");
     }
 
     @After
@@ -229,8 +226,8 @@
                 StateMachine.lookupStateMachineBySessionId(sessionId2);
         assertNull(machine2ShouldBeNull);
 
-        StateMachine stateMachine1 = new StateMachine(sessionId1, VlanId.vlanId((short) 2));
-        StateMachine stateMachine2 = new StateMachine(sessionId2, VlanId.vlanId((short) 2));
+        StateMachine stateMachine1 = new StateMachine(sessionId1);
+        StateMachine stateMachine2 = new StateMachine(sessionId2);
 
         assertEquals(stateMachine1,
                      StateMachine.lookupStateMachineBySessionId(sessionId1));
@@ -251,9 +248,9 @@
                 StateMachine.lookupStateMachineById((byte) 2);
         assertNull(machine2ShouldBeNull);
 
-        StateMachine stateMachine1 = new StateMachine(sessionId1, VlanId.vlanId((short) 2));
+        StateMachine stateMachine1 = new StateMachine(sessionId1);
         stateMachine1.start();
-        StateMachine stateMachine2 = new StateMachine(sessionId2, VlanId.vlanId((short) 2));
+        StateMachine stateMachine2 = new StateMachine(sessionId2);
         stateMachine2.start();
 
         assertEquals(stateMachine1,
@@ -276,7 +273,7 @@
         // 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));
+            StateMachine sm = new StateMachine(mac);
             sm.start();
             sm.setSupplicantAddress(MacAddress.valueOf(mac));
         }