@@ -28,6 +28,17 @@ class IsolatedMacVlans:
2828 NOTE: For the simple case when only one interface needs to be
2929 mapped, see IsolatedMacVlan below.
3030
31+ Args:
32+ ifmap: Dictionary mapping parent interface names to MACVLAN names
33+ lo: Enable loopback interface in the namespace (default: True)
34+ set_up: Automatically bring up the interfaces (default: True)
35+ mode: MACVLAN mode to use (default: "passthru")
36+ - "passthru": Exclusive access, single MACVLAN per parent.
37+ Parent interface becomes promiscuous.
38+ - "bridge": Shared access, allows multiple MACVLANs to
39+ communicate. Required for layer-2 tests that
40+ need full control of all frames.
41+
3142 Example:
3243
3344 netns = IsolatedMacVlans({ "eth2": "a", "eth3": "b" })
@@ -46,9 +57,10 @@ def Cleanup():
4657 for ns in list (IsolatedMacVlans .Instances ):
4758 ns .stop ()
4859
49- def __init__ (self , ifmap , lo = True , set_up = True ):
60+ def __init__ (self , ifmap , lo = True , set_up = True , mode = "passthru" ):
5061 self .sleeper = None
5162 self .ifmap , self .lo , self .set_up = ifmap , lo , set_up
63+ self .mode = mode
5264 self .ping_timeout = env .ENV .attr ("ping_timeout" , 5 )
5365
5466 def start (self ):
@@ -64,7 +76,8 @@ def start(self):
6476 "link" , parent ,
6577 "address" , self ._stable_mac (parent ),
6678 "netns" , str (self .sleeper .pid ),
67- "type" , "macvlan" , "mode" , "passthru" ], check = True )
79+ "type" , "macvlan" , "mode" , self .mode ],
80+ check = True )
6881 self .runsh (f"""
6982 while ! ip link show dev { ifname } ; do
7083 sleep 0.1
@@ -287,6 +300,17 @@ class IsolatedMacVlan(IsolatedMacVlans):
287300 moves that interface to a separate namespace, isolating it from
288301 all other interfaces.
289302
303+ Args:
304+ parent: Name of the parent interface on the controller
305+ ifname: Name of the MACVLAN interface in the namespace (default: "iface")
306+ lo: Enable loopback interface in the namespace (default: True)
307+ set_up: Automatically bring up the interface (default: True)
308+ mode: MACVLAN mode to use (default: "passthru")
309+ - "passthru": Exclusive access, single MACVLAN per parent.
310+ - "bridge": Shared access, required for layer-2 tests that
311+ need to communicate with other MACVLANs on the
312+ same parent or control all frames.
313+
290314 Example:
291315
292316 netns = IsolatedMacVlan("eth3")
@@ -298,10 +322,15 @@ class IsolatedMacVlan(IsolatedMacVlans):
298322 |
299323 eth0 eth1 eth2 eth3
300324
325+ Example with bridge mode:
326+
327+ netns = IsolatedMacVlan("eth3", mode="bridge")
328+
301329 """
302- def __init__ (self , parent , ifname = "iface" , lo = True , set_up = True ):
330+ def __init__ (self , parent , ifname = "iface" , lo = True , set_up = True , mode = "passthru" ):
303331 self ._ifname = ifname
304- return super ().__init__ (ifmap = {parent : ifname }, lo = lo , set_up = set_up )
332+ return super ().__init__ (ifmap = {parent : ifname }, lo = lo , set_up = set_up ,
333+ mode = mode )
305334
306335 def addip (self , addr , prefix_length = 24 , proto = "ipv4" ):
307336 return super ().addip (ifname = self ._ifname , addr = addr ,
@@ -388,10 +417,19 @@ class TPMR(IsolatedMacVlans):
388417
389418 This is useful to verify the correctness of fail-over behavior in
390419 various protocols. See ospf_bfd for a usage example.
420+
421+ Args:
422+ a: Name of the first parent interface on the controller
423+ b: Name of the second parent interface on the controller
424+ mode: MACVLAN mode to use (default: "passthru")
425+ - "passthru": Exclusive access (default)
426+ - "bridge": Shared access, allows communication between MACVLANs
427+ and full control of all frames. May be required for
428+ proper layer-2 relay functionality in some tests.
391429 """
392430
393- def __init__ (self , a , b ):
394- super ().__init__ (ifmap = { a : "a" , b : "b" }, lo = False )
431+ def __init__ (self , a , b , mode = "passthru" ):
432+ super ().__init__ (ifmap = { a : "a" , b : "b" }, lo = False , mode = mode )
395433
396434 def start (self , forward = True ):
397435 ret = super ().start ()
0 commit comments