topology: extract function fillAssocsForPortId

Ports for association are identified by e.g. `MB Upstream Port`. All
upstream and downstream paths on the same port become part of the
association definition.

Tested: Topology Unit Tests Pass

Change-Id: I34683f0831294c487164b7eeaeb8f9f99186b1c8
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index e798baa..b69448e 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -67,30 +67,38 @@
             continue;
         }
 
-        for (const Path& upstream : upstreamPortPair.second)
+        fillAssocsForPortId(result, boardPaths, upstreamPortPair.second,
+                            downstreamMatch->second);
+    }
+    return result;
+}
+
+void Topology::fillAssocsForPortId(
+    std::unordered_map<std::string, std::set<Association>>& result,
+    BoardPathsView boardPaths, const std::set<Path>& upstreamPaths,
+    const std::set<Path>& downstreamPaths)
+{
+    for (const Path& upstream : upstreamPaths)
+    {
+        if (boardTypes[upstream] == "Chassis" ||
+            boardTypes[upstream] == "Board")
         {
-            if (boardTypes[upstream] == "Chassis" ||
-                boardTypes[upstream] == "Board")
+            for (const Path& downstream : downstreamPaths)
             {
-                for (const Path& downstream : downstreamMatch->second)
+                // The downstream path must be one we care about.
+                if (std::ranges::contains(boardPaths, downstream))
                 {
-                    // The downstream path must be one we care about.
-                    if (std::ranges::contains(boardPaths, downstream))
+                    result[downstream].insert(
+                        {"contained_by", "containing", upstream});
+                    if (powerPaths.contains(downstream))
                     {
                         result[downstream].insert(
-                            {"contained_by", "containing", upstream});
-                        if (powerPaths.contains(downstream))
-                        {
-                            result[downstream].insert(
-                                {"powering", "powered_by", upstream});
-                        }
+                            {"powering", "powered_by", upstream});
                     }
                 }
             }
         }
     }
-
-    return result;
 }
 
 void Topology::remove(const std::string& boardName)
diff --git a/src/entity_manager/topology.hpp b/src/entity_manager/topology.hpp
index 1c2b3eb..40c610e 100644
--- a/src/entity_manager/topology.hpp
+++ b/src/entity_manager/topology.hpp
@@ -30,6 +30,13 @@
 
     void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem);
 
+    // @brief: fill associations map with the associations for a port identifier
+    // such as 'MB Upstream Port'
+    void fillAssocsForPortId(
+        std::unordered_map<std::string, std::set<Association>>& result,
+        BoardPathsView boardPaths, const std::set<Path>& upstreamPaths,
+        const std::set<Path>& downstreamPaths);
+
     std::unordered_map<PortType, std::set<Path>> upstreamPorts;
     std::unordered_map<PortType, std::set<Path>> downstreamPorts;
     std::set<Path> powerPaths;