Remove PDR's based on Terminus Handle

The current pldm infrastructure is written in way that
it deletes all the PDR's which are marked as "remote",when
we get a PDR refresh entire repository signal comes from remote
PLDM terminus,this does not work in muti-host scenario where BMC
talks to more than one HOST that talks pldm.

When a repository refresh signal comes form a remote PLDM terminus,
BMC is supposed to only delete the PDR's corresponding to the same
PLDM terminus.

Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: I51f77c3f9537da722a00d97070674958c5baf1b4
diff --git a/libpldm/pdr.c b/libpldm/pdr.c
index eeb9805..b057e3d 100644
--- a/libpldm/pdr.c
+++ b/libpldm/pdr.c
@@ -10,6 +10,7 @@
 	uint8_t *data;
 	struct pldm_pdr_record *next;
 	bool is_remote;
+	uint16_t terminus_handle;
 } pldm_pdr_record;
 
 typedef struct pldm_pdr {
@@ -60,7 +61,8 @@
 
 static pldm_pdr_record *make_new_record(const pldm_pdr *repo,
 					const uint8_t *data, uint32_t size,
-					uint32_t record_handle, bool is_remote)
+					uint32_t record_handle, bool is_remote,
+					uint16_t terminus_handle)
 {
 	assert(repo != NULL);
 	assert(size != 0);
@@ -71,6 +73,7 @@
 	    record_handle == 0 ? get_new_record_handle(repo) : record_handle;
 	record->size = size;
 	record->is_remote = is_remote;
+	record->terminus_handle = terminus_handle;
 	if (data != NULL) {
 		record->data = malloc(size);
 		assert(record->data != NULL);
@@ -93,13 +96,14 @@
 }
 
 uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
-		      uint32_t record_handle, bool is_remote)
+		      uint32_t record_handle, bool is_remote,
+		      uint16_t terminus_handle)
 {
 	assert(size != 0);
 	assert(data != NULL);
 
-	pldm_pdr_record *record =
-	    make_new_record(repo, data, size, record_handle, is_remote);
+	pldm_pdr_record *record = make_new_record(
+	    repo, data, size, record_handle, is_remote, terminus_handle);
 	add_record(repo, record);
 
 	return record->record_handle;
@@ -272,7 +276,8 @@
 	fru->entity_instance_num = htole16(entity_instance_num);
 	fru->container_id = htole16(container_id);
 
-	return pldm_pdr_add(repo, data, size, bmc_record_handle, false);
+	return pldm_pdr_add(repo, data, size, bmc_record_handle, false,
+			    terminus_handle);
 }
 
 const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
@@ -600,7 +605,8 @@
 					      pldm_pdr *repo, uint16_t size,
 					      uint8_t contained_count,
 					      uint8_t association_type,
-					      bool is_remote)
+					      bool is_remote,
+					      uint16_t terminus_handle)
 {
 	uint8_t pdr[size];
 	uint8_t *start = pdr;
@@ -642,11 +648,12 @@
 		node = node->next_sibling;
 	}
 
-	pldm_pdr_add(repo, pdr, size, 0, is_remote);
+	pldm_pdr_add(repo, pdr, size, 0, is_remote, terminus_handle);
 }
 
 static void entity_association_pdr_add_entry(pldm_entity_node *curr,
-					     pldm_pdr *repo, bool is_remote)
+					     pldm_pdr *repo, bool is_remote,
+					     uint16_t terminus_handle)
 {
 	uint8_t num_logical_children =
 	    pldm_entity_get_num_children(curr, PLDM_ENTITY_ASSOCIAION_LOGICAL);
@@ -660,7 +667,7 @@
 		    (num_logical_children * sizeof(pldm_entity));
 		_entity_association_pdr_add_entry(
 		    curr, repo, logical_pdr_size, num_logical_children,
-		    PLDM_ENTITY_ASSOCIAION_LOGICAL, is_remote);
+		    PLDM_ENTITY_ASSOCIAION_LOGICAL, is_remote, terminus_handle);
 	}
 
 	if (num_physical_children) {
@@ -670,7 +677,8 @@
 		    (num_physical_children * sizeof(pldm_entity));
 		_entity_association_pdr_add_entry(
 		    curr, repo, physical_pdr_size, num_physical_children,
-		    PLDM_ENTITY_ASSOCIAION_PHYSICAL, is_remote);
+		    PLDM_ENTITY_ASSOCIAION_PHYSICAL, is_remote,
+		    terminus_handle);
 	}
 }
 
