Learn PPPoE server MAC address from return packet

Change-Id: Ie3ecb4ed1e86878e8e61cdecb7d45d53d98c7770
diff --git a/app/src/main/java/org/opencord/bng/PppoeHandlerRelay.java b/app/src/main/java/org/opencord/bng/PppoeHandlerRelay.java
index e01db20..da77299 100644
--- a/app/src/main/java/org/opencord/bng/PppoeHandlerRelay.java
+++ b/app/src/main/java/org/opencord/bng/PppoeHandlerRelay.java
@@ -113,6 +113,7 @@
     private ApplicationId appId;
     private InternalPacketProcessor internalPacketProcessor;
     private PppoeRelayConfig pppoeRelayConfig;
+    private MacAddress macPppoeServer;
 
     /**
      * Ephemeral internal map to trace the attachment information. This map is
@@ -146,6 +147,7 @@
         pppoeRelayConfig = null;
         mapSrcMacToAttInfo = null;
         internalPacketProcessor = null;
+        macPppoeServer = null;
 
         log.info("PPPoE Handler Relay deactivated");
     }
@@ -216,6 +218,12 @@
 
         if (heardOn.equals(pppoeRelayConfig.getPppoeServerConnectPoint())) {
             // DOWNSTREAM PACKET: from the PPPoE server to the attachment.
+
+            // Learn the MAC address of the PPPoE server
+            if (macPppoeServer == null) {
+                macPppoeServer = eth.getSourceMAC();
+            }
+
             MacAddress dstMac = eth.getDestinationMAC();
             log.debug("Packet to the attachment: {}", eth);
             if (!mapSrcMacToAttInfo.containsKey(dstMac)) {
@@ -232,7 +240,6 @@
 
             // Generate the events for this attachment
             manageAttachmentStateDownstream(eth, pppoe, attInfo);
-
             modPacketForAttachment(eth, attInfo, bnguMac);
 
             log.debug("Packet modified as: {}", eth);
@@ -464,7 +471,11 @@
         }
         // Modify DST Mac Address with the one of the PPPoE Server
         if (!eth.getDestinationMAC().isBroadcast()) {
-            eth.setDestinationMACAddress(pppoeRelayConfig.getPppoeMacAddress());
+            if (macPppoeServer == null) {
+                log.warn("NO Mac address for PPPoE server available! Dropping packet");
+                return;
+            }
+            eth.setDestinationMACAddress(macPppoeServer);
         }
     }
 
diff --git a/app/src/main/java/org/opencord/bng/config/PppoeRelayConfig.java b/app/src/main/java/org/opencord/bng/config/PppoeRelayConfig.java
index c094f7f..6ade405 100644
--- a/app/src/main/java/org/opencord/bng/config/PppoeRelayConfig.java
+++ b/app/src/main/java/org/opencord/bng/config/PppoeRelayConfig.java
@@ -16,7 +16,6 @@
 
 package org.opencord.bng.config;
 
-import org.onlab.packet.MacAddress;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.config.Config;
@@ -29,12 +28,11 @@
 
     private static final String PPPOE_SERVER_CONNECT_POINT = "pppoeServerConnectPoint";
     private static final String OLT_CONNECT_POINT = "oltConnectPoint";
-    private static final String PPPOE_MAC_ADDRESS = "pppoeMacAddress";
 
     @Override
     public boolean isValid() {
-        return hasOnlyFields(PPPOE_SERVER_CONNECT_POINT, OLT_CONNECT_POINT, PPPOE_MAC_ADDRESS) &&
-                hasFields(PPPOE_SERVER_CONNECT_POINT, OLT_CONNECT_POINT, PPPOE_MAC_ADDRESS);
+        return hasOnlyFields(PPPOE_SERVER_CONNECT_POINT, OLT_CONNECT_POINT) &&
+                hasFields(PPPOE_SERVER_CONNECT_POINT, OLT_CONNECT_POINT);
     }
 
     /**
@@ -54,14 +52,5 @@
     public ConnectPoint getAsgToOltConnectPoint() {
         return ConnectPoint.deviceConnectPoint(object.path(OLT_CONNECT_POINT).asText());
     }
-
-    /**
-     * Gets the PPPoE server MAC address.
-     *
-     * @return PPPoE server MAC address
-     */
-    public MacAddress getPppoeMacAddress() {
-        return MacAddress.valueOf(object.path(PPPOE_MAC_ADDRESS).asText());
-    }
 }
 
diff --git a/app/src/main/java/org/opencord/bng/config/netcfg.json b/app/src/main/java/org/opencord/bng/config/netcfg.json
index c33fbf1..be62c34 100644
--- a/app/src/main/java/org/opencord/bng/config/netcfg.json
+++ b/app/src/main/java/org/opencord/bng/config/netcfg.json
@@ -4,7 +4,6 @@
       "pppoerelay": {
         "oltConnectPoint": "device:asg1/128",
         "pppoeServerConnectPoint": "device:asg1/140",
-        "pppoeMacAddress": "3c:fd:fe:9e:6e:40"
       },
       "bng": {
         "bnguDeviceId": "device:asg1"