Move AAA app to OLT

Change-Id: Ie1e41353177c8755f25bca1476b41df1f2826288
diff --git a/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java b/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java
index e7b3603..f46c2fc 100644
--- a/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java
+++ b/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java
@@ -232,6 +232,14 @@
         selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
         packetService.requestPackets(selector.build(),
                                      CONTROL, appId);
+
+        TrafficSelector radSelector = DefaultTrafficSelector.builder()
+                .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
+                .matchIPProtocol(IPv4.PROTOCOL_UDP)
+                .matchUdpDst((short) 1812)
+                .matchUdpSrc((short) 1812)
+                .build();
+        packetService.requestPackets(radSelector, CONTROL, appId);
     }
 
     /**
@@ -241,6 +249,14 @@
         TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
         selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
         packetService.cancelPackets(selector.build(), CONTROL, appId);
+
+        TrafficSelector radSelector = DefaultTrafficSelector.builder()
+                .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
+                .matchIPProtocol(IPv4.PROTOCOL_UDP)
+                .matchUdpDst((short) 1812)
+                .matchUdpSrc((short) 1812)
+                .build();
+        packetService.cancelPackets(radSelector, CONTROL, appId);
     }
 
     /**
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
index 4e1b90b..c8af1c1 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
@@ -26,6 +26,7 @@
 import org.apache.felix.scr.annotations.Service;
 import org.onlab.packet.Ethernet;
 import org.onlab.packet.IPv4;
+import org.onlab.packet.MacAddress;
 import org.onlab.packet.VlanId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
@@ -124,6 +125,16 @@
                 .matchInPort(PortNumber.portNumber(1))
                 .build();
 
+        TrafficSelector oltMgmtUp = DefaultTrafficSelector.builder()
+                .matchEthSrc(MacAddress.valueOf("00:0c:d5:00:01:01"))
+                .matchInPort(PortNumber.portNumber(2))
+                .build();
+
+        TrafficSelector oltMgmtDown = DefaultTrafficSelector.builder()
+                .matchEthDst(MacAddress.valueOf("00:0c:d5:00:01:01"))
+                .matchInPort(PortNumber.portNumber(9))
+                .build();
+
         TrafficTreatment up = DefaultTrafficTreatment.builder()
                 .setOutput(PortNumber.portNumber(1))
                 .build();
@@ -150,6 +161,9 @@
                 .setOutput(PortNumber.portNumber(2))
                 .build();
 
+        TrafficTreatment toVolt = DefaultTrafficTreatment.builder()
+                .setOutput(PortNumber.portNumber(9))
+                .build();
 
         TrafficTreatment sentToRadius = DefaultTrafficTreatment.builder()
                 .setOutput(PortNumber.portNumber(5))
@@ -193,12 +207,31 @@
                 .withTreatment(down)
                 .add();
 
+        ForwardingObjective upOltMgmt = DefaultForwardingObjective.builder()
+                .fromApp(appId)
+                .makePermanent()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(PRIORITY)
+                .withSelector(oltMgmtUp)
+                .withTreatment(toVolt)
+                .add();
+
+        ForwardingObjective downOltMgmt = DefaultForwardingObjective.builder()
+                .fromApp(appId)
+                .makePermanent()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(PRIORITY)
+                .withSelector(oltMgmtDown)
+                .withTreatment(toOlt)
+                .add();
 
 
         flowObjectiveService.forward(fabricDeviceId, upCtrl);
         flowObjectiveService.forward(fabricDeviceId, downCtrl);
         flowObjectiveService.forward(fabricDeviceId, radiusToServer);
         flowObjectiveService.forward(fabricDeviceId, serverToRadius);
+        flowObjectiveService.forward(fabricDeviceId, upOltMgmt);
+        flowObjectiveService.forward(fabricDeviceId, downOltMgmt);
     }
 
     @Override
diff --git a/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java b/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
index e43cf0c..21e8811 100644
--- a/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
+++ b/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
@@ -57,7 +57,9 @@
 
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static com.google.common.net.MediaType.JSON_UTF_8;
-import static java.net.HttpURLConnection.*;
+import static java.net.HttpURLConnection.HTTP_CREATED;
+import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
+import static java.net.HttpURLConnection.HTTP_OK;
 import static org.slf4j.LoggerFactory.getLogger;
 
 
@@ -87,6 +89,9 @@
     private static final int FABRIC_SERVER_PORT = 8181;
     private static final String FABRIC_BASE_URI = "/onos/cordfabric/vlans/add";
 
+    private static final DeviceId OLT_DEVICE_ID = DeviceId.deviceId("of:90e2ba82f97791e9");
+    private static final int OLT_UPLINK_PORT = 129;
+
     private static final ConnectPoint FABRIC_PORT = new ConnectPoint(
             DeviceId.deviceId("of:000090e2ba82f974"),
             PortNumber.portNumber(2));
@@ -154,11 +159,11 @@
                                                                   PortNumber.portNumber(3)));
 
         portToVlan = Maps.newHashMap();
-        portToVlan.putIfAbsent(2L, (short) 201);
+        portToVlan.putIfAbsent(1L, (short) 201);
         portToVlan.putIfAbsent(6L, (short) 401);
 
         portToSsid = Maps.newHashMap();
-        portToSsid.put(new ConnectPoint(FABRIC_DEVICE_ID, PortNumber.portNumber(2)), "0");
+        portToSsid.put(new ConnectPoint(OLT_DEVICE_ID, PortNumber.portNumber(1)), "0");
         portToSsid.put(new ConnectPoint(FABRIC_DEVICE_ID, PortNumber.portNumber(6)), "1");
     }
 
@@ -333,19 +338,25 @@
         if (providerServiceId == -1) {
             providerServiceId = xosProviderService;
         }
+
+        PortNumber onuPort = newTenant.port().port();
+        VlanId subscriberVlan = VlanId.vlanId(portToVlan.get(onuPort.toLong()));
+
         VoltTenant tenantToCreate = VoltTenant.builder()
                 .withProviderService(providerServiceId)
                 .withServiceSpecificId(portToSsid.get(newTenant.port()))
-                .withVlanId(newTenant.vlanId())
+                .withVlanId(String.valueOf(subscriberVlan.toShort()))
                 .withPort(newTenant.port())
                 .build();
         String json = tenantToJson(tenantToCreate);
 
+
+        provisionVlanOnPort(OLT_DEVICE_ID, OLT_UPLINK_PORT, onuPort, subscriberVlan.toShort());
         //provisionDataPlane(tenantToCreate);
 
         String retJson = postRest(json);
 
-        fetchCPELocation(newTenant, retJson);
+        fetchCPELocation(tenantToCreate, retJson);
 
         return newTenant;
     }
@@ -355,10 +366,11 @@
 
         if (json.get("computeNodeName") != null) {
             ConnectPoint point = nodeToPort.get(json.get("computeNodeName").asString());
-            ConnectPoint fromPoint = newTenant.port();
+            //ConnectPoint fromPoint = newTenant.port();
+            ConnectPoint oltPort = new ConnectPoint(FABRIC_DEVICE_ID, FABRIC_OLT_CONNECT_POINT);
 
             provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())),
-                            point, fromPoint);
+                            point, oltPort);
         }
 
     }
@@ -374,6 +386,50 @@
         }
     }
 
+    private void provisionVlanOnPort(DeviceId deviceId, int uplinkPort, PortNumber p, short vlanId) {
+
+        TrafficSelector upstream = DefaultTrafficSelector.builder()
+                .matchVlanId(VlanId.vlanId(vlanId))
+                .matchInPort(p)
+                .build();
+
+        TrafficSelector downstream = DefaultTrafficSelector.builder()
+                .matchVlanId(VlanId.vlanId(vlanId))
+                .matchInPort(PortNumber.portNumber(uplinkPort))
+                .build();
+
+        TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
+                .setOutput(PortNumber.portNumber(uplinkPort))
+                .build();
+
+        TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
+                .setOutput(p)
+                .build();
+
+
+        ForwardingObjective upFwd = DefaultForwardingObjective.builder()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(1000)
+                .makePermanent()
+                .withSelector(upstream)
+                .fromApp(appId)
+                .withTreatment(upstreamTreatment)
+                .add();
+
+        ForwardingObjective downFwd = DefaultForwardingObjective.builder()
+                .withFlag(ForwardingObjective.Flag.VERSATILE)
+                .withPriority(1000)
+                .makePermanent()
+                .withSelector(downstream)
+                .fromApp(appId)
+                .withTreatment(downstreamTreatment)
+                .add();
+
+        flowObjectiveService.forward(deviceId, upFwd);
+        flowObjectiveService.forward(deviceId, downFwd);
+
+    }
+
     private void provisionDataPlane(VoltTenant tenant) {
         VlanId vlan = VlanId.vlanId(Short.parseShort(tenant.vlanId()));
 
@@ -420,15 +476,8 @@
     }
 
     private void provisionFabric(VlanId vlanId, ConnectPoint point, ConnectPoint fromPoint) {
-        //String json = "{\"vlan\":" + vlanId + ",\"ports\":[";
-        //json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
-        //       + FABRIC_OLT_CONNECT_POINT.toString() + "\"},";
-        //json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
-        //        + FABRIC_VCPE_CONNECT_POINT.toString() + "\"}";
-        //json += "]}";
 
-        long vlan = portToVlan.get(fromPoint.port().toLong());
-
+        long vlan = vlanId.toShort();
 
         JsonObject node = new JsonObject();
         node.add("vlan", vlan);
diff --git a/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java b/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
index 0adc575..eebb2e2 100644
--- a/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
+++ b/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java
@@ -56,7 +56,7 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
- * Simple single table pipeline abstraction.
+ * Pipeliner for OLT device.
  */
 public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner {
 
@@ -101,10 +101,6 @@
                 .matchEthType(EthType.EtherType.EAPOL.ethType().toShort())
                 .build();
 
-        TrafficSelector arpSelector = DefaultTrafficSelector.builder()
-                .matchEthType(EthType.EtherType.ARP.ethType().toShort())
-                .build();
-
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .punt()
                 .build();
@@ -113,11 +109,7 @@
                                                 PacketPriority.CONTROL.priorityValue(),
                                                 appId, 0, true, null);
 
-        FlowRule arpRule = new DefaultFlowRule(deviceId, arpSelector, treatment,
-                                                PacketPriority.CONTROL.priorityValue(),
-                                                appId, 0, true, null);
-
-        flowRuleService.applyFlowRules(flowRule, arpRule);
+        flowRuleService.applyFlowRules(flowRule);
     }
 
     @Override