@@ -691,7 +699,8 @@
 
 static void entity_association_pdr_add(pldm_entity_node *curr, pldm_pdr *repo,
 				       pldm_entity **entities,
-				       size_t num_entities, bool is_remote)
+				       size_t num_entities, bool is_remote,
+				       uint16_t terminus_handle)
 {
 	if (curr == NULL) {
 		return;
@@ -699,33 +708,34 @@
 	bool to_add = true;
 	to_add = is_present(curr->entity, entities, num_entities);
 	if (to_add) {
-		entity_association_pdr_add_entry(curr, repo, is_remote);
+		entity_association_pdr_add_entry(curr, repo, is_remote,
+						 terminus_handle);
 	}
 	entity_association_pdr_add(curr->next_sibling, repo, entities,
-				   num_entities, is_remote);
+				   num_entities, is_remote, terminus_handle);
 	entity_association_pdr_add(curr->first_child, repo, entities,
-				   num_entities, is_remote);
+				   num_entities, is_remote, terminus_handle);
 }
 
 void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
-				     pldm_pdr *repo, bool is_remote)
+				     pldm_pdr *repo, bool is_remote,
+				     uint16_t terminus_handle)
 {
 	assert(tree != NULL);
 	assert(repo != NULL);
 
-	entity_association_pdr_add(tree->root, repo, NULL, 0, is_remote);
+	entity_association_pdr_add(tree->root, repo, NULL, 0, is_remote,
+				   terminus_handle);
 }
 
-void pldm_entity_association_pdr_add_from_node(pldm_entity_node *node,
-					       pldm_pdr *repo,
-					       pldm_entity **entities,
-					       size_t num_entities,
-					       bool is_remote)
+void pldm_entity_association_pdr_add_from_node(
+    pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities,
+    size_t num_entities, bool is_remote, uint16_t terminus_handle)
 {
 	assert(repo != NULL);
 
 	entity_association_pdr_add(node, repo, entities, num_entities,
-				   is_remote);
+				   is_remote, terminus_handle);
 }
 
 void find_entity_ref_in_tree(pldm_entity_node *tree_node, pldm_entity entity,
@@ -753,6 +763,53 @@
 	find_entity_ref_in_tree(tree->root, entity, node);
 }
 
+void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo,
+					     uint16_t terminus_handle)
+{
+	assert(repo != NULL);
+	bool removed = false;
+
+	pldm_pdr_record *record = repo->first;
+	pldm_pdr_record *prev = NULL;
+	while (record != NULL) {
+		pldm_pdr_record *next = record->next;
+		if (record->terminus_handle == terminus_handle) {
+			if (repo->first == record) {
+				repo->first = next;
+			} else {
+				prev->next = next;
+			}
+			if (repo->last == record) {
+				repo->last = prev;
+			}
+			if (record->data) {
+				free(record->data);
+			}
+			--repo->record_count;
+			repo->size -= record->size;
+			free(record);
+			removed = true;
+		} else {
+			prev = record;
+		}
+		record = next;
+	}
+
+	if (removed == true) {
+		record = repo->first;
+		uint32_t record_handle = 0;
+		while (record != NULL) {
+			record->record_handle = ++record_handle;
+			if (record->data != NULL) {
+				struct pldm_pdr_hdr *hdr =
+				    (struct pldm_pdr_hdr *)(record->data);
+				hdr->record_handle =
+				    htole32(record->record_handle);
+			}
+			record = record->next;
+		}
+	}
+}
 void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo)
 {
 	assert(repo != NULL);
diff --git a/libpldm/pdr.h b/libpldm/pdr.h
index 9e39da3..671b726 100644
--- a/libpldm/pdr.h
+++ b/libpldm/pdr.h
@@ -65,11 +65,13 @@
  *  @param[in] record_handle - record handle of input PDR record; if this is set
  *  to 0, then a record handle is computed and assigned to this PDR record
  *  @param[in] is_remote - if true, then the PDR is not from this terminus
+ *  @param[in] terminus_handle - terminus handle of the input PDR record
  *
  *  @return uint32_t - record handle assigned to PDR record
  */
 uint32_t pldm_pdr_add(pldm_pdr *repo, const uint8_t *data, uint32_t size,
-		      uint32_t record_handle, bool is_remote);
+		      uint32_t record_handle, bool is_remote,
+		      uint16_t terminus_handle);
 
 /** @brief Get record handle of a PDR record
  *
@@ -144,6 +146,14 @@
  */
 void pldm_pdr_remove_remote_pdrs(pldm_pdr *repo);
 
