A method for routing traffic between distinct InfiniBand, IB, subnets (101, 102, 103, 104) in a network environment, wherein the IB subnets are interconnected using routers (105, 106), operating at layer 3 of the IB addressing hierarchy, the method comprising, at such a router: receiving a list of destinations associated to a global identifier of the IB addressing hierarchy that the router is responsible for routing one or more packets to, wherein the router connects to at least one subnet in the network environment; receiving, from a subnet manager in the at least one subnet, port mappings for the router to learn which of its ports can be used to route a packet to a particular destination according to the associated global identifier of the packet characterized in that the method further comprises at said router: obtaining information, from one or more switches in the at least one subnet, on which downward output ports of the router can be used for routing the one or more packets, by querying switches (611, 612) that are connected to each router to learn which switch can act as the primary path towards a particular destination (621, 622, 623, 624), wherein only one of the switches may have a primary path towards a particular destination; and building a routing table based on the obtained information, in which the downward output port for the particular destination corresponds to the switch having a primary path towards the particular destination. receiving a list of destinations associated to a global identifier of the IB addressing hierarchy that the router is responsible for routing one or more packets to, wherein the router connects to at least one subnet in the network environment; receiving, from a subnet manager in the at least one subnet, port mappings for the router to learn which of its ports can be used to route a packet to a particular destination according to the associated global identifier of the packet characterized in that the method further comprises at said router: obtaining information, from one or more switches in the at least one subnet, on which downward output ports of the router can be used for routing the one or more packets, by querying switches (611, 612) that are connected to each router to learn which switch can act as the primary path towards a particular destination (621, 622, 623, 624), wherein only one of the switches may have a primary path towards a particular destination; and building a routing table based on the obtained information, in which the downward output port for the particular destination corresponds to the switch having a primary path towards the particular destination. obtaining information, from one or more switches in the at least one subnet, on which downward output ports of the router can be used for routing the one or more packets, by querying switches (611, 612) that are connected to each router to learn which switch can act as the primary path towards a particular destination (621, 622, 623, 624), wherein only one of the switches may have a primary path towards a particular destination; and building a routing table based on the obtained information, in which the downward output port for the particular destination corresponds to the switch having a primary path towards the particular destination.