Esempio n. 1
0
Packet* SimpleGen::generateMessage()
{
	char name[20];
	int src = getId();
	int dest = 31337;
	int priority = intrand(5) + 1;
	int Payload = 1;
	int ByteLength = intuniform(0, 1000);
	int ds = intrand(2);
	packetId += 1;

	// Generate simple message name
	sprintf(name, "msg-%d", packetId);

	//Create new packet
	Packet* packet = new Packet(name);

	// Set properties
	packet->setSessionID(sessionId);
	packet->setPacketID(packetId);
	packet->setSrc(src);
	packet->setDst(dest);
	packet->setSessionID(sessionId);
	packet->setPacketID(packetId);
	packet->setPriority(priority);
	packet->setPayload(Payload);
	packet->setByteLength(ByteLength);
	packet->setDs(ds);
	packet->setCreationTime(simTime().dbl());

	return packet;
}
Esempio n. 2
0
SimpleGen::SimpleGen()
{
	// Create event message
	event = new cMessage("event");
	// Initialize...
	sessionId = intuniform(100, 999);
	packetId = 0;
}
Esempio n. 3
0
TicTocMsg14*
Txc14::generateMessage()
{
    // The "current" module index.
    int src = getIndex();
    // The module size.
    int n = size();
    int dest = intuniform(0, n-1);

    char msgname[20];
    sprintf(msgname, "tic-%d-to-%d", src, dest);

    // Create message object and set source and destination field.
    TicTocMsg14 *msg = new TicTocMsg14(msgname);
    msg->setSource(src);
    msg->setDestination(dest);
    return msg;
}
Esempio n. 4
0
void
Txc13::forwardMessage(cMessage *msg)
{
    // check_and_cast from omnetpp.h perform a dynamic cast or raise an error
    // during the simulation instead of crash.
    TicTocMsg13 *ttmsg = check_and_cast<TicTocMsg13 *>(msg);

    // Incrementing the hop count.
    ttmsg->setHopCount(ttmsg->getHopCount() + 1);

    // In this example, we just pick a random gate to send it on.
    int n = gateSize("gate");
    EV << "Forwarding message...\n" <<"..Gate size: " << n <<";\n";
    // We draw a random number between 0 and n-1.
    int k = intuniform(0, n-1);
    EV << ".." <<msg <<" on gate[" <<k <<"].\n";
    // $o and $i suffix is used to identify the input/output part of a two way gate.
    send(ttmsg, "gate$o", k);
}