Showing posts with label OpenFlow. Show all posts
Showing posts with label OpenFlow. Show all posts

Sunday, May 12, 2013

PyTapDEMon - Part 5 Misc Tools

I developed various scripts and tools for the project with the intention of making them into more baked features. However, they remained to be half-baked at this time. I am putting them in this post for now, if they ever grow into a post of their own I will remove them from here.

### DPKT Ping Test meant to be executed from h1 ###

** Script **

#!/usr/bin/env python
#
# Example from:
# http://jon.oberheide.org/blog/2008/08/25/dpkt-tutorial-1-icmp-echo/
#
# More documentation:
# http://www.commercialventvac.com/dpkt.html#mozTocId305148
#
# This file sends ICMP packet to the destination host.
# This is meant to be run on h1 to generate interesting traffic.
# It has the same affect as Mininet "h1 ping h2"
#

import dpkt
import socket, random

echo = dpkt.icmp.ICMP.Echo()
echo.id = random.randint(0, 0xffff)
echo.seq = random.randint(0, 0xffff)
echo.data = 'hello world'

icmp = dpkt.icmp.ICMP()
icmp.type = dpkt.icmp.ICMP_ECHO
icmp.data = echo

destination = '10.0.0.2'
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, dpkt.ip.IP_PROTO_ICMP)
s.connect((destination, 1))
sent = s.send(str(icmp))

print 'sent %d bytes to %s' % (sent, destination)

** end script **
** output **


root@mininet-vm:~/PyTapDEMON/tests# ./dpktTest_h1_ping.py
sent 19 bytes to 10.0.0.2
root@mininet-vm:~/PyTapDEMON/tests#

### Scapy Ping Test meant to be executed from h1 ###

** Script **

#!/usr/bin/env python
#
# Example from:
# http://www.secdev.org/projects/scapy/build_your_own_tools.html
#
# This is meant to be executed on h1 to ping toward h2
#

from scapy.all import sr1, IP, ICMP

dstIP = '10.0.0.2'

packet = sr1(IP(dst=dstIP)/ICMP())
if packet:
    packet.show()

** end script **
** output **


root@mininet-vm:~/PyTapDEMON/tests# ./scapyTest_h1_ping.py
WARNING: No route found for IPv6 destination :: (no default route?)
Begin emission:
.*Finished to send 1 packets.

Received 2 packets, got 1 answers, remaining 0 packets
###[ IP ]###
  version   = 4L
  ihl       = 5L
  tos       = 0x0
  len       = 28
  id        = 51838
  flags     =
  frag      = 0L
  ttl       = 64
  proto     = icmp
  chksum    = 0x9c60
  src       = 10.0.0.2
  dst       = 10.0.0.1
  \options   \
###[ ICMP ]###
     type      = echo-reply
     code      = 0
     chksum    = 0xffff
     id        = 0x0
     seq       = 0x0
root@mininet-vm:~/PyTapDEMON/tests#

### Scapy Ethernet Sniffing Test meant to be executed on h11 ###

** Script **

#!/usr/bin/env python
#
# This test passively sniffs
# and look for Ethernet packets
# using Scapy.
#
# This is meant to be used on the sniffing
# host, h11 in the PyTapDEMon prototype
# setup.
#

from scapy.all import *

def parsePacket(pkt):
    if pkt.haslayer(Ether):
         print "Found Ethernet packet"
         print str(pkt[Ether].dst)

if __name__ == "__main__":
    sniff(prn=parsePacket, store=0)

** end script **
** output **

1. The tool sits quite until h1 pings h2:

mininet> h1 ping -c3 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=0.316 ms
64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.268 ms
64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=0.266 ms

--- 10.0.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.266/0.283/0.316/0.026 ms
mininet> 

root@mininet-vm:~/PyTapDEMON/tests# ./scapyTest_eth_sniff.py
WARNING: No route found for IPv6 destination :: (no default route?)
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
12:fd:b3:e2:3c:f7
Found Ethernet packet
2e:40:29:25:03:45
Found Ethernet packet
2e:40:29:25:03:45

### Twisted EchoServer and EchoClient ###

** Echoserver **
#
# Example taken from:
# Twisted Network Programming Essentials, 2nd Edition
# By: Jessica McKellar, Abe Fettig
# OReilly Media, Ebook ISBN:978-1-4493-3330-0
#

from twisted.internet import protocol, reactor
import json

class Echo(protocol.Protocol):
    def dataReceived(self, data):
        print "Received This Data: ", data
        ports = json.loads(data)
        for key in ports: 
            print key, ports[key]
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        print "Received from addr: ", addr
        return Echo()

reactor.listenTCP(8000, EchoFactory())
reactor.run()

*** EchoClient ***
#
# Example taken from:
# Twisted Network Programming Essentials, 2nd Edition
# By: Jessica McKellar, Abe Fettig
# OReilly Media, Ebook ISBN:978-1-4493-3330-0
#

from twisted.internet import reactor, protocol
import json

msg = json.dumps({"s1": {'s1MirrorSrc': [1], 's1MirrorDst': [6,7]}, "s2": {'s2MirrorSrc': [2], 's2MrrorDst': [7]}})

class EchoClient(protocol.Protocol):
    def connectionMade(self):
        print "Sending: ", msg
        self.transport.write(msg)

    def dataReceived(self, data):
        print "Server returned:", data
        self.transport.loseConnection()

class EchoFactory(protocol.ClientFactory):
    def buildProtocol(self, addr):
        print "Build on addr: ", addr
        return EchoClient()

    def clientConnectionFailed(self, connector, reason):
        print "Connection failed."
        reactor.stop()

    def clientConnctionLost(self, connector, reason):
        print "Connection lost."
        reactor.stop()

reactor.connectTCP("localhost", 8000, EchoFactory())
reactor.run()

*** output ***

