From 36a7c7e7a99eb651c982d4f40b231c046e5c57f0 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 5 Jul 2015 07:07:59 +0300 Subject: [PATCH] CATS and network compatibility checker removed --- dsdl | 2 +- .../uavcan/node/global_data_type_registry.hpp | 28 -- libuavcan/include/uavcan/node/node.hpp | 36 --- .../protocol/data_type_info_provider.hpp | 47 +-- .../protocol/network_compat_checker.hpp | 281 ------------------ .../src/node/uc_global_data_type_registry.cpp | 71 ----- .../dsdl_test/dsdl_uavcan_compilability.cpp | 1 - .../test/node/global_data_type_registry.cpp | 111 ------- libuavcan/test/node/node.cpp | 9 +- libuavcan/test/node/service_client.cpp | 10 - libuavcan/test/node/sub_node.cpp | 6 +- .../test/protocol/data_type_info_provider.cpp | 1 - .../test/protocol/network_compat_checker.cpp | 124 -------- .../linux/apps/test_file_server.cpp | 7 - .../linux/apps/test_multithreading.cpp | 7 - libuavcan_drivers/linux/apps/test_node.cpp | 10 - .../linux/apps/test_time_sync.cpp | 7 - .../apps/uavcan_dynamic_node_id_server.cpp | 7 - 18 files changed, 8 insertions(+), 757 deletions(-) delete mode 100644 libuavcan/include/uavcan/protocol/network_compat_checker.hpp delete mode 100644 libuavcan/test/protocol/network_compat_checker.cpp diff --git a/dsdl b/dsdl index bda1145252..4f8a54ef25 160000 --- a/dsdl +++ b/dsdl @@ -1 +1 @@ -Subproject commit bda11452523df8c0d0d7b98183c9f747c71e87cb +Subproject commit 4f8a54ef250ebcf6b22243bb0176473cc495be87 diff --git a/libuavcan/include/uavcan/node/global_data_type_registry.hpp b/libuavcan/include/uavcan/node/global_data_type_registry.hpp index 0f4550a19f..cedf0d9724 100644 --- a/libuavcan/include/uavcan/node/global_data_type_registry.hpp +++ b/libuavcan/include/uavcan/node/global_data_type_registry.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #if UAVCAN_DEBUG @@ -18,11 +17,6 @@ namespace uavcan { -/** - * Bit mask where bit at index X is set if there's a Data Type with ID X. - */ -typedef BitSet DataTypeIDMask; - /** * This singleton is shared among all existing node instances. It is instantiated automatically * when the C++ runtime executes contstructors before main(). @@ -151,28 +145,6 @@ public: */ const DataTypeDescriptor* find(DataTypeKind kind, DataTypeID dtid) const; - /** - * Computes Aggregate Signature for all known data types selected by the mask. - * Extra bits will be zeroed. - * Please read the DSDL specification. - * @param[in] kind Data Type Kind - messages or services. - * @param[inout] inout_id_mask Data types to compute aggregate signature for; bits at - * the positions of unknown data types will be cleared. - * @return Computed data type signature. - */ - DataTypeSignature computeAggregateSignature(DataTypeKind kind, DataTypeIDMask& inout_id_mask) const; - - /** - * Sets the mask so that only bits corresponding to known data types will be set. - * In other words: - * for data_type_id := [0, 1023] - * mask[data_type_id] := data_type_exists(data_type_id) - * - * @param[in] kind Data Type Kind - messages or services. - * @param[out] mask Output mask of known data types. - */ - void getDataTypeIDMask(DataTypeKind kind, DataTypeIDMask& mask) const; - /** * Returns the number of registered message types. */ diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index 8356d2244c..7a829c2e67 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -18,7 +18,6 @@ # include # include # include -# include #endif #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) @@ -150,15 +149,6 @@ public: */ int start(const TransferPriority node_status_transfer_priority = TransferPriority::Default); -#if !UAVCAN_TINY - /** - * Please read the specs to learn about Network Compatibility Check. - * Returns negative error code. - * @param[out] result Check result (output). - */ - int checkNetworkCompatibility(NetworkCompatibilityCheckResult& result); -#endif - /** * Sets the node name, e.g. "com.example.product_name". The node name can be set only once. * Must be executed before the node is started, otherwise the node will refuse to start up. @@ -305,32 +295,6 @@ fail: return res; } -#if !UAVCAN_TINY - -template -int Node:: -checkNetworkCompatibility(NetworkCompatibilityCheckResult& result) -{ - if (!started_) - { - return -ErrNotInited; - } - - int res = NetworkCompatibilityChecker::publishGlobalDiscoveryRequest(*this); - if (res < 0) - { - return res; - } - - NetworkCompatibilityChecker checker(*this); - StaticAssert<(sizeof(checker) < 2048)>::check(); // Making sure that the code footprint doesn't explode - res = checker.execute(); - result = checker.getResult(); - return res; -} - -#endif - } #endif // UAVCAN_NODE_NODE_HPP_INCLUDED diff --git a/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp b/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp index bc294d5c6f..3508450891 100644 --- a/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp +++ b/libuavcan/include/uavcan/protocol/data_type_info_provider.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -21,50 +20,19 @@ namespace uavcan */ class UAVCAN_EXPORT DataTypeInfoProvider : Noncopyable { - typedef MethodBinder - ComputeAggregateTypeSignatureCallback; - typedef MethodBinder GetDataTypeInfoCallback; - ServiceServer cats_srv_; ServiceServer gdti_srv_; - INode& getNode() { return cats_srv_.getNode(); } + INode& getNode() { return gdti_srv_.getNode(); } static bool isValidDataTypeKind(DataTypeKind kind) { return (kind == DataTypeKindMessage) || (kind == DataTypeKindService); } - void handleComputeAggregateTypeSignatureRequest(const protocol::ComputeAggregateTypeSignature::Request& request, - protocol::ComputeAggregateTypeSignature::Response&) - { - const DataTypeKind kind = DataTypeKind(request.kind.value); // No mapping needed - if (!isValidDataTypeKind(kind)) - { - UAVCAN_TRACE("DataTypeInfoProvider", "ComputeAggregateTypeSignature request with invalid DataTypeKind %d", - kind); - return; - } - -#if 0 /* TODO FIXME */ - UAVCAN_TRACE("DataTypeInfoProvider", "ComputeAggregateTypeSignature request for dtk=%d, len(known_ids)=%d", - int(request.kind.value), int(request.known_ids.size())); - - // Correcting the mask length according to the data type kind - response.mutually_known_ids = request.known_ids; - response.mutually_known_ids.resize( - static_cast(DataTypeID::getMaxValueForDataTypeKind(kind).get() + 1U)); - - response.aggregate_signature = - GlobalDataTypeRegistry::instance().computeAggregateSignature(kind, response.mutually_known_ids).get(); -#endif - } - void handleGetDataTypeInfoRequest(const protocol::GetDataTypeInfo::Request& request, protocol::GetDataTypeInfo::Response& response) { @@ -140,22 +108,14 @@ class UAVCAN_EXPORT DataTypeInfoProvider : Noncopyable } public: - explicit DataTypeInfoProvider(INode& node) - : cats_srv_(node) - , gdti_srv_(node) + explicit DataTypeInfoProvider(INode& node) : + gdti_srv_(node) { } int start() { int res = 0; - res = cats_srv_.start( - ComputeAggregateTypeSignatureCallback(this, &DataTypeInfoProvider::handleComputeAggregateTypeSignatureRequest)); - if (res < 0) - { - goto fail; - } - res = gdti_srv_.start(GetDataTypeInfoCallback(this, &DataTypeInfoProvider::handleGetDataTypeInfoRequest)); if (res < 0) { @@ -167,7 +127,6 @@ public: fail: UAVCAN_ASSERT(res < 0); - cats_srv_.stop(); gdti_srv_.stop(); return res; } diff --git a/libuavcan/include/uavcan/protocol/network_compat_checker.hpp b/libuavcan/include/uavcan/protocol/network_compat_checker.hpp deleted file mode 100644 index 60bbb055ac..0000000000 --- a/libuavcan/include/uavcan/protocol/network_compat_checker.hpp +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#ifndef UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED -#define UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace uavcan -{ - -struct UAVCAN_EXPORT NetworkCompatibilityCheckResult -{ - NodeID conflicting_node; ///< First detected conflicting node - uint8_t num_failed_nodes; ///< Number of nodes that did not respond to service requests (probably not supporting) - - NetworkCompatibilityCheckResult() - : num_failed_nodes(0) - { } - - /** - * Quick check if the network compatibility check did not discover any problems. - */ - bool isOk() const { return !conflicting_node.isValid(); } -}; - -/** - * Performs Network Compatibility Check. Please read the specs. - * - * This class does not issue GlobalDiscoveryRequest, assuming that it was done already by the caller. - * Instantiated object can @ref execute() only once. - * Objects of this class are intended for stack allocation. - */ -class UAVCAN_EXPORT NetworkCompatibilityChecker : Noncopyable -{ - typedef BitSet NodeIDMask; - typedef MethodBinder&)> - NodeStatusCallback; - typedef MethodBinder&)> - CATSResponseCallback; - - Subscriber ns_sub_; - ServiceClient cats_cln_; - NodeIDMask nid_mask_present_; - NodeIDMask nid_mask_checked_; - NetworkCompatibilityCheckResult result_; - DataTypeKind checking_dtkind_; - bool last_cats_request_ok_; - - INode& getNode() { return ns_sub_.getNode(); } - const INode& getNode() const { return ns_sub_.getNode(); } - - MonotonicDuration getNetworkDiscoveryDelay() const - { - // Base duration is constant - NodeStatus max publication period - MonotonicDuration dur = MonotonicDuration::fromMSec(protocol::NodeStatus::MAX_PUBLICATION_PERIOD_MS); - // Additional duration depends on the node priority - gets larger with higher Node ID - dur += MonotonicDuration::fromMSec(getNode().getNodeID().get() * 10); - return dur; - } - - NodeID findNextUncheckedNode() - { - for (uint8_t i = 1; i <= NodeID::Max; i++) - { - if (nid_mask_present_.test(i) && !nid_mask_checked_.test(i)) - { - nid_mask_checked_[i] = true; - return NodeID(i); - } - } - return NodeID(); - } - - int waitForCATSResponse() - { - while (cats_cln_.hasPendingCalls()) - { - const int res = getNode().spin(MonotonicDuration::fromMSec(10)); - if (res < 0 || !result_.isOk()) - { - return res; - } - } - return 0; - } - - void handleNodeStatus(const ReceivedDataStructure& msg) - { - if (!nid_mask_present_.test(msg.getSrcNodeID().get())) - { - UAVCAN_TRACE("NodeInitializer", "New node nid=%i", int(msg.getSrcNodeID().get())); - nid_mask_present_[msg.getSrcNodeID().get()] = true; - } - - if (msg.getSrcNodeID() == getNode().getNodeID()) - { - UAVCAN_TRACE("NodeInitializer", "Node ID collision; nid=%i", int(msg.getSrcNodeID().get())); - result_.conflicting_node = msg.getSrcNodeID(); - } - } - - void handleCATSResponse(ServiceCallResult& resp) - { - last_cats_request_ok_ = resp.isSuccessful(); - if (last_cats_request_ok_) - { -#if 0 /* TODO FIXME */ - const DataTypeSignature sign = GlobalDataTypeRegistry::instance(). - computeAggregateSignature(checking_dtkind_, resp.getResponse().mutually_known_ids); - - UAVCAN_TRACE("NodeInitializer", "CATS response from nid=%i; local=%llu remote=%llu", - int(resp.getCallID().server_node_id.get()), static_cast(sign.get()), - static_cast(resp.getResponse().aggregate_signature)); - - if (sign.get() != resp.getResponse().aggregate_signature) - { - result_.conflicting_node = resp.getCallID().server_node_id; - } -#endif - } - } - - int checkOneNodeOneDataTypeKind(NodeID nid, DataTypeKind kind) - { - StaticAssert::check(); - StaticAssert::check(); - - UAVCAN_ASSERT(nid.isUnicast()); - UAVCAN_ASSERT(!cats_cln_.hasPendingCalls()); - - checking_dtkind_ = kind; - protocol::ComputeAggregateTypeSignature::Request request; - request.kind.value = kind; - // TODO FIXME -// GlobalDataTypeRegistry::instance().getDataTypeIDMask(kind, request.known_ids); - - int res = cats_cln_.call(nid, request); - if (res < 0) - { - return res; - } - res = waitForCATSResponse(); - if (res < 0) - { - return res; - } - if (!last_cats_request_ok_) - { - return -ErrFailure; - } - return 0; - } - - int checkOneNode(NodeID nid) - { - if (nid == getNode().getNodeID()) - { - result_.conflicting_node = nid; // NodeID collision - return 0; - } - - const int res = checkOneNodeOneDataTypeKind(nid, DataTypeKindMessage); - if (res < 0 || !result_.isOk()) - { - return res; - } - return checkOneNodeOneDataTypeKind(nid, DataTypeKindService); - } - - int checkNodes() - { - (void)nid_mask_checked_.reset(); - result_ = NetworkCompatibilityCheckResult(); - - while (result_.isOk()) - { - const NodeID nid = findNextUncheckedNode(); - if (nid.isValid()) - { - UAVCAN_TRACE("NodeInitializer", "Checking nid=%i", int(nid.get())); - const int res = checkOneNode(nid); - if (res < 0) - { - result_.num_failed_nodes++; - } - UAVCAN_TRACE("NodeInitializer", "Checked nid=%i result=%i", int(nid.get()), res); - } - else { break; } - } - return 0; - } - -public: - explicit NetworkCompatibilityChecker(INode& node) - : ns_sub_(node) - , cats_cln_(node) - , checking_dtkind_(DataTypeKindService) - , last_cats_request_ok_(false) - { } - - /** - * Run the check. - * Beware: this method may block for a several seconds! - * - * If this method has been executed successfully, use @ref getResult() to get the actual check result. - * - * This method can be executed only once on a given instance of this class (shall be - * destroyed and reconstructed from scratch). - * - * Returns negative error code. - */ - int execute() - { - int res = 0; - - if (!getNode().getNodeID().isUnicast()) - { - result_.conflicting_node = getNode().getNodeID(); - goto exit; - } - - res = ns_sub_.start(NodeStatusCallback(this, &NetworkCompatibilityChecker::handleNodeStatus)); - if (res < 0) - { - goto exit; - } - - cats_cln_.setCallback(CATSResponseCallback(this, &NetworkCompatibilityChecker::handleCATSResponse)); - res = cats_cln_.init(); - if (res < 0) - { - goto exit; - } - - res = getNode().spin(getNetworkDiscoveryDelay()); - if (res < 0) - { - goto exit; - } - - res = checkNodes(); - - exit: - ns_sub_.stop(); - cats_cln_.cancelAllCalls(); - return res; - } - - /** - * This method can return a meaningful result only if @ref execute() has been executed successfully once. - */ - const NetworkCompatibilityCheckResult& getResult() const { return result_; } - - /** - * Convenience method. Should be called immediately before @ref execute(). - * Returns negative error code. - */ - static int publishGlobalDiscoveryRequest(INode& node) - { - Publisher pub(node); - return pub.broadcast(protocol::GlobalDiscoveryRequest()); - } -}; - -} - -#endif // UAVCAN_PROTOCOL_NETWORK_COMPAT_CHECKER_HPP_INCLUDED diff --git a/libuavcan/src/node/uc_global_data_type_registry.cpp b/libuavcan/src/node/uc_global_data_type_registry.cpp index f882348a81..0a09d44d2f 100644 --- a/libuavcan/src/node/uc_global_data_type_registry.cpp +++ b/libuavcan/src/node/uc_global_data_type_registry.cpp @@ -196,75 +196,4 @@ const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, DataTy return NULL; } -DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind kind, - DataTypeIDMask& inout_id_mask) const -{ - UAVCAN_ASSERT(isFrozen()); // Computing the signature if the registry is not frozen is pointless - - const List* list = selectList(kind); - if (!list) - { - UAVCAN_ASSERT(0); - return DataTypeSignature(); - } - - int prev_dtid = -1; - DataTypeSignature signature; - bool signature_initialized = false; - Entry* p = list->get(); - while (p) - { - const DataTypeDescriptor& desc = p->descriptor; - const int dtid = desc.getID().get(); - - if (inout_id_mask[unsigned(dtid)]) - { - if (signature_initialized) - { - signature.extend(desc.getSignature()); - } - else - { - signature = DataTypeSignature(desc.getSignature()); - } - signature_initialized = true; - } - - UAVCAN_ASSERT(prev_dtid < dtid); // Making sure that list is ordered properly - prev_dtid++; - while (prev_dtid < dtid) - { - inout_id_mask[unsigned(prev_dtid++)] = false; // Erasing bits for missing types - } - UAVCAN_ASSERT(prev_dtid == dtid); - - p = p->getNextListNode(); - } - prev_dtid++; - while (unsigned(prev_dtid) < inout_id_mask.size()) - { - inout_id_mask[unsigned(prev_dtid++)] = false; - } - - return signature; -} - -void GlobalDataTypeRegistry::getDataTypeIDMask(DataTypeKind kind, DataTypeIDMask& mask) const -{ - (void)mask.reset(); - const List* list = selectList(kind); - if (!list) - { - UAVCAN_ASSERT(0); - return; - } - Entry* p = list->get(); - while (p) - { - UAVCAN_ASSERT(p->descriptor.getKind() == kind); - mask[p->descriptor.getID().get()] = true; - p = p->getNextListNode(); - } -} - } diff --git a/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp index 11806784fe..abc1eade73 100644 --- a/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp +++ b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include diff --git a/libuavcan/test/node/global_data_type_registry.cpp b/libuavcan/test/node/global_data_type_registry.cpp index 7edf41d2b2..488320bcd9 100644 --- a/libuavcan/test/node/global_data_type_registry.cpp +++ b/libuavcan/test/node/global_data_type_registry.cpp @@ -61,7 +61,6 @@ uavcan::DataTypeDescriptor extractDescriptor(uint16_t dtid = Type::DefaultDataTy TEST(GlobalDataTypeRegistry, Basic) { using uavcan::GlobalDataTypeRegistry; - using uavcan::DataTypeIDMask; using uavcan::DataTypeSignature; GlobalDataTypeRegistry::instance().reset(); @@ -69,14 +68,6 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_EQ(0, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(0, GlobalDataTypeRegistry::instance().getNumServiceTypes()); - DataTypeIDMask dtmask; - dtmask.set(); - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask); - ASSERT_FALSE(dtmask.any()); - dtmask.set(); - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, dtmask); - ASSERT_FALSE(dtmask.any()); - /* * Static registrations */ @@ -86,12 +77,6 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(0, GlobalDataTypeRegistry::instance().getNumServiceTypes()); - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask); - ASSERT_TRUE(dtmask[0]); - ASSERT_TRUE(dtmask[42]); - dtmask[0] = dtmask[42] = false; - ASSERT_FALSE(dtmask.any()); - /* * Runtime registrations */ @@ -102,11 +87,6 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes()); - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, dtmask); - ASSERT_TRUE(dtmask[0]); - dtmask[0] = false; - ASSERT_FALSE(dtmask.any()); - /* * Runtime re-registration */ @@ -118,17 +98,6 @@ TEST(GlobalDataTypeRegistry, Basic) ASSERT_EQ(2, GlobalDataTypeRegistry::instance().getNumMessageTypes()); ASSERT_EQ(1, GlobalDataTypeRegistry::instance().getNumServiceTypes()); - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask); - ASSERT_TRUE(dtmask[0]); - ASSERT_TRUE(dtmask[741]); - dtmask[0] = dtmask[741] = false; - ASSERT_FALSE(dtmask.any()); - - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, dtmask); - ASSERT_TRUE(dtmask[147]); - dtmask[147] = false; - ASSERT_FALSE(dtmask.any()); - /* * These types will be necessary for the aggregate signature test */ @@ -139,19 +108,6 @@ TEST(GlobalDataTypeRegistry, Basic) GlobalDataTypeRegistry::instance().registerDataType(DataTypeC::DefaultDataTypeID)); uavcan::DefaultDataTypeRegistrator reg_DataTypeD; - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, dtmask); - ASSERT_TRUE(dtmask[0]); - ASSERT_TRUE(dtmask[741]); - ASSERT_TRUE(dtmask[1023]); - dtmask[0] = dtmask[1023] = dtmask[741] = false; - ASSERT_FALSE(dtmask.any()); - - GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, dtmask); - ASSERT_TRUE(dtmask[147]); - ASSERT_TRUE(dtmask[43]); - dtmask[43] = dtmask[147] = false; - ASSERT_FALSE(dtmask.any()); - /* * Frozen state */ @@ -199,73 +155,6 @@ TEST(GlobalDataTypeRegistry, Basic) } -TEST(GlobalDataTypeRegistry, AggregateSignature) -{ - using uavcan::GlobalDataTypeRegistry; - using uavcan::DataTypeIDMask; - using uavcan::DataTypeSignature; - - ASSERT_TRUE(GlobalDataTypeRegistry::instance().isFrozen()); - - DataTypeIDMask mask; - DataTypeSignature sign; - - // Zero - empty mask - sign = GlobalDataTypeRegistry::instance().computeAggregateSignature(uavcan::DataTypeKindMessage, mask); - - ASSERT_EQ(DataTypeSignature(), sign); - ASSERT_FALSE(mask.any()); - - // All set - mask.set(); - sign = GlobalDataTypeRegistry::instance().computeAggregateSignature(uavcan::DataTypeKindMessage, mask); - ASSERT_TRUE(mask[0]); // DataTypeAMessage - ASSERT_TRUE(mask[741]); // DataTypeB - ASSERT_TRUE(mask[1023]); // DataTypeC - mask[0] = mask[741] = mask[1023] = false; - ASSERT_FALSE(mask.any()); - { - DataTypeSignature check_signature(DataTypeAMessage::getDataTypeSignature()); // Order matters - low --> high - check_signature.extend(DataTypeB::getDataTypeSignature()); - check_signature.extend(DataTypeC::getDataTypeSignature()); - ASSERT_EQ(check_signature, sign); - } - - mask.set(); - sign = GlobalDataTypeRegistry::instance().computeAggregateSignature(uavcan::DataTypeKindService, mask); - ASSERT_TRUE(mask[43]); // DataTypeD - ASSERT_TRUE(mask[147]); // DataTypeAService - mask[43] = mask[147] = false; - ASSERT_FALSE(mask.any()); - { - DataTypeSignature check_signature(DataTypeD::getDataTypeSignature()); - check_signature.extend(DataTypeAService::getDataTypeSignature()); - ASSERT_EQ(check_signature, sign); - } - - // Random - mask[0] = mask[99] = mask[147] = mask[741] = mask[999] = mask[1022] = true; - sign = GlobalDataTypeRegistry::instance().computeAggregateSignature(uavcan::DataTypeKindMessage, mask); - ASSERT_TRUE(mask[0]); // DataTypeAMessage - ASSERT_TRUE(mask[741]); // DataTypeB - mask[0] = mask[741] = false; - ASSERT_FALSE(mask.any()); - { - DataTypeSignature check_signature(DataTypeAMessage::getDataTypeSignature()); // Order matters - low --> high - check_signature.extend(DataTypeB::getDataTypeSignature()); - ASSERT_EQ(check_signature, sign); - } - - // One - mask[1] = mask[43] = true; - sign = GlobalDataTypeRegistry::instance().computeAggregateSignature(uavcan::DataTypeKindService, mask); - ASSERT_TRUE(mask[43]); // DataTypeD - mask[43] = false; - ASSERT_FALSE(mask.any()); - ASSERT_EQ(DataTypeD::getDataTypeSignature(), sign); -} - - TEST(GlobalDataTypeRegistry, Reset) { using uavcan::GlobalDataTypeRegistry; diff --git a/libuavcan/test/node/node.cpp b/libuavcan/test/node/node.cpp index a9ddc6ec03..ac65e02bd4 100644 --- a/libuavcan/test/node/node.cpp +++ b/libuavcan/test/node/node.cpp @@ -14,7 +14,6 @@ static void registerTypes() uavcan::GlobalDataTypeRegistry::instance().reset(); uavcan::DefaultDataTypeRegistrator _reg1; uavcan::DefaultDataTypeRegistrator _reg2; - uavcan::DefaultDataTypeRegistrator _reg3; uavcan::DefaultDataTypeRegistrator _reg4; uavcan::DefaultDataTypeRegistrator _reg5; uavcan::DefaultDataTypeRegistrator _reg6; @@ -59,11 +58,7 @@ TEST(Node, Basic) /* * Init the second node - network is empty */ - uavcan::NetworkCompatibilityCheckResult result; ASSERT_LE(0, node2.start()); - ASSERT_LE(0, node2.checkNetworkCompatibility(result)); - ASSERT_TRUE(result.isOk()); - ASSERT_FALSE(node_status_monitor.findNodeWithWorstStatus().isValid()); /* @@ -72,10 +67,10 @@ TEST(Node, Basic) ASSERT_FALSE(node1.isStarted()); ASSERT_EQ(-uavcan::ErrNotInited, node1.spin(uavcan::MonotonicDuration::fromMSec(20))); ASSERT_LE(0, node1.start()); - ASSERT_LE(0, node1.checkNetworkCompatibility(result)); - ASSERT_TRUE(result.isOk()); ASSERT_TRUE(node1.isStarted()); + ASSERT_LE(0, node1.spin(uavcan::MonotonicDuration::fromMSec(2000))); + ASSERT_EQ(1, node_status_monitor.findNodeWithWorstStatus().get()); /* diff --git a/libuavcan/test/node/service_client.cpp b/libuavcan/test/node/service_client.cpp index 9efe023e3a..4c08c0f8a9 100644 --- a/libuavcan/test/node/service_client.cpp +++ b/libuavcan/test/node/service_client.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -444,15 +443,6 @@ TEST(ServiceClient, Sizes) { using namespace uavcan; - std::cout << "ComputeAggregateTypeSignature server: " << - sizeof(ServiceServer) << std::endl; - - std::cout << "ComputeAggregateTypeSignature client: " << - sizeof(ServiceClient) << std::endl; - - std::cout << "ComputeAggregateTypeSignature request data struct: " << - sizeof(protocol::ComputeAggregateTypeSignature::Request) << std::endl; - std::cout << "GetDataTypeInfo server: " << sizeof(ServiceServer) << std::endl; diff --git a/libuavcan/test/node/sub_node.cpp b/libuavcan/test/node/sub_node.cpp index 698573ed8f..2bf7a5ef8d 100644 --- a/libuavcan/test/node/sub_node.cpp +++ b/libuavcan/test/node/sub_node.cpp @@ -14,7 +14,6 @@ static void registerTypes() uavcan::GlobalDataTypeRegistry::instance().reset(); uavcan::DefaultDataTypeRegistrator _reg1; uavcan::DefaultDataTypeRegistrator _reg2; - uavcan::DefaultDataTypeRegistrator _reg3; uavcan::DefaultDataTypeRegistrator _reg4; uavcan::DefaultDataTypeRegistrator _reg5; uavcan::DefaultDataTypeRegistrator _reg6; @@ -59,11 +58,10 @@ TEST(SubNode, Basic) ASSERT_FALSE(node1.isStarted()); ASSERT_EQ(-uavcan::ErrNotInited, node1.spin(uavcan::MonotonicDuration::fromMSec(20))); ASSERT_LE(0, node1.start()); - uavcan::NetworkCompatibilityCheckResult result; - ASSERT_LE(0, node1.checkNetworkCompatibility(result)); - ASSERT_TRUE(result.isOk()); ASSERT_TRUE(node1.isStarted()); + ASSERT_LE(0, node1.spin(uavcan::MonotonicDuration::fromMSec(2000))); + ASSERT_EQ(1, node_status_monitor.findNodeWithWorstStatus().get()); /* diff --git a/libuavcan/test/protocol/data_type_info_provider.cpp b/libuavcan/test/protocol/data_type_info_provider.cpp index 0af4c532d3..bbf8c84d12 100644 --- a/libuavcan/test/protocol/data_type_info_provider.cpp +++ b/libuavcan/test/protocol/data_type_info_provider.cpp @@ -9,7 +9,6 @@ #include "helpers.hpp" using uavcan::protocol::GetDataTypeInfo; -using uavcan::protocol::ComputeAggregateTypeSignature; using uavcan::protocol::NodeStatus; using uavcan::protocol::DataTypeKind; using uavcan::ServiceCallResult; diff --git a/libuavcan/test/protocol/network_compat_checker.cpp b/libuavcan/test/protocol/network_compat_checker.cpp deleted file mode 100644 index 48b07bf9af..0000000000 --- a/libuavcan/test/protocol/network_compat_checker.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include -#include "helpers.hpp" - - -static void registerTypes() -{ - uavcan::GlobalDataTypeRegistry::instance().reset(); - uavcan::DefaultDataTypeRegistrator _reg1; - uavcan::DefaultDataTypeRegistrator _reg2; - uavcan::DefaultDataTypeRegistrator _reg3; - uavcan::DefaultDataTypeRegistrator _reg4; - uavcan::DefaultDataTypeRegistrator _reg5; -} - - -struct NetworkCompatibilityCheckerRemoteContext -{ - uavcan::NodeStatusProvider node_status_provider; - uavcan::DataTypeInfoProvider data_type_info_provider; - - NetworkCompatibilityCheckerRemoteContext(uavcan::INode& node) - : node_status_provider(node) - , data_type_info_provider(node) - { - node_status_provider.setName("com.example"); - uavcan::protocol::SoftwareVersion swver; - swver.vcs_commit = 1; - node_status_provider.setSoftwareVersion(swver); - } - - void start() - { - ASSERT_LE(0, node_status_provider.startAndPublish()); - ASSERT_LE(0, data_type_info_provider.start()); - } -}; - - -TEST(NetworkCompatibilityChecker, Size) -{ - // Objects are subject for stack allocation, hence the size matters - std::cout << "sizeof(uavcan::NetworkCompatibilityChecker): " - << sizeof(uavcan::NetworkCompatibilityChecker) << std::endl; - ASSERT_TRUE(sizeof(uavcan::NetworkCompatibilityChecker) < 2048); -} - - -TEST(NetworkCompatibilityChecker, EmptyNetwork) -{ - registerTypes(); - InterlinkedTestNodesWithSysClock nodes; - - ASSERT_LE(0, uavcan::NetworkCompatibilityChecker::publishGlobalDiscoveryRequest(nodes.a)); - - uavcan::NetworkCompatibilityChecker ni(nodes.a); - ASSERT_LE(0, ni.execute()); - ASSERT_TRUE(ni.getResult().isOk()); -} - - -TEST(NetworkCompatibilityChecker, Success) -{ - registerTypes(); - InterlinkedTestNodesWithSysClock nodes; - NetworkCompatibilityCheckerRemoteContext remote(nodes.b); - remote.start(); - - BackgroundSpinner bgspinner(nodes.b, nodes.a); - bgspinner.startPeriodic(uavcan::MonotonicDuration::fromMSec(10)); - - ASSERT_LE(0, uavcan::NetworkCompatibilityChecker::publishGlobalDiscoveryRequest(nodes.a)); - - uavcan::NetworkCompatibilityChecker ni(nodes.a); - ASSERT_LE(0, ni.execute()); - ASSERT_TRUE(ni.getResult().isOk()); -} - - -TEST(NetworkCompatibilityChecker, RequestTimeout) -{ - registerTypes(); - InterlinkedTestNodesWithSysClock nodes; - NetworkCompatibilityCheckerRemoteContext remote(nodes.b); - remote.start(); - - ASSERT_LE(0, uavcan::NetworkCompatibilityChecker::publishGlobalDiscoveryRequest(nodes.a)); - - uavcan::NetworkCompatibilityChecker ni(nodes.a); - // There is no background spinner, so CATS request will time out - // Despite the time out, the checker will not report failure - ASSERT_EQ(0, ni.execute()); - - // The one (and only) node has failed - ASSERT_EQ(1, ni.getResult().num_failed_nodes); - ASSERT_TRUE(ni.getResult().isOk()); -} - - -TEST(NetworkCompatibilityChecker, NodeIDCollision) -{ - registerTypes(); - InterlinkedTestNodesWithSysClock nodes(8, 8); // Same NID - NetworkCompatibilityCheckerRemoteContext remote(nodes.b); - remote.start(); - - BackgroundSpinner bgspinner(nodes.b, nodes.a); - bgspinner.startPeriodic(uavcan::MonotonicDuration::fromMSec(10)); - - ASSERT_LE(0, uavcan::NetworkCompatibilityChecker::publishGlobalDiscoveryRequest(nodes.a)); - - uavcan::NetworkCompatibilityChecker ni(nodes.a); - ASSERT_LE(0, ni.execute()); - ASSERT_FALSE(ni.getResult().isOk()); - ASSERT_EQ(8, ni.getResult().conflicting_node.get()); -} diff --git a/libuavcan_drivers/linux/apps/test_file_server.cpp b/libuavcan_drivers/linux/apps/test_file_server.cpp index 9ea9851c73..5dff22af36 100644 --- a/libuavcan_drivers/linux/apps/test_file_server.cpp +++ b/libuavcan_drivers/linux/apps/test_file_server.cpp @@ -41,13 +41,6 @@ uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::N const int start_res = node->start(); ENFORCE(0 == start_res); - uavcan::NetworkCompatibilityCheckResult check_result; - ENFORCE(0 == node->checkNetworkCompatibility(check_result)); - if (!check_result.isOk()) - { - throw std::runtime_error("Network conflict with node " + std::to_string(check_result.conflicting_node.get())); - } - node->setStatusOk(); return node; diff --git a/libuavcan_drivers/linux/apps/test_multithreading.cpp b/libuavcan_drivers/linux/apps/test_multithreading.cpp index da9ea875db..6a9f4fbb85 100644 --- a/libuavcan_drivers/linux/apps/test_multithreading.cpp +++ b/libuavcan_drivers/linux/apps/test_multithreading.cpp @@ -404,13 +404,6 @@ static uavcan_linux::NodePtr initMainNode(const std::vector& ifaces const int start_res = node->start(); ENFORCE(0 == start_res); - uavcan::NetworkCompatibilityCheckResult init_result; - ENFORCE(0 == node->checkNetworkCompatibility(init_result)); - if (!init_result.isOk()) - { - throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get())); - } - node->setStatusOk(); return node; } diff --git a/libuavcan_drivers/linux/apps/test_node.cpp b/libuavcan_drivers/linux/apps/test_node.cpp index 0226e6ee51..57f9bb9fc5 100644 --- a/libuavcan_drivers/linux/apps/test_node.cpp +++ b/libuavcan_drivers/linux/apps/test_node.cpp @@ -28,16 +28,6 @@ static uavcan_linux::NodePtr initNode(const std::vector& ifaces, ua std::cout << "Start returned: " << start_res << std::endl; ENFORCE(0 == start_res); - /* - * Checking if our node conflicts with other nodes. This may take a few seconds. - */ - uavcan::NetworkCompatibilityCheckResult init_result; - ENFORCE(0 == node->checkNetworkCompatibility(init_result)); - if (!init_result.isOk()) - { - throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get())); - } - std::cout << "Node started successfully" << std::endl; /* diff --git a/libuavcan_drivers/linux/apps/test_time_sync.cpp b/libuavcan_drivers/linux/apps/test_time_sync.cpp index c956a4912e..bd01c32c86 100644 --- a/libuavcan_drivers/linux/apps/test_time_sync.cpp +++ b/libuavcan_drivers/linux/apps/test_time_sync.cpp @@ -19,13 +19,6 @@ static uavcan_linux::NodePtr initNode(const std::vector& ifaces, ua ENFORCE(0 == node->start()); - uavcan::NetworkCompatibilityCheckResult init_result; - ENFORCE(0 == node->checkNetworkCompatibility(init_result)); - if (!init_result.isOk()) - { - throw std::runtime_error("Network conflict with node " + std::to_string(init_result.conflicting_node.get())); - } - node->setStatusOk(); return node; } diff --git a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp b/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp index 3d4f3de299..93852a0da4 100644 --- a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp +++ b/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp @@ -51,13 +51,6 @@ uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::N const int start_res = node->start(); ENFORCE(0 == start_res); - uavcan::NetworkCompatibilityCheckResult check_result; - ENFORCE(0 == node->checkNetworkCompatibility(check_result)); - if (!check_result.isOk()) - { - throw std::runtime_error("Network conflict with node " + std::to_string(check_result.conflicting_node.get())); - } - node->setStatusOk(); return node;