Skip to content

Commit a1e1076

Browse files
authored
Lag module fixes & cleanup (#1541)
1 parent e7952ac commit a1e1076

File tree

9 files changed

+415
-116
lines changed

9 files changed

+415
-116
lines changed

netsim/modules/lag.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,27 @@ def populate_lag_id_set(topology: Box) -> None:
2626
"""
2727
def create_lag_member_links(l: Box, topology: Box) -> None:
2828
lag_members = l.lag.members
29-
l.lag.pop("members",None) # Remove explicit list of members
30-
l2_ifdata = { 'type': "p2p", 'prefix': False } # Construct an L2 member link
29+
l.lag.pop("members",None) # Remove explicit list of members
30+
l2_ifdata = data.get_box({ 'type': "p2p", 'prefix': False }) # Construct an L2 member link
3131
for a in list(topology.defaults.lag.attributes.lag_l2_ifattr):
3232
if a in l:
3333
l2_ifdata[a] = l[a]
3434

3535
for idx,member in enumerate(lag_members):
3636
member = links.adjust_link_object(member,f'{l._linkname}.lag[{idx+1}]',topology.nodes)
3737

38-
if len(member.interfaces)!=2: # Check that there are exactly 2 nodes involved
38+
if 'lag' in member: # Catch potential sources for inconsistency
39+
log.error(f'LAG attributes must be configured on the link, not member interface {member._linkname}: {member.lag}',
40+
category=log.IncorrectAttr,
41+
module='lag')
42+
return
43+
44+
if len(member.interfaces)!=2: # Check that there are exactly 2 nodes involved
3945
log.error(f'Link {member._linkname} in LAG {l.lag.ifindex} must have exactly 2 nodes',
4046
category=log.IncorrectAttr,
4147
module='lag')
4248
return
43-
else: # Check that they all support LAG
49+
else: # Check that they all support LAG
4450
for i in member.interfaces:
4551
_n = topology.nodes[i.node]
4652
features = devices.get_device_features(_n,topology.defaults)
@@ -55,16 +61,16 @@ def create_lag_member_links(l: Box, topology: Box) -> None:
5561
module='lag')
5662
return
5763

58-
member = l2_ifdata + member # Copy L2 data into member link
64+
member = l2_ifdata + member # Copy L2 data into member link
5965
member.linkindex = len(topology.links)+1
60-
member.lag._parentindex = l.linkindex # Keep track of parent
66+
member.lag._parentindex = l.linkindex # Keep track of parent
6167
if log.debug_active('lag'):
6268
print(f'LAG create_lag_member_links -> adding link {member}')
6369
topology.links.append(member)
64-
if not l.interfaces: # Copy interfaces from first member link
65-
l.interfaces = member.interfaces + [] # Deep copy, assumes all links have same 2 nodes
70+
if not l.interfaces: # Copy interfaces from first member link
71+
l.interfaces = member.interfaces + [] # Deep copy, assumes all links have same 2 nodes
6672
else:
67-
base = { n.node for n in l.interfaces } # List the (2) nodes from the first link
73+
base = { n.node for n in l.interfaces } # List the (2) nodes from the first link
6874
others = { n.node for n in member.interfaces if n.node not in base }
6975
if others:
7076
log.error(f'All LAG link members must connect the same pair of nodes({base}), found {others}',
@@ -107,10 +113,10 @@ def module_pre_transform(self, topology: Box) -> None:
107113
def node_post_transform(self, node: Box, topology: Box) -> None:
108114
features = devices.get_device_features(node,topology.defaults)
109115
for i in node.interfaces:
110-
if 'lag' not in i:
116+
if i.type!='lag':
111117
continue
112118

113-
i.lag = node.get('lag',{}) + i.lag
119+
i.lag = node.get('lag',{}) + i.lag # Merge node level lag attributes
114120
lacp_mode = i.get('lag.lacp_mode') # Inheritance copying is done elsewhere
115121
if lacp_mode=='passive' and not features.lag.get('passive',False):
116122
log.error(f'Node {node.name} does not support passive LACP configured on interface {i.ifname}',

netsim/modules/lag.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ attributes:
2626

2727
# Copy only these L2 attributes into LAG physical link members
2828
lag_l2_ifattr:
29-
lag.ifindex:
3029
mtu:
3130
bandwidth:

netsim/modules/vlan.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ attributes:
5555
bandwidth:
5656
_selfloop_ifindex:
5757
stp:
58+
virtual_interface: # Use case: VLAN on lag interface
59+
lag: # Keep lag parameters such as lacp settings
60+
5861
#
5962
# Keep these subinterface attributes
6063
keep_subif:
6164
vlan:
6265
ifindex:
6366
ifname:
6467
type:
68+
virtual_interface:
6569

6670
features:
6771
model: Conceptual device configuration model

tests/integration/lag/02-lag-vlan-trunk.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ vlans:
2424

2525
links:
2626
- vlan.trunk: [ v1, v2 ]
27-
lag.members: [ dut-xs, dut-xs ]
27+
lag:
28+
members: [ dut-xs, dut-xs ]
29+
lacp: slow # Test that LACP settings are properly copied
2830

2931
validate:
3032
ping_v1:

0 commit comments

Comments
 (0)