INET Framework for OMNeT++/OMNEST
inet::rtp::RTCP Class Reference

The class RTCP is responsible for creating, receiving and processing of rtcp packets. More...

#include <RTCP.h>

Inheritance diagram for inet::rtp::RTCP:
inet::ILifecycle

Public Member Functions

 RTCP ()
 
virtual ~RTCP ()
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void initialize (int stage) override
 Initializes variables. More...
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 Message handling. More...
 
virtual void handleMessageFromRTP (cMessage *msg)
 Handles messages from the RTP module. More...
 
virtual void handleMessageFromUDP (cMessage *msg)
 Handles messages coming from the socket layer. More...
 
virtual void handleSelfMessage (cMessage *msg)
 Handles self messages. More...
 
virtual void handleInitializeRTCP (RTPInnerPacket *rinp)
 Initializes the rtcp module when the session is started. More...
 
virtual void handleSenderModuleInitialized (RTPInnerPacket *rinp)
 Stores information about the new transmission. More...
 
virtual void handleDataOut (RTPInnerPacket *packet)
 Stores information about an outgoing RTP data packet. More...
 
virtual void handleDataIn (RTPInnerPacket *rinp)
 Stores information about an outgoing RTP data packet. More...
 
virtual void handleLeaveSession (RTPInnerPacket *rinp)
 Makes the rtcp module send an RTCPByePacket in the next RTCPCompoundPacket to tell other participants in the RTP session that this end system leaves. More...
 
virtual void connectRet ()
 Called when the socket layer has finished a connect. More...
 
virtual void readRet (cPacket *sifpIn)
 Called when this rtcp module receives data from the socket layer. More...
 
virtual void createSocket ()
 Request a server socket from the socket layer. More...
 
virtual void chooseSSRC ()
 Chooses the ssrc identifier for this end system. More...
 
virtual void scheduleInterval ()
 Calculates the length of the next rtcp interval an issues a self message to remind itself. More...
 
virtual void createPacket ()
 Creates and sends an RTCPCompoundPacket. More...
 
virtual void processOutgoingRTPPacket (RTPPacket *packet)
 Extracts information of a sent RTPPacket. More...
 
virtual void processIncomingRTPPacket (RTPPacket *packet, IPv4Address address, int port)
 Extracts information of a received RTPPacket. More...
 
virtual void processIncomingRTCPPacket (RTCPCompoundPacket *packet, IPv4Address address, int port)
 Extracts information of a received RTCPCompoundPacket. More...
 
void processIncomingRTCPSenderReportPacket (RTCPSenderReportPacket *rtcpSenderReportPacket, IPv4Address address, int port)
 
void processIncomingRTCPReceiverReportPacket (RTCPReceiverReportPacket *rtcpReceiverReportPacket, IPv4Address address, int port)
 
void processIncomingRTCPSDESPacket (RTCPSDESPacket *rtcpSDESPacket, IPv4Address address, int port, simtime_t arrivalTime)
 
void processIncomingRTCPByePacket (RTCPByePacket *rtcpByePacket, IPv4Address address, int port)
 
virtual RTPParticipantInfofindParticipantInfo (uint32 ssrc)
 Returns the RTPParticipantInfo object used for storing information about the RTP end system with this ssrc identifier. More...
 
virtual void calculateAveragePacketSize (int size)
 Recalculates the average size of an RTCPCompoundPacket when one of this size has been sent or received. More...
 

Protected Attributes

int _mtu = 0
 The maximum size an RTCPCompundPacket can have. More...
 
int _bandwidth = 0
 The bandwidth for this RTP session. More...
 
int _rtcpPercentage = 0
 The percentage of bandwidth for rtcp. More...
 
IPv4Address _destinationAddress
 The destination address. More...
 
int _port = -1
 The rtcp port. More...
 
bool _ssrcChosen = false
 True when this end system has chosen its ssrc identifier. More...
 
bool _leaveSession = false
 True when this end system is about to leave the session. More...
 
RTPSenderInfo_senderInfo = nullptr
 The RTPSenderInfo about this end system. More...
 
cArray _participantInfos
 Information about all known RTP end system participating in this RTP session. More...
 
UDPSocket _udpSocket
 The UDP socket for sending/receiving rtcp packets. More...
 
int _packetsCalculated = 0
 The number of packets this rtcp module has calculated. More...
 
double _averagePacketSize = 0
 The average size of an RTCPCompoundPacket. More...
 

Static Protected Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 The output vector for statistical data about the behaviour of rtcp. More...
 

Detailed Description

The class RTCP is responsible for creating, receiving and processing of rtcp packets.

It also keeps track of this and other RTP end systems.

Constructor & Destructor Documentation

inet::rtp::RTCP::RTCP ( )
41 {
42 }
inet::rtp::RTCP::~RTCP ( )
virtual
69 {
70  if (!_ssrcChosen)
71  delete _senderInfo;
72 }
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
bool _ssrcChosen
True when this end system has chosen its ssrc identifier.
Definition: RTCP.h:200

