qacafe - ip test solutions
Knowledge Base > Basic Configuration > How can I send a packet from a capture file?

How can I send a packet from a capture file?

The following Tcl code snippet demonstrates how to send a previously captured packet during a test case. The capture file can be generated using BuddyWeb, the -capture option within buddy, or using other external tools such as Wireshark. This example assumes there is only a single packet in the capture file to send. Please see the Developer's Guide for more information on modifying existing test cases or creating custom test cases for CDRouter.

    global wanStack

    # -- open the capture file with the packet
    set handle [ pktsrc open-file /home/test/cdrouter/packet.cap ]

    # -- read the packet
    set packet [ $handle read ]
   
    # -- close the capture file since packet has been loaded
    $handle close

    # -- get the pktsrc handle for a stack - wanStack, lanStack
    set wan [ Stack_get_port wanStack ]

    # -- send the packet
    $wan send $packet

    # -- sending raw packets directly to the pktsrc handle will
    # not log the packet for the -pt or -capture options. You need
    # to manually log the packet using one of the *_log_send calls
    # below.
 
    # -- for ethernet
    Ethernet_log_send $packet wanStack

    # -- for ATM
    # ATM_log_send $packet wanStack