Hi
I'm very interested in NSIS protocol. and I applied the testbed that you put in the file in your homepage in the internet and I did a new NSLP application as you explain in this page : http://www.christian-dickmann.de/nsis.php?page=createnslp but I have some problems in extending the new application's message (in step 4 ( 4.Use the new object to send a new message type)) so, Please if you can help me and send to me more details about this file or this step or another example with more details or any way you see good for you !
Best regards Muataz
_________________________________________________________________ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/
Hi,
please find attached a short tutorial how to solve step 4 on Christian's page. Also the running code is included.
Best regards, Bernd
Muataz Bellah kanjo wrote:
Hi
I'm very interested in NSIS protocol. and I applied the testbed that you put in the file in your homepage in the internet and I did a new NSLP application as you explain in this page : http://www.christian-dickmann.de/nsis.php?page=createnslp but I have some problems in extending the new application's message (in step 4 ( 4.Use the new object to send a new message type)) so, Please if you can help me and send to me more details about this file or this step or another example with more details or any way you see good for you !
Best regards Muataz
More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/ _______________________________________________ Nsis_Imp mailing list Nsis_Imp@informatik.uni-goettingen.de https://user.informatik.uni-goettingen.de/mailman/listinfo/nsis_imp
4.1 Add sendHopDiscoveryMessage() to SampleNslpClient
Extend the file objects.xml file for SampleNslpHopCountObject by inserting <code>2</code> between <name> and <elements>. When running the php-script to generate the objects a #define SAMPLENSLPHOPCOUNTOBJECT 2 is included into the header file. Each object then has its own constant value. Note: SAMPLENSLPSAMPLEOBJECT is defined as 1.
You have to extend the enum command by tg_hopdiscovery_message. See the code example how to do this. The examples are in the "diff -Naur" style.
+++ sample/clientapi/SampleNslpCommunicator.h @@ -55,6 +55,7 @@
enum command { tg_sample_message, + tg_hopdiscovery_message, };
void recvSession(unsigned char sid[16]);
This enum value is used in the next code example to identify the hop discovery message. In SampleNslpClient.cpp add the function sendHopDiscoveryMessage(IPaddr destination) with destination ip address as argument. Using the communication library send the command and next the ip address to the server application. Finally wait for the return code of the received response.
+++ sample/clientapi/SampleNslpClient.cpp @@ -79,3 +79,12 @@ int respCode = communicator->recvResponse(); return respCode; } + +int SampleNslpClient::sendHopDiscoveryMessage(IPaddr destination) +{ + communicator->sendCommand(SampleNslpCommunicator::tg_hopdiscovery_message); + communicator->sendIP(destination); + int respCode = communicator->recvResponse(); + return respCode; +} +
Make the function known in the header file.
+++ sample/clientapi/SampleNslpClient.h @@ -56,6 +56,7 @@ void connectToDaemon();
int sendSampleMessage(IPaddr destination, int sequenceNumber); + int sendHopDiscoveryMessage(IPaddr destination);
private: int sock;
4.2 Change sample_client.cpp to use new message type
Add -s and -h as command line arguments to sample_client.cpp. The client application then knows what message to send (SampleMessage or HopDiscoveryMessage) and later what information it has to receive(response code or number of hops).
+++ sample/sample_client.cpp @@ -41,8 +41,10 @@
int main(int argc, char * argv[]) { - if (argc != 2) { - printf("Usage: %s <ip>\n", argv[0]); + if ((argc != 3) || (strcmp(argv[1], "-s") && strcmp(argv[1], "-h"))) { + printf("Usage: %s [-s] [-h] <ip>\n", argv[0]); + printf("-s: send SampleMessage\n"); + printf("-h: send HopDiscoveryMessage\n"); return 1; }
@@ -50,13 +52,22 @@
IPaddr addr; addr.version = 4; - addr.v4 = inet_addr(argv[1]); - + addr.v4 = inet_addr(argv[2]); + int res; + client->connectToDaemon(); printf("Connected to SampleNslp Daemon\n"); - int res = client->sendSampleMessage(addr, 1); - printf("Response code: %d\n", res); - + if(!strcmp(argv[1], "-s")) { + res = client->sendSampleMessage(addr, 1); + printf("Response code: %d\n", res); + } else if(!strcmp(argv[1], "-h")) { + res = client->sendHopDiscoveryMessage(addr); + printf("Number of hops to %s: %d\n", argv[2], res); + } else { + printf("unknown command\n"); + exit(-1); + } + delete client;
return 0;
4.3 Handle HopDiscoveryMessage in intermediate Nodes, Pass discovered HopCount to the client, add sendHopDiscoveryMessage() to SampleNslpFsm
On arrival of a hopCountObject in downstream direction the variable hopCount is incremented and the new value is written into the hopCountObject. Note: only on intermediate and the end node this value is incremented. If the sending node received the message the value is passed to the client. The code of sendSampleMessage() can be reused and is named void createMRI().
The function sendHopCountMessage() creates a SampleNslpMessage and a SampleNslpHopCountObject. The HopCountObject is added to message and is sent via the NSLP-API to GIST.
+++ sample/logic/SampleNslpFsm.cpp @@ -56,7 +56,15 @@ return; }
- printf("Received SampleNslp message\n"); + if(message->hopCountObject && data->mri->d == DOWNSTREAM) { + + int hopCount = message->hopCountObject->hopcount(); + hopCount++; + + printf("This is hop %d.\n", hopCount); + message->hopCountObject->hopcount(hopCount); + + }
if (data->isReceiver) { data->mri->d = UPSTREAM; @@ -75,18 +83,22 @@ SampleNslpFsmData * savedData = (SampleNslpFsmData*)server->api->getNslpState(data->sid); printf("Received Message and we are the initiator (clientSock = %d)\n", savedData->clientSock); - + int response_code = 0; + if(message->hopCountObject) { + response_code = message->hopCountObject->hopcount(); + } + server->communicator->setSocket(savedData->clientSock); - server->communicator->sendResponse(0); + server->communicator->sendResponse(response_code); // TODO: give sequence to client }
-void SampleNslpFsm::sendSampleMessage(SampleNslpFsmData * data, IPaddr destination, int sequenceNumber) -{ +void SampleNslpFsm::createMRI(SampleNslpFsmData *data, IPaddr destination) { + IPaddr localAddr = NsisConfiguration::general_localIPv4s[0];
// Generate MRI - msg_routing_info_path_coupled_t * mri = new msg_routing_info_path_coupled_t; + mri = new msg_routing_info_path_coupled_t; memset(mri, 0, sizeof(msg_routing_info_path_coupled_t));
mri->msgRoutingMethod = GIST_DEFAULT_MRM; @@ -111,7 +123,11 @@ } mri->d = DOWNSTREAM; data->mri = mri;
- +} + +void SampleNslpFsm::sendSampleMessage(SampleNslpFsmData * data, IPaddr destination, int sequenceNumber) +{ + createMRI(data, destination); // Generate Message SampleNslpMessage * message = new SampleNslpMessage(); SampleNslpSampleObject * sampleObject = new SampleNslpSampleObject(sequenceNumber); @@ -126,3 +142,21 @@ delete message; }
+void SampleNslpFsm::sendHopCountMessage(SampleNslpFsmData *data, IPaddr destination, int hopCount) { + + createMRI(data, destination); + // Generate Message + SampleNslpMessage * message = new SampleNslpMessage(); + SampleNslpHopCountObject * hopCountObject = new SampleNslpHopCountObject(hopCount); + message->addHopCountObject(hopCountObject); + + // Send Message + server->api->SendMessage((char*)message->getBuffer(), message->getLength(), + NULL, SAMPLENSLP_NSLP_ID, data->sid, (msg_routing_info_base_t*)data->mri, + 0 /* SII Handle */, data->reliability, data->security, FALSE, true, 2000, 10); + + delete mri; + delete message; +} + +
Make the functions createMRI() and sendHopCountMessage() known in the header-file.
++ sample/logic/SampleNslpFsm.h @@ -51,10 +51,13 @@
void handleIncomingMessage(SampleNslpFsmData * data, SampleNslpMessage * message); void receivedResponse(SampleNslpFsmData * data, SampleNslpMessage * message); + void createMRI(SampleNslpFsmData *data, IPaddr destination); void sendSampleMessage(SampleNslpFsmData * data, IPaddr destination, int sequenceNumber); + void sendHopCountMessage(SampleNslpFsmData *data, IPaddr destination, int hopCount);
private: SampleNslpServer * server; + msg_routing_info_path_coupled_t * mri; };
#endif /*DIAGFSM_H_*/
4.4 Add handler for new client trigger to SampleNslpServer
The handler for the new client trigger is copied from the first case (tg_sample_message). hopCount is initialized with 1. The DebugLogger shows that a HopDiscovery message is sent. After initilizing the SampleNslpFsmData and SessionID data, destination and hopCount is passed to sendHopCountMessage().
+++ sample/SampleNslpServer.cpp 2009-09-01 15:42:04.000000000 +0200 @@ -142,6 +142,26 @@ fsm->sendSampleMessage(data, destination, sequenceNumber); break; } + + + case SampleNslpCommunicator::tg_hopdiscovery_message: { + + int hopCount = 1; + DebugLogger::print(4, "Sending HopDiscovery message\n"); + IPaddr destination = communicator->recvIP(); + + SampleNslpFsmData * data = new SampleNslpFsmData(); + data->reliability = false; + data->security = false; + data->sid = new unsigned char[16]; + data->clientSock = sockfd; + newSession(data->sid); + + api->setNslpState(data->sid, data); + + fsm->sendHopCountMessage(data, destination, hopCount); + break; + } } } catch (std::runtime_error ex) { closeSocket(sockfd);
Sorry, the attachment got blocked. Please download it here:
https://user.informatik.uni-goettingen.de/~bschloer/sample.tar.gz
Regards, Bernd
Bernd Schloer wrote:
Hi,
please find attached a short tutorial how to solve step 4 on Christian's page. Also the running code is included.
Best regards, Bernd
Muataz Bellah kanjo wrote:
Hi
I'm very interested in NSIS protocol. and I applied the testbed that you put in the file in your homepage in the internet and I did a new NSLP application as you explain in this page : http://www.christian-dickmann.de/nsis.php?page=createnslp but I have some problems in extending the new application's message (in step 4 ( 4.Use the new object to send a new message type)) so, Please if you can help me and send to me more details about this file or this step or another example with more details or any way you see good for you !
Best regards Muataz
More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/ _______________________________________________ Nsis_Imp mailing list Nsis_Imp@informatik.uni-goettingen.de https://user.informatik.uni-goettingen.de/mailman/listinfo/nsis_imp
Nsis_Imp mailing list Nsis_Imp@informatik.uni-goettingen.de https://user.informatik.uni-goettingen.de/mailman/listinfo/nsis_imp
nsis_imp@informatik.uni-goettingen.de