Member Function Documentation

void inet::rtp::RTCP::calculateAveragePacketSize ( int  size)
protectedvirtual

Recalculates the average size of an RTCPCompoundPacket when one of this size has been sent or received.

Referenced by createPacket(), and processIncomingRTCPPacket().

526 {
527  // add size of ip and udp header to given size before calculating
528 #if 1
529  double sumPacketSize = (double)(_packetsCalculated) * _averagePacketSize + (double)(size + 20 + 8);
530  _averagePacketSize = sumPacketSize / (double)(++_packetsCalculated);
531 #else // if 1
532  _averagePacketSize += ((double)(size + 20 + 8) - _averagePacketSize) / (double)(++_packetsCalculated);
533 #endif // if 1
534 }
int _packetsCalculated
The number of packets this rtcp module has calculated.
Definition: RTCP.h:227
double _averagePacketSize
The average size of an RTCPCompoundPacket.
Definition: RTCP.h:232
void inet::rtp::RTCP::chooseSSRC ( )
protectedvirtual

Chooses the ssrc identifier for this end system.

Referenced by handleSelfMessage().

242 {
243  uint32 ssrc = 0;
244  bool ssrcConflict = false;
245  do {
246  ssrc = intrand(0x7fffffff);
247  ssrcConflict = findParticipantInfo(ssrc) != nullptr;
248  } while (ssrcConflict);
249 
250  EV_INFO << "chooseSSRC" << ssrc;
251  _senderInfo->setSsrc(ssrc);
253  _ssrcChosen = true;
254 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
virtual void setSsrc(uint32 ssrc) override
Sets the ssrc identifier.
Definition: RTPParticipantInfo.cc:138
uint32_t uint32
Definition: Compat.h:30
bool _ssrcChosen
True when this end system has chosen its ssrc identifier.
Definition: RTCP.h:200
void inet::rtp::RTCP::connectRet ( )
protectedvirtual

Called when the socket layer has finished a connect.

Referenced by createSocket().

200 {
201  // schedule first rtcp packet
202  double intervalLength = 2.5 * (dblrand() + 0.5);
203  cMessage *reminderMessage = new cMessage("Interval");
204  scheduleAt(simTime() + intervalLength, reminderMessage);
205 }
void inet::rtp::RTCP::createPacket ( )
protectedvirtual

Creates and sends an RTCPCompoundPacket.

Referenced by handleSelfMessage().

257 {
258  // first packet in an rtcp compound packet must
259  // be a sender or receiver report
260  RTCPReceiverReportPacket *reportPacket;
261 
262  // if this rtcp end system is a sender (see SenderInformation::isSender() for
263  // details) insert a sender report
264  if (_senderInfo->isSender()) {
265  RTCPSenderReportPacket *senderReportPacket = new RTCPSenderReportPacket("SenderReportPacket");
266  SenderReport *senderReport = _senderInfo->senderReport(simTime());
267  senderReportPacket->setSenderReport(*senderReport);
268  delete senderReport;
269  reportPacket = senderReportPacket;
270  }
271  else {
272  reportPacket = new RTCPReceiverReportPacket("ReceiverReportPacket");
273  }
274  reportPacket->setSsrc(_senderInfo->getSsrc());
275 
276  // insert receiver reports for packets from other sources
277  for (int i = 0; i < _participantInfos.size(); i++) {
278  if (_participantInfos.exist(i)) {
279  RTPParticipantInfo *participantInfo = (RTPParticipantInfo *)(_participantInfos.get(i));
280  if (participantInfo->getSsrc() != _senderInfo->getSsrc()) {
281  ReceptionReport *report = ((RTPReceiverInfo *)participantInfo)->receptionReport(simTime());
282  if (report != nullptr) {
283  reportPacket->addReceptionReport(report);
284  }
285  }
286  participantInfo->nextInterval(simTime());
287 
288  if (participantInfo->toBeDeleted(simTime())) {
289  _participantInfos.remove(participantInfo);
290  delete participantInfo;
291  // perhaps inform the profile
292  }
293  }
294  }
295 
296  // insert source description items (at least common name)
297  RTCPSDESPacket *sdesPacket = new RTCPSDESPacket("SDESPacket");
298 
299  SDESChunk *chunk = _senderInfo->getSDESChunk();
300  sdesPacket->addSDESChunk(chunk);
301 
302  RTCPCompoundPacket *compoundPacket = new RTCPCompoundPacket("RTCPCompoundPacket");
303 
304  compoundPacket->addRTCPPacket(reportPacket);
305  compoundPacket->addRTCPPacket(sdesPacket);
306 
307  // create rtcp app/bye packets if needed
308  if (_leaveSession) {
309  RTCPByePacket *byePacket = new RTCPByePacket("ByePacket");
310  byePacket->setSsrc(_senderInfo->getSsrc());
311  compoundPacket->addRTCPPacket(byePacket);
312  }
313 
314  calculateAveragePacketSize(compoundPacket->getByteLength());
315 
316  cPacket *msg = new cPacket("RTCPCompoundPacket");
317  msg->encapsulate(compoundPacket);
319 
320  if (_leaveSession) {
321  RTPInnerPacket *rinp = new RTPInnerPacket("sessionLeft()");
322  rinp->setSessionLeftPkt();
323  send(rinp, "rtpOut");
324  }
325 }
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
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
virtual SenderReport * senderReport(simtime_t now) override
Returns a SenderReport for this rtp endsystem.
Definition: RTPSenderInfo.cc:89
virtual void calculateAveragePacketSize(int size)
Recalculates the average size of an RTCPCompoundPacket when one of this size has been sent or receive...
Definition: RTCP.cc:525
int _port
The rtcp port.
Definition: RTCP.h:195
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
bool _leaveSession
True when this end system is about to leave the session.
Definition: RTCP.h:205
UDPSocket _udpSocket
The UDP socket for sending/receiving rtcp packets.
Definition: RTCP.h:221
virtual SDESChunk * getSDESChunk() const
Returns a copy of the sdes chunk used for storing source description items about this system...
Definition: RTPParticipantInfo.cc:98
IPv4Address _destinationAddress
The destination address.
Definition: RTCP.h:190
virtual bool isSender() const
Returns true if this endsystem has sent at least one RTP data packet during the last two rtcp interva...
Definition: RTPParticipantInfo.cc:108
virtual uint32 getSsrc() const override
Returns the ssrc identifier of the RTP endsystem.
Definition: RTPParticipantInfo.cc:133
void inet::rtp::RTCP::createSocket ( )
protectedvirtual

Request a server socket from the socket layer.

Referenced by handleInitializeRTCP().

215 {
216  _udpSocket.bind(_port); //XXX this will fail if this function is invoked multiple times; not sure that may (or is expected to) happen
217  MulticastGroupList mgl = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this)->collectMulticastGroups();
218  _udpSocket.joinLocalMulticastGroups(mgl); //TODO make it parameter-dependent
219  connectRet();
220 }
void joinLocalMulticastGroups(MulticastGroupList mgl)
Joins the socket to each multicast group that are registered with any of the interfaces.
Definition: UDPSocket.cc:194
int _port
The rtcp port.
Definition: RTCP.h:195
UDPSocket _udpSocket
The UDP socket for sending/receiving rtcp packets.
Definition: RTCP.h:221
virtual void connectRet()
Called when the socket layer has finished a connect.
Definition: RTCP.cc:199
void bind(int localPort)
Bind the socket to a local port number.
Definition: UDPSocket.cc:53
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:36
RTPParticipantInfo * inet::rtp::RTCP::findParticipantInfo ( uint32  ssrc)
protectedvirtual

