Skip to content
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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pip3 install -e .
- `IncorrectAttr`, `IncorrectType`, `IncorrectValue` for validation errors
- `MissingValue` for required but missing data
- Use `log.fatal()`, `log.error()`, `log.warning()` for user-facing messages
- Add a `doc_url` parameter to every new `log.error()`/`log.warning()` call that has relevant user documentation (see `docs/dev/error-doc-url.md`). Use relative URLs with existing MyST anchors (for example, `doc_url='links/#links-types'`); add a new anchor only when absolutely necessary. If the target section does not explain why the error could happen, add a short caveat to it
- Never use `print()` in library code (allowed in CLI modules)

### File Structure Patterns
Expand Down
11 changes: 11 additions & 0 deletions docs/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ Lab topology could contain *lan*, *p2p*, *stub*, *loopback*, *lag*, and *tunnel*

The only reason to change the link types for a regular link is to force a Linux bridge to be used between two *libvirt* nodes to enable [packet capture](libvirt-capture). You do have to set the link **type** attribute to create [additional loopbacks](links-loopback) and [tunnels](links-tunnel).

```{warning}
_netlab_ checks whether the number of nodes attached to a link matches the link **type**: a *p2p* link must have exactly two nodes, and a *stub* or *loopback* link must have a single node. If you get an error because you added a node to a link with an explicit **type**, remove the **type** attribute (and let _netlab_ select the link type) or change it to *lan*.
```

(links-default-pools)=
## Default Link Prefix Allocation

Expand Down Expand Up @@ -159,6 +163,11 @@ defaults:
devices.eos.features.stub_loopback: True
```

```{warning}
* A loopback link must have a single node attached to it.
* Not all devices support additional loopback interfaces; check the *Additional loopbacks* column in the [interface parameters table](platform-initial-interfaces). _netlab_ reports an error when you add a loopback link (or turn a stub link into a loopback with the **stub_loopback** setting) to a device that does not support loopback interfaces.
```

To turn stub links into loopback interfaces on all lab devices apart from Cisco IOSv routers, set the global default to *True* and the IOSv parameter to *False*:

```
Expand Down Expand Up @@ -498,6 +507,8 @@ There are two mechanisms to change an interface name in the lab topology:
* The **ifname** interface parameter specifies the desired interface name. You can use it with virtual interfaces (for example, loopbacks or tunnels) or when [configuring physical devices with _netlab_](lab-external). Do not use the **ifname** parameter to change the Ethernet interface names on virtual machines or containers.
* Use the **ifindex** interface parameter to change the Ethernet interface names. The final interface name is derived from the **ifindex** parameter using the device-specific interface naming scheme[^INS]. Do not use the **ifindex** parameter on virtual interfaces (tunnels, loopbacks, VLANs, LAGs)

_netlab_ generates the names of virtual interfaces from device-specific interface name templates. Many devices do not have templates for all virtual interface types (for example, most devices do not define the tunnel interface name template). You must set the **ifname** parameter on [tunnel interfaces](links-tunnel) and other virtual interfaces of such devices; _netlab_ reports an error if it cannot generate the interface name.

[^INS]: Many devices use **ifindex** in interface name. For example, **ifindex** set to three might result in the interface name **GigabitEthernet3**. Some devices use the `slot/port` naming convention; **ifindex** set to seven might result in the interface name **GigabitEthernet1/3**.

You don't have to use a contiguous range of **ifindex** values or sort them. *netlab* sorts the interfaces based on their **ifindex** parameter and adjusts the virtualization provider configuration to match the virtual NICs to the specified **ifindex** values:
Expand Down
14 changes: 9 additions & 5 deletions netsim/augment/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ def expand_group_members(
log.error(
f'Member {m_id} of group {g_name} is not a valid {g_type} or group name',
category=log.IncorrectValue,
module='groups')
module='groups',
doc_url='groups/#groups-members')

return members

Expand Down Expand Up @@ -440,7 +441,7 @@ def check_recursive_chain(topology: Box, chain: list, group: str) -> typing.Opti
for m in topology.groups[group].members:
if m in chain:
chain = chain + [ m ]
log.error(f'Recursive group definition chain {chain}', log.IncorrectValue, 'groups')
log.error(f'Recursive group definition chain {chain}', log.IncorrectValue, 'groups', doc_url='groups/#groups-hierarchy')
return chain
if m in topology.groups:
if check_recursive_chain(topology,chain,m):
Expand Down Expand Up @@ -492,7 +493,8 @@ def copy_group_device_module(topology: Box) -> None:
log.error(
f'Cannot use "device" attribute in group {grp} that has no direct or indirect members',
log.IncorrectValue,
'groups')
'groups',
doc_url='groups/#groups-device-module')
continue

