|
@@ -5,6 +5,7 @@
|
|
|
not open a TCP port. */
|
|
|
|
|
|
#include <open62541/server_config_default.h>
|
|
|
+#include <open62541/plugin/nodestore_default.h>
|
|
|
|
|
|
#include "server/ua_services.h"
|
|
|
#include "ua_server_internal.h"
|
|
@@ -16,56 +17,53 @@
|
|
|
#include "testing_networklayers.h"
|
|
|
#include "testing_policy.h"
|
|
|
|
|
|
-static UA_SecureChannel testChannel;
|
|
|
-static UA_SecurityPolicy dummyPolicy;
|
|
|
-static UA_Connection testingConnection;
|
|
|
-static funcs_called funcsCalled;
|
|
|
-static key_sizes keySizes;
|
|
|
+#define READNODES 10000 /* Number of nodes to be created for reading */
|
|
|
+#define READS 1000000 /* Number of reads to perform */
|
|
|
|
|
|
static UA_Server *server;
|
|
|
+static UA_NodeId readNodeIds[READNODES];
|
|
|
|
|
|
static void setup(void) {
|
|
|
- server = UA_Server_new();
|
|
|
- UA_ServerConfig_setDefault(UA_Server_getConfig(server));
|
|
|
-
|
|
|
- TestingPolicy(&dummyPolicy, UA_BYTESTRING_NULL, &funcsCalled, &keySizes);
|
|
|
- UA_SecureChannel_init(&testChannel);
|
|
|
- UA_SecureChannel_setSecurityPolicy(&testChannel, &dummyPolicy, &UA_BYTESTRING_NULL);
|
|
|
-
|
|
|
- testingConnection = createDummyConnection(65535, NULL);
|
|
|
- UA_Connection_attachSecureChannel(&testingConnection, &testChannel);
|
|
|
- testChannel.connection = &testingConnection;
|
|
|
+ UA_ServerConfig config;
|
|
|
+ memset(&config, 0, sizeof(UA_ServerConfig));
|
|
|
+ UA_Nodestore_HashMap(&config.nodestore);
|
|
|
+ server = UA_Server_newWithConfig(&config);
|
|
|
}
|
|
|
|
|
|
static void teardown(void) {
|
|
|
- UA_SecureChannel_close(&testChannel);
|
|
|
- UA_SecureChannel_deleteMembers(&testChannel);
|
|
|
- dummyPolicy.clear(&dummyPolicy);
|
|
|
- testingConnection.close(&testingConnection);
|
|
|
-
|
|
|
UA_Server_delete(server);
|
|
|
}
|
|
|
|
|
|
START_TEST(readSpeed) {
|
|
|
- /* add a variable node to the address space */
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+
|
|
|
+ /* Add variable nodes to the address space */
|
|
|
UA_VariableAttributes attr = UA_VariableAttributes_default;
|
|
|
UA_Int32 myInteger = 42;
|
|
|
UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
|
|
|
- attr.description = UA_LOCALIZEDTEXT("en-US","the answer");
|
|
|
- attr.displayName = UA_LOCALIZEDTEXT("en-US","the answer");
|
|
|
- UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
|
|
|
- UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
|
|
|
UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
|
|
|
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
|
|
|
- UA_StatusCode retval = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId,
|
|
|
- parentReferenceNodeId, myIntegerName,
|
|
|
- UA_NODEID_NULL, attr, NULL, NULL);
|
|
|
+ for(size_t i = 0; i < READNODES; i++) {
|
|
|
+ char varName[20];
|
|
|
+ UA_snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
|
|
+ UA_NodeId myNodeId = UA_NODEID_STRING(1, varName);
|
|
|
+ UA_QualifiedName myName = UA_QUALIFIEDNAME(1, varName);
|
|
|
+ retval = UA_Server_addVariableNode(server, myNodeId, parentNodeId,
|
|
|
+ parentReferenceNodeId, myName,
|
|
|
+ UA_NODEID_NULL, attr, NULL,
|
|
|
+ &readNodeIds[i]);
|
|
|
+ UA_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
+ }
|
|
|
+
|
|
|
+ UA_ByteString request_msg;
|
|
|
+ retval |= UA_ByteString_allocBuffer(&request_msg, 1000);
|
|
|
+ UA_ByteString response_msg;
|
|
|
+ retval |= UA_ByteString_allocBuffer(&response_msg, 1000);
|
|
|
UA_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
|
|
|
UA_ReadRequest request;
|
|
|
UA_ReadRequest_init(&request);
|
|
|
UA_ReadValueId rvi;
|
|
|
- rvi.nodeId = myIntegerNodeId;
|
|
|
rvi.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
rvi.indexRange = UA_STRING_NULL;
|
|
|
rvi.dataEncoding = UA_QUALIFIEDNAME(0, "Default Binary");
|
|
@@ -73,15 +71,74 @@ START_TEST(readSpeed) {
|
|
|
request.nodesToReadSize = 1;
|
|
|
request.nodesToRead = &rvi;
|
|
|
|
|
|
+ UA_ReadResponse res;
|
|
|
+ UA_ReadResponse_init(&res);
|
|
|
+
|
|
|
+ clock_t begin, finish;
|
|
|
+ begin = clock();
|
|
|
+
|
|
|
+ for(size_t i = 0; i < READS ; i++) {
|
|
|
+ /* Set the NodeId */
|
|
|
+ rvi.nodeId = readNodeIds[i % READNODES];
|
|
|
+
|
|
|
+ UA_LOCK(server->serviceMutex);
|
|
|
+ Service_Read(server, &server->adminSession, &request, &res);
|
|
|
+ UA_UNLOCK(server->serviceMutex);
|
|
|
+
|
|
|
+ UA_ReadResponse_deleteMembers(&res);
|
|
|
+ }
|
|
|
+
|
|
|
+ finish = clock();
|
|
|
+ ck_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ double time_spent = (double)(finish - begin) / CLOCKS_PER_SEC;
|
|
|
+ printf("duration was %f s\n", time_spent);
|
|
|
+ printf("retval is %s\n", UA_StatusCode_name(retval));
|
|
|
+
|
|
|
+ UA_ByteString_deleteMembers(&request_msg);
|
|
|
+ UA_ByteString_deleteMembers(&response_msg);
|
|
|
+
|
|
|
+ for(size_t i = 0; i < READNODES; i++)
|
|
|
+ UA_NodeId_clear(&readNodeIds[i]);
|
|
|
+}
|
|
|
+END_TEST
|
|
|
+
|
|
|
+START_TEST(readSpeedWithEncoding) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+
|
|
|
+ /* Add variable nodes to the address space */
|
|
|
+ UA_VariableAttributes attr = UA_VariableAttributes_default;
|
|
|
+ UA_Int32 myInteger = 42;
|
|
|
+ UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
|
|
|
+ UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
|
|
|
+ UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
|
|
|
+ for(size_t i = 0; i < READNODES; i++) {
|
|
|
+ char varName[20];
|
|
|
+ UA_snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
|
|
+ UA_NodeId myNodeId = UA_NODEID_STRING(1, varName);
|
|
|
+ UA_QualifiedName myName = UA_QUALIFIEDNAME(1, varName);
|
|
|
+ retval = UA_Server_addVariableNode(server, myNodeId, parentNodeId,
|
|
|
+ parentReferenceNodeId, myName,
|
|
|
+ UA_NODEID_NULL, attr, NULL,
|
|
|
+ &readNodeIds[i]);
|
|
|
+ UA_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
+ }
|
|
|
+
|
|
|
UA_ByteString request_msg;
|
|
|
retval |= UA_ByteString_allocBuffer(&request_msg, 1000);
|
|
|
UA_ByteString response_msg;
|
|
|
retval |= UA_ByteString_allocBuffer(&response_msg, 1000);
|
|
|
+ UA_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_Byte *pos = request_msg.data;
|
|
|
- const UA_Byte *end = &request_msg.data[request_msg.length];
|
|
|
- retval |= UA_encodeBinary(&request, &UA_TYPES[UA_TYPES_READREQUEST], &pos, &end, NULL, NULL);
|
|
|
- ck_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
+ UA_ReadRequest request;
|
|
|
+ UA_ReadRequest_init(&request);
|
|
|
+ UA_ReadValueId rvi;
|
|
|
+ rvi.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
+ rvi.indexRange = UA_STRING_NULL;
|
|
|
+ rvi.dataEncoding = UA_QUALIFIEDNAME(0, "Default Binary");
|
|
|
+ request.timestampsToReturn = UA_TIMESTAMPSTORETURN_NEITHER;
|
|
|
+ request.nodesToReadSize = 1;
|
|
|
+ request.nodesToRead = &rvi;
|
|
|
|
|
|
UA_ReadRequest req;
|
|
|
UA_ReadResponse res;
|
|
@@ -90,7 +147,17 @@ START_TEST(readSpeed) {
|
|
|
clock_t begin, finish;
|
|
|
begin = clock();
|
|
|
|
|
|
- for(size_t i = 0; i < 1000000; i++) {
|
|
|
+ for(size_t i = 0; i < READS; i++) {
|
|
|
+ /* Set the NodeId */
|
|
|
+ rvi.nodeId = readNodeIds[i % READNODES];
|
|
|
+
|
|
|
+ /* Encode the request */
|
|
|
+ UA_Byte *pos = request_msg.data;
|
|
|
+ const UA_Byte *end = &request_msg.data[request_msg.length];
|
|
|
+ retval |= UA_encodeBinary(&request, &UA_TYPES[UA_TYPES_READREQUEST], &pos, &end, NULL, NULL);
|
|
|
+ ck_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ /* Decode the request */
|
|
|
size_t offset = 0;
|
|
|
retval |= UA_decodeBinary(&request_msg, &offset, &req, &UA_TYPES[UA_TYPES_READREQUEST], NULL);
|
|
|
|
|
@@ -111,11 +178,14 @@ START_TEST(readSpeed) {
|
|
|
ck_assert(retval == UA_STATUSCODE_GOOD);
|
|
|
|
|
|
double time_spent = (double)(finish - begin) / CLOCKS_PER_SEC;
|
|
|
- printf("duration was %f s\n", time_spent);
|
|
|
+ printf("duration with encoding was %f s\n", time_spent);
|
|
|
printf("retval is %s\n", UA_StatusCode_name(retval));
|
|
|
|
|
|
UA_ByteString_deleteMembers(&request_msg);
|
|
|
UA_ByteString_deleteMembers(&response_msg);
|
|
|
+
|
|
|
+ for(size_t i = 0; i < READNODES; i++)
|
|
|
+ UA_NodeId_clear(&readNodeIds[i]);
|
|
|
}
|
|
|
END_TEST
|
|
|
|
|
@@ -125,6 +195,7 @@ static Suite * service_speed_suite (void) {
|
|
|
TCase* tc_read = tcase_create ("Read");
|
|
|
tcase_add_checked_fixture(tc_read, setup, teardown);
|
|
|
tcase_add_test (tc_read, readSpeed);
|
|
|
+ tcase_add_test (tc_read, readSpeedWithEncoding);
|
|
|
suite_add_tcase (s, tc_read);
|
|
|
|
|
|
return s;
|