Delete filter from agent

This commit is contained in:
Ofer Ben-Yacov 2017-01-26 14:15:05 +02:00
parent 1881830ed4
commit 220b277afe
4 changed files with 66 additions and 13 deletions

View File

@ -51,3 +51,7 @@ class AgentInterface(object):
def create_filter(self, tc_dict):
""" create traffic filter that is used to route packets to the
right queue"""
@abc.abstractmethod
def remove_filter(self, tc_dict):
""" remove traffic filter """

View File

@ -18,6 +18,8 @@ from subprocess import check_call
from oslo_log import log as logging
from neutron_lib import exceptions
import agent_api
LOG = logging.getLogger(__name__)
@ -68,7 +70,7 @@ class TcDriver(agent_api.AgentInterface):
def remove_traffic_class(self, tc_dict, with_filter=False):
if with_filter:
self._delete_filter(tc_dict)
self.remove_filter(tc_dict)
cmd = 'sudo tc class del dev %s classid 1:%s' % (
self.ports[tc_dict['port_side']],
tc_dict['child']
@ -88,19 +90,27 @@ class TcDriver(agent_api.AgentInterface):
check_call(cmd, shell=True)
def create_filter(self, tc_dict):
if tc_dict['protocol'] == 'vxlan':
self._create_vxlan_filter(tc_dict)
return
raise exceptions.BadRequest(msg='Protocol not supported')
def _create_vxlan_filter(self, tc_dict):
vni = tc_dict['match'].split('=')[1]
cmd = 'sudo tc filter add dev %s parent 1:0' % (
self.ports[tc_dict['port_side']])
cmd += ' protocol ip prio 1 u32'
if tc_dict['protocol'] and tc_dict['protocol'] == 'vxlan':
cmd += ' match ip protocol 17 0xFF' # UDP
cmd += ' match u16 0x12B5 0xFFFF at 22' # VxLAN port
cmd += ' match u32 0x%0.6X00 0xFFFFFF00 at 32' % tc_dict['vni']
cmd += ' flowid 1:%s' % tc_dict['child']
cmd += ' match ip protocol 17 0xFF' # UDP
cmd += ' match u16 0x12B5 0xFFFF at 22' # VxLAN port
cmd += ' match u32 0x%0.6X00 0xFFFFFF00 at 32' % int(vni)
cmd += ' flowid 1:%s' % tc_dict['child']
LOG.debug('creating filter: %s' % cmd)
check_call(cmd, shell=True)
def _delete_filter(self, tc_dict):
def remove_filter(self, tc_dict):
cmd = 'sudo tc filter del dev %s ' % self.ports[tc_dict['port_side']]
cmd += ' parent 1:0 protocol ip prio 1 u32'
cmd += ' flowid %s:%s' % (tc_dict['parent'], tc_dict['child'])
cmd += ' flowid 1:%s' % tc_dict['child']
check_call(cmd, shell=True)

View File

@ -123,7 +123,36 @@ class TcAgentManager(manager.Manager):
self.agent.remove_traffic_class(tc_dict)
def create_wtc_filter(self, context, wtc_filter):
pass
wtc_class = wtc_filter['class']
tc_dict = {
'child': wtc_class['class_ext_id'],
'protocol': wtc_filter['protocol'],
'match': wtc_filter['match']
}
port_side = wtc_class['direction']
if port_side == 'both' or port_side == 'in':
tc_dict['port_side'] = 'lan_port'
self.agent.create_filter(tc_dict)
if port_side == 'both' or port_side == 'out':
tc_dict['port_side'] = 'wan_port'
self.agent.create_filter(tc_dict)
def delete_wtc_filter(self, context, wtc_filter):
pass
wtc_class = wtc_filter['class']
port_side = wtc_class['direction']
tc_dict = {
'child': wtc_class['class_ext_id']
}
if port_side == 'both' or port_side == 'in':
tc_dict['port_side'] = 'lan_port'
self.agent.remove_filter(tc_dict)
if port_side == 'both' or port_side == 'out':
tc_dict['port_side'] = 'wan_port'
self.agent.remove_filter(tc_dict)

View File

@ -122,7 +122,12 @@ class WanQosPlugin(wantcfilter.WanTcFilterPluginBase,
marker, page_reverse)
def delete_wan_tc_filter(self, context, id):
self.db.delete_wan_tc_filter(context, id)
wtc_filter = self.get_wan_tc_filter(context, id)
if wtc_filter:
wtc_class = self.get_wan_tc_class(context, wtc_filter['class_id'])
self.db.delete_wan_tc_filter(context, id)
wtc_filter['class'] = wtc_class
self.agent_rpc.delete_wtc_filter(context, wtc_filter)
def get_wan_tc_filters(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
@ -132,8 +137,13 @@ class WanQosPlugin(wantcfilter.WanTcFilterPluginBase,
marker, page_reverse)
def create_wan_tc_filter(self, context, wan_tc_filter):
return self.db.create_wan_tc_filter(context,
wan_tc_filter['wan_tc_filter'])
wtc_filter = self.db.create_wan_tc_filter(context,
wan_tc_filter[
'wan_tc_filter'])
wtc_class = self.get_wan_tc_class(context, wtc_filter['class_id'])
wtc_filter['class'] = wtc_class
self.agent_rpc.create_wtc_filter(context, wtc_filter)
return wtc_filter
def update_wan_tc_filter(self, context, id, wan_tc_filter):
pass