From c3a37654e9a7187c830c508f93165f8373d92dd6 Mon Sep 17 00:00:00 2001 From: Viktor UZLOV Date: Wed, 27 Oct 2021 14:39:59 +0300 Subject: [PATCH] Test data transfer for CORBA, Implementation ZeroMQ library --- CMakeLists.txt | 8 ++- CTestTestfileInstall.cmake.in | 1 + SalomeKERNELConfig.cmake.in | 1 + bin/ORBConfigFile.py | 2 +- idl/SALOME_Component.idl | 3 + idl/SALOME_PyNode.idl | 8 +++ src/CMakeLists.txt | 1 + src/Container/Container_i.cxx | 15 ++++ src/Container/SALOME_ContainerPy.py | 7 ++ src/Container/SALOME_Container_i.hxx | 1 + src/Container/SALOME_PyNode.py | 19 +++++ src/Container/Test/CMakeLists.txt | 2 +- src/Container/Test/CTestTestfileInstall.cmake | 6 ++ src/Container/Test/testDataLimitation.py | 72 +++++++++++++++++++ src/SalomeZeroMQ/CMakeLists.txt | 46 ++++++++++++ src/SalomeZeroMQ/SALOME_ZeroMQ.hxx | 40 +++++++++++ src/SalomeZeroMQ/SalomeZeroMQ.cxx | 62 ++++++++++++++++ src/SalomeZeroMQ/SalomeZeroMQ.hxx | 39 ++++++++++ src/SalomeZeroMQ/SalomeZeroMQPy.py | 36 ++++++++++ src/SalomeZeroMQ/Test/CMakeLists.txt | 25 +++++++ .../Test/CTestTestfileInstall.cmake | 27 +++++++ src/SalomeZeroMQ/Test/testSalomeZeroMQ.py | 48 +++++++++++++ 22 files changed, 464 insertions(+), 5 deletions(-) create mode 100644 src/Container/Test/testDataLimitation.py create mode 100644 src/SalomeZeroMQ/CMakeLists.txt create mode 100644 src/SalomeZeroMQ/SALOME_ZeroMQ.hxx create mode 100644 src/SalomeZeroMQ/SalomeZeroMQ.cxx create mode 100644 src/SalomeZeroMQ/SalomeZeroMQ.hxx create mode 100644 src/SalomeZeroMQ/SalomeZeroMQPy.py create mode 100644 src/SalomeZeroMQ/Test/CMakeLists.txt create mode 100644 src/SalomeZeroMQ/Test/CTestTestfileInstall.cmake create mode 100644 src/SalomeZeroMQ/Test/testSalomeZeroMQ.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e644d97c..b823656d6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,8 @@ FIND_PACKAGE(SalomeSWIG REQUIRED) FIND_PACKAGE(SalomeLibXml2 REQUIRED) FIND_PACKAGE(SalomeHDF5 REQUIRED COMPONENTS C) FIND_PACKAGE(SalomeBoost REQUIRED) +FIND_PACKAGE(SalomeZeroMQ REQUIRED) +FIND_PACKAGE(SalomeCppZmq REQUIRED) # Optional prerequisites # ====================== @@ -207,7 +209,7 @@ INCLUDE(CMakePackageConfigHelpers) # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup" SET(_${PROJECT_NAME}_exposed_targets - SALOMEBasics SALOMELocalTrace SalomeHDFPersist OpUtil) + SALOMEBasics SALOMELocalTrace SalomeHDFPersist SalomeZeroMQ OpUtil) # CORBA specific targets: IF(NOT SALOME_LIGHT_ONLY) @@ -277,7 +279,7 @@ SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/inc # Build variables that will be expanded when configuring SalomeConfig.cmake: SALOME_CONFIGURE_PREPARE(CppUnit Graphviz Doxygen Sphinx MPI omniORB LibBatch - PThread Boost HDF5 libXml2 Python) + PThread Boost HDF5 libXml2 Python ZeroMQ cppzmq) CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake @@ -286,7 +288,7 @@ CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in CPPUNIT_ROOT_DIR GRAPHVIZ_ROOT_DIR DOXYGEN_ROOT_DIR SPHINX_ROOT_DIR MPI_ROOT_DIR OMNIORB_ROOT_DIR OMNIORBPY_ROOT_DIR LIBBATCH_ROOT_DIR PTHREAD_ROOT_DIR BOOST_ROOT_DIR HDF5_ROOT_DIR LIBXML2_ROOT_DIR - PYTHON_ROOT_DIR SWIG_ROOT_DIR) + PYTHON_ROOT_DIR SWIG_ROOT_DIR ZEROMQ_ROOT_DIR CPPZMQ_ROOT_DIR) # - in the install tree (VSR 16/08/2013: TEMPORARILY COMMENT THIS - TO REMOVE?): # Get the relative path of the include directory so diff --git a/CTestTestfileInstall.cmake.in b/CTestTestfileInstall.cmake.in index 245b6874c..01b11bc47 100644 --- a/CTestTestfileInstall.cmake.in +++ b/CTestTestfileInstall.cmake.in @@ -39,6 +39,7 @@ SUBDIRS( Launcher SALOMEDS SALOMEDSImpl SALOMESDS + SalomeZeroMQ Utils UnitTests salomeInstance diff --git a/SalomeKERNELConfig.cmake.in b/SalomeKERNELConfig.cmake.in index 2e2c0b9d0..59c5a7a4b 100644 --- a/SalomeKERNELConfig.cmake.in +++ b/SalomeKERNELConfig.cmake.in @@ -93,6 +93,7 @@ SET_AND_CHECK(HDF5_ROOT_DIR_EXP "@PACKAGE_HDF5_ROOT_DIR@") SET_AND_CHECK(LIBXML2_ROOT_DIR_EXP "@PACKAGE_LIBXML2_ROOT_DIR@") SET_AND_CHECK(PYTHON_ROOT_DIR_EXP "@PACKAGE_PYTHON_ROOT_DIR@") SET_AND_CHECK(SWIG_ROOT_DIR_EXP "@PACKAGE_SWIG_ROOT_DIR@") +SET_AND_CHECK(ZEROMQ_ROOT_DIR_EXP "@PACKAGE_ZEROMQ_ROOT_DIR@") # For all prerequisites, load the corresponding targets if the package was used # in CONFIG mode. This ensures dependent projects link correctly diff --git a/bin/ORBConfigFile.py b/bin/ORBConfigFile.py index b390bd146..ffc94f422 100755 --- a/bin/ORBConfigFile.py +++ b/bin/ORBConfigFile.py @@ -40,7 +40,7 @@ def readORBConfigFile(filename): # def fillOrbConfigFileNoNS(prefix,orbdata): - GIOP_MaxMsgSize = 2097152000 # 2 GBytes + GIOP_MaxMsgSize = 4294967290 # 4 Gb orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes"%(prefix,GIOP_MaxMsgSize)) orbdata.append("%straceLevel = 0 # critical errors only"%(prefix)) orbdata.append("%smaxGIOPConnectionPerServer = 500 # to allow containers parallel launch"%(prefix)) diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index d58943ad2..5207dd4ed 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -272,6 +272,9 @@ module Engines //! Obtain physical memory, used by the current process, in megabytes. long getTotalPhysicalMemoryInUseByMe(); + + //! Generate sequence of bytes and return it. + TMPFile sendData(in unsigned long size); }; /*! \brief Interface of the %component. diff --git a/idl/SALOME_PyNode.idl b/idl/SALOME_PyNode.idl index 548dec2fd..f6ad461e6 100644 --- a/idl/SALOME_PyNode.idl +++ b/idl/SALOME_PyNode.idl @@ -69,6 +69,14 @@ module Engines \return output argument values (tuple) as a python pickle */ pickledArgs execute(in string functionName, in pickledArgs inargs) raises (SALOME::SALOME_Exception); + + /*! \brief execute a python function defined in the node using ZeroMQ library + + \param functionName the python function defined in the node to execute + */ + void executeZMQ(in string functionName) raises (SALOME::SALOME_Exception); + + void setZmqSocketOpt(in string opt); } ; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 498a1f69a..b6ad73c4d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ SET(SUBDIR_BASE SALOMELocalTrace HDFPersist KERNEL_PY + SalomeZeroMQ Utils ) diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 8d23b70cc..416eb4d88 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -654,6 +654,21 @@ CORBA::Long Abstract_Engines_Container_i::getTotalPhysicalMemoryInUseByMe() return (CORBA::Long)n; } +//============================================================================= +//! +/*! +*/ +//============================================================================= +Engines::TMPFile* Abstract_Engines_Container_i::sendData(CORBA::ULong size) +{ + char* aBuffer= new char[size+1]; + for (unsigned long i = 0; i < size; ++i) + aBuffer[i] = 'D'; + unsigned long aBufferSize = strlen(aBuffer); + Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1); + return aStreamFile._retn(); +} + //============================================================================= //! Shutdown the container /*! diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index d5ee4ec14..a3bb7f6e5 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -243,6 +243,13 @@ class SALOME_ContainerPy_Gen_i(Engines__POA.Container): #------------------------------------------------------------------------- + def sendData(self, size): + aBuffer = size * "D" + aBuffer += "\0" + return (aBuffer.encode(), 1) + + #------------------------------------------------------------------------- + def _get_name(self): MESSAGE( "SALOME_ContainerPy_i::_get_name" ) return self._containerName diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index ee2c5db54..f7344bcda 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -103,6 +103,7 @@ public: CORBA::Long getTotalPhysicalMemory(); CORBA::Long getTotalPhysicalMemoryInUse(); CORBA::Long getTotalPhysicalMemoryInUseByMe(); + Engines::TMPFile* sendData(CORBA::ULong size); char *name(); char *workingdir(); char *logfilename(); diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index a4281285b..91a58912e 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -29,6 +29,7 @@ import pickle import Engines__POA import SALOME__POA import SALOME +from SalomeZeroMQPy import SalomeZeroMQ class Generic(SALOME__POA.GenericObj): """A Python implementation of the GenericObj CORBA IDL""" @@ -103,6 +104,24 @@ class PyNode_i (Engines__POA.PyNode,Generic): l=traceback.format_exception(exc_typ,exc_val,exc_fr) raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyNode: %s, function: %s" % (self.nodeName,funcName),0)) + def executeZMQ(self, funcName): + """Execute the function funcName found in local context using ZeroMQ""" + try: + input_data = self._zeroMQ.receive_data_zmq() + args,kwargs=pickle.loads(input_data) + func=self.context[funcName] + result_data=func(*args, **kwargs) + output_data=pickle.dumps(result_data, -1) + self._zeroMQ.send_data_zmq(output_data) + except: + exc_typ,exc_val,exc_fr=sys.exc_info() + l=traceback.format_exception(exc_typ,exc_val,exc_fr) + raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyNode: %s, function: %s" % (self.nodeName,funcName),0)) + + def setZmqSocketOpt(self, opt): + self._workingAddr = opt + self._zeroMQ = SalomeZeroMQ(self._workingAddr) + class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): """The implementation of the PyScriptNode CORBA IDL that executes a script""" def __init__(self, nodeName,code,poa,my_container): diff --git a/src/Container/Test/CMakeLists.txt b/src/Container/Test/CMakeLists.txt index 17d84c143..4c01605fa 100644 --- a/src/Container/Test/CMakeLists.txt +++ b/src/Container/Test/CMakeLists.txt @@ -18,7 +18,7 @@ # SET(LOCAL_TEST_DIR ${KERNEL_TEST_DIR}/Container) -INSTALL(FILES testcontainer.py DESTINATION ${LOCAL_TEST_DIR}) +INSTALL(FILES testcontainer.py testDataLimitation.py DESTINATION ${LOCAL_TEST_DIR}) INSTALL(FILES CTestTestfileInstall.cmake DESTINATION ${LOCAL_TEST_DIR} diff --git a/src/Container/Test/CTestTestfileInstall.cmake b/src/Container/Test/CTestTestfileInstall.cmake index 33360f185..c31367ca1 100644 --- a/src/Container/Test/CTestTestfileInstall.cmake +++ b/src/Container/Test/CTestTestfileInstall.cmake @@ -24,4 +24,10 @@ IF(NOT WIN32) LABELS "${COMPONENT_NAME}" ENVIRONMENT "LD_LIBRARY_PATH=${KERNEL_TEST_LIB}:$ENV{LD_LIBRARY_PATH}" ) + SET(TEST_NAME ${COMPONENT_NAME}_testDataLimitation) + ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} testDataLimitation.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + ENVIRONMENT "LD_LIBRARY_PATH=${KERNEL_TEST_LIB}:$ENV{LD_LIBRARY_PATH}" + ) ENDIF() diff --git a/src/Container/Test/testDataLimitation.py b/src/Container/Test/testDataLimitation.py new file mode 100644 index 000000000..73c9d4688 --- /dev/null +++ b/src/Container/Test/testDataLimitation.py @@ -0,0 +1,72 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest +from os import getcwd +from Engines import ContainerParameters, ResourceParameters +import SALOME +import salome + +from time import sleep + +class TestResourceManager(unittest.TestCase): + def getContainer(self, name): + rp = ResourceParameters(name="localhost", + hostname="localhost", + can_launch_batch_jobs=False, + can_run_containers=True, + OS="Linux", + componentList=[], + nb_proc=1, + mem_mb=1000, + cpu_clock=1000, + nb_node=1, + nb_proc_per_node=1, + policy="first", + resList=[]) + cp = ContainerParameters(container_name=name, + mode="start", + workingdir=getcwd(), + nb_proc=1, + isMPI=False, + parallelLib="", + resource_params=rp) + cm = salome.naming_service.Resolve("/ContainerManager") + return cm.GiveContainer(cp) + + def test1(self): + cont = self.getContainer("test_container_1") + cont.sendData(104550400) # 100 Mb + cont.Shutdown() + + def test2(self): + cont = self.getContainer("test_container_2") + cont.sendData(2143483648) # ~ 2Gb + cont.Shutdown() + + def test3(self): + cont = self.getContainer("test_container_3") + cont.sendData(2684354560) # 2.5 Gb + cont.Shutdown() + +if __name__ == '__main__': + salome.standalone() + salome.salome_init() + unittest.main() diff --git a/src/SalomeZeroMQ/CMakeLists.txt b/src/SalomeZeroMQ/CMakeLists.txt new file mode 100644 index 000000000..ee41f00d3 --- /dev/null +++ b/src/SalomeZeroMQ/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (C) 2012-2021 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE_DIRECTORIES( + ${cppzmq_INCLUDE_DIR} + ${ZeroMQ_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} +) + +# libraries to link to +SET(SalomeZeroQM_LIBRARIES + ${cppzmq_LIBRARY} + ${ZeroMQ_LIBRARY} + ) + +SET(SCRIPTS SalomeZeroMQPy.py) + +# Library +ADD_LIBRARY(SalomeZeroMQ SalomeZeroMQ.cxx) +TARGET_LINK_LIBRARIES(SalomeZeroMQ ${SalomeZeroQM_LIBRARIES}) +INSTALL(TARGETS SalomeZeroMQ EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +INSTALL(FILES SalomeZeroMQ.hxx SALOME_ZeroMQ.hxx DESTINATION ${SALOME_INSTALL_HEADERS}) + +# Executable scripts to be installed +SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${SALOME_INSTALL_PYTHON}) + +IF(SALOME_BUILD_TESTS) + ADD_SUBDIRECTORY(Test) +ENDIF(SALOME_BUILD_TESTS) \ No newline at end of file diff --git a/src/SalomeZeroMQ/SALOME_ZeroMQ.hxx b/src/SalomeZeroMQ/SALOME_ZeroMQ.hxx new file mode 100644 index 000000000..bf5c16f84 --- /dev/null +++ b/src/SalomeZeroMQ/SALOME_ZeroMQ.hxx @@ -0,0 +1,40 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SALOME_Utils.hxx +// Author : Alexander A. BORODIN +// Module : SALOME +// +#ifndef _SALOME_ZEROMQ_HXX_ +#define _SALOME_ZEROMQ_HXX_ + +#ifdef WIN32 +# if defined ZEROMQ_EXPORT +# define ZEROMQ_EXPORT __declspec( dllexport ) +# else +# define ZEROMQ_EXPORT __declspec( dllimport ) +# endif +#else +# define ZEROMQ_EXPORT +#endif + +#endif diff --git a/src/SalomeZeroMQ/SalomeZeroMQ.cxx b/src/SalomeZeroMQ/SalomeZeroMQ.cxx new file mode 100644 index 000000000..efc0c6f3a --- /dev/null +++ b/src/SalomeZeroMQ/SalomeZeroMQ.cxx @@ -0,0 +1,62 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once +#include + +#include "SalomeZeroMQ.hxx" + +DataZMQ::DataZMQ() +{ + this->cont = zmq::context_t(1); + this->addr = "inproc://hello"; + this->sock = zmq::socket_t(this->cont, zmq::socket_type::pair); +} + +void DataZMQ::connectDataZMQ() +{ + char port[1024]; + size_t size = sizeof(port); + try{ + this->sock.bind("tcp://*:*"); + } + catch (zmq::error_t&e ){ + std::cerr << "couldn't bind to socket: " << e.what(); + } + sock.getsockopt( ZMQ_LAST_ENDPOINT, &port, &size ); + std::cout << "socket is bound at port " << port << std::endl; + this->addr = std::string(port); +} + +void DataZMQ::sendDataZMQ(const char* data, int len) +{ + zmq::message_t message(len); + std::memcpy (message.data(), data, len); + this->sock.send(message); +} + +std::string DataZMQ::receiveDataZMQ() +{ + std::string s; + zmq::message_t reply{}; + this->sock.recv(reply, zmq::recv_flags::none); + s = reply.to_string(); + + return s; +} \ No newline at end of file diff --git a/src/SalomeZeroMQ/SalomeZeroMQ.hxx b/src/SalomeZeroMQ/SalomeZeroMQ.hxx new file mode 100644 index 000000000..983bf72b0 --- /dev/null +++ b/src/SalomeZeroMQ/SalomeZeroMQ.hxx @@ -0,0 +1,39 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#pragma once + +#include +#include +#include "SALOME_ZeroMQ.hxx" + +class ZEROMQ_EXPORT DataZMQ +{ +public: + DataZMQ(); + + ZEROMQ_EXPORT void sendDataZMQ(const char* data, int len); + ZEROMQ_EXPORT std::string receiveDataZMQ(); + ZEROMQ_EXPORT void connectDataZMQ(); + +public: + zmq::context_t cont; + zmq::socket_t sock; + std::string addr; +}; diff --git a/src/SalomeZeroMQ/SalomeZeroMQPy.py b/src/SalomeZeroMQ/SalomeZeroMQPy.py new file mode 100644 index 000000000..016713f7e --- /dev/null +++ b/src/SalomeZeroMQ/SalomeZeroMQPy.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python3 +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import zmq + +class SalomeZeroMQ(): + def __init__(self, addr) -> None: + self.addr = addr + self.context = zmq.Context() + self.socket = self.context.socket(zmq.PAIR) + self.socket.connect(self.addr) + + def send_data_zmq(self, msg): + self.socket.send(msg) + + def receive_data_zmq(self): + msg = self.socket.recv() + return msg diff --git a/src/SalomeZeroMQ/Test/CMakeLists.txt b/src/SalomeZeroMQ/Test/CMakeLists.txt new file mode 100644 index 000000000..c2b55fbd2 --- /dev/null +++ b/src/SalomeZeroMQ/Test/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (C) 2012-2021 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(LOCAL_TEST_DIR ${KERNEL_TEST_DIR}/SalomeZeroMQ) +INSTALL(FILES testSalomeZeroMQ.py DESTINATION ${LOCAL_TEST_DIR}) + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${LOCAL_TEST_DIR} + RENAME CTestTestfile.cmake) diff --git a/src/SalomeZeroMQ/Test/CTestTestfileInstall.cmake b/src/SalomeZeroMQ/Test/CTestTestfileInstall.cmake new file mode 100644 index 000000000..7e4d84e13 --- /dev/null +++ b/src/SalomeZeroMQ/Test/CTestTestfileInstall.cmake @@ -0,0 +1,27 @@ +# Copyright (C) 2015-2021 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +IF(NOT WIN32) + SET(TEST_NAME ${COMPONENT_NAME}_testSalomeZeroMQ) + ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} testSalomeZeroMQ.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES + LABELS "${COMPONENT_NAME}" + ENVIRONMENT "LD_LIBRARY_PATH=${KERNEL_TEST_LIB}:$ENV{LD_LIBRARY_PATH}" + ) +ENDIF() diff --git a/src/SalomeZeroMQ/Test/testSalomeZeroMQ.py b/src/SalomeZeroMQ/Test/testSalomeZeroMQ.py new file mode 100644 index 000000000..8a9fc6106 --- /dev/null +++ b/src/SalomeZeroMQ/Test/testSalomeZeroMQ.py @@ -0,0 +1,48 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest +import zmq +from os import getcwd +from SalomeZeroMQPy import SalomeZeroMQ +from Engines import ContainerParameters, ResourceParameters +import SALOME +import salome + +from time import sleep + +class TestSalomeZeroMQ(unittest.TestCase): + def test1(self): + context = zmq.Context() + serv_socket = context.socket(zmq.PAIR) + serv_socket.bind("tcp://*:*") + addr = serv_socket.getsockopt(zmq.LAST_ENDPOINT) + client = SalomeZeroMQ(addr) + aData = 3347433647 * b"D" # 3.1 Gb + # server -> client + serv_socket.send(aData) + msg = client.socket.recv() + # server <- client + client.socket.send(aData) + msg = serv_socket.recv + + +if __name__ == '__main__': + unittest.main() -- 2.39.2