Returns the RTPParticipantInfo object used for storing information about the RTP end system with this ssrc identifier.

Returns nullptr if this end system is unknown.

Referenced by chooseSSRC(), processIncomingRTCPByePacket(), processIncomingRTCPReceiverReportPacket(), processIncomingRTCPSDESPacket(), processIncomingRTCPSenderReportPacket(), and processIncomingRTPPacket().

520 {
521  std::string ssrcString = RTPParticipantInfo::ssrcToName(ssrc);
522  return (RTPParticipantInfo *)(_participantInfos.get(ssrcString.c_str()));
523 }
static std::string ssrcToName(uint32 ssrc)
This method returns the given 32 bit ssrc identifier as an 8 character hexadecimal number which is us...
Definition: RTPParticipantInfo.cc:148
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
void inet::rtp::RTCP::handleDataIn ( RTPInnerPacket rinp)
protectedvirtual

Stores information about an outgoing RTP data packet.

Referenced by handleMessageFromRTP().

188 {
189  RTPPacket *rtpPacket = check_and_cast<RTPPacket *>(rinp->decapsulate());
190  //rtpPacket->dump();
191  processIncomingRTPPacket(rtpPacket, rinp->getAddress(), rinp->getPort());
192 }
virtual void processIncomingRTPPacket(RTPPacket *packet, IPv4Address address, int port)
Extracts information of a received RTPPacket.
Definition: RTCP.cc:332
void inet::rtp::RTCP::handleDataOut ( RTPInnerPacket packet)
protectedvirtual

Stores information about an outgoing RTP data packet.

Referenced by handleMessageFromRTP().

182 {
183  RTPPacket *rtpPacket = check_and_cast<RTPPacket *>(packet->decapsulate());
184  processOutgoingRTPPacket(rtpPacket);
185 }
virtual void processOutgoingRTPPacket(RTPPacket *packet)
Extracts information of a sent RTPPacket.
Definition: RTCP.cc:327
void inet::rtp::RTCP::handleInitializeRTCP ( RTPInnerPacket rinp)
protectedvirtual

Initializes the rtcp module when the session is started.

