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 <[email protected]>:
Hi Alberto,
Please see inline ....
On Apr 8, 2015, at 1:54 AM,
[email protected]<mailto:[email protected]> 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
[email protected]<mailto:[email protected]>
http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org
_______________________________________________
Dev mailing list
[email protected]
http://lists.opencontrail.org/mailman/listinfo/dev_lists.opencontrail.org