+/** @brief Remove all remote PDR's that beling to a specific terminus
+ *         handle
+ *  @param[in] repo - opaque pointer acting as a PDR repo handle
+ *  @param[in] terminus_handle - Terminus Handle of the remove PLDM terminus
+ */
+void pldm_pdr_remove_pdrs_by_terminus_handle(pldm_pdr *repo,
+					     uint16_t terminus_handle);
+
 /** @brief Update the validity of TL PDR - the validity is decided based on
  * whether the valid bit is set or not as per the spec DSP0248
  *
@@ -304,20 +314,21 @@
  *  @param[in] tree - opaque pointer to entity association tree
  *  @param[in] repo - PDR repo where entity association records should be added
  *  @param[in] is_remote - if true, then the PDR is not from this terminus
+ *  @param[in] terminus_handle - terminus handle of the terminus
  */
 void pldm_entity_association_pdr_add(pldm_entity_association_tree *tree,
-				     pldm_pdr *repo, bool is_remote);
+				     pldm_pdr *repo, bool is_remote,
+				     uint16_t terminus_handle);
 /** @brief Add entity association pdr from node
  *
  *  @param[in] node - opaque pointer acting as a handle to an entity node
  *  @param[in] repo - PDR repo where entity association records should be added
  *  @param[in] is_remote  - if true, then the PDR is not from this terminus
+ *  @param[in] terminus_handle - terminus handle of the terminus
  */