Referenced by handleMessageFromRTP().

157 {
158  _mtu = rinp->getMTU();
159  _bandwidth = rinp->getBandwidth();
160  _rtcpPercentage = rinp->getRtcpPercentage();
161  _destinationAddress = rinp->getAddress();
162  _port = rinp->getPort();
163 
164  _senderInfo = new RTPSenderInfo();
165 
166  SDESItem *sdesItem = new SDESItem(SDESItem::SDES_CNAME, rinp->getCommonName());
167  _senderInfo->addSDESItem(sdesItem);
168 
169  // create server socket for receiving rtcp packets
170  createSocket();
171 }
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
int _rtcpPercentage
The percentage of bandwidth for rtcp.
Definition: RTCP.h:185
virtual void addSDESItem(SDESItem *sdesItem)
Adds this sdes item to the sdes chunk of this participant.
Definition: RTPParticipantInfo.cc:103
int _port
The rtcp port.
Definition: RTCP.h:195
int _bandwidth
The bandwidth for this RTP session.
Definition: RTCP.h:180
Definition: sdes.h:41
IPv4Address _destinationAddress
The destination address.
Definition: RTCP.h:190
int _mtu
The maximum size an RTCPCompundPacket can have.
Definition: RTCP.h:175
virtual void createSocket()
Request a server socket from the socket layer.
Definition: RTCP.cc:214
void inet::rtp::RTCP::handleLeaveSession ( RTPInnerPacket rinp)
protectedvirtual

Makes the rtcp module send an RTCPByePacket in the next RTCPCompoundPacket to tell other participants in the RTP session that this end system leaves.

Referenced by handleMessageFromRTP().

195 {
196  _leaveSession = true;
197 }
bool _leaveSession
True when this end system is about to leave the session.
Definition: RTCP.h:205
void inet::rtp::RTCP::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Message handling.

Dispatches messages by arrival gate.

75 {
76  // first distinguish incoming messages by arrival gate
77  if (msg->isSelfMessage()) {
78  handleSelfMessage(msg);
79  }
80  else if (msg->getArrivalGateId() == findGate("rtpIn")) {
82  }
83  else if (msg->getArrivalGateId() == findGate("udpIn")) {
85  }
86  else {
87  throw cRuntimeError("Message from unknown gate");
88  }
89 
90  delete msg;
91 }
virtual void handleMessageFromRTP(cMessage *msg)
Handles messages from the RTP module.
Definition: RTCP.cc:97
virtual void handleSelfMessage(cMessage *msg)
Handles self messages.
Definition: RTCP.cc:135
virtual void handleMessageFromUDP(cMessage *msg)
Handles messages coming from the socket layer.
Definition: RTCP.cc:129
void inet::rtp::RTCP::handleMessageFromRTP ( cMessage *  msg)
protectedvirtual

Handles messages from the RTP module.

Referenced by handleMessage().

98 {
99  // from the rtp module all messages are of type RTPInnerPacket
100  RTPInnerPacket *rinp = check_and_cast<RTPInnerPacket *>(msg);
101 
102  // distinguish by type
103  switch (rinp->getType()) {
105  handleInitializeRTCP(rinp);
106  break;
107 
110  break;
111 
112  case RTP_INP_DATA_OUT:
113  handleDataOut(rinp);
114  break;
115 
116  case RTP_INP_DATA_IN:
117  handleDataIn(rinp);
118  break;
119 
121  handleLeaveSession(rinp);
122  break;
123 
124  default:
125  throw cRuntimeError("Unknown RTPInnerPacket type");
126  }
127 }
virtual void handleSenderModuleInitialized(RTPInnerPacket *rinp)
Stores information about the new transmission.
Definition: RTCP.cc:173
virtual void handleDataOut(RTPInnerPacket *packet)
Stores information about an outgoing RTP data packet.
Definition: RTCP.cc:181
Definition: RTPInnerPacket_m.h:88
Definition: RTPInnerPacket_m.h:83
Definition: RTPInnerPacket_m.h:86
virtual void handleLeaveSession(RTPInnerPacket *rinp)
Makes the rtcp module send an RTCPByePacket in the next RTCPCompoundPacket to tell other participants...
Definition: RTCP.cc:194
Definition: RTPInnerPacket_m.h:89
Definition: RTPInnerPacket_m.h:76
virtual void handleDataIn(RTPInnerPacket *rinp)
Stores information about an outgoing RTP data packet.
Definition: RTCP.cc:187
virtual void handleInitializeRTCP(RTPInnerPacket *rinp)
Initializes the rtcp module when the session is started.
Definition: RTCP.cc:156
void inet::rtp::RTCP::handleMessageFromUDP ( cMessage *  msg)
protectedvirtual

Handles messages coming from the socket layer.

Referenced by handleMessage().

