Move common code from SG app to utils
There's a function needed in a subsequent patch in Flow Classifier app. This patch moves it to a common location Change-Id: I4ae962266af5f854be1b4354c76731234568141e
This commit is contained in:
parent
230efa1d97
commit
b453041019
|
@ -13,6 +13,7 @@
|
|||
|
||||
import struct
|
||||
|
||||
import netaddr
|
||||
from neutron.agent.common import utils
|
||||
from neutron_lib import constants as n_const
|
||||
from oslo_log import log
|
||||
|
@ -89,3 +90,13 @@ def ethertype_to_ip_version(ethertype):
|
|||
if ethertype == n_const.IPv6:
|
||||
return n_const.IP_VERSION_6
|
||||
raise exceptions.InvalidEtherTypeException(ethertype=ethertype)
|
||||
|
||||
|
||||
def get_port_match_list_from_port_range(port_range_min, port_range_max):
|
||||
port_range = netaddr.IPRange(port_range_min, port_range_max)
|
||||
ports_match_list = []
|
||||
for cidr in port_range.cidrs():
|
||||
port_num = int(cidr.network) & 0xffff
|
||||
mask = int(cidr.netmask) & 0xffff
|
||||
ports_match_list.append((port_num, mask))
|
||||
return ports_match_list
|
||||
|
|
|
@ -95,16 +95,6 @@ class SGApp(df_base_app.DFlowApp):
|
|||
new_cidr_set)
|
||||
return new_cidr_set, added_cidr, removed_cidr
|
||||
|
||||
@staticmethod
|
||||
def _get_port_match_list_from_port_range(port_range_min, port_range_max):
|
||||
port_range = netaddr.IPRange(port_range_min, port_range_max)
|
||||
ports_match_list = []
|
||||
for cidr in port_range.cidrs():
|
||||
port_num = int(cidr.network) & 0xffff
|
||||
mask = int(cidr.netmask) & 0xffff
|
||||
ports_match_list.append((port_num, mask))
|
||||
return ports_match_list
|
||||
|
||||
@staticmethod
|
||||
def _get_network_and_mask(cidr):
|
||||
result = netaddr.IPNetwork(cidr)
|
||||
|
@ -148,7 +138,7 @@ class SGApp(df_base_app.DFlowApp):
|
|||
int(port_range_max) == const.MAX_PORT)):
|
||||
results = [result_base]
|
||||
else:
|
||||
port_match_list = SGApp._get_port_match_list_from_port_range(
|
||||
port_match_list = utils.get_port_match_list_from_port_range(
|
||||
port_range_min, port_range_max)
|
||||
key = DEST_FIELD_NAME_BY_PROTOCOL_NUMBER[protocol]
|
||||
results = []
|
||||
|
|
|
@ -15,6 +15,7 @@ import testtools
|
|||
|
||||
from dragonflow.common import exceptions as df_exc
|
||||
from dragonflow.common import utils
|
||||
from dragonflow.controller.common import utils as controller_utils
|
||||
from dragonflow.db.neutron import lockedobjects_db as lock_db
|
||||
from dragonflow.tests import base as tests_base
|
||||
|
||||
|
@ -84,3 +85,16 @@ class TestLockedobjectsDB(tests_base.BaseTestCase):
|
|||
def test__get_lock_id_by_resource_type(self):
|
||||
with testtools.ExpectedException(df_exc.UnknownResourceException):
|
||||
lock_db._get_lock_id_by_resource_type("nobody")
|
||||
|
||||
|
||||
class TestControllerCommonUtils(tests_base.BaseTestCase):
|
||||
def test_aggregating_flows_for_port_range(self):
|
||||
# compute port match list
|
||||
port_range_min = 20
|
||||
port_range_max = 30
|
||||
port_match_list = controller_utils.get_port_match_list_from_port_range(
|
||||
port_range_min, port_range_max)
|
||||
expected_port_match_list = [(20, 0xfffc), (24, 0xfffc), (28, 0xfffe),
|
||||
(30, 0xffff)]
|
||||
|
||||
self.assertItemsEqual(port_match_list, expected_port_match_list)
|
||||
|
|
|
@ -559,14 +559,3 @@ class TestSGApp(test_app_base.DFAppTestBase):
|
|||
self.assertEqual(new_cidr_set, expected_new_cidr_set)
|
||||
self.assertEqual(added_cidr, expected_added_cidr)
|
||||
self.assertEqual(deleted_cidr, expected_deleted_cidr)
|
||||
|
||||
def test_aggregating_flows_for_port_range(self):
|
||||
# compute port match list
|
||||
port_range_min = 20
|
||||
port_range_max = 30
|
||||
port_match_list = self.app._get_port_match_list_from_port_range(
|
||||
port_range_min, port_range_max)
|
||||
expected_port_match_list = [(20, 0xfffc), (24, 0xfffc), (28, 0xfffe),
|
||||
(30, 0xffff)]
|
||||
|
||||
self.assertItemsEqual(port_match_list, expected_port_match_list)
|
||||
|
|
Loading…
Reference in New Issue