for name in g_members: # Iterate over group members
Expand All @@ -518,7 +520,8 @@ def copy_group_device_module(topology: Box) -> None:
log.error(
f'Cannot use "module" attribute in group {grp} that has no direct or indirect members',
log.IncorrectValue,
'groups')
'groups',
doc_url='groups/#groups-device-module')
continue

for name in g_members: # Iterate over group members
Expand Down Expand Up @@ -636,7 +639,8 @@ def create_bgp_autogroups(topology: Box) -> None:
log.error(
f'BGP AS group {gname} should not have static members',
log.IncorrectValue,
'groups')
'groups',
doc_url='groups/#groups-bgp')

for n_name,n_data in topology.nodes.items(): # Now iterate over nodes
#
Expand Down
18 changes: 12 additions & 6 deletions netsim/augment/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,15 @@ def create_virtual_interface(node: Box, ifdata: Box, defaults: Box) -> None:
log.error(
f'Device {node.device}/node {node.name} does not support loopback links',
log.IncorrectValue,
'links')
'links',
doc_url='links/#links-loopback')
else:
log.error(
f'Need explicit interface name (ifname) for {devtype} interface on node {node.name} ({node.device})',
category=log.IncorrectValue,
more_data=str(ifdata),
module='links')
module='links',
doc_url='links/#links-ifname')

def add_node_interface(node: Box, ifdata: Box, defaults: Box) -> Box:
if ifdata.get('type',None) in VIRTUAL_INTERFACE_TYPES:
Expand Down Expand Up @@ -542,7 +544,8 @@ def assign_link_prefix(
log.error(
f'Unknown address pool {link.pool} used in {link_path}',
log.IncorrectValue,
'links')
'links',
doc_url='links/#links-custom-pools')
pools = [ link.pool ] + pools
else:
if must_be_string(link,'role',link_path):
Expand Down Expand Up @@ -1106,23 +1109,26 @@ def check_link_type(data: Box) -> bool:
f'More than one node connected to a stub link {data._linkname}',
category=log.IncorrectValue,
more_data=[ str(data) ],
module='links')
module='links',
doc_url='links/#links-types')
return False

if link_type == 'p2p' and node_cnt != 2:
log.error(
f'Point-to-point link {data._linkname} needs exactly two nodes',
category=log.IncorrectValue,
more_data=[ str(data) ],
module='links')
module='links',
doc_url='links/#links-types')
return False

if link_type == 'loopback' and node_cnt != 1:
log.error(
f'Loopback link {data._linkname} can have a single node attached',
more_data=[ str(data) ],
category=log.IncorrectValue,
module='links')
module='links',
doc_url='links/#links-loopback')
return False

return True
Expand Down
6 changes: 4 additions & 2 deletions netsim/augment/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def find_node_device(n: Box, topology: Box) -> bool:
f'No device type specified for {"unmanaged " if u_node else ""}node {n.name} and there is no default device type',
log.MissingValue,
'nodes',
hint='unmanaged_device' if u_node else None)
hint='unmanaged_device' if u_node else None,
doc_url='defaults/#default-device-type')
return False

try:
Expand Down Expand Up @@ -423,7 +424,8 @@ def find_node_image(n: Box, topology: Box) -> bool:
log.error(
f'No image specified for device {n.device} (provider {provider}) used by node {n.name}',
log.MissingValue,
'nodes')
'nodes',
doc_url='defaults/#default-device-image')

return False

Expand Down
6 changes: 4 additions & 2 deletions netsim/modules/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def check_protocol_support(node: Box, topology: Box) -> bool:
log.error(
f'Node {node.name} ({node.device}) does not support gateway protocol {gw_proto}',
log.IncorrectValue,
'gateway')
'gateway',
doc_url='module/gateway/#gateway-support')

return OK

Expand Down Expand Up @@ -152,7 +153,8 @@ def module_init(self, topology: Box) -> None:
log.error(
f'Global/default gateway parameters are missing. We need at least a gateway ID',
log.IncorrectType,
'gateway')
'gateway',
doc_url='module/gateway/#gateway-global')
return

check_gw_protocol(gw,'topology.gateway',topology)
Expand Down
6 changes: 4 additions & 2 deletions netsim/modules/lag.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def check_lag_config(node: str, linkname: str, topology: Box) -> bool:
if 'lag' not in features:
log.error(f'Node {_n.name} ({_n.device}) does not support lag module, cannot be part of LAG {linkname}',
category=log.IncorrectAttr,
module='lag')
module='lag',
doc_url='module/lag/#lag-platform')
return False
if 'lag' not in _n.get('module',[]):
log.error(f'lag module not enabled for node {_n.name}, cannot be part of LAG {linkname}',
Expand Down Expand Up @@ -541,6 +542,7 @@ def node_post_transform(self, node: Box, topology: Box) -> None:
if uses_mlag and not (has_peerlink or uses_esi_lag):
log.error(f'Node {node.name} uses MLAG but has no peerlink (lag with {PEERLINK_ID_ATT}) or ESI-LAG configured',
category=log.IncorrectAttr,
module='lag')
module='lag',
doc_url='module/lag/#lag-mlag')

