Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate module support lists from device features (implements #689) #853

Merged
merged 6 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion netsim/augment/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,46 @@ def get_consolidated_device_data(node: Box, defaults: Box) -> Box:
def get_provider(node: Box, defaults: Box) -> str:
return node.get('provider',defaults.provider)

"""
Build module supported_on lists based on device features settings
"""
def build_module_support_lists(topology: Box) -> None:
sets = topology.defaults
devs = sets.devices

for dname in list(devs.keys()): # Iterate over all known devices
ddata = devs[dname]
if not 'features' in ddata: # Skip devices without features
continue

for m in list(ddata.features.keys()): # Iterate over device features
if not m in sets:
continue # Weird feature name, skip it

mdata = sets[m] # Get module data
if not 'attributes' in mdata: # Is this a valid module?
continue # ... not without attributes

if not 'supported_on' in mdata: # Create 'supported_on' list if needed
mdata.supported_on = []

if ddata.feature[m] is False and dname in mdata.supported_on:
mdata.supported_on.remove(dname) # The device DOES NOT support the module
ddata.features.pop(m) # Remove the feature so it won't crash the transformation
continue

if not dname in mdata.supported_on: # Append device to module support list if needed
mdata.supported_on.append(dname)

f_value = ddata.features[m]
if f_value is None or f_value is True: # Normalize features to dicts
ddata.features[m] = {}

"""
Initial device setting augmentation:

* Build supported_on module lists
* Future: Inherit device data from parent devices
"""
def augment_device_settings(topology: Box) -> None:
pass
build_module_support_lists(topology)
7 changes: 5 additions & 2 deletions netsim/augment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
from .. import devices as quirks
from ..data import global_vars

def transform_setup(topology: Box) -> None:
def topology_init(topology: Box) -> None:
global_vars.init(topology)
augment.config.attributes(topology)
augment.devices.augment_device_settings(topology)

def transform_setup(topology: Box) -> None:
topology_init(topology)
augment.topology.check_required_elements(topology)
topology.nodes = augment.nodes.create_node_dict(topology.nodes)
if 'links' in topology:
augment.links.links_init(topology)

augment.components.expand_components(topology)

augment.devices.augment_device_settings(topology)
augment.plugin.init(topology) # Initialize plugins very early on in case they modify extra attributes
augment.plugin.execute('init',topology)
augment.topology.check_tools(topology)
Expand Down
10 changes: 8 additions & 2 deletions netsim/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .. import common
from .. import read_topology
from .. import data
from ..augment import main

DEVICES_TO_SKIP = ['none','unknown']

Expand Down Expand Up @@ -133,8 +134,11 @@ def show_module_support(settings: Box, args: argparse.Namespace) -> None:
else:
dev_mods = [ m for m in mod_list if device in settings[m].supported_on ]
if args.device and args.format == 'yaml':
for m in mod_list:
result[m] = settings.devices[device].features.get(m,True)
for m in dev_mods:
f_value = settings.devices[device].features.get(m,True)
if f_value is None or (not f_value and isinstance(f_value,dict)):
f_value = True
result[m] = f_value
else:
result[device] = dev_mods
if args.format == 'text':
Expand Down Expand Up @@ -298,9 +302,11 @@ def run(cli_args: typing.List[str]) -> None:
empty_file = "package:cli/empty.yml"
loc_defaults = empty_file if args.system else ""
topology = read_topology.load(empty_file,loc_defaults,"package:topology-defaults.yml")

if topology is None:
common.fatal("Cannot read system settings")
return

main.topology_init(topology)
settings = topology.defaults
show_dispatch[args.action](settings,args)
42 changes: 24 additions & 18 deletions netsim/devices/csr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,39 @@ group_vars:
node:
min_mtu: 1500
features:
bgp:
local_as: True
vrf_local_as: True
local_as_ibgp: True
activate_af: True
initial:
ipv4:
unnumbered: True
unnumbered: true
ipv6:
lla: True
ospf:
unnumbered: True
lla: true
bfd: true
bgp:
activate_af: true
local_as: true
local_as_ibgp: true
vrf_local_as: true
eigrp: true
gateway:
protocol:
- vrrp
isis:
unnumbered:
ipv4: True
ipv6: True
network: True
ipv4: true
ipv6: true
network: true
mpls:
ldp: True
bgp: True
vpn: True
6pe: True
6pe: true
bgp: true
ldp: true
vpn: true
ospf:
unnumbered: true
sr: true
vlan:
model: switch
svi_interface_name: BDI{vlan}
gateway:
protocol: [ vrrp ]
vrf: true
vxlan: true
libvirt:
image: cisco/csr1000v
create:
Expand Down
54 changes: 29 additions & 25 deletions netsim/devices/eos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,44 @@ group_vars:
ansible_network_os: eos
ansible_connection: network_cli
features:
bgp:
local_as: True
vrf_local_as: True
local_as_ibgp: True
activate_af: True
initial:
system_mtu: True
system_mtu: true
ipv4:
unnumbered: True
unnumbered: true
ipv6:
lla: True
ospf:
unnumbered: True
lla: true
bfd: true
bgp:
activate_af: true
local_as: true
local_as_ibgp: true
vrf_local_as: true
evpn:
asymmetrical_irb: true
bundle: [ vlan_aware ]
irb: true
gateway:
protocol: [ anycast, vrrp ]
isis:
unnumbered:
ipv4: True
ipv6: True
network: True
ipv4: true
ipv6: true
network: true
mpls:
ldp: True
bgp: True
vpn: True
6pe: True
6pe: true
bgp: true
ldp: true
vpn: true
ospf:
unnumbered: true
sr: true
vlan:
model: l3-switch
native_routed: true
subif_name: '{ifname}.{subif_index}'
svi_interface_name: Vlan{vlan}
subif_name: "{ifname}.{subif_index}"
native_routed: True
evpn:
irb: True
asymmetrical_irb: True
bundle: [ vlan_aware ]
gateway:
protocol: [ anycast, vrrp ]
vrf: true
vxlan: true
clab:
interface:
name: et{ifindex}
Expand Down
35 changes: 19 additions & 16 deletions netsim/devices/iosv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,37 @@ libvirt:
virtualbox:
image: cisco/iosv
features:
bfd: true
bgp:
local_as: True
vrf_local_as: True
local_as_ibgp: True
activate_af: True
local_as: true
vrf_local_as: true
local_as_ibgp: true
activate_af: true
initial:
ipv4:
unnumbered: False
unnumbered: false
ipv6:
lla: True
lla: true
ospf:
unnumbered: True
unnumbered: true
isis:
unnumbered:
ipv4: True
ipv6: True
network: True
ipv4: true
ipv6: true
network: true
eigrp: true
mpls:
ldp: True
bgp: True
vpn: True
6pe: True
ldp: true
bgp: true
vpn: true
6pe: true
vlan:
model: router
svi_interface_name: BVI{bvi}
subif_name: "{ifname}.{subif_index}"
mixed_trunk: True
native_routed: True
mixed_trunk: true
native_routed: true
vrf: true
gateway:
protocol: [ vrrp ]
external:
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/bfd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BFD (RFC 5880) default settings and attributes
#
supported_on: [ srlinux, sros, iosv, csr, nxos, eos, vyos, arubacx, none ]
supported_on: [ srlinux, sros, nxos, vyos, arubacx, none ]
min_echo_rx: 0 # Echo function, 0=disabled by default
multiplier: 3 # Detection time multiplier, number of packets lost before down
attributes:
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/bgp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BGP default settings and attributes
#
supported_on: [ cumulus, cumulus_nvue, eos, frr, csr, iosv, nxos, asav, vsrx, vyos, routeros,
supported_on: [ cumulus, cumulus_nvue, frr, nxos, asav, vsrx, vyos, routeros,
srlinux, sros, none, dellos10, routeros7, vmx, iosxr, arubacx, vptx, none ]
ebgp_role: external
advertise_roles: [ stub ]
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/eigrp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EIGRP default settings and attributes
#
supported_on: [ csr, iosv, nxos, none ]
supported_on: [ nxos, none ]
transform_after: [ vlan,vrf ]
config_after: [ vlan ]
as: 1
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/evpn.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EVPN default settings and attributes
requires: [ bgp ]
supported_on: [ sros, srlinux, frr, eos, vyos, dellos10, cumulus, nxos, arubacx, vptx, none ]
supported_on: [ sros, srlinux, frr, vyos, dellos10, cumulus, nxos, arubacx, vptx, none ]
no_propagate: [ start_transit_vni, transport, vlan_bundle_service, as ]
transform_after: [ vlan, vxlan, vrf ]
config_after: [ vlan, vxlan, vrf ]
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/gateway.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gateway (FHRP) default settings and attributes
#
supported_on: [ none, eos, cumulus, iosv, csr, nxos, sros, srlinux, vyos, dellos10, arubacx ]
supported_on: [ none, cumulus, nxos, sros, srlinux, vyos, dellos10, arubacx ]
transform_after: [ vlan, vrf, ospf, isis, eigrp ]
config_after: [ vlan,vrf ]
id: -2
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/isis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ISIS default settings and attributes
#
supported_on: [ eos, frr, csr, iosv, nxos, asav, vsrx, srlinux, sros, vyos, vmx, iosxr, vptx, none ]
supported_on: [ frr, nxos, asav, vsrx, srlinux, sros, vyos, vmx, iosxr, vptx, none ]
area: "49.0001"
type: level-2
transform_after: [ vlan,vrf ]
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/mpls.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MPLS (LDP, BGP LU, L3VPN, 6PE) default settings and attributes
#
supported_on: [ eos, iosv, csr, routeros, vyos, routeros7, sros, vmx, vsrx, frr, none, vptx, arubacx ]
supported_on: [ routeros, vyos, routeros7, sros, vmx, vsrx, frr, none, vptx, arubacx ]
config_after: [ vlan, ospf, isis, bgp ]
transform_after: [ vlan, bgp ]
ldp: True
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/ospf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
area: 0.0.0.0
supported_on: [
arcos, cumulus, cumulus_nvue, eos, fortios, frr, csr, iosv, nxos, vsrx, vyos, routeros,
arcos, cumulus, cumulus_nvue, fortios, frr, nxos, vsrx, vyos, routeros,
srlinux, sros, dellos10, routeros7, vmx, iosxr, arubacx, vptx, none ]
transform_after: [ vlan,vrf ]
config_after: [ vlan ]
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/sr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SR-MPLS default settings and attributes
#
requires: [ isis ]
supported_on: [ csr, eos, srlinux, sros, vsrx, vmx, vptx, none ]
supported_on: [ srlinux, sros, vsrx, vmx, vptx, none ]
transform_after: [ vlan ]
attributes:
global:
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/vlan.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VLAN default settings and attributes
#
supported_on: [ eos, iosv, csr, vyos, dellos10, srlinux, none, routeros, nxos, frr, cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx, none ]
supported_on: [ vyos, dellos10, srlinux, none, routeros, nxos, frr, cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx, none ]
no_propagate: [ start_vlan_id, mode ]
start_vlan_id: 1000
mode: irb
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/vrf.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VRF default settings and attributes
#
supported_on: [ eos, iosv, csr, routeros, dellos10, vyos, cumulus_nvue, nxos, srlinux, frr, cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx, none ]
supported_on: [ routeros, dellos10, vyos, cumulus_nvue, nxos, srlinux, frr, cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx, none ]
config_after: [ vlan, ospf, isis, bgp, mpls ]
transform_after: [ vlan, bgp ]
as: 65000
Expand Down
2 changes: 1 addition & 1 deletion netsim/modules/vxlan.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VXLAN default settings and attributes
#
supported_on: [ eos, nxos, vyos, csr, dellos10, srlinux, frr, cumulus, sros, arubacx, vptx, none ]
supported_on: [ nxos, vyos, dellos10, srlinux, frr, cumulus, sros, arubacx, vptx, none ]
requires: [ vlan ]
config_after: [ vrf ] # For platforms that suppport L3 VXLAN, vrfs must be created first
transform_after: [ vlan, vrf ]
Expand Down