From 53c99c1f10556207b4075e25c9d2a62a8643fb6e Mon Sep 17 00:00:00 2001 From: jai Date: Thu, 15 Feb 2007 02:28:25 +0000 Subject: adding DS library --- modules/TAO/tests/DiffServ/README | 10 ++ modules/TAO/tests/DiffServ/client.cpp | 162 +++++++++++++++++++++++++ modules/TAO/tests/DiffServ/diffserv.mpc | 34 ++++++ modules/TAO/tests/DiffServ/server.cpp | 201 ++++++++++++++++++++++++++++++++ modules/TAO/tests/DiffServ/test.idl | 9 ++ 5 files changed, 416 insertions(+) create mode 100644 modules/TAO/tests/DiffServ/README create mode 100644 modules/TAO/tests/DiffServ/client.cpp create mode 100644 modules/TAO/tests/DiffServ/diffserv.mpc create mode 100644 modules/TAO/tests/DiffServ/server.cpp create mode 100644 modules/TAO/tests/DiffServ/test.idl diff --git a/modules/TAO/tests/DiffServ/README b/modules/TAO/tests/DiffServ/README new file mode 100644 index 00000000000..fbbbf2ae943 --- /dev/null +++ b/modules/TAO/tests/DiffServ/README @@ -0,0 +1,10 @@ +$Id$ + +This is a unit test for setting DiffServ Codepoint both in the +requests sent and the replies received. + +To run (on Unix): +----------------- + +$ ./server -ORBdebuglevel 1 -p 20000 +$ ./client -ORBdebuglevel 1 -n 10 -k file://simple_servant.ior diff --git a/modules/TAO/tests/DiffServ/client.cpp b/modules/TAO/tests/DiffServ/client.cpp new file mode 100644 index 00000000000..5255e9c068f --- /dev/null +++ b/modules/TAO/tests/DiffServ/client.cpp @@ -0,0 +1,162 @@ +// $Id$ + +#include "testC.h" +#include "ace/Get_Opt.h" +#include "tao/Policy_Manager.h" +#include "tao/DiffServPolicy/DiffServPolicyC.h" +#include "tao/DiffServPolicy/Client_Network_Priority_Policy.h" +#include "tao/DiffServPolicy/Server_Network_Priority_Policy.h" + +static const char *ior = "file://simple_servant.ior"; +static int iterations = 1; + +#define IPDSFIELD_DSCP_DEFAULT 0x00 +#define IPDSFIELD_DSCP_CS1 0x08 +#define IPDSFIELD_DSCP_CS2 0x10 +#define IPDSFIELD_DSCP_CS3 0x18 +#define IPDSFIELD_DSCP_CS4 0x20 +#define IPDSFIELD_DSCP_CS5 0x28 +#define IPDSFIELD_DSCP_CS6 0x30 +#define IPDSFIELD_DSCP_CS7 0x38 +#define IPDSFIELD_DSCP_AF11 0x0A +#define IPDSFIELD_DSCP_AF12 0x0C +#define IPDSFIELD_DSCP_AF13 0x0E +#define IPDSFIELD_DSCP_AF21 0x12 +#define IPDSFIELD_DSCP_AF22 0x14 +#define IPDSFIELD_DSCP_AF23 0x16 +#define IPDSFIELD_DSCP_AF31 0x1A +#define IPDSFIELD_DSCP_AF32 0x1C +#define IPDSFIELD_DSCP_AF33 0x1E +#define IPDSFIELD_DSCP_AF41 0x22 +#define IPDSFIELD_DSCP_AF42 0x24 +#define IPDSFIELD_DSCP_AF43 0x26 +#define IPDSFIELD_ECT_MASK 0x02 +#define IPDSFIELD_CE_MASK 0x01 +#define IPDSFIELD_DSCP_EF 0x2E + +static int const dscp[] = +{ + IPDSFIELD_DSCP_DEFAULT , + IPDSFIELD_DSCP_CS1 , + IPDSFIELD_DSCP_CS2 , + IPDSFIELD_DSCP_CS3 , + IPDSFIELD_DSCP_CS4 , + IPDSFIELD_DSCP_CS5 , + IPDSFIELD_DSCP_CS6 , + IPDSFIELD_DSCP_CS7 , + IPDSFIELD_DSCP_AF11 , + IPDSFIELD_DSCP_AF12 , + IPDSFIELD_DSCP_AF13 , + IPDSFIELD_DSCP_AF21 , + IPDSFIELD_DSCP_AF22 , + IPDSFIELD_DSCP_AF23 , + IPDSFIELD_DSCP_AF31 , + IPDSFIELD_DSCP_AF32 , + IPDSFIELD_DSCP_AF33 , + IPDSFIELD_DSCP_AF41 , + IPDSFIELD_DSCP_AF42 , + IPDSFIELD_DSCP_AF43 , + IPDSFIELD_DSCP_EF +}; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:n:x:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.opt_arg (); + break; + + // number of itarations + case 'n': + iterations = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s\n" + "\t-k [default is %s]\n" + "\t-n [defaults to %d]\n" + "\n", + argv [0], + ior, + iterations), + -1); + } + + return 0; +} + +int +main (int argc, char *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, ""); + + if (parse_args (argc, argv) != 0) + return -1; + + // Initialize and obtain reference to the Test object. + CORBA::Object_var client_object = + orb->string_to_object (ior); + + Test_var server = + Test::_narrow (client_object.in ()); + + TAO::DiffservCodepoint request_dscp; + TAO::DiffservCodepoint reply_dscp; + int request_array_slot = 12; + int reply_array_slot = 13; + long request_dscp_codepoint = dscp[request_array_slot]; + long reply_dscp_codepoint = dscp[reply_array_slot]; + request_dscp = request_dscp_codepoint; + reply_dscp = reply_dscp_codepoint; + + CORBA::PolicyList policy_list; + policy_list.length (1); + + CORBA::Policy_var client_network_policy = + orb->_create_policy (TAO::CLIENT_NETWORK_PRIORITY_TYPE); + + TAO::NetworkPriorityPolicy_var nw_priority = + TAO::NetworkPriorityPolicy::_narrow (client_network_policy.in ()); + + nw_priority->request_diffserv_codepoint ( + request_dscp); + + nw_priority->reply_diffserv_codepoint ( + reply_dscp); + + nw_priority->network_priority_model ( + TAO::CLIENT_PROPAGATED_NETWORK_PRIORITY); + + policy_list[0] = nw_priority.in (); + + CORBA::Object_var over_ridden_object = server->_set_policy_overrides ( + policy_list, CORBA::SET_OVERRIDE); + + server = Test::_narrow (over_ridden_object.in ()); + + // Make several invocation, + for (int i = 0; i < iterations; ++i) + { + server->test_method (); + } + + server->shutdown (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Caught exception:"); + return -1; + } + + return 0; +} diff --git a/modules/TAO/tests/DiffServ/diffserv.mpc b/modules/TAO/tests/DiffServ/diffserv.mpc new file mode 100644 index 00000000000..c0bcd397153 --- /dev/null +++ b/modules/TAO/tests/DiffServ/diffserv.mpc @@ -0,0 +1,34 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + test.idl + } + custom_only = 1 +} + +project(*client) : taoexe, portableserver, diffservpolicy, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + after += *idl + source_files { + client.cpp + } + source_files { + testC.cpp + } + IDL_Files { + } +} + +project(*server) : taoexe, portableserver, diffservpolicy, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + after += *client + source_files { + server.cpp + } + source_files { + testC.cpp + testS.cpp + } + IDL_Files { + } +} diff --git a/modules/TAO/tests/DiffServ/server.cpp b/modules/TAO/tests/DiffServ/server.cpp new file mode 100644 index 00000000000..a119f56527e --- /dev/null +++ b/modules/TAO/tests/DiffServ/server.cpp @@ -0,0 +1,201 @@ +// $Id$ + +#include "testS.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "tao/debug.h" +#include "tao/DiffServPolicy/DiffServPolicyC.h" +#include "tao/DiffServPolicy/Server_Network_Priority_Policy.h" +#include "tao/DiffServPolicy/Client_Network_Priority_Policy.h" + +#define IPDSFIELD_DSCP_DEFAULT 0x00 +#define IPDSFIELD_DSCP_CS1 0x08 +#define IPDSFIELD_DSCP_CS2 0x10 +#define IPDSFIELD_DSCP_CS3 0x18 +#define IPDSFIELD_DSCP_CS4 0x20 +#define IPDSFIELD_DSCP_CS5 0x28 +#define IPDSFIELD_DSCP_CS6 0x30 +#define IPDSFIELD_DSCP_CS7 0x38 +#define IPDSFIELD_DSCP_AF11 0x0A +#define IPDSFIELD_DSCP_AF12 0x0C +#define IPDSFIELD_DSCP_AF13 0x0E +#define IPDSFIELD_DSCP_AF21 0x12 +#define IPDSFIELD_DSCP_AF22 0x14 +#define IPDSFIELD_DSCP_AF23 0x16 +#define IPDSFIELD_DSCP_AF31 0x1A +#define IPDSFIELD_DSCP_AF32 0x1C +#define IPDSFIELD_DSCP_AF33 0x1E +#define IPDSFIELD_DSCP_AF41 0x22 +#define IPDSFIELD_DSCP_AF42 0x24 +#define IPDSFIELD_DSCP_AF43 0x26 +#define IPDSFIELD_ECT_MASK 0x02 +#define IPDSFIELD_CE_MASK 0x01 +#define IPDSFIELD_DSCP_EF 0x2E + +static int const dscp[] = +{ + IPDSFIELD_DSCP_DEFAULT , + IPDSFIELD_DSCP_CS1 , + IPDSFIELD_DSCP_CS2 , + IPDSFIELD_DSCP_CS3 , + IPDSFIELD_DSCP_CS4 , + IPDSFIELD_DSCP_CS5 , + IPDSFIELD_DSCP_CS6 , + IPDSFIELD_DSCP_CS7 , + IPDSFIELD_DSCP_AF11 , + IPDSFIELD_DSCP_AF12 , + IPDSFIELD_DSCP_AF13 , + IPDSFIELD_DSCP_AF21 , + IPDSFIELD_DSCP_AF22 , + IPDSFIELD_DSCP_AF23 , + IPDSFIELD_DSCP_AF31 , + IPDSFIELD_DSCP_AF32 , + IPDSFIELD_DSCP_AF33 , + IPDSFIELD_DSCP_AF41 , + IPDSFIELD_DSCP_AF42 , + IPDSFIELD_DSCP_AF43 , + IPDSFIELD_DSCP_EF +}; + + +class Test_i : public POA_Test +{ +public: + Test_i (CORBA::ORB_ptr orb); + + void test_method (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + void shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + CORBA::ORB_var orb_; +}; + +Test_i::Test_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +void +Test_i::test_method (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACE_DEBUG ((LM_DEBUG, + "Test_i::test_method\n")); +} + +void +Test_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER); +} + +static const char *simple_servant_ior_file = "simple_servant.ior"; + +void +create_object (PortableServer::POA_ptr poa, + CORBA::ORB_ptr orb, + Test_i *servant, + const char *filename) +{ + // Register with poa. + PortableServer::ObjectId_var id = + poa->activate_object (servant); + + CORBA::Object_var object = + poa->id_to_reference (id.in ()); + + CORBA::String_var ior = + orb->object_to_string (object.in ()); + + ACE_DEBUG ((LM_DEBUG, "<%s>\n\n", ior.in ())); + + FILE *output_file= ACE_OS::fopen (filename, "w"); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); +} + +int +main (int argc, char *argv[]) +{ + try + { + CORBA::Object_var object; + + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, ""); + + // RootPOA. + object = + orb->resolve_initial_references ("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (object.in ()); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + TAO::DiffservCodepoint request_dscp; + TAO::DiffservCodepoint reply_dscp; + int request_array_slot = 3; + int reply_array_slot = 2; + long request_dscp_codepoint = dscp[request_array_slot]; + long reply_dscp_codepoint = dscp[reply_array_slot]; + request_dscp = request_dscp_codepoint; + reply_dscp = reply_dscp_codepoint; + + TAO::NetworkPriorityModel npm = TAO::CLIENT_PROPAGATED_NETWORK_PRIORITY; + + CORBA::PolicyList policy_list; + policy_list.length (1); + + CORBA::Policy_var npp = + orb->_create_policy (TAO::NETWORK_PRIORITY_TYPE); + + TAO::NetworkPriorityPolicy_var nw_priority = + TAO::NetworkPriorityPolicy::_narrow (npp.in ()); + + nw_priority->network_priority_model ( + npm); + + nw_priority->request_diffserv_codepoint ( + request_dscp); + + nw_priority->reply_diffserv_codepoint ( + reply_dscp); + + policy_list[0] = nw_priority.in (); + + PortableServer::POA_var child_poa = + root_poa->create_POA ("Child_POA", + poa_manager.in (), + policy_list); + + // Servant. + Test_i servant (orb.in ()); + + // Create the first object in Root POA + create_object (child_poa.in (), + orb.in (), + &servant, + simple_servant_ior_file); + + // Activate POA manager. + poa_manager->activate (); + + // Start ORB event loop. + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "Server ORB event loop finished\n\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Unexpected exception caught:"); + return -1; + } + + return 0; +} diff --git a/modules/TAO/tests/DiffServ/test.idl b/modules/TAO/tests/DiffServ/test.idl new file mode 100644 index 00000000000..3ed4d3d20ea --- /dev/null +++ b/modules/TAO/tests/DiffServ/test.idl @@ -0,0 +1,9 @@ +// +// $Id$ +// + +interface Test +{ + void test_method (); + oneway void shutdown (); +}; -- cgit v1.2.1