Added common message classes.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2310 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2008-11-07 18:03:13 +00:00
parent 048914dd30
commit 77f3389dcf
2 changed files with 139 additions and 3 deletions

View File

@ -27,6 +27,30 @@
using namespace TelEngine;
#define MAKE_NAME(x) { #x, SIGTRAN::x }
static const TokenDict s_classes[] = {
// this list must be kept in synch with the header
MAKE_NAME(MGMT),
MAKE_NAME(TRAN),
MAKE_NAME(SSNM),
MAKE_NAME(ASPSM),
MAKE_NAME(ASPTM),
MAKE_NAME(QPTM),
MAKE_NAME(MAUP),
MAKE_NAME(CLMSG),
MAKE_NAME(COMSG),
MAKE_NAME(RKM),
MAKE_NAME(IIM),
MAKE_NAME(M2PA),
{ 0, 0 }
};
#undef MAKE_NAME
const TokenDict* SIGTRAN::classNames()
{
return s_classes;
}
SIGTRAN::SIGTRAN()
: m_trans(None), m_socket(0)
{
@ -37,15 +61,25 @@ SIGTRAN::~SIGTRAN()
terminate();
}
// Terminate the transport
void SIGTRAN::terminate()
{
Socket* tmp = m_socket;
m_trans = None;
m_socket = 0;
m_part.clear();
delete tmp;
}
// Check if a stream in the transport is connected
bool SIGTRAN::connected(int streamId) const
{
if ((m_trans == None) || !(m_socket && m_socket->valid()))
return false;
Debug(DebugStub,"Please implement SIGTRAN::connected()");
return true;
}
// Attach a socket to the SIGTRAN instance
bool SIGTRAN::attach(Socket* socket, Transport trans)
{
terminate();
@ -56,4 +90,40 @@ bool SIGTRAN::attach(Socket* socket, Transport trans)
return true;
}
// Build the common header and transmit a message to the network
bool SIGTRAN::transmitMSG(unsigned char msgVersion, unsigned char msgClass,
unsigned char msgType, const DataBlock& msg, int streamId)
{
if (!connected(streamId))
return false;
unsigned char hdr[8];
unsigned int len = 8 + msg.length();
hdr[0] = msgVersion;
hdr[1] = 0;
hdr[2] = msgClass;
hdr[3] = msgType;
hdr[4] = 0xff & (len >> 24);
hdr[5] = 0xff & (len >> 16);
hdr[6] = 0xff & (len >> 8);
hdr[7] = 0xff & len;
DataBlock header(hdr,8,false);
bool ok = transmitMSG(header,msg,streamId);
header.clear(false);
return ok;
}
// Generic message transmission method, can be overriden to improve performance
bool SIGTRAN::transmitMSG(const DataBlock& header, const DataBlock& msg, int streamId)
{
if (!connected(streamId))
return false;
DataBlock tmp(header);
tmp += msg;
int len = tmp.length();
return m_socket->send(tmp.data(),len) == len;
}
/* vi: set ts=8 sw=4 sts=4 noet: */

View File

@ -3584,10 +3584,42 @@ public:
enum Transport {
None = 0,
Sctp,
// All the following transports are not standard
Tcp,
Udp,
Unix,
};
/**
* Message classes
*/
enum MsgClass {
// Management (IUA/M2UA/M3UA/SUA)
MGMT = 0,
// Transfer (M3UA)
TRAN = 1,
// SS7 Signalling Network Management (M3UA/SUA)
SSNM = 2,
// ASP State Maintenance (IUA/M2UA/M3UA/SUA)
ASPSM = 3,
// ASP Traffic Maintenance (IUA/M2UA/M3UA/SUA)
ASPTM = 4,
// Q.921/Q.931 Boundary Primitives Transport (IUA)
QPTM = 5,
// MTP2 User Adaptation (M2UA)
MAUP = 6,
// Connectionless Messages (SUA)
CLMSG = 7,
// Connection-Oriented Messages (SUA)
COMSG = 8,
// Routing Key Management (M3UA)
RKM = 9,
// Interface Identifier Management (M2UA)
IIM = 10,
// M2PA Messages (M2PA)
M2PA = 11,
};
/**
* Constructs an uninitialized signalling transport
*/
@ -3603,6 +3635,19 @@ public:
*/
virtual void terminate();
/**
* Check if the network transport layer is connected
* @param streamId Identifier of the stream to check if applicable
* @return True if the transport (and stream if applicable) is connected
*/
virtual bool connected(int streamId = 0) const;
/**
* Message class names dictionary
* @return Pointer to dictionary of message classes
*/
static const TokenDict* classNames();
protected:
/**
* Attach an open socket
@ -3618,15 +3663,36 @@ protected:
* @param msgClass Class of the message
* @param msgType Type of the message, depends on the class
* @param msg Message data, may be empty
* @param streamId Identifier of the stream the message was received on
* @return True if the message was handled
*/
virtual bool processMSG(unsigned char msgVersion, unsigned char msgClass,
unsigned char msgType, const DataBlock& msg) = 0;
unsigned char msgType, const DataBlock& msg, int streamId) = 0;
/**
* Transmit a message to the network transport layer
* @param msgVersion Version of the protocol
* @param msgClass Class of the message
* @param msgType Type of the message, depends on the class
* @param msg Message data, may be empty
* @param streamId Identifier of the stream to send the data over
* @return True if the message was transmitted to network
*/
bool transmitMSG(unsigned char msgVersion, unsigned char msgClass,
unsigned char msgType, const DataBlock& msg, int streamId = 0);
/**
* Transmit a prepared message to the network transport layer
* @param header Message header, typically 8 octets
* @param msg Message data, may be empty
* @param streamId Identifier of the stream to send the data over
* @return True if the message was transmitted to network
*/
virtual bool transmitMSG(const DataBlock& header, const DataBlock& msg, int streamId = 0);
private:
Transport m_trans;
Socket* m_socket;
DataBlock m_part;
};
/**