1. start echoserver:
mininet@mininet-vm:~/PyTapDEMON/twisted$ python echoserver.py 

2. execute echoclient:
mininet@mininet-vm:~/PyTapDEMON/twisted$ python echoclient.py 
Build on addr:  IPv4Address(TCP, '127.0.0.1', 8000)
Sending:  {"s2": {"s2MrrorDst": [7], "s2MirrorSrc": [2]}, "s1": {"s1MirrorDst": [6, 7], "s1MirrorSrc": [1]}}
Server returned: {"s2": {"s2MrrorDst": [7], "s2MirrorSrc": [2]}, "s1": {"s1MirrorDst": [6, 7], "s1MirrorSrc": [1]}}

3. echoserver output:
Received from addr:  IPv4Address(TCP, '127.0.0.1', 35325)
Received This Data:  {"s2": {"s2MrrorDst": [7], "s2MirrorSrc": [2]}, "s1": {"s1MirrorDst": [6, 7], "s1MirrorSrc": [1]}}
s2 {u's2MrrorDst': [7], u's2MirrorSrc': [2]}
s1 {u's1MirrorDst': [6, 7], u's1MirrorSrc': [1]}








PyTapDEMon - Part 4 Unittest for the Network

Here are links to the first three parts of the project:


For part 4, I will attempt to write some testing for the project. Of course, as part of the TDD approach, this really should have been either part 2 of the project, or be integrated into all the steps during the development. But how many of us really write the tests first? So here I am, trying to write some tests. :)

To be honest, in my opinion, this is part of the larger problem that it is hard to write tests against code that either make changes to the network or monitors the network. The network is inherently distributed and traditionally been stateless from one another. Such as the case here, for the test, I can write test to test my code; or I can write test to query the network and see if it is in an expected state. If I have time, I should do both, but comparing the two, I have decided to write test for the network state because ultimately that is what I care about the most. 

The objectives are simple: 

1. Query the switches for the current flow information. 
2. Compare them to the expected port-based flow data. 

I am going to use ovs-ofctl as the OOB channel to query the OpenFlow switch data. This is what the flows should look like on s1, for example, when the flows are installed:

mininet@mininet-vm:~$ sudo ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
 cookie=0x0, duration=116.257s, table=0, n_packets=0, n_bytes=0, idle_timeout=120,hard_timeout=120,in_port=3 actions=output:4
 cookie=0x0, duration=116.259s, table=0, n_packets=3, n_bytes=238, idle_timeout=120,hard_timeout=120,in_port=1 actions=output:2,output:6,output:8
 cookie=0x0, duration=116.255s, table=0, n_packets=0, n_bytes=0, idle_timeout=120,hard_timeout=120,in_port=4 actions=output:3
 cookie=0x0, duration=116.258s, table=0, n_packets=3, n_bytes=238, idle_timeout=120,hard_timeout=120,in_port=2 actions=output:1,output:6,output:8
mininet@mininet-vm:~$

And here is what the output would look like when there are no flows: 

mininet@mininet-vm:~$ sudo ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
mininet@mininet-vm:~$


Here is the unittest code for the tests: 

***
#!/usr/bin/env python

import unittest
import subprocess

def parseFlows(flows):
    """
    Parse out the string representation of flows passed in.
    Example:
    NXST_FLOW reply (xid=0x4):
     cookie=0x0, duration=4.329s, table=0, n_packets=0, n_bytes=0, idle_timeout=120,hard_timeout=120,in_port=3 actions=output:4
    """
    switchFlows = {}
    for flow in flows.split('\n'):
        line = flow.split()
        if len(line) > 3: #get rid of first line in flow output
            inputPort = line[5].split(',')[2].split('=')[1]
            outputPorts = line[6].split('actions=')[1]
            switchFlows[inputPort] = outputPorts
    return switchFlows
    

globalFlows = {}
for i in range(1, 4):
    """Query switches s1, s2, s3 and dump flows, add to global flow dictionary"""
    switch = 's'+str(i)
    flows = subprocess.check_output(['sudo', 'ovs-ofctl', 'dump-flows', switch])
    switchFlows = parseFlows(flows)
    globalFlows[switch] = switchFlows


class PyTapDEMON_Test(unittest.TestCase):
    def test_s1_port1(self):
        self.assertEqual('output:2,output:6,output:8', globalFlows['s1']['1'])
   
    def test_s2_port1(self):
        self.assertEqual('output:2,output:6,output:8', globalFlows['s2']['1'])

    def test_s3_port10(self):
        self.assertEqual('output:11', globalFlows['s3']['10'])


if __name__ == '__main__':
    unittest.main()

***

Here is the output during passing state: 

1. Generate the packet to install flows in the switches: 

mininet> h1 ping -c3 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.329 ms
64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=0.106 ms

--- 10.0.0.2 ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.106/0.217/0.329/0.112 ms
mininet>

2. Run the test: 

mininet@mininet-vm:~/PyTapDEMON/tests$ pytest PyTapDEMON_Test.py
========================  PyTapDEMON_Test.py  ========================
...
----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK
*******************************************************************************

mininet@mininet-vm:~/PyTapDEMON/tests$

*** 

Here is the output during failing state (no flow installed):

1. Verified that there is no flow in s1: 

mininet@mininet-vm:~$ sudo ovs-ofctl dump-flows s1
NXST_FLOW reply (xid=0x4):
mininet@mininet-vm:~$

2. Run the test: 

mininet@mininet-vm:~/PyTapDEMON/tests$ pytest PyTapDEMON_Test.py
========================  PyTapDEMON_Test.py  ========================
EEE
======================================================================
ERROR: test_s1_port1 (PyTapDEMON_Test.PyTapDEMON_Test)
----------------------------------------------------------------------
Traceback (most recent call last)
  File "/usr/lib/python2.7/unittest/case.py", line 332, in run
    testMethod()
  File "/home/mininet/PyTapDEMON/tests/PyTapDEMON_Test.py", line 34, in test_s1_port1
    self.assertEqual('output:2,output:6,output:8', globalFlows['s1']['1'])
