Antonio Russo | 19 Dec 2011 20:20
Picon
Favicon
Gravatar

JICMP and Packet size

Dear all,
 I'd like to enhance the JICMP library in a manner that you can also set the packet size. 

 This is very important on MPLS network where the mtu size is fixed and can be tested using ping.

 Just taken a look at the code and it seems that actually we have a 56 byte fixed size packet.

  
 Here is the relevant code in ICMPEchoPacket

 /**
     * Unique named padding that is placed in front of the incremental padding.
     */
    private static final byte NAMED_PAD[] = { (byte) 'O', (byte) 'p', (byte) 'e', (byte) 'n', (byte) 'N',
(byte) 'M', (byte) 'S', (byte) '!' };

    /**
     * Timestamp when packet was sent
     */
    private long m_sent;

    /**
     * Timestamp of when packet was received.
     */
    private long m_recv;

    /**
     * The thread id of the sender. Effective key for the packet.
     */
    private long m_tid; // thread id

    /**
     * Padding used to make the packet conform to the defacto unix ping program
     * (56 bytes).
     */
    private byte[] m_pad;

  /**
     * The ping rtt (microseconds)
     */
    private long m_rtt;

    /**
     * This is the amount of padding required to make the ICMP echo request 56
     * bytes in length. This is just following the available code for ping ;)
     */
    private static final int PAD_SIZE = 16;

And when you construct the packet....

    /**
     * Creates a new discovery ping packet that can be sent to a remote protocol
     * stack. The ICMP type is set to an Echo Request. The next sequence in the
     * ICMPHeader base class is set and the sent time is set to the current
     * time.
     * 
     *  <at> param tid
     *            The thread id for the packet.
     * 
     *  <at> see java.lang.System#currentTimeMillis
     */
    public ICMPEchoPacket(long tid) {
        super(ICMPHeader.TYPE_ECHO_REQUEST, (byte) 0);
        setNextSequenceId();

        m_rtt = 0;
        m_sent = 0;
        m_recv = 0;
        m_tid = tid;

        m_pad = new byte[PAD_SIZE];
        for (int x = 0; x < NAMED_PAD.length && x < PAD_SIZE; x++)
            m_pad[x] = NAMED_PAD[x];
        for (int x = NAMED_PAD.length; x < PAD_SIZE; x++)
            m_pad[x] = (byte) x;

    }

Now if we add a new constructor we can also set the pad_size so that we can set the packet size:

    public ICMPEchoPacket(long tid, int pad_size) {
        super(ICMPHeader.TYPE_ECHO_REQUEST, (byte) 0);
        setNextSequenceId();

        m_rtt = 0;
        m_sent = 0;
        m_recv = 0;
        m_tid = tid;

        m_pad = new byte[pad_size];
        for (int x = 0; x < NAMED_PAD.length && x < pad_size; x++)
            m_pad[x] = NAMED_PAD[x];
        for (int x = NAMED_PAD.length; x < pad_size; x++)
            m_pad[x] = (byte) x;

    }

We can have packet of any size.

We can just add t MAX_PAD_SIZE to prevent creating arbitrary size ICMP row packets.

Any suggestion?

Antonio

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure

Gmane