topology: extract function fillAssocForPortId

Extract function fillAssocForPortId from fillAssocsForPortId.

Since for each port identifier (e.g. "MB Upstream Port",
"Backplane Port") there can be multiple upstream and downstream paths,
topology code iterates those in fillAssocsForPortId to fill in all the
required association definitions.

Separate this iteration logic from the code which is actually filling in
that association, which gets put in `fillAssocForPortId`.

Tested: Topology Unit Tests Pass.

Change-Id: I630a1707790c6dcf722e9545c30864b6082e5426
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index b69448e..a5037f0 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -80,22 +80,26 @@
 {
     for (const Path& upstream : upstreamPaths)
     {
-        if (boardTypes[upstream] == "Chassis" ||
-            boardTypes[upstream] == "Board")
+        for (const Path& downstream : downstreamPaths)
         {
-            for (const Path& downstream : downstreamPaths)
+            fillAssocForPortId(result, boardPaths, upstream, downstream);
+        }
+    }
+}
+
+void Topology::fillAssocForPortId(
+    std::unordered_map<std::string, std::set<Association>>& result,
+    BoardPathsView boardPaths, const Path& upstream, const Path& downstream)
+{
+    if (boardTypes[upstream] == "Chassis" || boardTypes[upstream] == "Board")
+    {
+        // 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))
             {
-                // 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(
-                            {"powering", "powered_by", upstream});
-                    }
-                }
+                result[downstream].insert({"powering", "powered_by", upstream});
             }
         }
     }
diff --git a/src/entity_manager/topology.hpp b/src/entity_manager/topology.hpp
index 40c610e..c912d42 100644
--- a/src/entity_manager/topology.hpp
+++ b/src/entity_manager/topology.hpp
@@ -37,6 +37,11 @@
         BoardPathsView boardPaths, const std::set<Path>& upstreamPaths,
         const std::set<Path>& downstreamPaths);
 
+    void fillAssocForPortId(
+        std::unordered_map<std::string, std::set<Association>>& result,
+        BoardPathsView boardPaths, const Path& upstream,
+        const Path& downstream);
+
     std::unordered_map<PortType, std::set<Path>> upstreamPorts;
     std::unordered_map<PortType, std::set<Path>> downstreamPorts;
     std::set<Path> powerPaths;