130 {
131  // from SocketLayer all message are of type cMessage
132  readRet(PK(msg));
133 }
virtual void readRet(cPacket *sifpIn)
Called when this rtcp module receives data from the socket layer.
Definition: RTCP.cc:207
#define PK(msg)
Definition: INETDefs.h:92
bool inet::rtp::RTCP::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overridevirtual

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.

537 {
538  Enter_Method_Silent();
539 
540  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
541  return true;
542 }
void inet::rtp::RTCP::handleSelfMessage ( cMessage *  msg)
protectedvirtual

Handles self messages.

Referenced by handleMessage().

136 {
137  // it's time to create an rtcp packet
138  if (!_ssrcChosen) {
139  chooseSSRC();
140  RTPInnerPacket *rinp1 = new RTPInnerPacket("rtcpInitialized()");
141  rinp1->setRtcpInitializedPkt(_senderInfo->getSsrc());
142  send(rinp1, "rtpOut");
143  }
144 
145  createPacket();
146 
147  if (!_leaveSession) {
149  }
150 }
virtual void scheduleInterval()
Calculates the length of the next rtcp interval an issues a self message to remind itself...
Definition: RTCP.cc:222
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
bool _leaveSession
True when this end system is about to leave the session.
Definition: RTCP.h:205
bool _ssrcChosen
True when this end system has chosen its ssrc identifier.
Definition: RTCP.h:200
virtual void createPacket()
Creates and sends an RTCPCompoundPacket.
Definition: RTCP.cc:256
virtual uint32 getSsrc() const override
Returns the ssrc identifier of the RTP endsystem.
Definition: RTPParticipantInfo.cc:133
virtual void chooseSSRC()
Chooses the ssrc identifier for this end system.
Definition: RTCP.cc:241
void inet::rtp::RTCP::handleSenderModuleInitialized ( RTPInnerPacket rinp)
protectedvirtual

Stores information about the new transmission.

Referenced by handleMessageFromRTP().

174 {
175  _senderInfo->setStartTime(simTime());
176  _senderInfo->setClockRate(rinp->getClockRate());
177  _senderInfo->setTimeStampBase(rinp->getTimeStampBase());
178  _senderInfo->setSequenceNumberBase(rinp->getSequenceNumberBase());
179 }
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
virtual void setStartTime(simtime_t startTime)
Sets the time (simTime) when this endsystem has started sending rtp packets.
Definition: RTPSenderInfo.cc:109
virtual void setSequenceNumberBase(uint16 sequenceNumberBase)
Sets the initial sequence number.
Definition: RTPSenderInfo.cc:124
virtual void setClockRate(int clockRate)
Sets the clock rate (in ticks per second) this sender increases the rtp time stamp.
Definition: RTPSenderInfo.cc:114
virtual void setTimeStampBase(uint32 timeStampBase)
Sets the initial rtp time stamp.
Definition: RTPSenderInfo.cc:119
void inet::rtp::RTCP::initialize ( int  stage)
overrideprotectedvirtual

Initializes variables.

45 {
46  cSimpleModule::initialize(stage);
47 
48  if (stage == INITSTAGE_LOCAL) {
49  // initialize variables
50  _ssrcChosen = false;
51  _leaveSession = false;
52  _udpSocket.setOutputGate(gate("udpOut"));
53 
55  _averagePacketSize = 0.0;
56 
57  _participantInfos.setName("ParticipantInfos");
58  }
59  else if (stage == INITSTAGE_TRANSPORT_LAYER) {
60  bool isOperational;
61  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
62  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
63  if (!isOperational)
64  throw cRuntimeError("This module doesn't support starting in node DOWN state");
65  }
66 }
Initialization of transport-layer protocols.
Definition: InitStages.h:90
int _packetsCalculated
The number of packets this rtcp module has calculated.
Definition: RTCP.h:227
double _averagePacketSize
The average size of an RTCPCompoundPacket.
Definition: RTCP.h:232
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UDPSocket.h:110
bool _leaveSession
True when this end system is about to leave the session.
Definition: RTCP.h:205
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
UDPSocket _udpSocket
The UDP socket for sending/receiving rtcp packets.
Definition: RTCP.h:221
bool _ssrcChosen
True when this end system has chosen its ssrc identifier.
Definition: RTCP.h:200
Definition: NodeStatus.h:40
virtual int inet::rtp::RTCP::numInitStages ( ) const
inlineoverrideprotectedvirtual
58 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::rtp::RTCP::processIncomingRTCPByePacket ( RTCPByePacket rtcpByePacket,
IPv4Address  address,
int  port 
)
protected

Referenced by processIncomingRTCPPacket().

