-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsdn-pox-openflow-fw.py
42 lines (35 loc) · 1.15 KB
/
sdn-pox-openflow-fw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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' ]
''' Add your global variables here ... '''
class Firewall (EventMixin):
def __init__(self):
self.listenTo(core.openflow)
log.debug("Enabling Firewall Module")
self.deny = []
with open(policyFile, 'rb') as f:
reader = csv.DictReader(f)
for row in reader:
self.deny.append((EthAddr(row['mac_0']), EthAddr(row['mac_1'])))
self.deny.append((EthAddr(row['mac_1']), EthAddr(row['mac_0'])))
def _handle_ConnectionUp(self, event):
for (src, dst) in self.deny:
match = of.ofp_match()
match.dl_src = src
match.dl_dst = dst
msg = of.ofp_flow_mod()
msg.match = match
event.connection.send(msg)
log.debug("Firewall rules installed on %s", dpidToStr(event.dpid))
def launch():
'''
Starting the Firewall module
'''
core.registerNew(Firewall)