SS7 work-in-proggress.

git-svn-id: http://yate.null.ro/svn/yate/trunk@832 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2006-06-02 18:16:03 +00:00
parent 69b6f89ece
commit 4badd3bff0
6 changed files with 113 additions and 11 deletions

View File

@ -79,6 +79,14 @@ bool SS7MTP2::control(Operation oper, NamedList* params)
}
}
void SS7MTP2::timerTick(const Time& when)
{
if (aligned())
transmitFISU();
else
transmitLSSU();
}
// Transmit a MSU retaining a copy for retransmissions
bool SS7MTP2::transmitMSU(const SS7MSU& msu)
{
@ -115,7 +123,6 @@ bool SS7MTP2::transmitMSU(const SS7MSU& msu)
// Decode a received packet into signalling units
bool SS7MTP2::receivedPacket(const DataBlock& packet)
{
Debug("STUB",DebugWarn,"Please implement SS7MTP2::receivedPacket()");
if (packet.length() < 3) {
XDebug(engine(),DebugMild,"Received short packet of length %u [%p]",
packet.length(),this);
@ -138,6 +145,13 @@ bool SS7MTP2::receivedPacket(const DataBlock& packet)
bool fib = (buf[1] & 0x80) != 0;
// lock the object as we modify members
lock();
XDebug(engine(),DebugInfo,"got bsn=%u/%d fsn=%u/%d local bsn=%u/%d fsn=%u/%d [%p]",
bsn,bib,fsn,fib,m_bsn,m_bib,m_fsn,m_fib,this);
ok = (fsn == ((m_bsn + 1) & 0x7f));
if (ok)
m_bsn = fsn;
unlock();
//TODO: implement Q.703 6.3.1
@ -153,6 +167,9 @@ bool SS7MTP2::receivedPacket(const DataBlock& packet)
processFISU();
return ok;
}
// just drop MSUs
if (!(ok && aligned()))
return false;
SS7MSU msu((void*)(buf+3),len,false);
ok = receivedMSU(msu);
msu.clear(false);
@ -162,12 +179,45 @@ bool SS7MTP2::receivedPacket(const DataBlock& packet)
// Process incoming FISU
void SS7MTP2::processFISU()
{
XDebug(toString(),DebugStub,"Please implement SS7MTP2::processFISU()");
switch (m_status) {
case EmergencyAlignment:
m_status = NormalAlignment;
case NormalAlignment:
transmitFISU();
break;
default:
transmitLSSU();
}
}
// Process incoming LSSU
void SS7MTP2::processLSSU(unsigned int status)
{
Debug("STUB",DebugWarn,"Please implement SS7MTP2::processLSSU()");
XDebug(toString(),DebugStub,"Please implement SS7MTP2::processLSSU(%u)",status);
switch (status) {
case NormalAlignment:
case EmergencyAlignment:
switch (m_status) {
case NormalAlignment:
case EmergencyAlignment:
m_status = NormalAlignment;
transmitFISU();
break;
default:
m_status = status;
transmitLSSU();
}
break;
default:
switch (m_status) {
case NormalAlignment:
case EmergencyAlignment:
m_status = OutOfAlignment;
}
transmitLSSU();
break;
}
}
// Emit a locally generated LSSU
@ -211,12 +261,18 @@ bool SS7MTP2::transmitFISU()
void SS7MTP2::startAlignment()
{
lock();
m_status = OutOfAlignment;
m_queue.clear();
unlock();
}
void SS7MTP2::abortAlignment()
{
lock();
m_status = OutOfService;
m_queue.clear();
unlock();
}
/* vi: set ts=8 sw=4 sts=4 noet: */

View File

@ -28,13 +28,13 @@ using namespace TelEngine;
void SS7MTP3::attach(SS7Layer2* link)
{
Debug("STUB",DebugWarn,"Please implement SS7MTP3::attach()");
Debug(toString(),DebugStub,"Please implement SS7MTP3::attach()");
SignallingComponent::insert(link);
}
bool SS7MTP3::receivedMSU(const SS7MSU& msu)
{
Debug("STUB",DebugWarn,"Please implement SS7MTP3::receivedMSU()");
Debug(toString(),DebugStub,"Please implement SS7MTP3::receivedMSU()");
return false;
}

View File

@ -28,13 +28,13 @@ using namespace TelEngine;
void SS7Router::attach(SS7Layer3* network)
{
Debug("STUB",DebugWarn,"Please implement SS7Router::attach()");
Debug(toString(),DebugStub,"Please implement SS7Router::attach()");
SignallingComponent::insert(network);
}
void SS7Router::attach(SS7Layer4* service)
{
Debug("STUB",DebugWarn,"Please implement SS7Router::attach()");
Debug(toString(),DebugStub,"Please implement SS7Router::attach()");
SignallingComponent::insert(service);
}

View File

@ -1242,6 +1242,11 @@ public:
virtual bool control(Operation oper, NamedList* params = 0);
protected:
/**
* Periodical timer tick used to perform alignment and housekeeping
* @param when Time to use as computing base for events and timeouts
*/
virtual void timerTick(const Time& when);
/**
* Process a Signalling Packet received by the hardware interface

View File

@ -87,6 +87,7 @@ private:
String m_device;
WpSigThread* m_thread;
bool m_received;
int m_overRead;
};
class WpSigThread : public Thread
@ -107,13 +108,17 @@ YSIGFACTORY2(WpInterface,SignallingInterface);
void* WpInterface::create(const String& type, const NamedList& name)
{
if (type == "WpInterface")
return static_cast<WpInterface*>(new WpInterface(name.getValue("card"),name.getValue("device")));
if (type == "WpInterface") {
WpInterface* iface = new WpInterface(name.getValue("card"),name.getValue("device"));
iface->setName(name.getValue("name",type));
return iface;
}
return 0;
}
WpInterface::WpInterface(const char* card, const char* device)
: m_card(card), m_device(device), m_thread(0), m_received(false)
: m_card(card), m_device(device), m_thread(0), m_received(false),
m_overRead(3)
{
Debug(DebugAll,"WpInterface::WpInterface('%s','%s') [%p]",
card,device,this);
@ -136,6 +141,23 @@ bool WpInterface::transmitPacket(const DataBlock& packet, bool repeat, PacketTyp
if (!m_socket.valid())
return false;
#ifdef XDEBUG
if (debugAt(DebugAll)) {
const char hex[] = "0123456789abcdef";
unsigned char* s = (unsigned char*) packet.data();
unsigned int len = packet.length();
String str(' ',3*len);
char* d = (char*) str.c_str();
for (unsigned int i = 0; i < len; i++) {
unsigned char c = *s++;
*d++ = ' ';
*d++ = hex[(c >> 4) & 0x0f];
*d++ = hex[c & 0x0f];
}
Debug(toString(),DebugAll,"Sending %u bytes:%s",packet.length(),str.c_str());
}
#endif
int sz = WP_HEADER + packet.length();
DataBlock data(0,WP_HEADER);
data += packet;
@ -162,6 +184,7 @@ bool WpInterface::transmitPacket(const DataBlock& packet, bool repeat, PacketTyp
DDebug(toString(),DebugWarn,"Sent %d instead of %d bytes [%p]",w,sz,this);
return false;
}
w -= WP_HEADER;
XDebug(toString(),DebugAll,"Successfully sent %d bytes packet [%p]",w,this);
return true;
}
@ -179,8 +202,8 @@ void WpInterface::receiveAttempt()
m_socket.error(),::strerror(m_socket.error()),this);
return;
}
if (r > WP_HEADER) {
r -= WP_HEADER;
if (r > (WP_HEADER + m_overRead)) {
r -= (WP_HEADER + m_overRead);
XDebug(toString(),DebugAll,"Received %d bytes packet [%p]",r,this);
if (buf[WP_RD_ERROR]) {
DDebug(toString(),DebugWarn,"Packet got error: %u [%p]",
@ -193,6 +216,23 @@ void WpInterface::receiveAttempt()
notify(AlignError);
return;
}
#ifdef XDEBUG
if (debugAt(DebugAll)) {
const char hex[] = "0123456789abcdef";
unsigned char* s = buf+WP_HEADER;
String str(' ',3*r);
char* d = (char*) str.c_str();
for (unsigned int i = 0; i < (unsigned int)r; i++) {
unsigned char c = *s++;
*d++ = ' ';
*d++ = hex[(c >> 4) & 0x0f];
*d++ = hex[c & 0x0f];
}
Debug(toString(),DebugAll,"Received %d bytes:%s",r,str.c_str());
}
#endif
m_received = true;
DataBlock data(buf+WP_HEADER,r);
receivedPacket(data);

View File

@ -77,6 +77,7 @@ void SigDriver::buildStack()
link->SignallingReceiver::attach(iface);
m_engine->start("SS7test",Thread::Normal,20000);
iface->control(SignallingInterface::Enable);
link->control(SS7Layer2::Align);
}
void SigDriver::initialize()