BREAKING: Change Name LSAs to propagate cost which are applied to remote routes

This is a stopgap change to address a lack of functionality in the NDN testbed.
Current restrictions:
-Cost must be set from NFD readvertisement
-Cost is applied after routing calculations but before FIB insertion; lowest cost
nexthop will be chosen but may not be the optimal path given this cost.

Further work will be required to move the application of cost as part of routing
and to make this functionality more easily accessible.

Refs #5349

Change-Id: I914dc5c2d5d3cb6bfa13f5730df0eae66d115c60
diff --git a/tests/lsa/test-name-lsa.cpp b/tests/lsa/test-name-lsa.cpp
index 6f9928e..0634dd7 100644
--- a/tests/lsa/test-name-lsa.cpp
+++ b/tests/lsa/test-name-lsa.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2024,  The University of Memphis,
+ * Copyright (c) 2014-2025,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -20,6 +20,9 @@
  */
 
 #include "lsa/name-lsa.hpp"
+#include "name-prefix-list.hpp"
+
+#include "ndn-cxx/encoding/buffer-stream.hpp"
 
 #include "tests/boost-test.hpp"
 
@@ -28,34 +31,90 @@
 BOOST_AUTO_TEST_SUITE(TestNameLsa)
 
 const uint8_t NAME_LSA1[] = {
-  0x89, 0x37, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
-  0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
-  0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
-  0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32
+  0x89, 0x4F, //name lsa
+  0x80, 0x23, // lsa
+  0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, // router name (router1)
+  0x82, 0x01, 0x0C, // sequence number (12)
+  0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34,
+  0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, // expiration time
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, // name (name1)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, // name (name2)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
 };
 
 const uint8_t NAME_LSA_EXTRA_NAME[] = {
-  0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
-  0x82, 0x01, 0x0C, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
-  0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
-  0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
-  0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
+  0x89, 0x64, //name lsa
+  0x80, 0x23, // lsa
+  0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, // router name (router1)
+  0x82, 0x01, 0x0C, // sequence number (12)
+  0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34,
+  0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, // expiration time
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, // name (name1)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, // name (name2)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33, // name (name3)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
 };
 
 const uint8_t NAME_LSA_DIFF_SEQ[] = {
-  0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
-  0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
-  0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
-  0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
-  0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
+  0x89, 0x64, //name lsa
+  0x80, 0x23, // lsa
+  0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, // router name (router1)
+  0x82, 0x01, 0x0E, // sequence number (12)
+  0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34,
+  0x3A, 0x31, 0x33, 0x3A, 0x33, 0x34, // expiration time
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, // name (name1)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, // name (name2)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33, // name (name3)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
 };
 
 const uint8_t NAME_LSA_DIFF_TS[] = {
-  0x89, 0x40, 0x80, 0x23, 0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31,
-  0x82, 0x01, 0x0E, 0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36,
-  0x20, 0x30, 0x34, 0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61,
-  0x6D, 0x65, 0x31, 0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, 0x07, 0x07, 0x08,
-  0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33
+  0x89, 0x64, //name lsa
+  0x80, 0x23, // lsa
+  0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, // router name (router1)
+  0x82, 0x01, 0x0E, // sequence number (12)
+  0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34,
+  0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, // expiration time (10s higher)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, // name (name1)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, // name (name2)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33, // name (name3)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+};
+
+const uint8_t NAME_LSA_DIFF_COST[] = {
+  0x89, 0x64, //name lsa
+  0x80, 0x23, // lsa
+  0x07, 0x09, 0x08, 0x07, 0x72, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x31, // router name (router1)
+  0x82, 0x01, 0x0E, // sequence number (12)
+  0x8B, 0x13, 0x32, 0x30, 0x32, 0x30, 0x2D, 0x30, 0x33, 0x2D, 0x32, 0x36, 0x20, 0x30, 0x34,
+  0x3A, 0x31, 0x33, 0x3A, 0x34, 0x34, // expiration time (10s higher)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x31, // name (name1)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x32, // name (name2)
+  0x8C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (0)
+  0x92, 0x13, // prefix info
+  0x07, 0x07, 0x08, 0x05, 0x6E, 0x61, 0x6D, 0x65, 0x33, // name (name3)
+  0x8C, 0x08, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // cost (10)
 };
 
 BOOST_AUTO_TEST_CASE(Basic)
@@ -76,7 +135,7 @@
   auto wire = nlsa1.wireEncode();
   BOOST_TEST(wire == NAME_LSA1, boost::test_tools::per_element());
 
-  nlsa1.addName("name3");
+  nlsa1.addName(PrefixInfo(ndn::Name("name3"), 0));
   wire = nlsa1.wireEncode();
   BOOST_TEST(wire == NAME_LSA_EXTRA_NAME, boost::test_tools::per_element());
 
@@ -90,6 +149,9 @@
   wire = nlsa1.wireEncode();
   BOOST_TEST(wire == NAME_LSA_DIFF_TS, boost::test_tools::per_element());
 
+  nlsa1.addName(PrefixInfo(ndn::Name("name3"), 10));
+  wire = nlsa1.wireEncode();
+  BOOST_TEST(wire == NAME_LSA_DIFF_COST, boost::test_tools::per_element());
   // Not testing router name as not sure if that will ever change once set
 }
 