node.pop('_lag_ifindex',None) # Cleanup
6 changes: 4 additions & 2 deletions netsim/modules/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def check_link_vlan_attributes(obj: Box, link: Box, v_attr: Box, topology: Box)
text=f'VLAN {vname} used in vlan.{attr}{node_error} is not defined',
more_data=f'{link}',
category=log.IncorrectValue,
module='vlan')
module='vlan',
doc_url='module/vlan/#module-vlan-definition')
link_ok = False

return link_ok
Expand Down Expand Up @@ -368,7 +369,8 @@ def check_link_interface_attributes(link: Box, intf: Box, topology: Box) -> None
f"Link {link._linkname}, node {intf.node}, vlan {intf.vlan.access}",
f"Interface VLAN forwarding mode: {vlan_mode}, unexpected attributes {','.join(invalid)}", f"{intf}" ],
category=log.IncorrectValue,
module='vlan')
module='vlan',
doc_url='module/vlan/#vlan-interface-parameters')

"""
validate_trunk_vlan_list -- validate that the nodes connected to a VLAN trunk have at least some common VLANs
Expand Down
3 changes: 2 additions & 1 deletion netsim/modules/vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ def node_post_link_transform(self, node: Box, topology: Box) -> None:
log.error(
f'VRF {ifdata.vrf} used on an interface in {node.name} is not defined in the node or globally',
log.MissingValue,
'vrf')
'vrf',
doc_url='module/vrf/#module-vrf-definition')
continue

if not ifdata.vrf in node.vrfs: # Local VRF not present, mark as required
Expand Down
1 change: 1 addition & 0 deletions tests/coverage/errors/device-image-missing.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MissingValue in nodes: No image specified for device fake (provider libvirt) used by node r1
... See also: https://netlab.tools/defaults/#default-device-image
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/coverage/errors/group-device-no-members.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IncorrectValue in groups: Cannot use "device" attribute in group g2 that has no direct or indirect members
... See also: https://netlab.tools/groups/#groups-device-module
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/bgp-auto-group.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IncorrectValue in groups: BGP AS group as65005 should not have static members
... See also: https://netlab.tools/groups/#groups-bgp
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/groups-recursive.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IncorrectValue in groups: Recursive group definition chain ['g1', 'g2', 'g1']
... See also: https://netlab.tools/groups/#groups-hierarchy
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/invalid-group-member-element.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IncorrectValue in groups: Member wrong of group g1 is not a valid node or group name
... See also: https://netlab.tools/groups/#groups-members
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/invalid-group-member.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IncorrectValue in groups: Member a3 of group g1 is not a valid node or group name
... See also: https://netlab.tools/groups/#groups-members
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/node-no-device.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MissingValue in nodes: No device type specified for node r1 and there is no default device type
... See also: https://netlab.tools/defaults/#default-device-type
MissingValue in nodes: No device type specified for node r2 and there is no default device type
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/node-unmanaged-device-type.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MissingValue in nodes: No device type specified for unmanaged node sw and there is no default device type
... See also: https://netlab.tools/defaults/#default-device-type
... Netlab uses the node device type for unmanaged nodes to figure out what features the
node supports. If you're using a device that is not supported by netlab, set the
device type to 'none'.
Expand Down
1 change: 1 addition & 0 deletions tests/errors/node-wrong-device.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MissingValue in nodes: No device type specified for node r1 and there is no default device type
... See also: https://netlab.tools/defaults/#default-device-type
IncorrectValue in nodes: attribute 'nodes.r2.device' must be known device type identifier (got wtf)
... Use 'netlab show devices' to display a list of valid devices
Fatal error in netlab: Cannot proceed beyond this point due to errors, exiting
1 change: 1 addition & 0 deletions tests/errors/vlan-link-error.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
IncorrectValue in vlan: VLAN wtf used in vlan.access in link links[1] is not defined
... {'_linkname': 'links[1]', 'vlan': {'access': 'wtf'}, 'interfaces': [{'node':
... 'n1'}, {'node': 'n2'}], 'linkindex': 1}
... See also: https://netlab.tools/module/vlan/#module-vlan-definition
IncorrectValue in vlan: VLAN wtf used in vlan.access in node n1 on link links[7] is not defined
... {'_linkname': 'links[7]', 'interfaces': [{'vlan': {'access': 'wtf'}, 'node':
... 'n1'}, {'node': 'n2'}], 'linkindex': 7}
Expand Down