KeyError: '1'

                              no stdout                              
                              no stderr                              
======================================================================
ERROR: test_s2_port1 (PyTapDEMON_Test.PyTapDEMON_Test)
----------------------------------------------------------------------
Traceback (most recent call last)
  File "/usr/lib/python2.7/unittest/case.py", line 332, in run
    testMethod()
  File "/home/mininet/PyTapDEMON/tests/PyTapDEMON_Test.py", line 37, in test_s2_port1
    self.assertEqual('output:2,output:6,output:8', globalFlows['s2']['1'])
KeyError: '1'

                              no stdout                              
                              no stderr                              
======================================================================
ERROR: test_s3_port10 (PyTapDEMON_Test.PyTapDEMON_Test)
----------------------------------------------------------------------
Traceback (most recent call last)
  File "/usr/lib/python2.7/unittest/case.py", line 332, in run
    testMethod()
  File "/home/mininet/PyTapDEMON/tests/PyTapDEMON_Test.py", line 40, in test_s3_port10
    self.assertEqual('output:11', globalFlows['s3']['10'])
KeyError: '10'

                              no stdout                              
                              no stderr                              
----------------------------------------------------------------------
Ran 3 tests in 0.041s

FAILED (errors=3)
*******************************************************************************

mininet@mininet-vm:~/PyTapDEMON/tests$

***

It is pretty easy to write 'unittest' for your network in an OpenFlow enabled network, in this example I query the switches individually, but in theory I should interface directly with the controller. 

Cheers. Leave me comments and let me know what you think. 




Sunday, April 21, 2013

PyTapDEMon - Part 2 Prototype

This is part 2 of my PyTapDEMON project. Here is the link for the overview of the project:
http://blog.pythonicneteng.com/2013/04/introducing-pytapdemon.html

Here is a screencast of the prototype. Sorry about the small font, I will edit this when I have some time to go thru the tutorial for Camtasia, but all the commands in the screencast are listed in this blog:



For my prototype, I am using Mininet included in the OpenFlow VM to simulate 2 filter switch (s1 and s2) with 5 hosts each (h1-h5 on s1, h6-h10 on s2), 5x uplinks to aggregation switch (s3), and a capture host (h11) attached to Eth11 on s3.

Here is the normal state (The custom Mininet config code is toward the end of the post):














The Red link indicates the 'always forward' state. For example, eth6 will always forward to eth1 on s3 and s3 will always forward all traffic from eth1-10 to eth11 to the capture host.

Here is the simulation state:








On s1, (port 1 / port 2) and (port 3 / port 4) will always forward traffic to each other. On s2, (port 1 / port 2) will forward traffic to each other. Switch s1 traffic on eth1 will be mirrored to eth6 and switch s2 eth2 traffic will be mirrored to eth7. To keep things simple, only 1 link on the mirrored is picked so I dont see the same traffic multiple times and eth3/eth4 traffic on s1 is not mirrored to show isolation.

Here is the POX component code:

#!/usr/bin/env python
"""
Custom Topology: PyTapDEMON_topo.py
"""
# These next two imports are common POX convention
from pox.core import core
import pox.openflow.libopenflow_01 as of
# Even a simple usage of the logger is much nicer than print!
log = core.getLogger()
# global flow timeout
timeout = 120
# flow simulation on ports
s1PortPairs = [(1,2), (3,4)]
s2PortPairs = [(1,2)]
# mirror source and destination
f = open('ext/mirrorPorts.txt', 'r')
for num, item in enumerate(f.readlines()):
    if num == 0:
        s1MirrorSrc = item.strip().split(',')[1:]
        s1MirrorSrc = map(lambda x: int(x), s1MirrorSrc) #convert to int
    if num == 1:
        s1MirrorDst = item.strip().split(',')[1:]
        s1MirrorDst = map(lambda x: int(x), s1MirrorDst)
    if num == 2:
        s2MirrorSrc = item.strip().split(',')[1:]
        s2MirrorSrc = map(lambda x: int(x), s2MirrorSrc)
    if num == 3:
        s2MirrorDst = item.strip().split(',')[1:]
        s2MirrorDst = map(lambda x: int(x), s2MirrorDst)

def _PortFlowMod(srcPort, dstPort, timeout, mirrorSrc, mirrorDst):
    print "Push Flow from Source Port %s to Destion Port %s with %s seconds timeout" % \
    (srcPort, dstPort, timeout)
    forwardFlow = of.ofp_flow_mod()
    forwardFlow.idle_timeout = timeout
    forwardFlow.hard_timeout = timeout
    forwardFlow.match.in_port = srcPort
    forwardFlow.actions.append(of.ofp_action_output(port=dstPort))
    # add mirror src and destination
    if srcPort in mirrorSrc:
        for dstMirror in s1MirrorDst:
            forwardFlow.actions.append(of.ofp_action_output(port=dstMirror))
    return forwardFlow

def _simulateTraffic(portPairs, switch):
    print "***Simulating Traffic flow for switch %s" % str(switch)
    for pair in portPairs:
        srcPort, dstPort = pair[0], pair[1]
        print "Pushing flow from %s to %s" % (srcPort, dstPort)
        core.openflow.getConnection(switch).send(_PortFlowMod(srcPort, dstPort, timeout, \
            mirrorSrc=s1MirrorSrc, mirrorDst=s1MirrorDst))
        core.openflow.getConnection(switch).send(_PortFlowMod(dstPort, srcPort, timeout, \
            mirrorSrc=s2MirrorSrc, mirrorDst=s2MirrorDst))

