Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Tx/Rx ring buffer threads #31

Open
mikeawalker opened this issue May 23, 2024 · 1 comment
Open

Configurable Tx/Rx ring buffer threads #31

mikeawalker opened this issue May 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mikeawalker
Copy link

mikeawalker commented May 23, 2024

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

@ccie18643
Copy link
Owner

Sure please create merge request. Thank you.

@ccie18643 ccie18643 added the enhancement New feature or request label Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants