Hi Alberto, Sorry for the delay. Please see inline … On Apr 13, 2015, at 3:14 AM, <aguti...@ac.upc.edu> <aguti...@ac.upc.edu> wrote:
> Hi, > > I got the following code modifying the test suite available in the Sandesh > C++ library folder: > > int port = 8086; > ASSERT_LT(0, port); > std::cout << "Initializing Generator" << std::endl; > Sandesh::InitGenerator("SandeshUVEAlarmTest-Client", "192.168.100.1", > "Test", "0", evm_.get(), 0, NULL); > std::cout << "Connecting to collector" << std::endl; > Sandesh::ConnectToCollector("192.168.100.10", port); > std::cout << "Handshake done" << std::endl; > TASK_UTIL_EXPECT_TRUE(Sandesh::client()->state() == > SandeshClientSM::ESTABLISHED); [Megh]: This should make sure that the client status is ESTABLISHED before sending the message below. > std::cout << "Connection to collector should be established" << std::endl; > // add uve > // case 0 > SandeshUVEData uve_data1; > uve_data1.set_name("uve1"); > SandeshUVETest::Send(uve_data1); > > Here I disabled the sever initialization step as I want to use a real > collector node (192.168.100.10). The execution is sent from IP 192.168.100.1. > > However, when evaluating the client status it's not > SandeshClientSM::ESTABLISHED, it's in fact status 2, which is CONNECT. So it > seems to be a step missing. > > On the connector log I get the following output for the execution: > 2015-04-13 Mon 10:05:02:264.921 UTC contrail [Thread 140679780972416, Pid > 1975]: Session 192.168.100.10:8086::192.168.100.1:54945(15)< Accepted session > from 192.168.100.1:54945 > > 2015-04-13 Mon 10:05:21:736.472 UTC contrail [Thread 140679780972416, Pid > 1975]: Session 192.168.100.10:8086::192.168.100.1:54945(15)< Read failed due > to error 2 : End of file > > On the application I get the following: > 2015-04-13 Mon 12:11:17:354.925 CEST Mahalanobis [Thread 140662758741952, > Pid 5233]: primary 192.168.100.10:8086 > 2015-04-13 Mon 12:11:17:354.945 CEST Mahalanobis [Thread 140662758741952, > Pid 5233]: secondary 0.0.0.0:0 > Handshake done > 2015-04-13 Mon 12:11:17:355.309 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Processing scm::EvStart in state Idle > 2015-04-13 Mon 12:11:17:355.415 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Disconnect > 2015-04-13 Mon 12:11:17:355.566 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Processing scm::EvDiscUpdate in state Disconnect > 2015-04-13 Mon 12:11:17:355.850 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Connect : Start Connect timer 192.168.100.10:8086 [Megh]: From the logs it does not seem that the state machine has moved to ESTABLISHED. Your code should have failed when checking for the state above. > 2015-04-13 Mon 12:11:17:355.984 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Processing scm::EvSandeshSend in state Connect > 2015-04-13 Mon 12:11:17:356.012 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Wrong state: Connect for event: EvSandeshSend > 2015-04-13 Mon 12:11:17:356.043 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Processing scm::EvSandeshSend in state Connect > 2015-04-13 Mon 12:11:17:356.065 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Wrong state: Connect for event: EvSandeshSend > 2015-04-13 Mon 12:11:17:356.093 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Processing scm::EvSandeshSend in state Connect > 2015-04-13 Mon 12:11:17:356.116 CEST Mahalanobis [Thread 140662631671552, > Pid 5233]: Wrong state: Connect for event: EvSandeshSend > > > > So, it seems to connects correctly but fails sending the UVE. > > > > Could anyone help me with this? Pointers to documentation would be really > valuable. My guess is that the TASK_UTIL_EXPECT_TRUE code is not waiting enough. Can you please check? The client state machine after connecting to the collector, sends a control message to move to ClientInit state, and after that on receipt of the reply from the collector moves to established. You can look at the code in sandesh_client_sm.cc for details. https://github.com/Juniper/contrail-sandesh/blob/master/library/cpp/sandesh_client_sm.cc Thanks Megh > > Best regards, > Alberto. > > Quoting aguti...@ac.upc.edu: > >> Hi Megh, >> >> Thanks for your help. With that I think I got the compilation at hand. >> >> Now I'm trying to do a small application to send one message and die. >> >> I defined the following toy sandesh for testing: >> struct UveVirtualNetworkAgent { >> 1: string name(key="ObjectVNTable") >> 2: optional i32 cpu >> } >> >> uve sandesh UveVirtualNetworkAgentTrace { >> 1: UveVirtualNetworkAgent data; >> } >> >> Then I did the following code: >> int main() { >> Sandesh::InitGenerator() >> >> UveVirtualNetworkAgent a; >> a.set_name("TestUnit"); >> a.set_cpu(100); >> UveVirtualNetworkAgentTrace::Send(a); >> } >> >> However I don't know which of the 2 InitGenerator functions from the Sandesh >> module should I use and what is the meaning of each parameter. >> >> static bool InitGenerator(const std::string &module, >> const std::string &source, >> const std::string &node_type, >> const std::string &instance_id, >> EventManager *evm, >> unsigned short http_port, >> CollectorSubFn csf, >> const std::vector<std::string> &collectors, >> SandeshContext *client_context = NULL); >> >> static void InitGenerator(const std::string &module, >> const std::string &source, >> const std::string &node_type, >> const std::string &instance_id, >> EventManager *evm, >> unsigned short http_port, >> SandeshContext *client_context = NULL); >> >> Is there any source where it explains this part? I haven't found it yet. >> >> And one more question: Does setting name(key="ObjectVNTable") to "TestUnit" >> create a new table in the database that I could query using de API of the >> analytics module? >> >> Thank you for the support. >> >> Best regards, >> Alberto. >> >> Quoting Megh Bhatt <me...@juniper.net>: >> >>> Hi Alberto, >>> Please see inline .... >>> >>> On Apr 8, 2015, at 1:54 AM, aguti...@ac.upc.edu<mailto:aguti...@ac.upc.edu> >>> wrote: >>> >>> Dear all, >>> >>> I'm trying to create a new message to send with Sandesh protocol, however I >>> don't know how to compile the generated code. >>> >>> Just a high level overview which you might already know. The sandesh >>> compiler/code generator will be present in build/bin/sandesh after you >>> execute scons at the top level. The source code for same is at This is used >>> to generate the python/C++ code based on the .sandesh file. The generated >>> code - .py files for python and .cpp files for C++ need to be used with the >>> pysandesh package for python and libsandesh for C++ in client applications >>> to send Sandesh messages to the contrail collector. >>> >>> Are you using C++ or python? >>> >>> We intend to use this messaging for testing purposes (at the moment) by >>> means of an extra application which will send Sandesh messages each second. >>> >>> >>> I have found the following explaination for the compilation with Scons: >>> -------- >>> To use Sandesh, the following needs to be added to the module SConscript: >>> / >>> # Generate the source files >>> SandeshGenFiles = env.SandeshGenCpp('VNS.sandesh') >>> SandeshGenFiles += env.SandeshGenCpp('VNSwitch.sandesh') >>> >>> # The above returns VNS_types.h, VNS_types.cpp, VNS_constants.h >>> # VNS_constants.cpp, VNSwitch_types.h, VNSwitch_types.cpp, >>> # VNSwitch_constants.h, VNSwitch_constants.cpp >>> >>> # To include the header files above from your module's sources >>> env.Append(CPPPATH = env['TOP']) >>> >>> # Extract the .cpp files to be used as sources >>> SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles) >>> >>> Add SandeshGenSrcs to the module source files >>> >>> Add libsandesh, and libbase to the module libraries. >>> -------- >>> >>> However I don't really get what's going on (I'm new to Scons). >>> >>> The SandeshGenCpp function/ scons builder is defined in >>> tools/build/rules.py - https://github.com/Juniper/contrail-build >>> >>> Below is a relevant snippet ... >>> >>> >>> # SandeshGenCpp Methods >>> def SandeshCppBuilder(target, source, env): >>> opath = target[0].dir.path >>> sname = os.path.join(opath, os.path.splitext(source[0].name)[0]) >>> >>> code = subprocess.call(env['SANDESH'] + ' --gen cpp --gen html -I >>> controller/src/ -I tools -out ' >>> + opath + " " + source[0].path, shell=True) >>> if code != 0: >>> raise SCons.Errors.StopError(SandeshCodeGeneratorError, >>> 'SandeshCpp code generation failed') >>> tname = sname + "_html_template.cpp" >>> hname = os.path.basename(sname + ".xml") >>> cname = sname + "_html.cpp" >>> if not env.Detect('xxd'): >>> raise SCons.Errors.StopError(SandeshCodeGeneratorError, >>> 'xxd not detected on system') >>> os.system("echo \"namespace {\"" + " >> " + cname) >>> os.system("(cd " + opath + " ; xxd -i " + hname + " >> " + >>> os.path.basename(cname) + " )") >>> os.system("echo \"}\"" + " >> " + cname) >>> os.system("cat " + tname + " >> " + cname) >>> >>> >>> >>> As you can see, it runs build/bin/sandesh --gen cpp --gen html <other >>> options> <.sandesh file> to produce the .cpp, .h files which then need to >>> be compiled in the client application. >>> >>> >>> I tried to copy the SConscript of the control module and adapt it but >>> without results. >>> >>> Can anyone help me? >>> >>> Hope the above helps and please let me know if any more information is >>> needed. >>> >>> Thanks >>> >>> Megh >>> >>> >>> Best Regards, >>> Alberto. >>> >>> >>> >>> _______________________________________________ >>> Dev mailing list >>> Dev@lists.opencontrail.org<mailto:Dev@lists.opencontrail.org> >>> http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org >>> >>> >> >> >> > > _______________________________________________ Dev mailing list Dev@lists.opencontrail.org http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org