def _handle_pytap (event):
    # packet is an instance of class 'pox.lib.packet.ethernet.ethernet'
    packet = event.parsed
    #print packet.dst, packet.src
    #each switch is a separate conneciton object
    for conn in core.openflow.connections:
        print "Switch %s with DPID %s is connected" % (conn, conn.dpid)
    # push static flows from agg switche ports to packet inspection host
    print "***Pushing static flow on switch " + str(core.openflow.getConnection(3).dpid)
    for port in range(1,11):
        core.openflow.getConnection(3).send(_PortFlowMod(port,11,timeout, [], []))
    # simulation s1 traffic flows
    _simulateTraffic(s1PortPairs, 1)
    # simulation s2 traffic flows
    _simulateTraffic(s2PortPairs, 2)

# function that is invoked upon load to ensure that listeners are
# registered appropriately.
def launch ():
    core.openflow.addListenerByName("PacketIn", _handle_pytap)
    log.info("PyTapDEMON is running.")
As you can see from the code, I have moved the mirror port source and destination into a separate file so they can be changed independent of the code.


mininet@mininet-vm:~/pox/ext$ cat mirrorPorts.txt
s1MirrorSrc,1
s1MirrorDst,6
s2MirrorSrc,2
s2MirrorDst,7
mininet@mininet-vm:~/pox/ext$


Here is the Mininet code:


#!/usr/bin/env python
"""
author: Eric Chou (@ericchou)
1. 2x port Filter Switches with 5 hosts and 5 trunk ports.
2. 1x port Aggregation Switch with 10 trunk ports and Deep inspection host
"""
from mininet.net import Mininet
from mininet.node import OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
def PyTapDEMON():
    net = Mininet( switch=OVSSwitch, build=False)
    print "** Creating controllers"
    c1 = net.addController('c1', port=6633)
    print "*** Creating switches"
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')
    s3 = net.addSwitch('s3')
    print "*** Creating hosts"
    host1 = [ net.addHost('h%d' % n) for n in range(1,6)]
    host2 = [ net.addHost('h%d' % n) for n in range(6,11)]
    host3 = net.addHost('h11')
    print "*** Creating links"
    for h in host1:
        net.addLink (s1, h)
    for h in host2:
        net.addLink (s2, h)
    for i in range(1,6):
        net.addLink(s1, s3)
    for i in range(1,6):
        net.addLink(s2, s3)
    net.addLink(host3, s3)
    print "*** Starting network"
    net.build()
    s1.start ( [ c1 ])
    s2.start ( [ c1 ])
    s3.start ( [ c1 ])
    print "*** Running CLI"
    CLI( net )

if __name__ == '__main__':
    setLogLevel('info')
    PyTapDEMON()

Moment of truth:

1. Launch mininet topology on Terminal 1:

mininet@mininet-vm:~/PyTapDEMON/MininetTopology$ sudo mn -c

mininet@mininet-vm:~/PyTapDEMON/MininetTopology$ sudo ./PyTapDEMON_topo.py
** Creating controllers
*** Creating switches
*** Creating hosts
*** Creating links
*** Starting network
*** Configuring hosts
h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11
*** Running CLI
*** Starting CLI:
mininet> net
c1
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0 s1-eth4:h4-eth0 s1-eth5:h5-eth0 s1-eth6:s3-eth1 s1-eth7:s3-eth2 s1-eth8:s3-eth3 s1-eth9:s3-eth4 s1-eth10:s3-eth5
s2 lo:  s2-eth1:h6-eth0 s2-eth2:h7-eth0 s2-eth3:h8-eth0 s2-eth4:h9-eth0 s2-eth5:h10-eth0 s2-eth6:s3-eth6 s2-eth7:s3-eth7 s2-eth8:s3-eth8 s2-eth9:s3-eth9 s2-eth10:s3-eth10
s3 lo:  s3-eth1:s1-eth6 s3-eth2:s1-eth7 s3-eth3:s1-eth8 s3-eth4:s1-eth9 s3-eth5:s1-eth10 s3-eth6:s2-eth6 s3-eth7:s2-eth7 s3-eth8:s2-eth8 s3-eth9:s2-eth9 s3-eth10:s2-eth10 s3-eth11:h11-eth0
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
h4 h4-eth0:s1-eth4
h5 h5-eth0:s1-eth5
h6 h6-eth0:s2-eth1
h7 h7-eth0:s2-eth2
h8 h8-eth0:s2-eth3
h9 h9-eth0:s2-eth4
h10 h10-eth0:s2-eth5
h11 h11-eth0:s3-eth11
mininet>

2. Launch POX and my component on Terminal 2: 

mininet@mininet-vm:~/pox$ ./pox.py log.level --DEBUG echou_pytapFinal py
POX 0.1.0 (betta) / Copyright 2011-2013 James McCauley, et al.
INFO:echou_pytapFinal:PyTapDEMON is running.
DEBUG:core:POX 0.1.0 (betta) going up...
DEBUG:core:Running on CPython (2.7.3/Sep 26 2012 21:51:14)
DEBUG:core:Platform is Linux-3.5.0-17-generic-x86_64-with-Ubuntu-12.10-quantal
INFO:core:POX 0.1.0 (betta) is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
DEBUG:openflow.of_01:Listening on 0.0.0.0:6633
Ready.
POX> 
INFO:openflow.of_01:[00-00-00-00-00-02 1] connected
INFO:openflow.of_01:[00-00-00-00-00-03 3] connected
INFO:openflow.of_01:[00-00-00-00-00-01 2] connected

POX> 

3. Launch Wireshark and starts to capture on s3-eth11. 
4. Launch Xterm for h11 and starts tcpdump: 















5. Now we need an event to trigger all the flow pushes: 

mininet> h1 ping -c3 h2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=997 ms
64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.119 ms
64 bytes from 10.0.0.2: icmp_req=3 ttl=64 time=0.115 ms

