Commit fc3a4b39 by Guba Sándor

fixing netowrk driver flow commands

parent 7e5cf646
...@@ -14,16 +14,27 @@ class NWDriver: ...@@ -14,16 +14,27 @@ class NWDriver:
'''Execute OpenVSwitch commands '''Execute OpenVSwitch commands
command - List of strings command - List of strings
''' '''
return_val = subprocess.call(['sudo', 'ovs-vsctl'] + command) command = ['sudo', 'ovs-vsctl'] + command
return_val = subprocess.call(command)
logging.info('OVS command: %s executed.', command) logging.info('OVS command: %s executed.', command)
return return_val return return_val
def ofctl_command_execute(self, command):
'''Execute OpenVSwitch flow commands
command - List of strings
'''
command = ['sudo', 'ovs-ofctl'] + command
return_val = subprocess.call(command)
logging.info('OVS flow command: %s executed.', command)
return return_val
def nw_create(self, vm): def nw_create(self, vm):
for network in vm.network_list: for network in vm.network_list:
self.port_create(network) self.port_create(network)
def nw_delete(self, vm): def nw_delete(self, vm):
pass for network in vm.network_list:
self.port_delete(network)
def port_create(self, network): def port_create(self, network):
''' '''
...@@ -37,11 +48,11 @@ class NWDriver: ...@@ -37,11 +48,11 @@ class NWDriver:
add-flow cloud in_port=245,priority=39000,actions=drop". add-flow cloud in_port=245,priority=39000,actions=drop".
''' '''
# Create the port for virtual network # Create the port for virtual network
cmd_list = ['add_port', network.bridge, network.name] cmd_list = ['add-port', network.bridge, network.name]
self.ovs_command_execute(cmd_list) self.ovs_command_execute(cmd_list)
# Set VLAN parameter for tap interface # Set VLAN parameter for tap interface
cmd_list = ['set', 'Port', network.name, network.vlan] cmd_list = ['set', 'Port', network.name, 'tag='+str(network.vlan)]
self.ovs_command_execute(cmd_list) self.ovs_command_execute(cmd_list)
# Getting network FlowPortNumber # Getting network FlowPortNumber
...@@ -53,7 +64,7 @@ class NWDriver: ...@@ -53,7 +64,7 @@ class NWDriver:
'in_port=%(port_number)s,dl_src=%(mac)s,udp,tp_dst=68,\ 'in_port=%(port_number)s,dl_src=%(mac)s,udp,tp_dst=68,\
priority=43000,actions=drop' % { priority=43000,actions=drop' % {
'port_number': port_number, 'mac': network.mac}] 'port_number': port_number, 'mac': network.mac}]
self.ovs_command_execute(cmd_list) self.ofctl_command_execute(cmd_list)
# Set flow rules 2 (ipv4 filter) # Set flow rules 2 (ipv4 filter)
cmd_list = ['add-flow', network.bridge, cmd_list = ['add-flow', network.bridge,
...@@ -61,7 +72,7 @@ class NWDriver: ...@@ -61,7 +72,7 @@ class NWDriver:
nw_src=%(ipv4)s,priority=42000,actions=normal' % { nw_src=%(ipv4)s,priority=42000,actions=normal' % {
'port_number': port_number, 'port_number': port_number,
'mac': network.mac, 'ipv4': network.ipv4}] 'mac': network.mac, 'ipv4': network.ipv4}]
self.ovs_command_execute(cmd_list) self.ofctl_command_execute(cmd_list)
# Set flow rules 3 (ipv6 filter) # Set flow rules 3 (ipv6 filter)
cmd_list = ['add-flow', network.bridge, cmd_list = ['add-flow', network.bridge,
...@@ -69,7 +80,7 @@ class NWDriver: ...@@ -69,7 +80,7 @@ class NWDriver:
nw_src=%(ipv6)s,priority=42000,actions=normal' % { nw_src=%(ipv6)s,priority=42000,actions=normal' % {
'port_number': port_number, 'port_number': port_number,
'mac': network.mac, 'ipv6': network.ipv6}] 'mac': network.mac, 'ipv6': network.ipv6}]
self.ovs_command_execute(cmd_list) self.ofctl_command_execute(cmd_list)
# Set flow rules 4 (enabling arp) # Set flow rules 4 (enabling arp)
cmd_list = ['add-flow', network.bridge, cmd_list = ['add-flow', network.bridge,
...@@ -77,24 +88,28 @@ class NWDriver: ...@@ -77,24 +88,28 @@ class NWDriver:
nw_src=%(ipv4)s,priority=41000,actions=normal' % { nw_src=%(ipv4)s,priority=41000,actions=normal' % {
'port_number': port_number, 'port_number': port_number,
'mac': network.mac, 'ipv4': network.ipv4}] 'mac': network.mac, 'ipv4': network.ipv4}]
self.ovs_command_execute(cmd_list) self.ofctl_command_execute(cmd_list)
# Set flow rules 5 (enabling arp) # Set flow rules 5 (enabling arp)
cmd_list = ['add-flow', network.bridge, cmd_list = ['add-flow', network.bridge,
'in_port=%(port_number)s,dl_src=%(mac)s,udp,tp_dst=67,\ 'in_port=%(port_number)s,dl_src=%(mac)s,udp,tp_dst=67,\
priority=40000,actions=normal' % { priority=40000,actions=normal' % {
'port_number': port_number, 'mac': network.mac}] 'port_number': port_number, 'mac': network.mac}]
self.ovs_command_execute(cmd_list) self.ofctl_command_execute(cmd_list)
# Set flow rule 6 (disable other protocols) # Set flow rule 6 (disable other protocols)
cmd_list = ['add-flow', network.bridge, cmd_list = ['add-flow', network.bridge,
'in_port=%(port_number)s,priority=39000,actions=drop' % { 'in_port=%(port_number)s,priority=39000,actions=drop' % {
'port_number': port_number}] 'port_number': port_number}]
self.ofctl_command_execute(cmd_list)
def port_delete(self, network):
cmd_list = ['del-port', network.name]
self.ovs_command_execute(cmd_list) self.ovs_command_execute(cmd_list)
def get_port_number(self, network): def get_port_number(self, network):
'''Returns the OpenFlow port number for a given network '''Returns the OpenFlow port number for a given network
''' '''
output = subprocess.check_output( output = subprocess.check_output(
['ovs-ofctl', 'dump-ports', network.bridge, network.name]) ['sudo', 'ovs-ofctl', 'dump-ports', network.bridge, network.name])
return re.search('port ([0-9]+)', output).group(1) return re.search('port *([0-9]+)', output).group(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment