INET Framework for OMNeT++/OMNEST
inet::SimpleVoIPSender Class Reference

Implements a simple VoIP source. More...

#include <SimpleVoIPSender.h>

Inheritance diagram for inet::SimpleVoIPSender:
inet::ILifecycle

Public Member Functions

virtual ~SimpleVoIPSender ()
 
 SimpleVoIPSender ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

void talkspurt (simtime_t dur)
 
void selectTalkOrSilenceInterval ()
 
void sendVoIPPacket ()
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Private Attributes

UDPSocket socket
 
simtime_t stopTime
 
simtime_t packetizationInterval
 
int localPort = -1
 
int destPort = -1
 
int talkPacketSize = 0
 
L3Address destAddress
 
cMessage * selfSender = nullptr
 
cMessage * selfSource = nullptr
 
simtime_t silenceDuration
 
simtime_t talkspurtDuration
 
int packetID = -1
 
int talkspurtID = -1
 
int talkspurtNumPackets = 0
 
bool isTalk = false
 

Detailed Description

Implements a simple VoIP source.

See the NED file for more information.

Constructor & Destructor Documentation

inet::SimpleVoIPSender::~SimpleVoIPSender ( )
virtual
35 {
36  cancelAndDelete(selfSender);
37  cancelAndDelete(selfSource);
38 }
cMessage * selfSender
Definition: SimpleVoIPSender.h:48
cMessage * selfSource
Definition: SimpleVoIPSender.h:49
inet::SimpleVoIPSender::SimpleVoIPSender ( )
31 {
32 }

Member Function Documentation

void inet::SimpleVoIPSender::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
85 {
86  if (msg->isSelfMessage()) {
87  if (msg == selfSender)
89  else
91  }
92 }
void sendVoIPPacket()
Definition: SimpleVoIPSender.cc:143
cMessage * selfSender
Definition: SimpleVoIPSender.h:48
void selectTalkOrSilenceInterval()
Definition: SimpleVoIPSender.cc:114
virtual bool inet::SimpleVoIPSender::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
inlineoverrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

66  { Enter_Method_Silent(); throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName()); return true; }
void inet::SimpleVoIPSender::initialize ( int  stage)
overrideprotectedvirtual
41 {
42  EV_TRACE << "VoIP Sender initialize: stage " << stage << endl;
43 
44  cSimpleModule::initialize(stage);
45 
46  // avoid multiple initializations
47  if (stage == INITSTAGE_LOCAL) {
49  silenceDuration = 0;
50  selfSource = new cMessage("selfSource");
51  isTalk = false;
52  talkspurtID = 0;
54  packetID = 0;
55  talkPacketSize = par("talkPacketSize");
56  packetizationInterval = par("packetizationInterval").doubleValue();
57  selfSender = new cMessage("selfSender");
58  localPort = par("localPort");
59  destPort = par("destPort");
60  }
61  else if (stage == INITSTAGE_APPLICATION_LAYER) {
62  bool isOperational;
63  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
64  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
65  if (!isOperational)
66  throw cRuntimeError("This module doesn't support starting in node DOWN state");
67 
68  socket.setOutputGate(gate("udpOut"));
70 
71  EV_INFO << "VoIPSender::initialize - binding to port: local:" << localPort << " , dest:" << destPort << endl;
72 
73  // calculating traffic starting time
74  simtime_t startTime = par("startTime").doubleValue();
75  stopTime = par("stopTime").doubleValue();
76  if (stopTime >= SIMTIME_ZERO && stopTime < startTime)
77  throw cRuntimeError("Invalid startTime/stopTime settings: startTime %g s greater than stopTime %g s", SIMTIME_DBL(startTime), SIMTIME_DBL(stopTime));
78 
79  scheduleAt(startTime, selfSource);
80  EV_INFO << "\t starting traffic in " << startTime << " s" << endl;
81  }
82 }
simtime_t talkspurtDuration
Definition: SimpleVoIPSender.h:51
simtime_t silenceDuration
Definition: SimpleVoIPSender.h:50
simtime_t packetizationInterval
Definition: SimpleVoIPSender.h:41
UDPSocket socket
Definition: SimpleVoIPSender.h:37
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UDPSocket.h:110
int talkspurtID
Definition: SimpleVoIPSender.h:53
int talkspurtNumPackets
Definition: SimpleVoIPSender.h:54
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
cMessage * selfSender
Definition: SimpleVoIPSender.h:48
cMessage * selfSource
Definition: SimpleVoIPSender.h:49
int localPort
Definition: SimpleVoIPSender.h:42
int talkPacketSize
Definition: SimpleVoIPSender.h:44
simtime_t stopTime
Definition: SimpleVoIPSender.h:40
bool isTalk
Definition: SimpleVoIPSender.h:55
int packetID
Definition: SimpleVoIPSender.h:52
int destPort
Definition: SimpleVoIPSender.h:43
void bind(int localPort)
Bind the socket to a local port number.
Definition: UDPSocket.cc:53
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
virtual int inet::SimpleVoIPSender::numInitStages ( ) const
inlineoverrideprotectedvirtual
62 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::SimpleVoIPSender::selectTalkOrSilenceInterval ( )
protected

Referenced by handleMessage().