--- 10.0.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.115/332.493/997.247/470.052 ms
mininet>

6. On the POX Terminal all the print messages will be shown: 

POX> 
***Pushing static flow on switch 3
Push Flow from Source Port 1 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 2 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 3 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 4 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 5 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 6 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 7 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 8 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 9 to Destion Port 11 with 120 seconds timeout
Push Flow from Source Port 10 to Destion Port 11 with 120 seconds timeout
***Simulating Traffic flow for switch 1
Pushing flow from 1 to 2
Push Flow from Source Port 1 to Destion Port 2 with 120 seconds timeout
Push Flow from Source Port 2 to Destion Port 1 with 120 seconds timeout
Pushing flow from 3 to 4
Push Flow from Source Port 3 to Destion Port 4 with 120 seconds timeout
Push Flow from Source Port 4 to Destion Port 3 with 120 seconds timeout
***Simulating Traffic flow for switch 2
Pushing flow from 1 to 2
Push Flow from Source Port 1 to Destion Port 2 with 120 seconds timeout
Push Flow from Source Port 2 to Destion Port 1 with 120 seconds timeout

POX> 



7. Yay! I can see the h1-h2 traffic on h11:

root@mininet-vm:~/PyTapDEMON/MininetTopology# sudo tcpdump -i h11-eth0 -vvv
tcpdump: listening on h11-eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
18:08:24.151762 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    10.0.0.1 > 10.0.0.2: ICMP echo request, id 2588, seq 1, length 64
18:08:24.151836 IP (tos 0x0, ttl 64, id 16487, offset 0, flags [none], proto ICMP (1), length 84)
    10.0.0.2 > 10.0.0.1: ICMP echo reply, id 2588, seq 1, length 64
18:08:25.153466 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    10.0.0.1 > 10.0.0.2: ICMP echo request, id 2588, seq 2, length 64
18:08:25.153478 IP (tos 0x0, ttl 64, id 16488, offset 0, flags [none], proto ICMP (1), length 84)
    10.0.0.2 > 10.0.0.1: ICMP echo reply, id 2588, seq 2, length 64
18:08:26.154104 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    10.0.0.1 > 10.0.0.2: ICMP echo request, id 2588, seq 3, length 64
18:08:26.154204 IP (tos 0x0, ttl 64, id 16489, offset 0, flags [none], proto ICMP (1), length 84)
    10.0.0.2 > 10.0.0.1: ICMP echo reply, id 2588, seq 3, length 64

8. .. and Wireshark:













9. Repeat and rinse for h6-h7 on s2:


mininet> h6 ping -c3 h7
PING 10.0.0.7 (10.0.0.7) 56(84) bytes of data.
64 bytes from 10.0.0.7: icmp_req=1 ttl=64 time=998 ms
64 bytes from 10.0.0.7: icmp_req=2 ttl=64 time=0.127 ms
64 bytes from 10.0.0.7: icmp_req=3 ttl=64 time=0.069 ms

--- 10.0.0.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.069/332.780/998.145/470.484 ms
mininet>












10. Repeat and rinse for h3-h4 on s1. Ping succeeds but I dont see the mirrored traffic on h11 nor Wireshark:


mininet> h3 ping -c3 h4
PING 10.0.0.4 (10.0.0.4) 56(84) bytes of data.
64 bytes from 10.0.0.4: icmp_req=1 ttl=64 time=0.242 ms
64 bytes from 10.0.0.4: icmp_req=2 ttl=64 time=0.111 ms
64 bytes from 10.0.0.4: icmp_req=3 ttl=64 time=0.109 ms

--- 10.0.0.4 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.109/0.154/0.242/0.062 ms
mininet>

The next step for me is to add a web frontend for users to indicate the desired mirrored port.

I will do a separate post to dissect the POX component code.

Leave me comments for any feedbacks! :)





Friday, April 12, 2013

PyTapDEMon - Part 1 Introduction


PyTapDEMON is a project that I am working on for a Python class at UW Extension. It is a Distributed Ethernet MOnitoring (DEMon) using OpenFlow-enabled switch with POX as the controller. This is not a new concept, Rich Groves presented this project at Sharkfest. There a number of reports and commercial offerings on the idea. 
I believe this has a lot of potential in offering a cheap, distributed system that is capable of monitoring datacetner-scale networks with extensible capabilities. 

Here is a simple overview: 

Here is the GitHub link for the project: https://github.com/ericchou-python/PyTapDEMON

Here are some links for the tools I will be using to develop this project:
Hardware used for initial testing
Here is a list of the hardware that I will be using to test the setup: 

1. A Linksys WRT54GL flashed with OpenWRT OpenFlow image, http://www.openflow.org/wp/openwrt/.

2. Raspberry Pi for physical hosts, although virtual host will do also.

3. A dump hub to simulate tap ports.



Will update when there are enough progress to warrant an update. Leave me comments if you have any suggestions or questions. :)

Cheers.



Saturday, February 2, 2013

OpenFlow Tutorial with POX - Part 1

*****

[Update 11/25/2016: I humbly invite you to check out my InternetworkExpert Class on Learn SDN with OpenFlow and Ryu Controller]

*****



The OpenFlow Tutorial is simply awesome. It is hands down the best way to gain some hands on experience with OpenFlow. Everything is encapsulated into a VirtualBox VM and you simply need to bootstrap it. Everything you need for network component is included in Mininet, which is another awesome tool in itself. The wireshark component has the OpenFlow dissect included already. And to run simple OpenFlow test you can use the built-in dpctl.

I do, however, think when it comes to actually construct a Controller + Mininet network the tutorial needs more example and hand-holding. Let's face it, for those of us coming from Cisco / Juniper background with some Python chops it is still a very steep learning curve when:

[If this is helpful to you, please leave me a note. If enough people respond, we can add a few items to the tutorial wiki. Otherwise I will just keep it here on my blog]

