现在neutron支持创建不同的网络指定不同的mtu,这个应用场景主要是vlan和vxlan混用的情况下。
具体配置
1、neutron.conf
network_device_mtu=1450
# 生效的设备:neutron 网络节点上的 qdhcp 和 qrouter network namespace
的 qr,qg 和 ns 接口以及对应的 veth tap 设备
/usr/lib/python2.7/site-packages/neutron/agent/linux/interface.py
if self.conf.network_device_mtu:
ns_dev.link.set_mtu(self.conf.network_device_mtu)
if self.conf.ovs_use_veth:
root_dev.link.set_mtu(self.conf.network_device_mtu)
2、ml2_conf.ini path_mtu = 9000 segment_mtu = 1500
flat网络类型如何获取MTU:
/usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/type_flat.py
class FlatTypeDriver(helpers.BaseTypeDriver): # 父类BaseTypeDriver
"""Manage state for flat networks with ML2.
The FlatTypeDriver implements the 'flat' network_type. Flat
network segments provide connectivity between VMs and other
devices using any connected IEEE 802.1D conformant
physical_network, without the use of VLAN tags, tunneling, or
other segmentation mechanisms. Therefore at most one flat network
segment can exist on each available physical_network.
"""
def __init__(self):
super(FlatTypeDriver, self).__init__()
self._parse_networks(cfg.CONF.ml2_type_flat.flat_networks)
# 如果定义了flat provider的physet_mtus,取physical_network_mtus和segment_mtu的最小值
def get_mtu(self, physical_network):
seg_mtu = super(FlatTypeDriver, self).get_mtu()
mtu = []
if seg_mtu > 0:
mtu.append(seg_mtu)
if physical_network in self.physnet_mtus:
mtu.append(int(self.physnet_mtus[physical_network]))
return min(mtu) if mtu else 0
/usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/helpers.py
class BaseTypeDriver(api.TypeDriver):
"""BaseTypeDriver for functions common to Segment and flat."""
def __init__(self):
try:
self.physnet_mtus = utils.parse_mappings(
cfg.CONF.ml2.physical_network_mtus
)
except Exception:
self.physnet_mtus = []
def get_mtu(self, physical_network=None):
return cfg.CONF.ml2.segment_mtu
vlan网络类型如何获取MTU:
class VlanTypeDriver(helpers.SegmentTypeDriver): # 父类SegmentTypeDriver
"""Manage state for VLAN networks with ML2.
The VlanTypeDriver implements the 'vlan' network_type. VLAN
network segments provide connectivity between VMs and other
devices using any connected IEEE 802.1Q conformant
physical_network segmented into virtual networks via IEEE 802.1Q
headers. Up to 4094 VLAN network segments can exist on each
available physical_network.
"""
def __init__(self):
super(VlanTypeDriver, self).__init__(VlanAllocation)
self._parse_network_vlan_ranges()
# vlan的获取mtu方式和flat一样
def get_mtu(self, physical_network):
seg_mtu = super(VlanTypeDriver, self).get_mtu()
mtu = []
if seg_mtu > 0:
mtu.append(seg_mtu)
if physical_network in self.physnet_mtus:
mtu.append(int(self.physnet_mtus[physical_network]))
return min(mtu) if mtu else 0
/usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/helpers.py
class BaseTypeDriver(api.TypeDriver):
"""BaseTypeDriver for functions common to Segment and flat."""
def __init__(self):
try:
self.physnet_mtus = utils.parse_mappings(
cfg.CONF.ml2.physical_network_mtus
)
except Exception:
self.physnet_mtus = []
def get_mtu(self, physical_network=None):
return cfg.CONF.ml2.segment_mtu
class SegmentTypeDriver(BaseTypeDriver):
"""SegmentTypeDriver for segment allocation.
Provide methods helping to perform segment allocation fully or partially
specified.
"""
def __init__(self, model):
super(SegmentTypeDriver, self).__init__()
self.model = model
self.primary_keys = set(dict(model.__table__.columns))
self.primary_keys.remove("allocated")
vxlan网络类型如何获取MTU:
class VxlanTypeDriver(type_tunnel.EndpointTunnelTypeDriver): # 父类EndpointTunnelTypeDriver
def __init__(self):
super(VxlanTypeDriver, self).__init__(
VxlanAllocation, VxlanEndpoints)
def get_type(self):
return p_const.TYPE_VXLAN
def initialize(self):
try:
self._initialize(cfg.CONF.ml2_type_vxlan.vni_ranges)
except n_exc.NetworkTunnelRangeError:
LOG.exception(_LE("Failed to parse vni_ranges. "
"Service terminated!"))
raise SystemExit()
def get_endpoints(self):
"""Get every vxlan endpoints from database."""
vxlan_endpoints = self._get_endpoints()
return [{'ip_address': vxlan_endpoint.ip_address,
'udp_port': vxlan_endpoint.udp_port,
'host': vxlan_endpoint.host}
for vxlan_endpoint in vxlan_endpoints]
def add_endpoint(self, ip, host, udp_port=p_const.VXLAN_UDP_PORT):
return self._add_endpoint(ip, host, udp_port=udp_port)
def get_mtu(self, physical_network=None):
mtu = super(VxlanTypeDriver, self).get_mtu()
return mtu - p_const.VXLAN_ENCAP_OVERHEAD if mtu else 0 # mtu - vxlan开销,自动减去vxlan overhead
from neutron.plugins.common import constants as p_const
/usr/lib/python2.7/site-packages/neutron/plugins/common/constants.py
# Network Type MTU overhead
GENEVE_ENCAP_MIN_OVERHEAD = 50
GRE_ENCAP_OVERHEAD = 42
VXLAN_ENCAP_OVERHEAD = 50 # vxlan开销
class EndpointTunnelTypeDriver(TunnelTypeDriver):
class TunnelTypeDriver(helpers.SegmentTypeDriver):
"""Define stable abstract interface for ML2 type drivers.
tunnel type networks rely on tunnel endpoints. This class defines abstract
methods to manage these endpoints.
"""
def get_mtu(self, physical_network=None):
seg_mtu = super(TunnelTypeDriver, self).get_mtu()
mtu = []
if seg_mtu > 0:
mtu.append(seg_mtu)
if cfg.CONF.ml2.path_mtu > 0:
mtu.append(cfg.CONF.ml2.path_mtu)
return min(mtu) if mtu else 0
gre网络类型如何获取MTU:
class GreTypeDriver(type_tunnel.EndpointTunnelTypeDriver): # 父类也是EndpointTunnelTypeDriver
def __init__(self):
super(GreTypeDriver, self).__init__(
GreAllocation, GreEndpoints)
def get_type(self):
return p_const.TYPE_GRE
def initialize(self):
try:
self._initialize(cfg.CONF.ml2_type_gre.tunnel_id_ranges)
except n_exc.NetworkTunnelRangeError:
LOG.exception(_LE("Failed to parse tunnel_id_ranges. "
"Service terminated!"))
raise SystemExit()
def get_endpoints(self):
"""Get every gre endpoints from database."""
gre_endpoints = self._get_endpoints()
return [{'ip_address': gre_endpoint.ip_address,
'host': gre_endpoint.host}
for gre_endpoint in gre_endpoints]
def add_endpoint(self, ip, host):
return self._add_endpoint(ip, host)
def get_mtu(self, physical_network=None):
mtu = super(GreTypeDriver, self).get_mtu(physical_network)
return mtu - p_const.GRE_ENCAP_OVERHEAD if mtu else 0 # mtu - gre开销,自动减去gre overhead
from neutron.plugins.common import constants as p_const
/usr/lib/python2.7/site-packages/neutron/plugins/common/constants.py
# Network Type MTU overhead
GENEVE_ENCAP_MIN_OVERHEAD = 50
GRE_ENCAP_OVERHEAD = 42 # gre开销,为什么是42,还不清楚
VXLAN_ENCAP_OVERHEAD = 50 # vxlan开销
L版发现neutron多了种网络类型geneve,Geneve简介,暂时还不知道怎么玩的
http://blog.csdn.net/yeasy/article/details/39928153
3、neutron.conf
advertise_mtu = true
以前的做法:
[root@controller2 ~(keystone_admin)]# cat /etc/neutron/dnsmasq-neutron.conf # 对所有network都生效
dhcp-option-force=26,1450 # 现在可以把这个去掉
log-facility=/var/log/neutron/neutron-dnsmasq.log
/usr/lib/python2.7/site-packages/neutron/agent/linux/dhcp.py
class Dnsmasq(DhcpLocalProcess):
# The ports that need to be opened when security policies are active
# on the Neutron port used for DHCP. These are provided as a convenience
# for users of this class.
if cfg.CONF.advertise_mtu:
mtu = self.network.mtu
# Do not advertise unknown mtu
if mtu > 0:
cmd.append('--dhcp-option-force=option:mtu,%d' % mtu) # 看这里
# Cap the limit because creating lots of subnets can inflate
# this possible lease cap.
cmd.append('--dhcp-lease-max=%d' %
min(possible_leases, self.conf.dnsmasq_lease_max))
cmd.append('--conf-file=%s' % self.conf.dnsmasq_config_file)
if self.conf.dnsmasq_dns_servers:
cmd.extend(
'--server=%s' % server
for server in self.conf.dnsmasq_dns_servers)
参考链接
http://www.cnblogs.com/sammyliu/p/5079898.html
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。