VOL-149: Configure RADIUS Attributes as per subscriber information
VOL-148: RADIUS VLAN ID configurable

Change-Id: I2a51dbf316637e685b7e3c36595a27922c79b23c
diff --git a/src/main/java/org/opencord/aaa/AaaConfig.java b/src/main/java/org/opencord/aaa/AaaConfig.java
index 0dfa142..8ffdf00 100644
--- a/src/main/java/org/opencord/aaa/AaaConfig.java
+++ b/src/main/java/org/opencord/aaa/AaaConfig.java
@@ -15,13 +15,22 @@
  */
 package org.opencord.aaa;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+
+import com.google.common.collect.ImmutableSet;
+
 import org.onosproject.core.ApplicationId;
+import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.basics.BasicElementConfig;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import java.util.HashSet;
+import java.util.Set;
+
 /**
  * Network config for the AAA app.
  */
@@ -33,8 +42,16 @@
     private static final String NAS_IP = "nasIp";
     private static final String NAS_MAC = "nasMac";
     private static final String RADIUS_SECRET = "radiusSecret";
-    private static final String RADIUS_SWITCH = "radiusSwitch";
-    private static final String RADIUS_PORT = "radiusPort";
+    private static final String RADIUS_VLAN_ID = "vlanId";
+    private static final String RADIUS_VLAN_PRIORITY_BIT = "radiusPBit";
+    private static final String RADIUS_CONNECTION_TYPE =  "radiusConnectionType";
+    private static final String RADIUS_SERVER_CONNECTPOINTS = "radiusServerConnectPoints";
+    // Which packet customizer to use
+    // "packetCustomizer" : "sample" -- Means use SamplePAcketCustomizer
+    // "packetCustomizer" : "default" -- No customization of packets
+    // if param is missing it is treated as default
+    // This class should be a subclass of PacketCustomizer
+    private static final String PACKET_CUSTOMIZER = "packetCustomizer";
 
     // RADIUS server IP address
     protected static final String DEFAULT_RADIUS_IP = "10.128.10.4";
@@ -51,15 +68,22 @@
     // RADIUS server shared secret
     protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
 
-    // Radius Switch Id
-    protected static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9";
-
-    // Radius Port Number
-    protected static final String DEFAULT_RADIUS_PORT = "1811";
-
     // Radius Server UDP Port Number
     protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812";
 
+    // Radius Server Vlan ID
+    protected static final String DEFAULT_RADIUS_VLAN_ID = "4093";
+
+    // Radius Sever P-Bit
+    protected static final String DEFAULT_RADIUS_VLAN_PRIORITY_BIT = "3";
+
+    // Whether to use socket or not to communicate with RADIUS Server
+    protected static final String DEFAULT_RADIUS_CONNECTION_TYPE = "socket";
+
+    // Packet Customizer Default value
+    protected static final String DEFAULT_PACKET_CUSTOMIZER = "default";
+
+
     /**
      * Gets the value of a string property, protecting for an empty
      * JSON object.
@@ -179,44 +203,6 @@
     }
 
     /**
-     * Returns the ID of the RADIUS switch.
-     *
-     * @return radius switch ID or null if not set
-     */
-    public String radiusSwitch() {
-        return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH);
-    }
-
-    /**
-     * Sets the ID of the RADIUS switch.
-     *
-     * @param switchId new RADIUS switch ID; null to clear
-     * @return self
-     */
-    public BasicElementConfig radiusSwitch(String switchId) {
-        return (BasicElementConfig) setOrClear(RADIUS_SWITCH, switchId);
-    }
-
-    /**
-     * Returns the RADIUS port.
-     *
-     * @return radius port or null if not set
-     */
-    public long radiusPort() {
-        return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT));
-    }
-
-    /**
-     * Sets the RADIUS port.
-     *
-     * @param port new RADIUS port; null to clear
-     * @return self
-     */
-    public BasicElementConfig radiusPort(long port) {
-        return (BasicElementConfig) setOrClear(RADIUS_PORT, port);
-    }
-
-    /**
      * Returns the RADIUS server UDP port.
      *
      * @return radius server UDP port.
@@ -236,4 +222,69 @@
         return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
     }
 
+    /**
+     * Returns the RADIUS server vlan ID.
+     *
+     * @return Radius Server VLan id or default if not set
+     */
+    public short radiusServerVlanId() {
+        return Short.parseShort(getStringProperty(RADIUS_VLAN_ID, DEFAULT_RADIUS_VLAN_ID));
+    }
+
+    /**
+     * Returns the type of connection to use to communicate with the RADIUS Server.
+     *
+     * @return "socket" or "packet_out"
+     */
+    public String radiusConnectionType() {
+        return getStringProperty(RADIUS_CONNECTION_TYPE, DEFAULT_RADIUS_CONNECTION_TYPE);
+    }
+
+    /**
+     * Returns the RADIUS server p-bit.
+     *
+     * @return Radius Server P-bit to use, default if not set
+     */
+    public byte radiusServerPBit() {
+        return Byte.parseByte(getStringProperty(RADIUS_VLAN_PRIORITY_BIT, DEFAULT_RADIUS_VLAN_PRIORITY_BIT));
+    }
+
+    /**
+     * Returns the PACKET CUSTOMIZER CLASS NAME.
+     *
+     * @return PACKET CUSTOMIZER, default if not set
+     */
+    public String radiusPktCustomizer() {
+        return getStringProperty(PACKET_CUSTOMIZER, DEFAULT_PACKET_CUSTOMIZER);
+    }
+
+    /**
+     * Returns the List of ConnectPoints to reach the Radius Server.
+     *
+     * @return List of ConnectPoints
+     */
+    public Set<ConnectPoint> radiusServerConnectPoints() {
+        if (object == null) {
+            return new HashSet<ConnectPoint>();
+        }
+
+        if (!object.has(RADIUS_SERVER_CONNECTPOINTS)) {
+            return ImmutableSet.of();
+        }
+
+        ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
+        ArrayNode arrayNode = (ArrayNode) object.path(RADIUS_SERVER_CONNECTPOINTS);
+        for (JsonNode jsonNode : arrayNode) {
+            String portName = jsonNode.asText(null);
+            if (portName == null) {
+                return null;
+            }
+            try {
+                builder.add(ConnectPoint.deviceConnectPoint(portName));
+            } catch (IllegalArgumentException e) {
+                return null;
+            }
+        }
+        return builder.build();
+    }
 }