1. You dont know which portion is OpenFlow, which is Python, and which is Controller. 

For example, when the tutorial reference of.ofp_flow_mod() and "this instructs a switch to install a flow table entry"; it includes all three components, POX/OpenFlow/Python. The flow_mod is just an OpenFlow message, while it is implemented by POX via a Python function. But it is not until I read the POX WIki that I realize the the function is implemented in the "pox.openflow.libopenflow_01" module and the example probably skipped the potion where 'import pox.openflow.libopenflow_01 as of' at the top of the file.

2. Most of the pointers later on are task oriented, there is no end-to-end examples to build from.

So here I aim to pick up at the "Create Learning Switch" section and provide a more detailed example using POX as the controller.


[Update 04/06/2013: If you are using the new VM with mininet 2.0 (added Feb 2013) in the tutorial, the new s1 switch port 1 and port 2 now connects to h1 and h2 instead of h2 and h3. The section below used the old image, which uses h2 and h3 at the first two ports. Please adjust accordingly if you use the new image.
old:
Old:
openflow@openflowtutorial:~$ sudo mn --topo single,3 --mac --switch ovsk --controller remote
*** Adding links:
(s1, h2) (s1, h3) (s1, h4)
***
mininet> net
s1 <-> h2-eth0 h3-eth0 h4-eth0
mininet>
New:
mininet@mininet-vm:~$ sudo mn --topo single,3 --mac --switch ovsk --controller remote
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
***
mininet> net
c0
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0 s1-eth3:h3-eth0
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s1-eth3
mininet>
]


1. Clone the POX controller from Git repository, Git is already pre-installed on the VM:
openflow@openflowtutorial:~$ git clone http://github.com/noxrepo/pox
Cloning into pox…
2. Verify and change into the directory:
openflow@openflowtutorial:~$ ls
mininet nox oflops oftest openflow openvswitch pox
openflow@openflowtutorial:~$ cd pox
openflow@openflowtutorial:~/pox$ ls
COPYING debug-pox.py doc ext pox pox.py README setup.cfg tests tools
openflow@openflowtutorial:~/pox$
3. Open up a separate window and start the simple Mininet topology:
openflow@openflowtutorial:~$ sudo mn --topo single,3 --mac --switch ovsk --controller remote
*** Adding controller
*** Creating network
*** Adding hosts:
h2 h3 h4
*** Adding switches:
s1
*** Adding links:
(s1, h2) (s1, h3) (s1, h4)
*** Configuring hosts
h2 h3 h4
*** Starting controller
*** Starting 1 switches
s1
*** Starting CLI:
mininet>
4. Test your POX controller by starting the POX, look for the switch registration message. You can optionally open up wireshark to verify:
openflow@openflowtutorial:~/pox$ ./pox.py
POX 0.0.0 / Copyright 2011 James McCauley
DEBUG:core:POX 0.0.0 going up...
DEBUG:core:Running on CPython (2.7.1+/Apr 11 2011 18:05:24)
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
DEBUG:openflow.of_01:Listening for connections on 0.0.0.0:6633
INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01
Ready.
POX>
POX> 

5. If you go back to the Mininet window and try to have H2 ping H3, nothing will happen because the controller is not doing anything. This is pretty boring.
mininet> h2 ping h3
<nothing>
<ctrl+c to kill>

6. At this point, exit the interactive prompt with exit(). You can leave the Mininet topology running or kill it in another window. I find it easier to kill it and just 'up arrow + enter' every time to see my controller messages.
POX> exit()
7. The way POX initiate components, is to use the component name as the argument. To use a pre-built L2 learning switch component, you can use 'forwarding.l2_learning' as the first argument.
openflow@openflowtutorial:~/pox$ ./pox.py forwarding.l2_learning
POX 0.0.0 / Copyright 2011 James McCauley
DEBUG:core:POX 0.0.0 going up...
DEBUG:core:Running on CPython (2.7.1+/Apr 11 2011 18:05:24)
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
DEBUG:openflow.of_01:Listening for connections on 0.0.0.0:6633
Ready.
POX>
POX> INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01
DEBUG:forwarding.l2_learning:Connection [Con 1/1]
7. At this point, if you go back to Mininet window, you can see that as a learning switch, h2 can now poing h3:
mininet> h2 ping -c5 h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=17.4 ms
64 bytes from 10.0.0.3: icmp_req=2 ttl=64 time=0.298 ms
64 bytes from 10.0.0.3: icmp_req=3 ttl=64 time=0.041 ms
64 bytes from 10.0.0.3: icmp_req=4 ttl=64 time=0.050 ms
64 bytes from 10.0.0.3: icmp_req=5 ttl=64 time=0.000 ms
--- 10.0.0.3 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 0.000/3.559/17.407/6.924 ms
mininet> 
And your POX controller prompt should show the controller installing the flows:
POX>
POX> DEBUG:forwarding.l2_learning:installing flow for 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.1
DEBUG:forwarding.l2_learning:installing flow for 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.2
DEBUG:forwarding.l2_learning:installing flow for 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.1
DEBUG:forwarding.l2_learning:installing flow for 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.1
DEBUG:forwarding.l2_learning:installing flow for 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.2
POX> 
You can also use the dpctl tool to verify that the flows are installed:
openflow@openflowtutorial:~/pox$ dpctl dump-flows tcp:127.0.0.1:6634
stats_reply (xid=0xad1245f1): flags=none type=1(flow)
  cookie=0, duration_sec=4s, duration_nsec=993000000s, table_id=0, priority=32768, n_packets=1, n_bytes=42, idle_timeout=10,hard_timeout=30,arp,dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=00:00:00:00:00:02,dl_dst=00:00:00:00:00:03,nw_src=10.0.0.2,nw_dst=10.0.0.3,nw_tos=0x00,nw_proto=2,tp_src=0,tp_dst=0,actions=output:2
  cookie=0, duration_sec=9s, duration_nsec=1000000s, table_id=0, priority=32768, n_packets=7, n_bytes=686, idle_timeout=10,hard_timeout=30,icmp,dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=00:00:00:00:00:02,dl_dst=00:00:00:00:00:03,nw_src=10.0.0.2,nw_dst=10.0.0.3,nw_tos=0x00,icmp_type=8,icmp_code=0,actions=output:2
  cookie=0, duration_sec=4s, duration_nsec=994000000s, table_id=0, priority=32768, n_packets=1, n_bytes=42, idle_timeout=10,hard_timeout=30,arp,dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=00:00:00:00:00:03,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.3,nw_dst=10.0.0.2,nw_tos=0x00,nw_proto=1,icmp_type=0,icmp_code=0,actions=output:1
  cookie=0, duration_sec=10s, duration_nsec=32000000s, table_id=0, priority=32768, n_packets=9, n_bytes=882, idle_timeout=10,hard_timeout=30,icmp,dl_vlan=0xffff,dl_vlan_pcp=0x00,dl_src=00:00:00:00:00:03,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.3,nw_dst=10.0.0.2,nw_tos=0x00,icmp_type=0,icmp_code=0,actions=output:1
