Skip to content

Commit

Permalink
Add relevant VRF & static routing configuration for Cisco nodes. (#238)
Browse files Browse the repository at this point in the history
* Add management VRF and default route for csr1kv and cat8kv.

* Update hostfwd rules and add mgmt VRF configuration to IOS-XR.

* Add static route in management VRF for n9kv.

* Add mgmt vrf static route for cat9kv

* format

* Add VRF config for gRPC on XR

---------

Co-authored-by: Roman Dodin <dodin.roman@gmail.com>
  • Loading branch information
kaelemc and hellt authored Aug 1, 2024
1 parent a5238e0 commit 92756b6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 45 deletions.
9 changes: 9 additions & 0 deletions c8000v/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,17 @@ def bootstrap_config(self):
else:
self.wait_write("ip domain-name example.com")
self.wait_write("crypto key generate rsa modulus 2048")

self.wait_write("vrf definition clab-mgmt")
self.wait_write("address-family ipv4")
self.wait_write("exit")
self.wait_write("description Containerlab management VRF (DO NOT DELETE)")
self.wait_write("exit")

self.wait_write("ip route vrf clab-mgmt 0.0.0.0 0.0.0.0 10.0.0.2")

self.wait_write("interface GigabitEthernet1")
self.wait_write("vrf forwarding clab-mgmt")
self.wait_write("ip address 10.0.0.15 255.255.255.0")
self.wait_write("no shut")
self.wait_write("exit")
Expand Down
3 changes: 3 additions & 0 deletions cat9kv/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def bootstrap_config(self):

self.wait_write("no ip domain lookup")

# add mgmt vrf static route
self.wait_write("ip route vrf Mgmt-vrf 0.0.0.0 0.0.0.0 10.0.0.2")

self.wait_write("interface GigabitEthernet0/0")
self.wait_write("ip address 10.0.0.15 255.255.255.0")
self.wait_write("no shut")
Expand Down
9 changes: 9 additions & 0 deletions csr/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,17 @@ def bootstrap_config(self):
else:
self.wait_write("ip domain-name example.com")
self.wait_write("crypto key generate rsa modulus 2048")

self.wait_write("vrf definition clab-mgmt")
self.wait_write("address-family ipv4")
self.wait_write("exit")
self.wait_write("description Containerlab management VRF (DO NOT DELETE)")
self.wait_write("exit")

self.wait_write("ip route vrf clab-mgmt 0.0.0.0 0.0.0.0 10.0.0.2")

self.wait_write("interface GigabitEthernet1")
self.wait_write("vrf forwarding clab-mgmt")
self.wait_write("ip address 10.0.0.15 255.255.255.0")
self.wait_write("no shut")
self.wait_write("exit")
Expand Down
20 changes: 5 additions & 15 deletions n9kv/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,6 @@ def __init__(self, hostname, username, password, conn_mode):
]
)

def gen_mgmt(self):
"""
Augment the parent class function to add gRPC port forwarding
"""
# call parent function to generate the mgmt interface
res = super(N9KV_vm, self).gen_mgmt()

# append gRPC forwarding if it was not added by common lib
if "hostfwd=tcp::50051-10.0.0.15:50051" not in res[-1]:
res[-1] = res[-1] + ",hostfwd=tcp::17051-10.0.0.15:50051"
vrnetlab.run_command(
["socat", "TCP-LISTEN:50051,fork", "TCP:127.0.0.1:17051"],
background=True,
)
return res

def bootstrap_spin(self):
"""This function should be called periodically to do work."""
Expand Down Expand Up @@ -153,6 +138,11 @@ def bootstrap_config(self):
self.wait_write(
f"username {self.username} password 0 {self.password} role network-admin"
)

# configure management vrf
self.wait_write("vrf context management")
self.wait_write("ip route 0.0.0.0/0 10.0.0.2")
self.wait_write("exit")

# configure mgmt interface
self.wait_write("interface mgmt0")
Expand Down
45 changes: 25 additions & 20 deletions xrv/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,42 @@ def bootstrap_config(self):
self.wait_write("show interface description")
self.wait_write("configure")
self.wait_write("hostname {}".format(self.hostname))
# configure netconf

# configure management vrf
self.wait_write("vrf clab-mgmt")
self.wait_write("description Containerlab management VRF (DO NOT DELETE)")
self.wait_write("address-family ipv4 unicast")
self.wait_write("exit")
self.wait_write("exit")

# add static route for management
self.wait_write("router static")
self.wait_write("vrf clab-mgmt")
self.wait_write("address-family ipv4 unicast")
self.wait_write("0.0.0.0/0 10.0.0.2")
self.wait_write("exit")
self.wait_write("exit")
self.wait_write("exit")

