@@ -0,0 +1,2386 @@
+# Copyright 2011 James McCauley%0A#%0A# This file is part of POX.%0A#%0A# POX is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# POX is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with POX.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A%0A%22%22%22%0AThis is the world's simplest OpenFlow learning switch.%0A%22%22%22%0A%0Afrom pox.core import core%0Afrom pox.lib.addresses import EthAddr%0Aimport pox.openflow.libopenflow_01 as of%0A%0Alog = core.getLogger()%0A%0A%0Adef _handle_PacketIn (event):%0A  packet = event.parsed%0A%0A  # If we get a packet FROM some src address on some input port, we%0A  # know that if we want to send TO that address, we should send it%0A  # out that port.  Install a rule for this.%0A  msg = of.ofp_flow_mod()%0A  msg.match.dl_dst = packet.src%0A  msg.actions.append(of.ofp_action_output(port = event.port))%0A  event.connection.send(msg)%0A%0A  # Now since we got a packet at the controller, that must mean%0A  # that we hadn't installed a rule for the destination address%0A  # yet -- we don't know where it is.  So, we'll just send the%0A  # packet out all ports (except the one it came in on!) and%0A  # hope the destination is out there somewhere. :)%0A  msg = of.ofp_packet_out()%0A  msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))%0A  msg.buffer_id = event.ofp.buffer_id # Resend the incoming packet%0A  msg.in_port = event.port # Don't flood out the incoming port%0A  event.connection.send(msg)%0A%0A%0Adef _handle_ConnectionUp (event):%0A  # Install rule so that broadcast packets just get flooded%0A  msg = of.ofp_flow_mod()%0A  msg.match.dl_dst = EthAddr(%22ff:ff:ff:ff:ff:ff%22) # Broadcast%0A  msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD))%0A                                                  # FLOOD means all ports%0A  event.connection.send(msg)%0A  log.info(%22Switch connected.%22)%0A%0A%0Adef launch ():%0A  core.openflow.addListenerByName(%22ConnectionUp%22, _handle_ConnectionUp)%0A  core.openflow.addListenerByName(%22PacketIn%22, _handle_PacketIn)%0A%0A  log.info(%22Learning switch running.%22)%0A

Add simplest learning switch ever