505 {
506  uint32 ssrc = rtcpByePacket->getSsrc();
507  RTPParticipantInfo *participantInfo = findParticipantInfo(ssrc);
508 
509  if (participantInfo != nullptr && participantInfo != _senderInfo) {
510  _participantInfos.remove(participantInfo);
511 
512  delete participantInfo;
513  // perhaps it would be useful to inform
514  // the profile to remove the corresponding
515  // receiver module
516  }
517 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
uint32_t uint32
Definition: Compat.h:30
void inet::rtp::RTCP::processIncomingRTCPPacket ( RTCPCompoundPacket packet,
IPv4Address  address,
int  port 
)
protectedvirtual

Extracts information of a received RTCPCompoundPacket.

Referenced by readRet().

366 {
367  calculateAveragePacketSize(packet->getByteLength());
368  cArray& rtcpPackets = packet->getRtcpPackets();
369  simtime_t arrivalTime = packet->getArrivalTime();
370 
371  for (int i = 0; i < rtcpPackets.size(); i++) {
372  RTCPPacket *rtcpPacket = (RTCPPacket *)(rtcpPackets.remove(i));
373  if (rtcpPacket) {
374  // remove the rtcp packet from the rtcp compound packet
375  switch (rtcpPacket->getPacketType()) {
376  case RTCP_PT_SR:
378  (RTCPSenderReportPacket *)rtcpPacket, address, port);
379  break;
380 
381  case RTCP_PT_RR:
383  (RTCPReceiverReportPacket *)rtcpPacket, address, port);
384  break;
385 
386  case RTCP_PT_SDES:
388  (RTCPSDESPacket *)rtcpPacket, address, port, arrivalTime);
389  break;
390 
391  case RTCP_PT_BYE:
393  (RTCPByePacket *)rtcpPacket, address, port);
394  break;
395 
396  default:
397  // app rtcp packets
398  break;
399  }
400  delete rtcpPacket;
401  }
402  }
403  delete packet;
404 }
Definition: RTCPPacket1_m.h:54
void processIncomingRTCPByePacket(RTCPByePacket *rtcpByePacket, IPv4Address address, int port)
Definition: RTCP.cc:504
virtual void calculateAveragePacketSize(int size)
Recalculates the average size of an RTCPCompoundPacket when one of this size has been sent or receive...
Definition: RTCP.cc:525
void processIncomingRTCPReceiverReportPacket(RTCPReceiverReportPacket *rtcpReceiverReportPacket, IPv4Address address, int port)
Definition: RTCP.cc:443
Definition: RTCPPacket1_m.h:56
Definition: RTCPPacket1_m.h:55
Definition: RTCPPacket1_m.h:57
void processIncomingRTCPSDESPacket(RTCPSDESPacket *rtcpSDESPacket, IPv4Address address, int port, simtime_t arrivalTime)
Definition: RTCP.cc:478
void processIncomingRTCPSenderReportPacket(RTCPSenderReportPacket *rtcpSenderReportPacket, IPv4Address address, int port)
Definition: RTCP.cc:406
void inet::rtp::RTCP::processIncomingRTCPReceiverReportPacket ( RTCPReceiverReportPacket rtcpReceiverReportPacket,
IPv4Address  address,
int  port 
)
protected

Referenced by processIncomingRTCPPacket().

