Search code examples
rubylinuxnetwork-programmingqos

Ruby - How to do DSCP marking in packets?


I have a need to mark packets with DSCP markers for testing a product, but I'm not seeing a way to do this directly. Am I just missing something, or do I really need to start learning network programming in C to get this done?

Or, which may be easier, is there a program out there (for Linux) that will send data with DSCP markers better than iperf? I know you can mark with ping, also, but it won't suit my needs for testing (iperf does, to an extent, but it's been unreliable for heavy testing purposes.)


Solution

  • You should use Ruby's setsockopt, which wraps the Linux system call.

    require "socket"
    s = TCPSocket.new("example.com", 80)
    s.setsockopt(Socket::IPPROTO_IP, Socket::IP_TOS, 32)
    

    See a list of TOS/DSCP settings here.

    Also see the answer to this question.