Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Software Defined Networking
- Pox Controller module
- Simple firewall module
- All deny rules located in the firewall-policies file in CSV format
- '''
- from pox.core import core
- import pox.openflow.libopenflow_01 as of
- from pox.lib.revent import *
- from pox.lib.util import dpidToStr
- from pox.lib.addresses import EthAddr
- from collections import namedtuple
- import os
- import csv
- log = core.getLogger()
- policyFile = "%s/pox/pox/misc/firewall-policies.csv" % os.environ[ 'HOME' ]
- rules = []
- with open(policyFile, 'rb') as f:
- reader = csv.reader(f)
- header = f.readline()
- for row in reader:
- row.pop(0)
- rules.append(row)
- log = core.getLogger()
- HARD_TIMEOUT = 30
- IDLE_TIMEOUT = 30
- class FirewallLogic (EventMixin):
- def __init__ (self,connection):
- self.connection= connection
- self.listenTo(connection)
- def _handle_PacketIn (self, event):
- for (src,dst) in rules:
- # drop - no action
- log.debug("Packet from %s to %s is not allowed" % (src, dst))
- match = of.ofp_match()
- match.dl_src = src
- match.dl_dst = dst
- msg = of.ofp_packet_out()
- msg.match = match
- self.connection.send(msg)
- return
- class Firewall (EventMixin):
- def __init__ (self):
- self.listenTo(core.openflow)
- log.debug("Enabling Firewall Module")
- def _handle_ConnectionUp (self, event):
- FirewallLogic(event.connection)
- log.debug("Firewall rules installed on %s", dpidToStr(event.dpid))
- def launch ():
- '''
- Starting the Firewall module
- '''
- core.registerNew(Firewall)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement