def on_connect(self, switch):
        print "switch connected", switch.id

        if switch.id == 1:
            r = Rule()
            r.MATCH('IP_DST', '20.0.0.0/16')
            r.ACTION('OUTPUT', 5)
            send_rule(r, switch)

        if switch.id == 2:
            r = Rule()
            r.MATCH('IP_DST', '20.0.1.0/24')
            r.ACTION('OUTPUT', 2)
            send_rule(r, switch)

            r = Rule()
            r.MATCH('IP_DST', '20.0.2.0/24')
            r.ACTION('OUTPUT', 3)
            send_rule(r, switch)

            r = Rule()
            r.MATCH('IP_DST', '20.0.3.0/24')
            r.ACTION('OUTPUT', 4)
            send_rule(r, switch)

            r = Rule()
            r.MATCH('IP_DST', '20.0.4.0/24')
            r.ACTION('OUTPUT', 5)
            send_rule(r, switch)
Example #2
0
 def on_packet_in(self, packet, switch, inport):
     print("\n>> ", inport, "switch", switch.id, packet)
     # the magic oracle function knows what to do with the packet...
     use_port = get_port_by_ip(switch, packet.ip_dst)
     if use_port >= 0:
         r = Rule()
         r.MATCH('IP_DST', packet.ip_dst)
         r.ACTION('OUTPUT', use_port)
         send_rule(r, switch)
         # important to not loose any packets!
         send_packet(packet, switch, use_port)