MCPcopy Create free account
hub / github.com/NetSys/bess / _collect_output

Method _collect_output

bessctl/test_utils.py:321–358  ·  view source on GitHub ↗

Collects output on self.sockets[] per ogates. Returns a dictionary indexed by ogate with a list of each packet wrapped by scapy.Ether.

(self, ogates, proto)

Source from the content-addressed store, hash-verified

319 return out_pkts
320
321 def _collect_output(self, ogates, proto):
322 """
323 Collects output on self.sockets[] per ogates. Returns a
324 dictionary indexed by ogate with a list of each packet
325 wrapped by scapy.Ether.
326 """
327 def get_all_pkts(sock):
328 """
329 Reads all immediately-available packets. Wrecks
330 the current timeout/nonblock setting.
331 """
332 ret = []
333 sock.settimeout(0.0)
334 while True:
335 try:
336 received_data = sock.recv(2048)
337 ret.append(proto(received_data))
338 # NB: sock.settimeout(0.0) logically should
339 # produce a socket.timeout, not a socket.error
340 # with EAGAIN, but in fact we get the latter.
341 except socket.error as e:
342 if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
343 return ret
344 raise
345 except socket.timeout:
346 return ret
347
348 timeout = {}
349 out_pkts = {}
350 for ogate in ogates:
351 timeout[ogate] = self.sockets[ogate].gettimeout()
352 try:
353 for ogate in ogates:
354 out_pkts[ogate] = get_all_pkts(self.sockets[ogate])
355 return out_pkts
356 finally:
357 for ogate in ogates:
358 self.sockets[ogate].settimeout(timeout[ogate])
359
360 def run_module(self, module, igate, input_pkts, ogates=range(16),
361 time_out=3, proto=scapy.Ether):

Callers 1

run_pipelineMethod · 0.95

Calls 1

settimeoutMethod · 0.80

Tested by

no test coverage detected