-void pldm_entity_association_pdr_add_from_node(pldm_entity_node *node,
-					       pldm_pdr *repo,
-					       pldm_entity **entities,
-					       size_t num_entities,
-					       bool is_remote);
+void pldm_entity_association_pdr_add_from_node(
+    pldm_entity_node *node, pldm_pdr *repo, pldm_entity **entities,
+    size_t num_entities, bool is_remote, uint16_t terminus_handle);
 
 /** @brief Find entity reference in tree
  *
diff --git a/libpldm/tests/libpldm_pdr_test.cpp b/libpldm/tests/libpldm_pdr_test.cpp
index d908345..666145a 100644
--- a/libpldm/tests/libpldm_pdr_test.cpp
+++ b/libpldm/tests/libpldm_pdr_test.cpp
@@ -18,17 +18,17 @@
     auto repo = pldm_pdr_init();
 
     std::array<uint8_t, 10> data{};
-    auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(handle, 1u);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size());
 
-    handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false);
+    handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false, 1);
     EXPECT_EQ(handle, 2u);
-    handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false);
+    handle = pldm_pdr_add(repo, data.data(), data.size(), 0u, false, 1);
     EXPECT_EQ(handle, 3u);
     handle = pldm_pdr_add(repo, data.data(), data.size(), htole32(0xdeeddeedu),
-                          false);
+                          false, 1);
     EXPECT_EQ(handle, htole32(0xdeeddeed));
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), data.size() * 4u);
@@ -36,6 +36,47 @@
     pldm_pdr_destroy(repo);
 }
 
+TEST(PDRRemoveByTerminus, testRemoveByTerminus)
+{
+    std::array<uint8_t, 10> data{};
+
+    auto repo = pldm_pdr_init();
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u);
+    pldm_pdr_destroy(repo);
+
+    repo = pldm_pdr_init();
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 2);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
+    pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
+    pldm_pdr_destroy(repo);
+
+    repo = pldm_pdr_init();
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 2);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 2);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
+    pldm_pdr_remove_pdrs_by_terminus_handle(repo, 2);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
+    pldm_pdr_destroy(repo);
+
+    repo = pldm_pdr_init();
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 2);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
+    pldm_pdr_remove_remote_pdrs(repo);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
+    pldm_pdr_remove_pdrs_by_terminus_handle(repo, 1);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
+    pldm_pdr_remove_pdrs_by_terminus_handle(repo, 2);
+    EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u);
+    pldm_pdr_destroy(repo);
+}
+
 TEST(PDRUpdate, testRemove)
 {
     std::array<uint8_t, 10> data{};
@@ -46,161 +87,161 @@
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 0u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 5u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 3u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     pldm_pdr_destroy(repo);
 
     repo = pldm_pdr_init();
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, false);
-    pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
+    pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     pldm_pdr_remove_remote_pdrs(repo);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 2u);
-    auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto handle = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     EXPECT_EQ(handle, 3u);
-    handle = pldm_pdr_add(repo, data.data(), data.size(), 0, true);
+    handle = pldm_pdr_add(repo, data.data(), data.size(), 0, true, 1);
     EXPECT_EQ(handle, 4u);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     pldm_pdr_destroy(repo);
@@ -212,7 +253,7 @@
 
     std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123};
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()), sizeof(in), 1,
-                 false);
+                 false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in));
     uint32_t size{};
@@ -244,11 +285,11 @@
     std::array<uint32_t, 10> in2{1000, 3450, 30,  60,     890,
                                  0,    110,  450, 234034, 123123};
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 2,
-                 false);
+                 false, 1);
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 3,
-                 false);
+                 false, 1);
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 4,
-                 true);
+                 true, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4);
     hdl = pldm_pdr_find_record(repo, 0, &outData, &size, &nextRecHdl);
@@ -294,7 +335,7 @@
 
     std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123};
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()), sizeof(in), 1,
-                 false);
+                 false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 1u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in));
     uint32_t size{};
@@ -310,11 +351,11 @@
     std::array<uint32_t, 10> in2{1000, 3450, 30,  60,     890,
                                  0,    110,  450, 234034, 123123};
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 2,
-                 false);
+                 false, 1);
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 3,
-                 false);
+                 false, 1);
     pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()), sizeof(in2), 4,
-                 false);
+                 false, 1);
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 4u);
     EXPECT_EQ(pldm_pdr_get_repo_size(repo), sizeof(in2) * 4);
     hdl = pldm_pdr_get_next_record(repo, hdl, &outData, &size, &nextRecHdl);
@@ -346,13 +387,13 @@
     std::array<uint8_t, sizeof(pldm_pdr_hdr)> data{};
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(data.data());
     hdr->type = 1;
-    auto first = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto first = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     hdr->type = 2;
-    auto second = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto second = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     hdr->type = 3;
-    auto third = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto third = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
     hdr->type = 4;
-    auto fourth = pldm_pdr_add(repo, data.data(), data.size(), 0, false);
+    auto fourth = pldm_pdr_add(repo, data.data(), data.size(), 0, false, 1);
 
     uint8_t* outData = nullptr;
     uint32_t size{};
@@ -901,7 +942,7 @@
               1);
 
     auto repo = pldm_pdr_init();
-    pldm_entity_association_pdr_add(tree, repo, false);
+    pldm_entity_association_pdr_add(tree, repo, false, 1);
 
     EXPECT_EQ(pldm_pdr_get_record_count(repo), 6u);