Recursively process the route to support list branching (e.g.
71 def _process_route_recursive(self, bwPacket, start_index):
72 r"""!Recursively process the route to support list branching (e.g. for multicast)
73
74 @param bwPacket: current packet to process
75 @param start_index: index of the routeList to start from
76 @return processed bwPacket, list of packets, or False
77 """
78
79 if isinstance(bwPacket, list):
80 logging.debug("[%s] Received a list of %d packets from manager. Branching immediately.", self.name, len(bwPacket))
81 results = []
82 for single_packet in bwPacket:
83 res = self._process_route_recursive(single_packet, start_index)
84 if res is not False and res is not None:
85 if isinstance(res, list):
86 results.extend(res)
87 else:
88 results.append(res)
89 return results if results else False
90
91
92 current_packet = bwPacket
93
94 for i in range(start_index, len(self.routeList)):
95 routeObject = self.routeList[i]
96 logging.debug("[%s] -> run route: %s", self.name, routeObject.name)
97
98
99 bwPacket_tmp = routeObject.callback(copy.deepcopy(current_packet))
100
101 if bwPacket_tmp is None:
102
103 continue
104
105 if bwPacket_tmp is False:
106 if routeObject.isRouter:
107
108
109 logging.debug("[%s] sub-router '%s' returned False - continuing with next route point", self.name, routeObject.name)
110 continue
111
112
113 logging.debug("[%s] stopped at route %s", self.name, routeObject.name)
114 return False
115
116 if isinstance(bwPacket_tmp, list):
117
118 logging.debug("[%s] route %s returned a list. Branching for %d packets.", self.name, routeObject.name, len(bwPacket_tmp))
119 results = []
120
121 for single_packet in bwPacket_tmp:
122
123 res = self._process_route_recursive(single_packet, i + 1)
124
125
126 if res is not False and res is not None:
127 if isinstance(res, list):
128 results.extend(res)
129 else:
130 results.append(res)
131
132
133
134 return results if results else False
135
136
137 current_packet = bwPacket_tmp
138
139 return current_packet
140