20
20
MCTPD_MCTP_P = '/au/com/codeconstruct/mctp1'
21
21
MCTPD_MCTP_I = 'au.com.codeconstruct.MCTP.BusOwner1'
22
22
MCTPD_ENDPOINT_I = 'au.com.codeconstruct.MCTP.Endpoint1'
23
+ MCTPD_ENDPOINT_BRIDGE_I = 'au.com.codeconstruct.MCTP.Bridge1'
23
24
DBUS_OBJECT_MANAGER_I = 'org.freedesktop.DBus.ObjectManager'
24
25
DBUS_PROPERTIES_I = 'org.freedesktop.DBus.Properties'
25
26
@@ -971,3 +972,125 @@ async def test_assign_dynamic_bridge_eid(dbus, mctpd):
971
972
assert ep .eid < br_ep .eid <= ep .eid + ep .allocated_pool_size
972
973
(_ , new ) = await net .call_learn_endpoint (br_ep .eid )
973
974
assert new
975
+
976
+ """ Test that we truncate the requested pool size to
977
+ the max_pool_size config """
978
+ async def test_assign_dynamic_eid_limited_pool (nursery , dbus , sysnet ):
979
+ max_pool_size = 1
980
+ config = f"""
981
+ [bus-owner]
982
+ max_pool_size = { max_pool_size }
983
+ """
984
+
985
+ mctpd = MctpdWrapper (dbus , sysnet , config = config )
986
+ await mctpd .start_mctpd (nursery )
987
+
988
+ iface = mctpd .system .interfaces [0 ]
989
+ ep = mctpd .network .endpoints [0 ]
990
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
991
+
992
+ # Set up bridged endpoints as undiscovered EID 0
993
+ for i in range (0 , 2 ):
994
+ br_ep = Endpoint (iface , bytes (), types = [0 , 2 ])
995
+ ep .add_bridged_ep (br_ep )
996
+ mctpd .network .add_endpoint (br_ep )
997
+
998
+ # dynamic EID assigment for dev1
999
+ (eid , _ , path , new ) = await mctp .call_assign_endpoint (
1000
+ ep .lladdr ,
1001
+ )
1002
+
1003
+ assert new
1004
+
1005
+ bridge_obj = await dbus .get_proxy_object (MCTPD_C , path )
1006
+ props_iface = await bridge_obj .get_interface (DBUS_PROPERTIES_I )
1007
+ pool_end = await props_iface .call_get (MCTPD_ENDPOINT_BRIDGE_I , "PoolEnd" )
1008
+ pool_size = pool_end .value - eid
1009
+ assert pool_size == max_pool_size
1010
+
1011
+ res = await mctpd .stop_mctpd ()
1012
+ assert res == 0
1013
+
1014
+ """ Test that no pool is assigned for requested pool size from
1015
+ unavailable pool space"""
1016
+ async def test_assign_dynamic_unavailable_pool (nursery , dbus , sysnet ):
1017
+ (min_dyn_eid , max_dyn_eid ) = (8 , 12 )
1018
+ config = f"""
1019
+ [bus-owner]
1020
+ dynamic_eid_range = [{ min_dyn_eid } , { max_dyn_eid } ]
1021
+ """
1022
+
1023
+ mctpd = MctpdWrapper (dbus , sysnet , config = config )
1024
+ await mctpd .start_mctpd (nursery )
1025
+
1026
+ iface = mctpd .system .interfaces [0 ]
1027
+ ep = mctpd .network .endpoints [0 ]
1028
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
1029
+
1030
+ # Set up bridged endpoints as undiscovered EID 0
1031
+ for i in range (0 , 2 ):
1032
+ br_ep = Endpoint (iface , bytes (), types = [0 , 2 ])
1033
+ ep .add_bridged_ep (br_ep )
1034
+ mctpd .network .add_endpoint (br_ep )
1035
+
1036
+ # consume middle eid from the range to dev2
1037
+ dev2 = Endpoint (iface , bytes ([0x09 ]))
1038
+ mctpd .network .add_endpoint (dev2 )
1039
+ (eid , _ , path , new ) = await mctp .call_assign_endpoint_static (
1040
+ dev2 .lladdr ,
1041
+ 10
1042
+ )
1043
+ assert new
1044
+
1045
+ # dynamic EID assigment for dev1
1046
+ (eid , _ , path , new ) = await mctp .call_assign_endpoint (
1047
+ ep .lladdr ,
1048
+ )
1049
+ assert new
1050
+ # Interface should not be present for unavailable pool space
1051
+ with pytest .raises (asyncdbus .errors .InterfaceNotFoundError ):
1052
+ bridge_obj = await dbus .get_proxy_object (MCTPD_C , path )
1053
+ await bridge_obj .get_interface (MCTPD_ENDPOINT_BRIDGE_I )
1054
+
1055
+ res = await mctpd .stop_mctpd ()
1056
+ assert res == 0
1057
+
1058
+ """During Allocate Endpoint ID exchange, return completion code failure
1059
+ to indicate no pool has been assigned to the bridge"""
1060
+ async def test_assign_dynamic_eid_allocation_failure (dbus , mctpd ):
1061
+ class BridgeEndpoint (Endpoint ):
1062
+ async def handle_mctp_control (self , sock , src_addr , msg ):
1063
+ flags , opcode = msg [0 :2 ]
1064
+ if opcode != 0x8 :
1065
+ return await super ().handle_mctp_control (sock , src_addr , msg )
1066
+ dst_addr = MCTPSockAddr .for_ep_resp (self , src_addr , sock .addr_ext )
1067
+
1068
+ msg = bytes ([
1069
+ flags & 0x1f , # Rsp
1070
+ 0x08 , # opcode: Allocate Endpoint ID
1071
+ 0x01 , # cc: failure
1072
+ 0x01 , # allocation rejected
1073
+ 0x00 , # pool size
1074
+ 0x00 , # pool start
1075
+ ])
1076
+ await sock .send (dst_addr , msg )
1077
+
1078
+ iface = mctpd .system .interfaces [0 ]
1079
+ ep = BridgeEndpoint (iface , bytes ([0x1e ]))
1080
+ mctpd .network .add_endpoint (ep )
1081
+ # Set up downstream endpoints as undiscovered EID 0
1082
+ for i in range (0 , 2 ):
1083
+ br_ep = Endpoint (iface , bytes (), types = [0 , 2 ])
1084
+ ep .add_bridged_ep (br_ep )
1085
+ mctpd .network .add_endpoint (br_ep )
1086
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
1087
+
1088
+ # dynamic EID assigment for dev1
1089
+ (eid , _ , path , new ) = await mctp .call_assign_endpoint (
1090
+ ep .lladdr ,
1091
+ )
1092
+ assert new
1093
+ # Interface should not be present for failed pool allocation
1094
+ with pytest .raises (asyncdbus .errors .InterfaceNotFoundError ):
1095
+ bridge_obj = await dbus .get_proxy_object (MCTPD_C , path )
1096
+ await bridge_obj .get_interface (MCTPD_ENDPOINT_BRIDGE_I )
0 commit comments