core.c: Add rebalancing mechanism for supporting unordered bringup

The pupose of algorithm for distribution tree rebalancing
is to balance the number of children for distribution
and access layers.

Balanced tree assures that maximum difference in
fanout (number of children) between nodes, that belong
to the same layer, is not more than 1.

The algorithm works as follows:

- Maximum fanout is being calculated per layer

- For each node whose actual fanout is larger
  than the maximum allowed, we take the proper number
  of children, reset their member_record parent_gid
  field and add them to orphan list.

- Orphan list members are being adopted (assigned with
  new parents)

Algorithm purpose is to keep ssa distribution tree
balanced in case of unordered ssa fabric bringup.

IMPORTANT NOTE:
Current rebalancing mechanism is currently only accurate at
initial ssa bring-up phase, because it relies
on children counters that are not currently updated when
some node leaves the distribution tree.

Signed-off-by: Ilya Nelkenbaum <ilyan@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>