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