Skip to content

Commit

Permalink
cms/openstack: Set MTU for VM and GW ports.
Browse files Browse the repository at this point in the history
Signed-off-by: Frode Nordahl <frode.nordahl@canonical.com>
  • Loading branch information
fnordahl committed Oct 25, 2023
1 parent 1817839 commit e6d992e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
25 changes: 17 additions & 8 deletions ovn-tester/cms/openstack/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class NeutronNetwork:
network: LSwitch
ports: Dict[str, LSPort]
name: str
mtu: int
security_group: Optional[PortGroup] = None

def __post_init__(self):
Expand Down Expand Up @@ -204,7 +205,8 @@ def new_external_network(
"""
ext_net_uuid = uuid.uuid4()
ext_net_name = f"ext_net_{ext_net_uuid}"
ext_net = self._create_project_net(f"ext_net_{ext_net_uuid}", 1500)
mtu = 1500
ext_net = self._create_project_net(f"ext_net_{ext_net_uuid}", mtu)
ext_net_port = self._add_metadata_port(ext_net, str(ext_net_uuid))
provider_port = self._add_provider_network_port(
ext_net, provider_network
Expand All @@ -216,6 +218,7 @@ def new_external_network(
provider_port.uuid: provider_port,
},
name=ext_net_name,
mtu=mtu,
)

def connect_external_network_to_project(
Expand Down Expand Up @@ -273,14 +276,16 @@ def add_internal_network_to_project(
:return: None
"""
int_net_name = f"int_net_{project.uuid}"
int_net = self._create_project_net(int_net_name, 1442)
mtu = 1442
int_net = self._create_project_net(int_net_name, mtu)

int_net_port = self._add_metadata_port(int_net, project.uuid)
security_group = self._create_default_security_group()
neutron_int_network = NeutronNetwork(
network=int_net,
ports={int_net_port.uuid: int_net_port},
name=int_net_name,
mtu=mtu,
security_group=security_group,
)

Expand All @@ -301,7 +306,7 @@ def add_vm_to_project(self, project: Project, vm_name: str):
vm_port = self._add_vm_port(
project.int_net, project.uuid, compute, vm_name
)
compute.bind_port(vm_port)
compute.bind_port(vm_port, mtu_request=project.int_net.mtu)

project.vm_ports.append(vm_port)

Expand Down Expand Up @@ -442,9 +447,7 @@ def _add_vm_port(
"neutron:subnet_pool_addr_scope4": "",
"neutron:subnet_pool_addr_scope6": "",
}
port_options = (
f"requested-chassis={chassis.container}"
)
port_options = f"requested-chassis={chassis.container}"
ls_port = self.nbctl.ls_port_add(
lswitch=neutron_net.network,
name=port_name,
Expand Down Expand Up @@ -543,7 +546,7 @@ def _add_router_port_external_gw(
"""
port_ip = self.next_external_ip()
return self._add_router_port(
neutron_net.network, router, port_ip, "", True
neutron_net.network, router, port_ip, "", True, neutron_net.mtu
)

def _add_router_port(
Expand All @@ -553,6 +556,7 @@ def _add_router_port(
port_ip: DualStackIP,
project_id: str = "",
is_gw: bool = False,
mtu: Optional[int] = None,
) -> (LSPort, LRPort):
"""Add a pair of ports that connect Logical Router and Logical Switch.
Expand Down Expand Up @@ -594,7 +598,12 @@ def _add_router_port(
}

lr_port = self.nbctl.lr_port_add(
router, router_port_name, str(RandMac()), port_ip, lrp_external_ids
router,
router_port_name,
str(RandMac()),
port_ip,
lrp_external_ids,
{"gateway_mtu": str(mtu)} if mtu else None,
)

ls_port = self.nbctl.ls_port_add(
Expand Down
30 changes: 27 additions & 3 deletions ovn-tester/ovn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ def set_global_external_id(self, key, value):
("external_ids", {key: str(value)}),
).execute(check_error=True)

def add_port(self, port, bridge, internal=True, ifaceid=None):
def add_port(
self,
port,
bridge,
internal=True,
ifaceid=None,
mtu_request: Optional[int] = None,
):
name = port.name
with self.idl.transaction(check_error=True) as txn:
txn.add(self.idl.add_port(bridge, name))
Expand All @@ -221,6 +228,12 @@ def add_port(self, port, bridge, internal=True, ifaceid=None):
txn.add(
self.idl.iface_set_external_id(name, "iface-id", ifaceid)
)
if mtu_request:
txn.add(
self.idl.db_set(
"Interface", name, ("mtu_request", mtu_request)
)
)

def del_port(self, port):
self.idl.del_port(port.name).execute(check_error=True)
Expand Down Expand Up @@ -448,7 +461,13 @@ def lr_add(self, name, ext_ids: Optional[Dict] = None):
return LRouter(name=name, uuid=uuid)

def lr_port_add(
self, router, name, mac, dual_ip=None, ext_ids: Optional[Dict] = None
self,
router,
name,
mac,
dual_ip=None,
ext_ids: Optional[Dict] = None,
options: Optional[Dict] = None,
):
ext_ids = {} if ext_ids is None else ext_ids
networks = []
Expand All @@ -458,7 +477,12 @@ def lr_port_add(
networks.append(f'{dual_ip.ip6}/{dual_ip.plen6}')

self.idl.lrp_add(
router.uuid, name, str(mac), networks, external_ids=ext_ids
router.uuid,
name,
str(mac),
networks,
external_ids=ext_ids,
options=options,
).execute()
return LRPort(name=name, mac=mac, ip=dual_ip)

Expand Down
10 changes: 8 additions & 2 deletions ovn-tester/ovn_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ def unprovision_port(self, cluster, port):
self.lports.remove(port)

@ovn_stats.timeit
def bind_port(self, port):
def bind_port(self, port, mtu_request: Optional[int] = None):
log.info(f'Binding lport {port.name} on {self.container}')
self.vsctl.add_port(port, 'br-int', internal=True, ifaceid=port.name)
self.vsctl.add_port(
port,
'br-int',
internal=True,
ifaceid=port.name,
mtu_request=mtu_request,
)
# Skip creating a netns for "passive" ports, we won't be sending
# traffic on those.
if not port.passive:
Expand Down

0 comments on commit e6d992e

Please sign in to comment.