Fixes #711 in private. We now check RTP ports before allocation, to ensure they're not already in use.

git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@3225 19bc5d8c-e614-43d4-8b26-e1612bc8e597
This commit is contained in:
kurtis.heimerl
2012-02-24 07:59:11 +00:00
parent 7830f252c6
commit b0f5d61bf5
5 changed files with 33 additions and 4 deletions

View File

@@ -72,17 +72,20 @@ using namespace Control;
*/
unsigned allocateRTPPorts()
{
// FIXME -- We need a real port allocator.
const unsigned base = gConfig.getNum("RTP.Start");
const unsigned range = gConfig.getNum("RTP.Range");
const unsigned top = base+range;
static Mutex lock;
// Pick a random starting point.
static unsigned port = base + 2*(random()%(range/2));
unsigned retVal;
lock.lock();
unsigned retVal = port;
port += 2;
if (port>=top) port=base;
//This is a little hacky as RTPAvail is O(n)
do {
retVal = port;
port += 2;
if (port>=top) port=base;
} while (!gTransactionTable.RTPAvailable(retVal));
lock.unlock();
return retVal;
}

View File

@@ -805,5 +805,19 @@ TransactionEntry* TransactionTable::findLongestCall()
/* linear, we should move the actual search into this structure */
bool TransactionTable::RTPAvailable(short rtpPort)
{
ScopedLock lock(mLock);
clearDeadEntries();
bool avail = true;
for (TransactionMap::iterator itr = mTable.begin(); itr!=mTable.end(); ++itr) {
if (itr->second->mSIP.RTPPort() == rtpPort){
avail = false;
break;
}
}
return avail;
}
// vim: ts=4 sw=4

View File

@@ -337,6 +337,12 @@ class TransactionTable {
*/
TransactionEntry* findLongestCall();
/**
Return the availability of this particular RTP port
@return True if Port is available, False otherwise
*/
bool RTPAvailable(short rtpPort);
/**
Remove an entry from the table and from gSIPMessageMap.
@param wID The transaction ID to search.