444 {
445  uint32 ssrc = rtcpReceiverReportPacket->getSsrc();
446  RTPParticipantInfo *participantInfo = findParticipantInfo(ssrc);
447  if (participantInfo == nullptr) {
448  participantInfo = new RTPReceiverInfo(ssrc);
449  participantInfo->setAddress(address);
450  participantInfo->setRTCPPort(port);
451  _participantInfos.add(participantInfo);
452  }
453  else {
454  if ((participantInfo->getAddress() == address) &&
455  (participantInfo->getRTCPPort() == PORT_UNDEF))
456  {
457  participantInfo->setRTCPPort(port);
458  }
459  else {
460  // check for ssrc conflict
461  }
462  }
463 
464  cArray& receptionReports = rtcpReceiverReportPacket->getReceptionReports();
465  for (int j = 0; j < receptionReports.size(); j++) {
466  if (receptionReports.exist(j)) {
467  ReceptionReport *receptionReport = (ReceptionReport *)(receptionReports.remove(j));
468  if (_senderInfo && (receptionReport->getSsrc() == _senderInfo->getSsrc())) {
469  _senderInfo->processReceptionReport(receptionReport, simTime());
470  }
471  else
472  //cancelAndDelete(receptionReport);
473  delete receptionReport;
474  }
475  }
476 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
virtual void processReceptionReport(ReceptionReport *report, simtime_t arrivalTime)
Processes an incoming ReceptionReport for this sender.
Definition: RTPSenderInfo.cc:84
const short PORT_UNDEF
TCP/UDP port numbers.
Definition: IPv4Address.h:39
uint32_t uint32
Definition: Compat.h:30
virtual uint32 getSsrc() const override
Returns the ssrc identifier of the RTP endsystem.
Definition: RTPParticipantInfo.cc:133
void inet::rtp::RTCP::processIncomingRTCPSDESPacket ( RTCPSDESPacket rtcpSDESPacket,
IPv4Address  address,
int  port,
simtime_t  arrivalTime 
)
protected

Referenced by processIncomingRTCPPacket().

479 {
480  cArray& sdesChunks = rtcpSDESPacket->getSdesChunks();
481 
482  for (int j = 0; j < sdesChunks.size(); j++) {
483  if (sdesChunks.exist(j)) {
484  // remove the sdes chunk from the cArray of sdes chunks
485  SDESChunk *sdesChunk = (SDESChunk *)(sdesChunks.remove(j));
486  // this is needed to avoid seg faults
487  //sdesChunk->setOwner(this);
488  uint32 ssrc = sdesChunk->getSsrc();
489  RTPParticipantInfo *participantInfo = findParticipantInfo(ssrc);
490  if (participantInfo == nullptr) {
491  participantInfo = new RTPReceiverInfo(ssrc);
492  participantInfo->setAddress(address);
493  participantInfo->setRTCPPort(port);
494  _participantInfos.add(participantInfo);
495  }
496  else {
497  // check for ssrc conflict
498  }
499  participantInfo->processSDESChunk(sdesChunk, arrivalTime);
500  }
501  }
502 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
uint32_t uint32
Definition: Compat.h:30
void inet::rtp::RTCP::processIncomingRTCPSenderReportPacket ( RTCPSenderReportPacket rtcpSenderReportPacket,
IPv4Address  address,
int  port 
)
protected

Referenced by processIncomingRTCPPacket().

407 {
408  uint32 ssrc = rtcpSenderReportPacket->getSsrc();
409  RTPParticipantInfo *participantInfo = findParticipantInfo(ssrc);
410 
411  if (participantInfo == nullptr) {
412  participantInfo = new RTPReceiverInfo(ssrc);
413  participantInfo->setAddress(address);
414  participantInfo->setRTCPPort(port);
415  _participantInfos.add(participantInfo);
416  }
417  else {
418  if ((participantInfo->getAddress() == address) &&
419  (participantInfo->getRTCPPort() == PORT_UNDEF))
420  {
421  participantInfo->setRTCPPort(port);
422  }
423  else {
424  // check for ssrc conflict
425  }
426  }
427  participantInfo->processSenderReport(rtcpSenderReportPacket->getSenderReport(), simTime());
428 
429  cArray& receptionReports = rtcpSenderReportPacket->getReceptionReports();
430  for (int j = 0; j < receptionReports.size(); j++) {
431  if (receptionReports.exist(j)) {
432  ReceptionReport *receptionReport = (ReceptionReport *)(receptionReports.remove(j));
433  if (_senderInfo && (receptionReport->getSsrc() == _senderInfo->getSsrc())) {
434  _senderInfo->processReceptionReport(receptionReport, simTime());
435  }
436  else
437  //cancelAndDelete(receptionReport);
438  delete receptionReport;
439  }
440  }
441 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
virtual void processReceptionReport(ReceptionReport *report, simtime_t arrivalTime)
Processes an incoming ReceptionReport for this sender.
Definition: RTPSenderInfo.cc:84
const short PORT_UNDEF
TCP/UDP port numbers.
Definition: IPv4Address.h:39
uint32_t uint32
Definition: Compat.h:30
virtual uint32 getSsrc() const override
Returns the ssrc identifier of the RTP endsystem.
Definition: RTPParticipantInfo.cc:133
void inet::rtp::RTCP::processIncomingRTPPacket ( RTPPacket packet,
IPv4Address  address,
int  port 
)
protectedvirtual

Extracts information of a received RTPPacket.

Referenced by handleDataIn().

333 {
334  bool good = false;
335  uint32 ssrc = packet->getSsrc();
336  RTPParticipantInfo *participantInfo = findParticipantInfo(ssrc);
337  if (participantInfo == nullptr) {
338  participantInfo = new RTPParticipantInfo(ssrc);
339  participantInfo->setAddress(address);
340  participantInfo->setRTPPort(port);
341  _participantInfos.add(participantInfo);
342  good = true;
343  }
344  else {
345  // check for ssrc conflict
346  if (participantInfo->getAddress() == address) {
347  if (participantInfo->getRTPPort() == port) {
348  good = true;
349  }
350  else if (participantInfo->getRTPPort() == PORT_UNDEF) {
351  participantInfo->setRTPPort(port);
352  good = true;
353  }
354  }
355  }
356  if (good) {
357  participantInfo->processRTPPacket(packet, getId(), packet->getArrivalTime());
358  }
359  else {
360  EV_INFO << "Incoming packet address/port conflict, packet dropped.\n";
361  delete packet;
362  }
363 }
virtual RTPParticipantInfo * findParticipantInfo(uint32 ssrc)
Returns the RTPParticipantInfo object used for storing information about the RTP end system with this...
Definition: RTCP.cc:519
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
const short PORT_UNDEF
TCP/UDP port numbers.
Definition: IPv4Address.h:39
uint32_t uint32
Definition: Compat.h:30
void inet::rtp::RTCP::processOutgoingRTPPacket ( RTPPacket packet)
protectedvirtual

Extracts information of a sent RTPPacket.

Referenced by handleDataOut().

328 {
329  _senderInfo->processRTPPacket(packet, getId(), simTime());
330 }
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
virtual void processRTPPacket(RTPPacket *packet, int id, simtime_t arrivalTime) override
Stores information about this outgoing RTPPacket.
Definition: RTPSenderInfo.cc:73
void inet::rtp::RTCP::readRet ( cPacket *  sifpIn)
protectedvirtual

Called when this rtcp module receives data from the socket layer.

Referenced by handleMessageFromUDP().

208 {
209  emit(rcvdPkSignal, sifpIn);
210  RTCPCompoundPacket *packet = check_and_cast<RTCPCompoundPacket *>(sifpIn->decapsulate());
211  processIncomingRTCPPacket(packet, IPv4Address(_destinationAddress), _port);
212 }
virtual void processIncomingRTCPPacket(RTCPCompoundPacket *packet, IPv4Address address, int port)
Extracts information of a received RTCPCompoundPacket.
Definition: RTCP.cc:365
int _port
The rtcp port.
Definition: RTCP.h:195
static simsignal_t rcvdPkSignal
The output vector for statistical data about the behaviour of rtcp.
Definition: RTCP.h:242
IPv4Address _destinationAddress
The destination address.
Definition: RTCP.h:190
void inet::rtp::RTCP::scheduleInterval ( )
protectedvirtual

Calculates the length of the next rtcp interval an issues a self message to remind itself.

Referenced by handleSelfMessage().

223 {
224  simtime_t intervalLength = _averagePacketSize * (simtime_t)(_participantInfos.size())
225  / (simtime_t)(_bandwidth * _rtcpPercentage * (_senderInfo->isSender() ? 1.0 : 0.75) / 100.0);
226 
227  // interval length must be at least 5 seconds
228  if (intervalLength < 5.0)
229  intervalLength = 5.0;
230 
231  // to avoid rtcp packet bursts multiply calculated interval length
232  // with a random number between 0.5 and 1.5
233  intervalLength = intervalLength * (0.5 + dblrand());
234 
235  intervalLength /= (double)(2.71828 - 1.5); // [RFC 3550] , by Ahmed ayadi
236 
237  cMessage *reminderMessage = new cMessage("Interval");
238  scheduleAt(simTime() + intervalLength, reminderMessage);
239 }
double _averagePacketSize
The average size of an RTCPCompoundPacket.
Definition: RTCP.h:232
RTPSenderInfo * _senderInfo
The RTPSenderInfo about this end system.
Definition: RTCP.h:210
int _rtcpPercentage
The percentage of bandwidth for rtcp.
Definition: RTCP.h:185
cArray _participantInfos
Information about all known RTP end system participating in this RTP session.
Definition: RTCP.h:216
int _bandwidth
The bandwidth for this RTP session.
Definition: RTCP.h:180
virtual bool isSender() const
Returns true if this endsystem has sent at least one RTP data packet during the last two rtcp interva...
Definition: RTPParticipantInfo.cc:108

Member Data Documentation

double inet::rtp::RTCP::_averagePacketSize = 0
protected
int inet::rtp::RTCP::_bandwidth = 0
protected

The bandwidth for this RTP session.

Referenced by handleInitializeRTCP(), and scheduleInterval().

IPv4Address inet::rtp::RTCP::_destinationAddress
protected

The destination address.

Referenced by createPacket(), handleInitializeRTCP(), and readRet().

bool inet::rtp::RTCP::_leaveSession = false
protected

True when this end system is about to leave the session.

Referenced by createPacket(), handleLeaveSession(), handleSelfMessage(), and initialize().

int inet::rtp::RTCP::_mtu = 0
protected

The maximum size an RTCPCompundPacket can have.

Referenced by handleInitializeRTCP().

int inet::rtp::RTCP::_packetsCalculated = 0
protected

The number of packets this rtcp module has calculated.

Referenced by calculateAveragePacketSize(), and initialize().

int inet::rtp::RTCP::_port = -1
protected

The rtcp port.

Referenced by createPacket(), createSocket(), handleInitializeRTCP(), and readRet().

int inet::rtp::RTCP::_rtcpPercentage = 0
protected

The percentage of bandwidth for rtcp.

Referenced by handleInitializeRTCP(), and scheduleInterval().

bool inet::rtp::RTCP::_ssrcChosen = false
protected

True when this end system has chosen its ssrc identifier.

Referenced by chooseSSRC(), handleSelfMessage(), initialize(), and ~RTCP().

UDPSocket inet::rtp::RTCP::_udpSocket
protected

The UDP socket for sending/receiving rtcp packets.

Referenced by createPacket(), createSocket(), and initialize().

simsignal_t inet::rtp::RTCP::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

The output vector for statistical data about the behaviour of rtcp.

Every participant's rtcp module writes its calculated rtcp interval (without variation

Referenced by readRet().


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