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)
| 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): |
no test coverage detected