Skip to content

Commit

Permalink
chore(TC_OPCREDS_3.2): get currentFabric
Browse files Browse the repository at this point in the history
  • Loading branch information
gvargas-csa committed Feb 13, 2024
1 parent 122207f commit 8367f6e
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions src/python_testing/TC_OPCREDS_3_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,51 @@
import random

import chip.clusters as Clusters
from chip.utils import CommissioningBuildingBlocks
from chip import ChipDeviceCtrl
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts


class TC_OPCREDS_3_2(MatterBaseTest):
# All global functions
@async_test_body
async def test_TC_OPCREDS_3_2(self):
self.print_step(1, "Factory Reset DUT")
# self.th1 = self.default_controller

# Create and setup TH1
th1_ca = self.certificate_authority_manager.NewCertificateAuthority()
th1_fabric_admin = th1_ca.NewFabricAdmin(vendorId=0xFFF1, fabricId=1111)
th1_nodeId = self.default_controller.nodeId+1
self.th1 = th1_fabric_admin.NewController(nodeId=th1_nodeId)

# Commissioning Process
newNodeId = self.dut_node_id+1
params = self.openCommissioningWindow(self.default_controller, self.dut_node_id)
errcode = self.th1.CommissionOnNetwork(
nodeId=newNodeId, setupPinCode=params.commissioningParameters.setupPinCode,
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)
logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format(errcode.is_success, errcode))
self.print_step(3, "TH0 commissions DUT")

# NOCResponse is need it

# It is not necessary implement factory reset to DUT
self.print_step(1, "Step 1: Factory Reset DUT")

dev_ctrl = self.default_controller

new_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority()
th1_new_fabric_admin = new_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=2222)
th1_nodeid = self.default_controller.nodeId+1
th1_dut_nodeid = self.dut_node_id+1

th1_new_admin_ctrl = th1_new_fabric_admin.NewController(nodeId=th1_nodeid)
resp = await CommissioningBuildingBlocks.AddNOCForNewFabricFromExisting(
commissionerDevCtrl=dev_ctrl, newFabricDevCtrl=th1_new_admin_ctrl,
existingNodeId=self.dut_node_id, newNodeId=th1_dut_nodeid
)

self.print_step(2, "Commission DUT to TH1's Fabric")

# CommissioningBuildingBlocks just return a boolean. I need to get the NOC Response
# so I just I will add a new step for now update the fabric label just to get the NOC response.
opcreds = Clusters.OperationalCredentials
nonce = random.randbytes(32)
cmd = opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)
resp = await self.send_single_cmd(dev_ctrl=self.th1, node_id=newNodeId, cmd=cmd)
# resp = await self.th1.SendCommand(nodeid=newNodeId, endpoint=0, payload=cmd)
print("HELLO HERE IS")
print(resp)
print("HELLO ABOVE MUST BE THERE")
cmd = opcreds.Commands.UpdateFabricLabel(label="Label1")
resp = await self.send_single_cmd(cmd=cmd, dev_ctrl=th1_new_admin_ctrl, node_id=th1_dut_nodeid)
self.print_step(3, "When DUT sends NOC response save FabricIndex as FabricIndex_TH1")
FabricIndex_TH1 = resp.fabricIndex

self.print_step(4, "Save TH1's Fabric ID as FabricID1")
TH1_CurrentFabricIndex = await self.read_single_attribute_check_success(
cluster=opcreds, attribute=opcreds.Attributes.CurrentFabricIndex, dev_ctrl=th1_new_admin_ctrl, node_id=th1_dut_nodeid)

self.print_step(5, "From TH1 read the CurrentFabricIndex")
print(TH1_CurrentFabricIndex)




if __name__ == "__main__":
Expand Down

0 comments on commit 8367f6e

Please sign in to comment.