How to get the total number of openflow-related packets that are transmitted between controller and switches?

 

[Motivation]

  Sometimes we need to get the total number of openflow-related packets that are transmitted between controller and switches. Because we may to know whether the performance of normal data flow communications between hosts are affected by the different control policies, e.g. install the rules when the switches are connected to the controller or when the switches does not know how to handle the packets and then forward the packets to the controller. These different control policies will generate different number of openflow-related packets. So in the lab, I will show how to get the number of openflow-related packets.

 

[test_capture.py]

#!/usr/bin/python

import time

 

"""

Script created by VND - Visual Network Description (SDN version)

"""

from mininet.net import Mininet

from mininet.node import Controller, RemoteController, OVSKernelSwitch, IVSSwitch, UserSwitch

from mininet.link import Link, TCLink

from mininet.cli import CLI

from mininet.log import setLogLevel

 

def topology():

 

    "Create a network."

    net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch )

 

    print "*** Creating nodes"

    h1 = net.addHost( 'h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8' )

    h2 = net.addHost( 'h2', mac='00:00:00:00:00:02', ip='10.0.0.2/8' )

    s1 = net.addSwitch( 's1', listenPort=6673, mac='00:00:00:00:00:03' )

    c0 = net.addController( 'c0' )

 

    print "*** Creating links"

    net.addLink(s1, h1)

    net.addLink(s1, h2)

 

    print "*** Starting network"

    net.build()

    c0.start()

    # use the following command to capture the openflow-related packts. Because the controller will open 6633 for communicating with switches. Then save the captured packets in the mylog file.

    c0.cmd("tcpdump -i any -nn port 6633 -U -w mylog &")

    time.sleep(1)

    s1.start( [c0] )

 

    print "*** Running CLI"

    #CLI( net )

    h1.cmdPrint("ping 10.0.0.2 -c 3")

    c0.cmd("pkill tcpdump")

 

    print "*** Stopping network"

    net.stop()

 

if __name__ == '__main__':

    setLogLevel( 'info' )

    topology()

 

 

[parse_caputre.sh: a shell script to parse different openflow packets]

#!/usr/bin/bash

input=$1

tshark -d tcp.port==6633,openflow -r $input > mlog

sed -n '/Type:/p' "mlog" | awk '{print $9}' > mlog_1

 

HELLO=0

PORT_STATUS=0

SET_CONFIG=0

FEATURES_REQUEST=0

FEATURES_REPLY=0

PACKET_IN=0

PACKET_OUT=0

FLOW_MOD=0

STATS_REQUEST=0

STATS_REPLY=0

BARRIER_REQUEST=0

BARRIER_REPLY=0

total=0

 

while read -r line

do

  if [ "$line" = "OFPT_PORT_STATUS" ]

  then

    PORT_STATUS=$(($PORT_STATUS+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_FEATURES_REQUEST" ]

  then

    FEATURES_REQUEST=$(($FEATURES_REQUEST+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_FEATURES_REPLY" ]

  then

    FEATURES_REPLY=$(($FEATURES_REPLY+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_SET_CONFIG" ]

  then

    SET_CONFIG=$(($SET_CONFIG+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_PACKET_IN" ]

  then

    PACKET_IN=$((PACKET_IN+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_PACKET_OUT" ]

  then

    PACKET_OUT=$((PACKET_OUT+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_FLOW_MOD" ]

  then

    FLOW_MOD=$((FLOW_MOD+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_HELLO" ]

  then

    HELLO=$(($HELLO+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_STATS_REQUEST" ]

  then

    STATS_REQUEST=$(($STATS_REQUEST+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_STATS_REPLY" ]

  then

    STATS_REPLY=$(($STATS_REPLY+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_BARRIER_REQUEST" ]

  then

    BARRIER_REQUEST=$((BARRIER_REQUEST+1))

    total=$(($total+1))

  elif [ "$line" = "OFPT_BARRIER_REPLY" ]

  then

    BARRIER_REPLY=$(($BARRIER_REPLY+1))

    total=$(($total+1))

  else

    echo $line

  fi

done < "mlog_1"

 

echo "HELLO=" $HELLO

echo "PORT_STATUS=" $PORT_STATUS

echo "FEATURES_REQUEST=" $FEATURES_REQUEST

echo "FEATURES_REPLY=" $FEATURES_REPLY

echo "SET_CONFIG=" $SET_CONFIG

echo "PACKET_IN=" $PACKET_IN

echo "PACKET_OUT=" $PACKET_OUT

echo "FLOW_MOD=" $FLOW_MOD

echo "STATS_REQUEST=" $STATS_REQUEST

echo "STATS_REPLY=" $STATS_REPLY

echo "BARRIER_REQUEST=" $BARRIER_REQUEST

echo "BARRIER_REPLY=" $BARRIER_REPLY

echo "number of OpenFlow packets=" $total

 

[Execution]

Run the mininet script. Then you will get mylog file.

 

Parse the mylog file to get the total number of openflow-related packets.

 

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

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.