115 {
116  simtime_t now = simTime();
117  if (stopTime >= SIMTIME_ZERO && now >= stopTime)
118  return;
119 
120  if (isTalk) {
121  silenceDuration = par("silenceDuration").doubleValue();
122  EV_DEBUG << "SILENCE: " << "Duration: " << silenceDuration << " seconds\n\n";
123  simtime_t endSilence = now + silenceDuration;
124  if (stopTime >= SIMTIME_ZERO && endSilence > stopTime)
125  endSilence = stopTime;
126  scheduleAt(endSilence, selfSource);
127  isTalk = false;
128  }
129  else {
130  talkspurtDuration = par("talkspurtDuration").doubleValue();
131  EV_DEBUG << "TALKSPURT: " << talkspurtID << " Duration: " << talkspurtDuration << " seconds\n\n";
132  simtime_t endTalk = now + talkspurtDuration;
133  if (stopTime >= SIMTIME_ZERO && endTalk > stopTime) {
134  endTalk = stopTime;
135  talkspurtDuration = stopTime - now;
136  }
137  talkspurt(talkspurtDuration);
138  scheduleAt(endTalk, selfSource);
139  isTalk = true;
140  }
141 }
simtime_t talkspurtDuration
Definition: SimpleVoIPSender.h:51
simtime_t silenceDuration
Definition: SimpleVoIPSender.h:50
int talkspurtID
Definition: SimpleVoIPSender.h:53
cMessage * selfSource
Definition: SimpleVoIPSender.h:49
simtime_t stopTime
Definition: SimpleVoIPSender.h:40
bool isTalk
Definition: SimpleVoIPSender.h:55
void talkspurt(simtime_t dur)
Definition: SimpleVoIPSender.cc:94
void inet::SimpleVoIPSender::sendVoIPPacket ( )
protected

Referenced by handleMessage().

144 {
146  destAddress = L3AddressResolver().resolve(par("destAddress").stringValue());
147 
148  SimpleVoIPPacket *packet = new SimpleVoIPPacket("VoIP");
149  packet->setTalkspurtID(talkspurtID - 1);
150  packet->setTalkspurtNumPackets(talkspurtNumPackets);
151  packet->setPacketID(packetID);
152  packet->setVoipTimestamp(simTime() - packetizationInterval); // start time of voice in this packet
153  packet->setVoiceDuration(packetizationInterval);
154  packet->setByteLength(talkPacketSize);
155  EV_INFO << "TALKSPURT " << talkspurtID - 1 << " sending packet " << packetID << "\n";
156 
157  socket.sendTo(packet, destAddress, destPort);
158  ++packetID;
159 
160  if (packetID < talkspurtNumPackets)
161  scheduleAt(simTime() + packetizationInterval, selfSender);
162 }
void sendTo(cPacket *msg, L3Address destAddr, int destPort, const SendOptions *options=nullptr)
Sends a data packet to the given address and port.
Definition: UDPSocket.cc:88
L3Address destAddress
Definition: SimpleVoIPSender.h:45
simtime_t packetizationInterval
Definition: SimpleVoIPSender.h:41
UDPSocket socket
Definition: SimpleVoIPSender.h:37
int talkspurtID
Definition: SimpleVoIPSender.h:53
int talkspurtNumPackets
Definition: SimpleVoIPSender.h:54
bool isUnspecified() const
Definition: L3Address.cc:133
cMessage * selfSender
Definition: SimpleVoIPSender.h:48
#define stringValue()
Definition: NedFunctions.cc:24
int talkPacketSize
Definition: SimpleVoIPSender.h:44
int packetID
Definition: SimpleVoIPSender.h:52
int destPort
Definition: SimpleVoIPSender.h:43
void inet::SimpleVoIPSender::talkspurt ( simtime_t  dur)
protected

Referenced by selectTalkOrSilenceInterval().

95 {
96  simtime_t curTime = simTime();
97  simtime_t startTime = curTime;
98  if (selfSender->isScheduled()) {
99  // silence was too short, detected overlapping talkspurts
100  simtime_t delta = selfSender->getArrivalTime() - curTime;
101  startTime += delta;
102  dur -= SIMTIME_DBL(delta);
103  cancelEvent(selfSender);
104  }
105 
106  talkspurtID++;
107  packetID = 0;
109  EV_DEBUG << "TALKSPURT " << talkspurtID - 1 << " will be sent " << talkspurtNumPackets << " packets\n\n";
110 
111  scheduleAt(startTime + packetizationInterval, selfSender);
112 }
simtime_t packetizationInterval
Definition: SimpleVoIPSender.h:41
int talkspurtID
Definition: SimpleVoIPSender.h:53
int talkspurtNumPackets
Definition: SimpleVoIPSender.h:54
cMessage * selfSender
Definition: SimpleVoIPSender.h:48
int packetID
Definition: SimpleVoIPSender.h:52

Member Data Documentation

L3Address inet::SimpleVoIPSender::destAddress
private

Referenced by sendVoIPPacket().

int inet::SimpleVoIPSender::destPort = -1
private

Referenced by initialize(), and sendVoIPPacket().

bool inet::SimpleVoIPSender::isTalk = false
private
int inet::SimpleVoIPSender::localPort = -1
private

Referenced by initialize().

int inet::SimpleVoIPSender::packetID = -1
private
simtime_t inet::SimpleVoIPSender::packetizationInterval
private
cMessage* inet::SimpleVoIPSender::selfSender = nullptr
private
cMessage* inet::SimpleVoIPSender::selfSource = nullptr
private
simtime_t inet::SimpleVoIPSender::silenceDuration
private
UDPSocket inet::SimpleVoIPSender::socket
private

Referenced by initialize(), and sendVoIPPacket().

simtime_t inet::SimpleVoIPSender::stopTime
private
int inet::SimpleVoIPSender::talkPacketSize = 0
private

Referenced by initialize(), and sendVoIPPacket().

simtime_t inet::SimpleVoIPSender::talkspurtDuration
private
int inet::SimpleVoIPSender::talkspurtID = -1
private
int inet::SimpleVoIPSender::talkspurtNumPackets = 0
private

The documentation for this class was generated from the following files: