Following the NS-3 nomenclature, Libns3-amqtt is an implementation model which includes the most used MQTT messages. We assume you know the basic NS-3 concepts.
The “libns3-amqtt.so" contains this necessary libraries for implementing the protocol from scratch. The supported version is the MQTT 3.1.
You can also see a guide of how to integrate this library into the NS-3 here:
Once you install the library (as a NS-3 model library), you must add an the "include" in the source file where you will use it. Afterwards, we provide the following example:
Following the NS-3 nomenclature, Libns3-amqtt is an implementation model which includes the most used MQTT messages. We assume you know the basic NS-3 concepts.
The “libns3-amqtt.so" contains this necessary libraries for implementing the protocol from scratch. The supported version is the MQTT 3.1.
You can also see a guide of how to integrate this library into the NS-3 here:
http://www.eg.bucknell.edu/~perrone/2010/08/27/creating-a-new-module-in-ns-3/
By now, the supported messages are:
CONNECT
CONNACK
PUBLISH
PUBACK
SUBSCRIBE
SUBACK
Once you install the library (as a NS-3 model library), you must add an the "include" in the source file where you will use it. Afterwards, we provide the following example:
#include ...
#include "ns3/amqtt-module.h"
void SendStuff (Ptr<Socket> sock, InetSocketAddress Isa, uint8_t type, uint16_t msgid, std::string MSG);
int
main (int argc, char *argv[])
{
std::string Massage;
Simulator::Schedule (Seconds (0.1),&SendStuff, srcSocket, dst, SUBSCRIBE, 10, Massage);
Simulator::Stop (Seconds (3.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
void SendStuff (Ptr<Socket> sock, InetSocketAddress Isa, uint8_t type, uint16_t msgid, std::string MSG) {
int s=0;
mqtt omqtt;
omqtt.SetHeader(type);
switch (type >> 4)
{
case 1: // CONNECT
omqtt.SetData("12345678910 Esta es una prueba de MQTT, OK ...");
break;
case 2: // CONNACK
break;
case 3: // PUBLISH Topic, id Mensaje, publicación
omqtt.SetPublish("La michamacha",1,"Actualización de prueba1");
break;
case 4: // PUBACK
omqtt.SetMsgid(msgid);
break;
case 8: // SUBSCRIBE
omqtt.SetMsgid(msgid);
omqtt.SetData(MSG);
break;
case 9: // SUBACK
omqtt.SetMsgid(msgid);
omqtt.SetData("1");
break;
}
omqtt.Print(std::cout);
Ptr<Packet> p = Create <Packet> (); //(reinterpret_cast<const uint8_t*="">;
p->AddHeader(omqtt);
Address addr;
sock->GetSockName(addr);
InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
s = sock->SendTo (p, 0, Isa);
return;
}
Last edit: Augusto Morales. UPM 2012-10-15