@@ -107,9 +169,10 @@
 
 BOOST_AUTO_TEST_CASE(OperatorEquals)
 {
-  ndn::Name name1("/ndn/test/name1");
-  ndn::Name name2("/ndn/test/name2");
-  ndn::Name name3("/ndn/some/other/name1");
+  PrefixInfo name1 = PrefixInfo(ndn::Name("/ndn/test/name1"), 0);
+  PrefixInfo name2 = PrefixInfo(ndn::Name("/ndn/test/name2"), 0);
+  PrefixInfo name3 = PrefixInfo(ndn::Name("/ndn/some/other/name1"), 0);
+  PrefixInfo name4 = PrefixInfo(ndn::Name("/ndn/some/other/name1"), 1);
 
   NameLsa lsa1;
   lsa1.addName(name1);
@@ -123,6 +186,18 @@
 
   lsa2.addName(name3);
   BOOST_CHECK_EQUAL(lsa1, lsa2);
+
+  NameLsa lsa3;
+  lsa3.addName(name1);
+  lsa3.addName(name2);
+  lsa3.addName(name4);
+  BOOST_CHECK_NE(lsa2, lsa3);
+
+  NameLsa lsa4;
+  lsa4.addName(name1);
+  lsa4.addName(name2);
+  lsa4.addName(name4);
+  BOOST_CHECK_EQUAL(lsa3, lsa4);
 }
 
 BOOST_AUTO_TEST_CASE(Update)
@@ -131,8 +206,8 @@
   knownNameLsa.m_originRouter = ndn::Name("/yoursunny/_/%C1.Router/dal");
   knownNameLsa.m_seqNo = 2683;
   knownNameLsa.setExpirationTimePoint(ndn::time::system_clock::now() + 3561_ms);
-  knownNameLsa.addName("/yoursunny/_/dal");
-  knownNameLsa.addName("/ndn");
+  knownNameLsa.addName(PrefixInfo(ndn::Name("/yoursunny/_/dal"), 0));
+  knownNameLsa.addName(PrefixInfo(ndn::Name("/ndn"), 0));
 
   auto rcvdLsa = std::make_shared<NameLsa>();
   rcvdLsa->m_originRouter = ndn::Name("/yoursunny/_/%C1.Router/dal");
@@ -140,10 +215,10 @@
   rcvdLsa->setExpirationTimePoint(ndn::time::system_clock::now() + 3600_ms);
 
   auto nlsa = std::static_pointer_cast<NameLsa>(rcvdLsa);
-  nlsa->addName("/ndn");
-  nlsa->addName("/yoursunny/_/dal");
-  ndn::Name addedName1("/yoursunny/video/ndn-dpdk_acmicn20_20200917");
-  ndn::Name addedName2("/yoursunny/pushups");
+  nlsa->addName(PrefixInfo(ndn::Name("/ndn"), 0));
+  nlsa->addName(PrefixInfo(ndn::Name("/yoursunny/_/dal"), 0));
+  PrefixInfo addedName1 = PrefixInfo(ndn::Name("/yoursunny/video/ndn-dpdk_acmicn20_20200917"), 0);
+  PrefixInfo addedName2 = PrefixInfo(ndn::Name("/yoursunny/pushups"), 0);
   nlsa->addName(addedName1);
   nlsa->addName(addedName2);