Skip to content

Commit 9078c56

Browse files
michelredondovista-Arthur-K-99kaelemchellt
authored
nokia_sros: Add pass-through management interface support (#272)
* vrnetlab: Add pass-through management interfaces * vjunos: Add pass-through management interface support * vrnetlab: Use JSON output of iproute2 * vrnetlab: Add exception for serial console ports 5000-5007 for transparent mode mgmt interface * vrnetlab: Remove non-working port 5000 tc mirred exception, redirect to correct interface * vrnetlab: Use tc clsact qdisc and flower matching as best practice * vrnetlab: Re-add workaround for serial ports in transparent mgmt mode * vrnetlab: Add IPv6 support to management address/gw functions * vjunos: Add IPv6 management addresses, fix v4 address templating * vrnetlab: Set dummy IPv6 address/gw for hostfwd management * Fix CSR1000v and c8000v (#269) * Remove whitespaces from IMG_NAME and IMG_VENDOR * Fix Cisco CSR1000v * Fix Cisco c8000v * Use env var passed from containerlab for IOL launch PID (#270) * nokia_sros: Add pass-through management interface support * fix comment * change mgmt address parsing * added self.mgmt_nic_passthrough to VR and VM classes * remove copy of a healthcheck * formatting * added mgmt passthrough to the VR class and aligned SR OS * added v6 address to bof --------- Co-authored-by: vista <vista@birb.network> Co-authored-by: Athanasios Kompouras <kompourasathanasios1999@gmail.com> Co-authored-by: Kaelem <62122480+kaelemc@users.noreply.github.com> Co-authored-by: Roman Dodin <dodin.roman@gmail.com>
1 parent baeab04 commit 9078c56

File tree

3 files changed

+371
-152
lines changed

3 files changed

+371
-152
lines changed

common/vrnetlab.py

+43-26
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
self._cpu = cpu
9999
self._smp = smp
100100

101-
# various settings
101+
# various settings
102102
self.uuid = None
103103
self.fake_start_date = None
104104
self.nic_type = "e1000"
@@ -109,14 +109,18 @@ def __init__(
109109
# to have them allocated sequential from eth1
110110
self.highest_provisioned_nic_num = 0
111111

112-
# Whether the management interface is pass-through or host-forwarded
113-
self.mgmt_nic_passthrough = mgmt_passthrough
112+
# Whether the management interface is pass-through or host-forwarded.
113+
# Host-forwarded is the original vrnetlab mode where a VM gets a static IP for its management address,
114+
# which **does not** match the eth0 interface of a container.
115+
# In pass-through mode the VM container uses the same IP as the container's eth0 interface and transparently forwards traffic between the two interfaces.
116+
# See https://github.com/hellt/vrnetlab/issues/286
117+
self.mgmt_passthrough = mgmt_passthrough
114118
mgmt_passthrough_override = os.environ.get("CLAB_MGMT_PASSTHROUGH", "")
115119
if mgmt_passthrough_override:
116-
self.mgmt_nic_passthrough = mgmt_passthrough_override.lower() == "true"
120+
self.mgmt_passthrough = mgmt_passthrough_override.lower() == "true"
117121

118122
# Populate management IP and gateway
119-
if self.mgmt_nic_passthrough:
123+
if self.mgmt_passthrough:
120124
self.mgmt_address_ipv4, self.mgmt_address_ipv6 = self.get_mgmt_address()
121125
self.mgmt_gw_ipv4, self.mgmt_gw_ipv6 = self.get_mgmt_gw()
122126
else:
@@ -353,11 +357,13 @@ def gen_mgmt(self):
353357
self.mgmt_mac = mac
354358
res.append(self.nic_type + f",netdev=p00,mac={self.mgmt_mac}")
355359

356-
if self.mgmt_nic_passthrough:
360+
if self.mgmt_passthrough:
357361
# mgmt interface is passthrough - we just create a normal mirred tap interface
358362
if self.conn_mode == "tc":
359363
res.append("-netdev")
360-
res.append("tap,id=p00,ifname=tap0,script=/etc/tc-tap-mgmt-ifup,downscript=no")
364+
res.append(
365+
"tap,id=p00,ifname=tap0,script=/etc/tc-tap-mgmt-ifup,downscript=no"
366+
)
361367
self.create_tc_tap_mgmt_ifup()
362368
else:
363369
# mgmt interface is special - we use qemu user mode network
@@ -379,41 +385,42 @@ def gen_mgmt(self):
379385
return res
380386

381387
def get_mgmt_address(self):
382-
""" Returns the IPv4 and IPv6 address of the eth0 interface of the container"""
388+
"""Returns the IPv4 and IPv6 address of the eth0 interface of the container"""
383389
stdout, _ = run_command(["ip", "--json", "address", "show", "dev", "eth0"])
384-
command_json = json.loads(stdout.decode('utf-8'))
385-
intf_addrinfos = command_json[0]['addr_info']
386-
390+
command_json = json.loads(stdout.decode("utf-8"))
391+
intf_addrinfos = command_json[0]["addr_info"]
387392
mgmt_cidr_v4 = None
388393
mgmt_cidr_v6 = None
389394
for addrinfo in intf_addrinfos:
390-
if addrinfo['family'] == 'inet' and addrinfo['scope'] == 'global':
391-
mgmt_address_v4 = addrinfo['local']
392-
mgmt_prefixlen_v4 = addrinfo['prefixlen']
393-
mgmt_cidr_v4 = mgmt_address_v4 + '/' + str(mgmt_prefixlen_v4)
394-
if addrinfo['family'] == 'inet6' and addrinfo['scope'] == 'global':
395-
mgmt_address_v6 = addrinfo['local']
396-
mgmt_prefixlen_v6 = addrinfo['prefixlen']
397-
mgmt_cidr_v6 = mgmt_address_v6 + '/' + str(mgmt_prefixlen_v6)
395+
if addrinfo["family"] == "inet" and addrinfo["scope"] == "global":
396+
mgmt_address_v4 = addrinfo["local"]
397+
mgmt_prefixlen_v4 = addrinfo["prefixlen"]
398+
mgmt_cidr_v4 = mgmt_address_v4 + "/" + str(mgmt_prefixlen_v4)
399+
if addrinfo["family"] == "inet6" and addrinfo["scope"] == "global":
400+
mgmt_address_v6 = addrinfo["local"]
401+
mgmt_prefixlen_v6 = addrinfo["prefixlen"]
402+
mgmt_cidr_v6 = mgmt_address_v6 + "/" + str(mgmt_prefixlen_v6)
398403

399404
if not mgmt_cidr_v4:
400405
raise ValueError("No IPv4 address set on management interface eth0!")
401406

402407
return mgmt_cidr_v4, mgmt_cidr_v6
403408

404409
def get_mgmt_gw(self):
405-
""" Returns the IPv4 and IPv6 default gateways of the container, used for generating the management default route"""
410+
"""Returns the IPv4 and IPv6 default gateways of the container, used for generating the management default route"""
406411
stdout_v4, _ = run_command(["ip", "--json", "-4", "route", "show", "default"])
407-
command_json_v4 = json.loads(stdout_v4.decode('utf-8'))
412+
command_json_v4 = json.loads(stdout_v4.decode("utf-8"))
408413
try:
409-
mgmt_gw_v4 = command_json_v4[0]['gateway']
414+
mgmt_gw_v4 = command_json_v4[0]["gateway"]
410415
except IndexError as e:
411-
raise IndexError("No default gateway route on management interface eth0!") from e
416+
raise IndexError(
417+
"No default gateway route on management interface eth0!"
418+
) from e
412419

413420
stdout_v6, _ = run_command(["ip", "--json", "-6", "route", "show", "default"])
414-
command_json_v6 = json.loads(stdout_v6.decode('utf-8'))
421+
command_json_v6 = json.loads(stdout_v6.decode("utf-8"))
415422
try:
416-
mgmt_gw_v6 = command_json_v6[0]['gateway']
423+
mgmt_gw_v6 = command_json_v6[0]["gateway"]
417424
except IndexError:
418425
mgmt_gw_v6 = None
419426

@@ -723,9 +730,19 @@ def qemu_additional_args(self):
723730

724731

725732
class VR:
726-
def __init__(self, username, password):
733+
def __init__(self, username, password, mgmt_passthrough: bool = False):
727734
self.logger = logging.getLogger()
728735

736+
# Whether the management interface is pass-through or host-forwarded.
737+
# Host-forwarded is the original vrnetlab mode where a VM gets a static IP for its management address,
738+
# which **does not** match the eth0 interface of a container.
739+
# In pass-through mode the VM container uses the same IP as the container's eth0 interface and transparently forwards traffic between the two interfaces.
740+
# See https://github.com/hellt/vrnetlab/issues/286
741+
self.mgmt_passthrough = mgmt_passthrough
742+
mgmt_passthrough_override = os.environ.get("CLAB_MGMT_PASSTHROUGH", "")
743+
if mgmt_passthrough_override:
744+
self.mgmt_passthrough = mgmt_passthrough_override.lower() == "true"
745+
729746
try:
730747
os.mkdir("/tftpboot")
731748
except:

sros/docker/healthcheck.py

-18
This file was deleted.

0 commit comments

Comments
 (0)