One PC Two Interfaces: one send and one receive

[topology]

 

Note. With this setting, we don’t need to care about the time synchronization. We can use this topology to test the routing performance of H2.

 

[test.py]

#!/usr/bin/env python

from mininet.cli import CLI

from mininet.net import Mininet

from mininet.link import Link,TCLink,Intf

 

if '__main__' == __name__:

  net = Mininet(link=TCLink)

  h1 = net.addHost('h1')

  h2 = net.addHost('h2')

  Link(h1, h2)

  Link(h1, h2)

  net.build()

  h2.cmd('ifconfig h2-eth0 192.168.1.254 netmask 255.255.255.0')

  h2.cmd('ifconfig h2-eth1 192.168.2.254 netmask 255.255.255.0')

  h2.cmd('ifconfig h2-eth0 hw ether 00:00:00:00:02:00')

  h2.cmd('ifconfig h2-eth1 hw ether 00:00:00:00:02:01')    

  h2.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")

  h1.cmd("ifconfig h1-eth0 0")

  h1.cmd("ifconfig h1-eth1 0")

  h1.cmd("ifconfig h1-eth0 192.168.1.1 netmask 255.255.255.0")

  h1.cmd("ifconfig h1-eth1 192.168.2.1 netmask 255.255.255.0")     

  h1.cmd('ifconfig h1-eth0 hw ether 00:00:00:00:01:00')

  h1.cmd('ifconfig h1-eth1 hw ether 00:00:00:00:01:01')

  h1.cmd("route add -host 192.168.2.1  gw 192.168.1.254 h1-eth0")

  h1.cmd("route add -host 192.168.1.1  gw 192.168.2.254 h1-eth1")

  CLI(net)

  net.stop()

 

[send.py]

#!/usr/bin/env python

import argparse

import sys

import socket

import random

import struct

import datetime

 

from scapy.all import sendp, send, get_if_list, get_if_hwaddr

from scapy.all import Packet

from scapy.all import Ether, IP, UDP, TCP

 

def main():

 

    if len(sys.argv)<3:

        print 'pass 2 arguments: <destination> "<message>"'

        exit(1)

 

    addr = socket.gethostbyname(sys.argv[1])

    iface = "h1-eth0"

 

    print "sending on interface %s to %s" % (iface, str(addr))

    pkt =  Ether(src=get_if_hwaddr(iface))

    pkt = pkt /IP(dst=addr) / TCP(dport=1234, sport=random.randint(49152,65535)) / sys.argv[2]

    pkt.show2()

    print datetime.datetime.now()

    sendp(pkt, iface=iface, verbose=False)

 

 

if __name__ == '__main__':

    main()

 

[receive.py]

#!/usr/bin/env python

import sys

import struct

import os

import datetime

 

from scapy.all import sniff, sendp, hexdump, get_if_list, get_if_hwaddr, bind_layers

from scapy.all import Packet, IPOption, Ether

from scapy.all import ShortField, IntField, LongField, BitField, FieldListField, FieldLenField

from scapy.all import IP, UDP, TCP, Raw, ls

from scapy.layers.inet import _IPOption_HDR

 

def handle_pkt(pkt):

    print "Controller got a packet"

    if TCP in pkt:

      print datetime.datetime.now()

      print pkt.summary()

 

def main():

    if len(sys.argv) < 2:

        iface = 'h1-eth1'

    else:

        iface = sys.argv[1]

 

    print "sniffing on %s" % iface

    sys.stdout.flush()

    sniff(iface = iface,

          prn = lambda x: handle_pkt(x))

 

if __name__ == '__main__':

    main()

 

[execution]

 

Open two terminals. One for send and the other for receive.

 

We got the sending and receiving time. Then we can obtain the time difference for transmission delays and the packet processing delay in h2.

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.