Open
Description
Loving this library....really useful for some network simulation and learning I am doing.
For my use case I dont want to use a tap device. Instead I just want to intercept the ethernet frames and 'transport' them via my own means. I can do this as is with the following hack
class QueueTxRing( pytcp.subsystems.tx_ring.TxRing ):
def __init__( self ):
self.queue = queue.Queue( maxsize = 10000 )
super().__init__( )
def start( self , fd ):
self._run_thread = True
threading.Thread(target=self.__thread_transmit).start()
time.sleep(0.1)
def get( self ):
return self.queue.get( )
def __thread_transmit( self ):
log.info("IP Stack using overwritten tx thread - yay!")
MAX_LEN = config.TAP_MTU
frame_buffer = bytearray( MAX_LEN )
while self._run_thread:
self._packet_enqueued.acquire(timeout=0.1)
if not self._tx_ring:
continue
packet_tx = self._tx_ring.pop(0)
packet_tx_len = len( packet_tx )
if packet_tx_len > MAX_LEN:
continue
frame = memoryview( frame_buffer)[:packet_tx_len ]
packet_tx.assemble( frame )
try:
self.queue.put( frame )
# write to queue
pass
except:
log.error("fail ethernet tx")
continue
log.debug("Tx ring stopped")
stack.tx_ring = QueueTxRing( )
I'd be interested in submitting a formal feature where the use of a tap (or otherwise) is configurable at run time. If this is something you'd except let me know and I can create a merge request