# configure ssh & netconf w/ vrf
self.wait_write("ssh server v2")
self.wait_write("ssh server vrf clab-mgmt")
self.wait_write("ssh server netconf port 830") # for 5.1.1
self.wait_write("ssh server netconf vrf default") # for 5.3.3
self.wait_write("ssh server netconf vrf clab-mgmt") # for 5.3.3
self.wait_write("netconf agent ssh") # for 5.1.1
self.wait_write("netconf-yang agent ssh") # for 5.3.3

# configure gNMI
self.wait_write("grpc port 57400")
self.wait_write("grpc vrf clab-mgmt")
self.wait_write("grpc no-tls")

# configure xml agent
self.wait_write("xml agent tty")

# configure mgmt interface
self.wait_write("interface MgmtEth 0/0/CPU0/0")
self.wait_write("vrf clab-mgmt")
self.wait_write("no shutdown")
self.wait_write("ipv4 address 10.0.0.15/24")
self.wait_write("exit")
Expand Down Expand Up @@ -210,23 +232,6 @@ def startup_config(self):
self.wait_write("exit")


def gen_mgmt(self):
"""
Augment the parent class function to add gNMI port forwarding
"""
# call parent function to generate first mgmt interface (e1000)
res = super(XRV_vm, self).gen_mgmt()

# append gNMI forwarding if it was not added by common lib
if "hostfwd=tcp::57400-10.0.0.15:57400" not in res[-1]:
res[-1] = res[-1] + ",hostfwd=tcp::17400-10.0.0.15:57400"
vrnetlab.run_command(
["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"],
background=True,
)
return res


class XRV(vrnetlab.VR):
def __init__(self, hostname, username, password, conn_mode):
super(XRV, self).__init__(username, password)
Expand Down
40 changes: 30 additions & 10 deletions xrv9k/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def gen_mgmt(self):
res.extend(
[
"-netdev",
"user,id=mgmt,net=10.0.0.0/24,tftp=/tftpboot,hostfwd=tcp::2022-10.0.0.15:22,hostfwd=udp::2161-10.0.0.15:161,hostfwd=tcp::2830-10.0.0.15:830,hostfwd=tcp::17400-10.0.0.15:57400",
"user,id=mgmt,net=10.0.0.0/24,"
"tftp=/tftpboot,"
"hostfwd=tcp:0.0.0.0:22-10.0.0.15:22,"
"hostfwd=udp:0.0.0.0:161-10.0.0.15:161,"
"hostfwd=tcp:0.0.0.0:830-10.0.0.15:830,"
"hostfwd=tcp:0.0.0.0:57400-10.0.0.15:57400"
]
)
# dummy interface for xrv9k ctrl interface
Expand All @@ -103,11 +108,6 @@ def gen_mgmt(self):
"tap,ifname=dev-dummy,id=dev-dummy,script=no,downscript=no",
]
)
# add socat for gNMI port we added on L76, since it's not part of vrnetlab core lib
vrnetlab.run_command(
["socat", "TCP-LISTEN:57400,fork", "TCP:127.0.0.1:17400"],
background=True,
)

return res

Expand Down Expand Up @@ -238,21 +238,41 @@ def bootstrap_config(self):

self.wait_write("configure")
self.wait_write(f"hostname {self.hostname}")
# configure netconf

# configure management vrf
self.wait_write("vrf clab-mgmt")
self.wait_write("description Containerlab management VRF (DO NOT DELETE)")
self.wait_write("address-family ipv4 unicast")
self.wait_write("exit")
self.wait_write("exit")

# add static route for management
self.wait_write("router static")
self.wait_write("vrf clab-mgmt")
self.wait_write("address-family ipv4 unicast")
self.wait_write("0.0.0.0/0 10.0.0.2")
self.wait_write("exit")
self.wait_write("exit")
self.wait_write("exit")

# configure ssh & netconf w/ vrf
self.wait_write("ssh server v2")
self.wait_write("ssh server vrf clab-mgmt")
self.wait_write("ssh server netconf port 830") # for 5.1.1
self.wait_write("ssh server netconf vrf default") # for 5.3.3
self.wait_write("ssh server netconf vrf clab-mgmt") # for 5.3.3
self.wait_write("netconf agent ssh") # for 5.1.1
self.wait_write("netconf-yang agent ssh") # for 5.3.3
# configure gNMI
self.wait_write("grpc port 57400")
self.wait_write("grpc vrf clab-mgmt")
self.wait_write("grpc no-tls")

# configure xml agent
self.wait_write("xml agent tty")

# configure mgmt interface
self.wait_write("interface MgmtEth 0/RP0/CPU0/0")
self.wait_write("interface MgmtEth0/RP0/CPU0/0")
self.wait_write("vrf clab-mgmt")
self.wait_write("no shutdown")
self.wait_write("ipv4 address 10.0.0.15/24")
self.wait_write("exit")
Expand Down

0 comments on commit 92756b6

Please sign in to comment.