Learning POX OpenFlow controller : L2 switch implementation

The application name is l2learning.py. The idea behind this app is to show one of possible L2 switch implementation. An exact match rule is created based on each and every PacketIn that corresponds to unicast packet.

msg = of.ofp_flow_mod()
msg.match = of.ofp_match.from_packet(packet, event.port)
msg.idle_timeout = 10
msg.hard_timeout = 30
msg.actions.append(of.ofp_action_output(port = port))
msg.data = event.ofp

The purpose of ofp_match.from_packet method is to create match fields with data copied from packet fields

Match fields after conversion from a received packet look the following way.

wildcards: nw_tos|tp_dst|tp_src (1000000000000011000000 = 2000c0)
in_port: 2
dl_src: c6:26:f3:2b:ce:a0
dl_dst: 82:b5:7a:0b:0d:78
dl_vlan: 65535
dl_vlan_pcp: 0
dl_type: 0x806
nw_proto: 2

A controller maintains a forwarding database to convert destination MAC to an egress port. Thus a dictionary with MAC address as a key and port as a value is updated each time when controller receives a packet.

self.macToPort[packet.src] = event.port

Notice that this app is designed to work with one switch only. Otherwise the dictionary would have to include switch information as well.

The logic of flooding packets and installing rules is already familiar to us from the overview of the first module. With one difference, namely the usage of timeouts. Idle timeout value indicates that switch will remove the flow in case of no traffic and hard timeout is for removing a rule unconditionally. There is an extra logic to drop a packet in case if dictionary lookup result in the port where it was captured.

msg = of.ofp_flow_mod()
msg.match = of.ofp_match.from_packet(packet)
msg.idle_timeout = duration[0]
msg.hard_timeout = duration[1]
msg.buffer_id = event.ofp.buffer_id

According to Openflow reference document a rule without actions will drop packets. References

2 thoughts on “Learning POX OpenFlow controller : L2 switch implementation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s