openflow@openflowtutorial:~/pox$
Notice the first ICMP reply is really slow, waiting for the flow to be installed. But later packets are fast.

8. So now we know POX works, let's start with some boiler plate code so we can learn. Toward the end of the POX Wiki, there is a link for the code prepared by William Emmanuel Yu (not sure if all the codes were written by him). Get his codes from Git as well.

openflow@openflowtutorial:~/pox$ git clone https://github.com/hip2b2/poxstuff.git
Cloning into poxstuff...
remote: Counting objects: 70, done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 70 (delta 39), reused 59 (delta 28)
Unpacking objects: 100% (70/70), done.
openflow@openflowtutorial:~/pox$ 
Note. There is also the interactive version of the same of_sw_tutorial_oo.py that is listed in the POX Wiki. But it did not work for me. Gave me the error below. I also prefer to do the 'dumb' thing and just type out code to help me learn. Just FYI.
openflow@openflowtutorial:~/pox$ ./pox.py of_sw_tutorial_oo
POX 0.0.0 / Copyright 2011 James McCauley
DEBUG:ext.of_sw_tutorial_oo:Initializing switch SW_IDEALPAIRSWITCH.
Traceback (most recent call last):
  File "./pox.py", line 352, in main
    if doLaunch():
  File "./pox.py", line 152, in doLaunch
    f(**params)
  File "/home/openflow/pox/ext/of_sw_tutorial_oo.py", line 327, in launch
    core.Interactive.variables['MySwitch'] = MySwitch
  File "/home/openflow/pox/pox/core.py", line 346, in __getattr__
    raise AttributeError("'%s' not registered" % (name,))
AttributeError: 'Interactive' not registeredopenflow@openflowtutorial:~/pox$
9. POX controller will automatically look for the ext/ directory for components. You can copy the of_switch_tutorial.py file to the ext/ folder if you want the POX controller to be able to find it automatically.
openflow@openflowtutorial:~/pox$ cp poxstuff/of_sw_tutorial.py ext/
openflow@openflowtutorial:~/pox$ ./pox.py of_sw_tutorial
POX 0.0.0 / Copyright 2011 James McCauley
INFO:ext.of_sw_tutorial:Switch Tutorial is running.
DEBUG:core:POX 0.0.0 going up...
DEBUG:core:Running on CPython (2.7.1+/Apr 11 2011 18:05:24)
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
DEBUG:openflow.of_01:Listening for connections on 0.0.0.0:6633
Ready.
POX>
POX> INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01
10. To build muscle memory, I manually create a Python file, can start typing in line-by-line in order to learn. Here is the link I look at, https://github.com/hip2b2/poxstuff/blob/master/of_sw_tutorial.py.

11. For example, to build a dumb hub, follow the code and only write out what is required. Here is a block-by-block:
  1 #!/usr/bin/env python
  2
  3 # Copy and paste https://github.com/hip2b2/poxstuff/blob/master/of_sw_tutorial.py
  4 # step by step to understand the process
  5 
- The pox.core and pox.openflow.libopenflow_01 are the packages being in use in the functions:
  6 from pox.core import core
  7 import pox.openflow.libopenflow_01 as of
  8 
- Logging for output:
  9 log = core.getLogger()
 10
 11 table = {}
 12 
- This is a base function to allow sending packets out:
 13 def send_packet(event, dst_port = of.OFPP_ALL):
 14     msg = of.ofp_packet_out(in_port=event.ofp.in_port)
 15     if event.ofp.buffer_id != -1 and event.ofp.buffer_id is not None:
 16         msg.buffer_id = event.ofp.buffer_id
 17     else:
 18         if event.ofp.data:
 19             return
 20         msg.data = event.ofp.data
 21     msg.actions.append(of.ofp_action_output(port = dst_port))
 22     event.connection.send(msg)
 23 
- Here is the dumb hub function itself:
 24 def _handle_dumbhub_packetin(event):
 25     packet = event.parsed
 26     send_packet(event, of.OFPP_ALL)
 27
 28     log.debug("Broadcasting %s.%i -> %s.%i" %
 29         (packet.src, event.ofp.in_port, packet.dst, of.OFPP_ALL))
 30 
- Here is the launch() function to specify which function to use:
 31 # launch whichever implementation you want via function
 32 def launch():
 33     core.openflow.addListenerByName("PacketIn", _handle_dumbhub_packetin)
 34
 35     log.info("Switch Tutorial is running.")
 36
