Added vlan range management for OVS plugin
* Added integer config flags: vlan_min, vlan_max * If vlan_min is larger than vlan_max log warn and use default values * Changed test_vlan_map.py in favor removed definitions of VlanMap class Change-Id: Iaba819e62d70a9c9935cae195718dbf74d13884a
This commit is contained in:
parent
412c7aa030
commit
faea848d5f
@ -28,6 +28,10 @@ tunnel_bridge = br-tun
|
||||
# Set local-ip to be the local IP address of this hypervisor.
|
||||
# local_ip = 10.0.0.3
|
||||
|
||||
# Uncomment if you want to use custom VLAN range.
|
||||
# vlan_min = 1
|
||||
# vlan_max = 4094
|
||||
|
||||
[AGENT]
|
||||
# Agent's polling interval in seconds
|
||||
polling_interval = 2
|
||||
|
@ -27,6 +27,8 @@ ovs_opts = [
|
||||
cfg.StrOpt('integration_bridge', default='br-int'),
|
||||
cfg.StrOpt('tunnel_bridge', default='br-tun'),
|
||||
cfg.StrOpt('local_ip', default='10.0.0.3'),
|
||||
cfg.IntOpt('vlan_min', default=1),
|
||||
cfg.IntOpt('vlan_max', default=4094),
|
||||
]
|
||||
|
||||
agent_opts = [
|
||||
|
@ -45,13 +45,13 @@ class VlanMap(object):
|
||||
vlans = {}
|
||||
net_ids = {}
|
||||
free_vlans = set()
|
||||
VLAN_MIN = 1
|
||||
VLAN_MAX = 4094
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, vlan_min=1, vlan_max=4094):
|
||||
self.vlan_min = vlan_min
|
||||
self.vlan_max = vlan_max
|
||||
self.vlans.clear()
|
||||
self.net_ids.clear()
|
||||
self.free_vlans = set(xrange(self.VLAN_MIN, self.VLAN_MAX + 1))
|
||||
self.free_vlans = set(xrange(self.vlan_min, self.vlan_max + 1))
|
||||
|
||||
def already_used(self, vlan_id, network_id):
|
||||
self.free_vlans.remove(vlan_id)
|
||||
@ -102,7 +102,16 @@ class OVSQuantumPlugin(QuantumPluginBase):
|
||||
options.update({"reconnect_interval": reconnect_interval})
|
||||
db.configure_db(options)
|
||||
|
||||
self.vmap = VlanMap()
|
||||
vlan_min = conf.OVS.vlan_min
|
||||
vlan_max = conf.OVS.vlan_max
|
||||
|
||||
if vlan_min > vlan_max:
|
||||
LOG.warn("Using default VLAN values! vlan_min = %s is larger"
|
||||
" than vlan_max = %s!" % (vlan_min, vlan_max))
|
||||
vlan_min = 1
|
||||
vlan_max = 4094
|
||||
|
||||
self.vmap = VlanMap(vlan_min, vlan_max)
|
||||
# Populate the map with anything that is already present in the
|
||||
# database
|
||||
vlans = ovs_db.get_vlans()
|
||||
|
@ -32,8 +32,8 @@ class VlanMapTest(unittest.TestCase):
|
||||
|
||||
def testAddVlan(self):
|
||||
vlan_id = self.vmap.acquire("foobar")
|
||||
self.assertTrue(vlan_id >= VlanMap.VLAN_MIN)
|
||||
self.assertTrue(vlan_id <= VlanMap.VLAN_MAX)
|
||||
self.assertTrue(vlan_id >= self.vmap.vlan_min)
|
||||
self.assertTrue(vlan_id <= self.vmap.vlan_max)
|
||||
|
||||
def testReleaseVlan(self):
|
||||
vlan_id = self.vmap.acquire("foobar")
|
||||
@ -41,11 +41,11 @@ class VlanMapTest(unittest.TestCase):
|
||||
|
||||
def testAddRelease4kVlans(self):
|
||||
vlan_id = None
|
||||
num_vlans = VlanMap.VLAN_MAX - VlanMap.VLAN_MIN
|
||||
num_vlans = self.vmap.vlan_max - self.vmap.vlan_min
|
||||
for id in xrange(num_vlans):
|
||||
vlan_id = self.vmap.acquire("net-%s" % id)
|
||||
self.assertTrue(vlan_id >= VlanMap.VLAN_MIN)
|
||||
self.assertTrue(vlan_id <= VlanMap.VLAN_MAX)
|
||||
self.assertTrue(vlan_id >= self.vmap.vlan_min)
|
||||
self.assertTrue(vlan_id <= self.vmap.vlan_max)
|
||||
for id in xrange(num_vlans):
|
||||
self.vmap.release("net-%s" % id)
|
||||
|
||||
@ -56,7 +56,7 @@ class VlanMapTest(unittest.TestCase):
|
||||
# this value is high enough that we will exhaust
|
||||
# all VLANs. We want to make sure 'existing_vlan'
|
||||
# is never reallocated.
|
||||
num_vlans = VlanMap.VLAN_MAX - VlanMap.VLAN_MIN + 1
|
||||
num_vlans = self.vmap.vlan_max - self.vmap.vlan_min + 1
|
||||
for x in xrange(num_vlans):
|
||||
vlan_id = self.vmap.acquire("net-%x" % x)
|
||||
self.assertTrue(vlan_id != existing_vlan)
|
||||
|
Loading…
Reference in New Issue
Block a user