Add support to CordMcast for sending multicast sink ports to remote cluster.

Change-Id: Ib915c68218033e1dcfa6f738a629c2d1d8442261
diff --git a/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java
index 8d14dde..de7a342 100644
--- a/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java
+++ b/apps/cordconfig/src/main/java/org/onosproject/cordconfig/access/AccessAgentData.java
@@ -17,12 +17,15 @@
 package org.onosproject.cordconfig.access;
 
 import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onlab.packet.MacAddress;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -30,32 +33,41 @@
  * Information about an access agent.
  */
 public class AccessAgentData {
+
     private static final String DEVICE_ID_MISSING = "Device ID cannot be null";
     private static final String OLT_INFO_MISSING = "OLT information cannot be null";
     private static final String AGENT_MAC_MISSING = "Agent mac cannot be null";
     private static final String VTN_MISSING = "VTN location cannot be null";
 
+    private static final int CHIP_PORT_RANGE_SIZE = 130;
 
     private final Map<ConnectPoint, MacAddress> oltMacInfo;
     private final MacAddress agentMac;
     private final Optional<ConnectPoint> vtnLocation;
     private final DeviceId deviceId;
 
+    // OLT chip information sorted by ascending MAC address
+    private final List<Pair<ConnectPoint, MacAddress>> sortedOltChips;
 
     /**
-     * Constucts an agent configuration for a given device.
+     * Constructs an agent configuration for a given device.
      *
-     * @param deviceId    access device id
+     * @param deviceId    access device ID
      * @param oltMacInfo  a map of olt chips and their mac address
-     * @param agentMac    the mac address of the agent
+     * @param agentMac    the MAC address of the agent
      * @param vtnLocation the location of the agent
      */
     public AccessAgentData(DeviceId deviceId, Map<ConnectPoint, MacAddress> oltMacInfo,
                            MacAddress agentMac, Optional<ConnectPoint> vtnLocation) {
         this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING);
-        this.oltMacInfo = checkNotNull(oltMacInfo, OLT_INFO_MISSING);
+        this.oltMacInfo = ImmutableMap.copyOf(checkNotNull(oltMacInfo, OLT_INFO_MISSING));
         this.agentMac = checkNotNull(agentMac, AGENT_MAC_MISSING);
         this.vtnLocation = checkNotNull(vtnLocation, VTN_MISSING);
+
+        this.sortedOltChips = oltMacInfo.entrySet().stream()
+                .sorted((e1, e2) -> Long.compare(e1.getValue().toLong(), e2.getValue().toLong()))
+                .map(e -> Pair.of(e.getKey(), e.getValue()))
+                .collect(Collectors.toList());
     }
 
     /**
@@ -68,17 +80,17 @@
     }
 
     /**
-     * Returns the mapping of olt chips to mac addresses. Each chip is
+     * Returns the mapping of OLT chips to MAC addresses. Each chip is
      * symbolized by a connect point.
      *
-     * @return a mapping of chips (as connect points) to mac addresses
+     * @return a mapping of chips (as connect points) to MAC addresses
      */
     public Map<ConnectPoint, MacAddress> getOltMacInfo() {
-        return ImmutableMap.copyOf(oltMacInfo);
+        return oltMacInfo;
     }
 
     /**
-     * Reuturns the agents mac address.
+     * Returns the agent's MAC address.
      *
      * @return a mac address
      */
@@ -94,4 +106,21 @@
     public Optional<ConnectPoint> getVtnLocation() {
         return vtnLocation;
     }
+
+    /**
+     * Returns the point where the OLT is connected to the fabric given a
+     * connect point on the agent device.
+     *
+     * @param agentConnectPoint connect point on the agent device
+     * @return point were OLT is connected to fabric
+     */
+    public Optional<ConnectPoint> getOltConnectPoint(ConnectPoint agentConnectPoint) {
+        int index = ((int) agentConnectPoint.port().toLong()) / CHIP_PORT_RANGE_SIZE;
+
+        if (index >= sortedOltChips.size()) {
+            return Optional.empty();
+        }
+
+        return Optional.of(sortedOltChips.get(index).getKey());
+    }
 }