12. Let's start our simple dumb hub controller: 
openflow@openflowtutorial:~/pox$ ./pox.py of_sw_tutorial_myTestPOX 0.0.0 / Copyright 2011 James McCauley
INFO:ext.of_sw_tutorial_myTest:Switch Tutorial is running.
DEBUG:core:POX 0.0.0 going up...
DEBUG:core:Running on CPython (2.7.1+/Apr 11 2011 18:05:24)
INFO:core:POX 0.0.0 is up.
This program comes with ABSOLUTELY NO WARRANTY.  This program is free software,
and you are welcome to redistribute it under certain conditions.
Type 'help(pox.license)' for details.
DEBUG:openflow.of_01:Listening for connections on 0.0.0.0:6633
Ready.
POX>
POX> INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01

mininet> h2 ping -c5 h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=74.3 ms
64 bytes from 10.0.0.3: icmp_req=2 ttl=64 time=33.4 ms
64 bytes from 10.0.0.3: icmp_req=3 ttl=64 time=44.9 ms
64 bytes from 10.0.0.3: icmp_req=4 ttl=64 time=21.6 ms
64 bytes from 10.0.0.3: icmp_req=5 ttl=64 time=6.10 ms
--- 10.0.0.3 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4026ms
rtt min/avg/max/mdev = 6.101/36.093/74.358/23.053 ms
mininet> 
Notice the packet time are longer on the first packet, and subsequent packets have longer time compare to the L2 learning switch. 

You will also see the broadcast packets on the POX console: 
POX> DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> ff:ff:ff:ff:ff:ff.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
13. You can now start to experiment with the functions. Say, you can insert a print statement to see what the parsed packet look like: 
 23
 24 def _handle_dumbhub_packetin(event):
 25     packet = event.parsed
 26     print packet 27     send_packet(event, of.OFPP_ALL)
 28
 29     log.debug("Broadcasting %s.%i -> %s.%i" %
 30         (packet.src, event.ofp.in_port, packet.dst, of.OFPP_ALL))
 31 
Restart the controller, you will now see the packet: 
POX> INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01
[00:00:00:00:00:02>00:00:00:00:00:03:IP]|([v:4hl:5l:84t:64]ICMP cs:26a5[10.0.0.2>10.0.0.3]){t:ECHO_REQUEST c:0 chk:23e7}{id:2835 seq:3}DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
[00:00:00:00:00:03>00:00:00:00:00:02:IP]|([v:4hl:5l:84t:64]ICMP cs:dfc5[10.0.0.3>10.0.0.2]){t:ECHO_REPLY c:0 chk:2be7}{id:2835 seq:3}DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
[00:00:00:00:00:02>00:00:00:00:00:03:IP]|([v:4hl:5l:84t:64]ICMP cs:26a5[10.0.0.2>10.0.0.3]){t:ECHO_REQUEST c:0 chk:4fd1}{id:2835 seq:4}
14. Or if you want to look at the packet out message: 
 13 def send_packet(event, dst_port = of.OFPP_ALL):
 14     msg = of.ofp_packet_out(in_port=event.ofp.in_port)
 15     print msg 16     if event.ofp.buffer_id != -1 and event.ofp.buffer_id is not None:
 17         msg.buffer_id = event.ofp.buffer_id
 18     else:
 19         if event.ofp.data:
 20             return
 21         msg.data = event.ofp.data
 22     msg.actions.append(of.ofp_action_output(port = dst_port))
 23     event.connection.send(msg)
 24 
POX> ofp_packet_out  header:     version: 1    type:    13 (OFPT_PACKET_OUT)    length:  8    xid:     None  buffer_id: -1  in_port: 1  actions_len: 0  actions:DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:02.1 -> 00:00:00:00:00:03.65532
ofp_packet_out  header:     version: 1    type:    13 (OFPT_PACKET_OUT)    length:  8    xid:     None  buffer_id: -1  in_port: 2  actions_len: 0  actions:DEBUG:ext.of_sw_tutorial_myTest:Broadcasting 00:00:00:00:00:03.2 -> 00:00:00:00:00:02.65532
15. Let's try the lazyhub function, just create the lazyhub function and change the launch() function: 
 23
 24 def _handle_lazyhub_packetin (event): 25     packet = event.parsed 26      27     msg = of.ofp_flow_mod() 28     msg.idle_timeout = 10 29     msg.hard_timeout = 30 30     msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL)) 31     event.connection.send(msg) 32      33     log.debug("Installing %s.%i -> %s.%i" % 34         ("ff:ff:ff:ff:ff:ff", event.ofp.in_port, "ff:ff:ff:ff:ff:ff", of.OFPF_ALL)) 35          36      
 37 # launch whichever implementation you want via function
 38 def launch():
 39     core.openflow.addListenerByName("PacketIn", _handle_lazyhub_packetin)
 40  
 41     log.info("Switch Tutorial is running.")
 42 
mininet> h2 ping -c5 h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_req=2 ttl=64 time=0.674 ms
64 bytes from 10.0.0.3: icmp_req=3 ttl=64 time=0.060 ms
64 bytes from 10.0.0.3: icmp_req=4 ttl=64 time=0.041 ms
64 bytes from 10.0.0.3: icmp_req=5 ttl=64 time=0.286 ms
--- 10.0.0.3 ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 4014ms
rtt min/avg/max/mdev = 0.041/0.265/0.674/0.255 ms
mininet>
POX>
POX> INFO:openflow.of_01:[Con 1/1] Connected to 00-00-00-00-00-01
DEBUG:ext.of_sw_tutorial_myTest:Installing ff:ff:ff:ff:ff:ff.1 -> ff:ff:ff:ff:ff:ff.65532
POX> 
I am not sure if this is helpful for others, but at least for me, this provides me with a good entry point to start understanding the different aspects of the POX controller and to proceed. 

Cheers. Leave me comments to let me know how to improve.