提交 fd7fc027 编写于 作者: C calincerchez

got to connection

上级 59c26afd
......@@ -21,6 +21,11 @@
#define TGPP 10415
#define S6a 16777251
/*
* Class for holding info about Diameter application. At the moment
* it only holds application id and vendor id for S6a application.
* Maybe it should be moved in peer class...
*/
class DiameterApplication {
public:
unsigned applId;
......
......@@ -165,10 +165,7 @@ void DiameterBase::loadPeersFromXML(const cXMLElement& diameterNode) {
DiameterConnection *conn = createConnection(addresses, port);
DiameterPeer *peer = createPeer(fqdn, realm, conn, appl);
peer->setType(STATIC);
peer->startTimer(peer->tcTimer, "TC-TIMER", TC_TIMER_TIMEOUT);
conn->setPeer(peer);
}
}
}
......
......@@ -21,9 +21,9 @@
#include <omnetpp.h>
#include <string>
#include "SCTPSocket.h"
#include "DiameterConnectionMap.h"
#include "DiameterConnection.h"
#include "DiameterSession.h"
#include "DiameterPeerTable.h"
#include "DiameterPeer.h"
#include "RoutingTableAccess.h"
/*
......@@ -41,7 +41,7 @@
* Diameter base class holds the server socket from which each Diameter connection is forked.
* Also it manages the connection table, peer table and session table.
*
* All Diameter base protocol model is implemented according to RFC 3588.
* Diameter base protocol model is implemented according to RFC 3588.
*/
class DiameterBase : public cSimpleModule {
protected:
......
......@@ -222,3 +222,53 @@ unsigned DiameterConnection::processOrigin(DiameterPeer *&peer, DiameterMessage
}
return DIAMETER_SUCCESS;
}
DiameterConnectionMap::DiameterConnectionMap() {
// TODO Auto-generated constructor stub
}
DiameterConnectionMap::~DiameterConnectionMap() {
// TODO Auto-generated destructor stub
}
DiameterConnection *DiameterConnectionMap::findConnectionFor(cMessage *msg) {
SCTPCommand *ind = dynamic_cast<SCTPCommand *>(msg->getControlInfo());
if (!ind)
opp_error("DiameterConnectionMap: findConnectionFor(): no SCTPCommand control info in message (not from SCTP?)");
int assocId = ind->getAssocId();
ConnMap::iterator i = connMap.find(assocId);
ASSERT(i == connMap.end() || i->first == i->second->getConnectionId());
return (i == connMap.end()) ? NULL : i->second;
}
void DiameterConnectionMap::addConnection(DiameterConnection *conn) {
ASSERT(connMap.find(conn->getConnectionId()) == connMap.end());
connMap[conn->getConnectionId()] = conn;
}
DiameterConnection *DiameterConnectionMap::removeConnection(DiameterConnection *conn) {
ConnMap::iterator i = connMap.find(conn->getConnectionId());
if (i != connMap.end())
connMap.erase(i);
printConnectionMap();
return conn;
}
/*
void DiameterConnectionMap::deleteConnections()
{
for (ConnMap::iterator i = connMap.begin(); i != connMap.end(); ++i)
delete i->second;
}
*/
void DiameterConnectionMap::printConnectionMap() {
EV << "=====================================================================\n"
<< "Connection Map:\n"
<< "-------------------------------------------------------------------------------\n"
<< "Conn Id\t| Local Addr\t| Local Port\t| Remote Addr\t| Remote Port\n"
<< "---------------------------------------------------------------------\n";
for (ConnMap::iterator i = connMap.begin(); i != connMap.end(); ++i)
EV << (i->second)->getConnectionId() << endl;// << "\t| " << (i->second)->getLocalAddresses().at(0) << "\t| " << "" << "\t| " << "" << "\t| " << "" << endl;
EV << "=====================================================================\n";
}
......@@ -29,10 +29,13 @@
class DiameterPeer;
class DiameterBase;
/*
* Class for Diameter connection.
*/
class DiameterConnection : public SCTPSocket::CallbackInterface {
private:
bool type; // initiator or responder
bool ignore;
bool ignore; // used because socketClosed is called twice
DiameterBase *module;
DiameterPeer *peer;
......@@ -71,4 +74,21 @@ public:
int getConnectionId() { return socket->getConnectionId(); }
};
class DiameterConnectionMap {
private:
typedef std::map<int,DiameterConnection*> ConnMap;
ConnMap connMap;
public:
DiameterConnectionMap();
virtual ~DiameterConnectionMap();
DiameterConnection *findConnectionFor(cMessage *msg);
void addConnection(DiameterConnection *conn);
DiameterConnection *removeConnection(DiameterConnection *conn);
unsigned int size() {return connMap.size();}
// void deleteConnections();
void printConnectionMap();
};
#endif /* DIAMETERCONNECTION_H_ */
......@@ -20,10 +20,6 @@
#include "DiameterUtils.h"
#include "DiameterSerializer.h"
DiameterPeerStateVariables::DiameterPeerStateVariables() {
msg = NULL;
}
DiameterPeer::DiameterPeer(DiameterBase *module) {
// TODO Auto-generated constructor stub
this->module = module;
......@@ -37,19 +33,21 @@ DiameterPeer::DiameterPeer(DiameterBase *module) {
fsm.setName(fsmname);
fsm.setState(CLOSED);
state = new DiameterPeerStateVariables();
iConn = NULL;
rConn = NULL;
tsTimer = NULL;
startTimer(tcTimer, "TC-TIMER", TC_TIMER_TIMEOUT);
tcTimer = NULL;
twTimer = NULL;
teTimer = NULL;
appl = NULL;
msg = NULL;
}
DiameterPeer::~DiameterPeer() {
// TODO Auto-generated destructor stub
delete state;
// msg will be deleted at receiver end
if (twTimer != NULL) {
if (twTimer->getContextPointer() != NULL)
module->cancelEvent(twTimer);
......@@ -72,6 +70,7 @@ DiameterPeer::~DiameterPeer() {
}
if (appl != NULL)
delete appl;
// iConn and rConn will be deleted in connection map
}
......@@ -147,7 +146,7 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
if ((resCode / 1000) != 2) {
break;
}
state->msg = msg;
this->msg = msg;
FSM_Goto(fsm, WAIT_CONN_ACK_ELECT);
break;
}
......@@ -174,7 +173,7 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
if ((resCode / 1000) != 2) {
break;
}
state->msg = msg;
this->msg = msg;
FSM_Goto(fsm, WAIT_RETURNS);
break;
}
......@@ -201,7 +200,7 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
FSM_Goto(fsm, WAIT_RETURNS);
break;
case I_RCV_CONN_NACK:
sendCEA(rConn, state->msg, DIAMETER_SUCCESS);
sendCEA(rConn, this->msg, DIAMETER_SUCCESS);
FSM_Goto(fsm, R_OPEN);
break;
case R_PEER_DISC:
......@@ -227,7 +226,7 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
switch(event) {
case WIN_ELECTION:
iDisconnect();
sendCEA(rConn, state->msg, DIAMETER_SUCCESS);
sendCEA(rConn, this->msg, DIAMETER_SUCCESS);
FSM_Goto(fsm, R_OPEN);
break;
case I_PEER_DISC:
......@@ -261,7 +260,7 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
switch(event) {
case SEND_MESSAGE:
sendApplMessage(rConn, msg);
//remain in this state
//stay in this state
break;
case R_RCV_MESSAGE:
processApplMessage(rConn, msg);
......@@ -311,11 +310,11 @@ void DiameterPeer::performStateTransition(PeerEvent &event, DiameterMessage *msg
switch(event) {
case SEND_MESSAGE:
sendApplMessage(iConn, msg);
//remain in this state
//stay in this state
break;
case I_RCV_MESSAGE:
processApplMessage(iConn, msg);
//remain in this state
//stay in this state
break;
case I_RCV_DWR: {
unsigned resCode = processDWR(msg);
......@@ -677,11 +676,90 @@ void DiameterPeer::elect() {
}
}
bool DiameterPeer::getConnectionType() {
const char *DiameterPeer::getTypeName(){
if (type == STATIC)
return "STATIC";
else
return "DYNAMIC";
}
int DiameterPeer::getConnectionId() {
if (rConn == NULL)
return iConn->getConnectionId();
else
return rConn->getConnectionId();
}
int DiameterPeer::getConnectionType() {
if (iConn != NULL)
return INITIATOR;
else if (rConn != NULL)
return RESPONDER;
else
return 0;
return -1;
}
DiameterPeerTable::DiameterPeerTable() {
// TODO Auto-generated constructor stub
}
DiameterPeerTable::~DiameterPeerTable() {
// TODO Auto-generated destructor stub
}
DiameterPeer *DiameterPeerTable::findPeer(std::string dFQDN, std::string dRealm) {
if (dRealm == "") {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if ((peer->dFQDN.find(dFQDN)) != std::string::npos)
return peer;
}
} else {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if ((peer->dFQDN == dFQDN) && (peer->dRealm == dRealm))
return peer;
}
}
return NULL;
}
DiameterPeer *DiameterPeerTable::findPeer(unsigned applId) {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if (peer->appl->applId == applId)
return peer;
}
return NULL;
}
void DiameterPeerTable::erase(unsigned start, unsigned end) {
PeerTable::iterator first = peers.begin() + start;
PeerTable::iterator last = peers.begin() + end;
PeerTable::iterator i = first;
for (;i != last; ++i)
delete *i;
peers.erase(first, last);
}
void DiameterPeerTable::print() {
EV << "=====================================================================\n"
<< "Diameter Peer Table:\n";
for (unsigned int i = 0; i < peers.size(); i++) {
EV << "DiameterPeer nr. " << i << ":{\n";
DiameterPeer *peer = peers.at(i);
EV << "\torigFQDN:" << peer->oFQDN << endl;
EV << "\tdestFQDN:" << peer->dFQDN << endl;
EV << "\tstate:" << peer->stateName(peer->getState()) << endl;
if (peer->appl) {
EV << "\tappl:{\n";
EV << "\t\tapplId:" << peer->appl->applId << endl;
EV << "\t\tvendorId:" << peer->appl->vendorId << endl;
EV << "}\n";
}
EV << "}\n";
}
EV << "=====================================================================\n";
}
......@@ -72,18 +72,57 @@ enum PeerEvent {
STOP
};
class DiameterPeerStateVariables : public cPolymorphic {
public:
DiameterPeerStateVariables();
DiameterMessage *msg; // for inter state message handling
};
/*
* Class for Diameter peer. A Diameter peer can have a initiating
* or a responding Diameter connection which is basically just the
* SCTP socket. It can have both for a limited period of time during
* the election process. All the message processing (base protocol
* messages and application messages) is done during the state machine
* changes, described in the specification. For more info contact RFC 3588.
*/
class DiameterPeer : public cPolymorphic {
private:
bool type;
bool isTLSEnabled;
bool type; // dummy
bool isTLSEnabled; // dummy
DiameterBase *module;
cFSM fsm;
DiameterMessage *msg; // for inter state message handling
cMessage *tcTimer; // connection initiation timer
cMessage *twTimer; // watchdog
cMessage *tsTimer; // test timer
cMessage *teTimer; // connection expire timer
/*
* Methods for base protocol message processing. CER and CEA are
* for connection setup, DWR and DWA are the watchdog messages,
* DPR and DPA are termination messages.
*/
void sendCER(DiameterConnection *conn);
unsigned processCER(DiameterMessage *msg);
void sendCEA(DiameterConnection *conn, DiameterMessage *cer, unsigned resCode);
unsigned processCEA(DiameterMessage *msg);
void sendDWR(DiameterConnection *conn);
unsigned processDWR(DiameterMessage *msg);
void sendDWA(DiameterConnection *conn, DiameterMessage *dwr, unsigned resCode);
unsigned processDWA(DiameterMessage *msg);
void sendDPR(DiameterConnection *conn);
void sendDPA(DiameterConnection *conn, DiameterMessage *dpr);
/*
* Methods for cleaning up the Diameter connections.
*/
void iDisconnect();
void rDisconnect();
void cleanup();
void error() { cleanup(); }
/*
* Method for electing the Diameter connection which will be used by the peer.
* Election is done by comparing destination FQDN with origin FQDN and is
* described in more detail in the standard.
*/
void elect();
public:
std::string dFQDN;
std::string oFQDN;
......@@ -92,56 +131,83 @@ public:
DiameterApplication *appl;
DiameterConnection *iConn;
DiameterConnection *rConn;
cMessage *tcTimer;
cMessage *twTimer; // watchdog
cMessage *tsTimer; // test timer
cMessage *teTimer; // connection expire timer
private:
DiameterPeerStateVariables *state;
void sendCER(DiameterConnection *conn);
unsigned processCER(DiameterMessage *msg);
void sendCEA(DiameterConnection *conn, DiameterMessage *cer, unsigned resCode);
unsigned processCEA(DiameterMessage *msg);
void sendDWR(DiameterConnection *conn);
unsigned processDWR(DiameterMessage *msg);
void sendDWA(DiameterConnection *conn, DiameterMessage *dwr, unsigned resCode);
unsigned processDWA(DiameterMessage *msg);
void sendDPR(DiameterConnection *conn);
void sendDPA(DiameterConnection *conn, DiameterMessage *dpr);
const char *stateName(int state);
const char *eventName(int event);
public:
DiameterPeer(DiameterBase *module);
virtual ~DiameterPeer();
void iDisconnect();
void rDisconnect();
void cleanup();
void error() { cleanup(); }
void elect();
DiameterConnection *getIConnection() { return iConn; }
DiameterConnection *getRConnection() { return rConn; }
/*
* Getter methods.
*/
bool getType() { return type; }
const char *getTypeName() { if (type == STATIC) return "STATIC"; else return "DYNAMIC"; }
void setType(bool type) { this->type = type; }
bool getConnectionType();
int getConnectionId() { if (rConn == NULL) return iConn->getConnectionId(); else return rConn->getConnectionId(); }
const char *getTypeName();
int getConnectionType();
int getConnectionId();
int getState() { return fsm.getState(); }
const char *getStateName() { return stateName(fsm.getState()); }
/*
* Setter methods.
*/
void setType(bool type) { this->type = type; }
/*
* Utility methods for timer.
*/
void startTimer(cMessage *&timer, const char *name, simtime_t timeout);
void processTimer(cMessage *timer);
/*
* Utility methods for state processing.
*/
void performStateTransition(PeerEvent &event, DiameterMessage *msg);
void stateEntered();
const char *stateName(int state);
const char *eventName(int event);
void startTimer(cMessage *&timer, const char *name, simtime_t timeout);
/*
* Methods for processing the application messages. The application
* messages are forwarded and received from the appropriate session.
*/
void sendApplMessage(DiameterConnection *conn, DiameterMessage *msg);
void processApplMessage(DiameterConnection *conn, DiameterMessage *msg);
};
/*
* Class for Diameter peer table. This table will hold all the peers
* owned by the Diameter base protocol model implementation.
*/
class DiameterPeerTable {
private:
typedef std::vector<DiameterPeer*>PeerTable;
PeerTable peers;
public:
DiameterPeerTable();
virtual ~DiameterPeerTable();
/*
* Methods for find a Diameter peer. The method returns the
* peer if it is found, or NULL otherwise.
*/
DiameterPeer *findPeer(std::string dFQDN, std::string dRealm = "");
DiameterPeer *findPeer(unsigned applId);
/*
* Method for deleting Diameter peer. The method calls first
* the destructor for each peer between start and end position
* and removes them afterwards.
*/
void erase(unsigned start, unsigned end);
/*
* Method for printing the peer table.
*/
void print();
/*
* Wrapper methods.
*/
void push_back(DiameterPeer *peer) { peers.push_back(peer); }
unsigned size() { return peers.size(); }
DiameterPeer *at(unsigned i) { return peers[i]; }
};
#endif /* DIAMETERPEER_H_ */
......@@ -21,7 +21,7 @@
DiameterSession::DiameterSession(DiameterBase *module, bool state) {
// TODO Auto-generated constructor stub
this->state = state;
this->type = type;
this->module = module;
char time[10];
......@@ -81,7 +81,7 @@ void DiameterSession::performStateTransition(SessionEvent &event, unsigned applI
void DiameterSession::sendDiameterMessage(unsigned applId, DiameterPeer *peer, DiameterMessage *msg) {
msg->insertAvp(0, DiameterUtils().createUTF8StringAVP(AVP_SessionId, 0, 1, 0, 0, id));
msg->insertAvp(1, DiameterUtils().createInteger32AVP(AVP_AuthSessionState, 0, 1, 0, 0, state ? NO_STATE_MAINTAINED : STATE_MAINTAINED));
msg->insertAvp(1, DiameterUtils().createInteger32AVP(AVP_AuthSessionState, 0, 1, 0, 0, type ? NO_STATE_MAINTAINED : STATE_MAINTAINED));
PeerEvent event = SEND_MESSAGE;
peer->performStateTransition(event, msg);
}
......
......@@ -42,9 +42,9 @@ enum SessionEvent {
};
/*
* Class Diameter session. The class implements the session state machine
* and processes Diameter application messages which are not meant for
* Diameter base protocol.
* Class for Diameter session. The class implements the session state
* machine and processes Diameter application messages which are not
* meant for Diameter base protocol.
*/
class DiameterSession : public cPolymorphic {
private:
......@@ -54,9 +54,10 @@ private:
// cMessage *sTimer;
DiameterBase *module;
const char *stateName(int state);
const char *eventName(int event);
/*
* Methods for sending and processing Diameter messages. Message handling
* will not be done directly, it will be done during a state transition.
*/
void sendDiameterMessage(unsigned applId, DiameterPeer *peer, DiameterMessage *req);
void processDiameterMessage(unsigned applId, DiameterPeer *peer, DiameterMessage *msg);
public:
......@@ -64,13 +65,22 @@ public:
virtual ~DiameterSession();
/*
* Getter methods
* Getter methods.
*/
std::string getId() { return id; }
/*
* Methods for managing the session state machine
*/
void performStateTransition(SessionEvent &event, unsigned applId, DiameterPeer *peer, DiameterMessage *msg);
const char *stateName(int state);
const char *eventName(int event);
};
/*
* Class for Diameter session table. This table will hold all the sessions
* owned by the Diameter base protocol model implementation.
*/
class DiameterSessionTable {
private:
typedef std::vector<DiameterSession*> SessionTable;
......@@ -79,11 +89,25 @@ public:
DiameterSessionTable();
virtual ~DiameterSessionTable();
/*
* Method for find a Diameter session with a specific id. The method
* returns the session if it is found, or NULL otherwise.
*/
DiameterSession *find(std::string id);
DiameterSession *at(unsigned i) { return sessions.at(i); }
void push_back(DiameterSession *session) { sessions.push_back(session); }
/*
* Method for deleting Diameter sessions. The method calls first
* the destructor for each session between start and end position
* and removes them afterwards.
*/
void erase(unsigned start, unsigned end);
/*
* Wrapper methods.
*/
unsigned size() {return sessions.size();}
DiameterSession *at(unsigned i) { return sessions.at(i); }
void push_back(DiameterSession *session) { sessions.push_back(session); }
// void deleteSessions();
};
......
//
// Copyright (C) 2012 Calin Cerchez
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "DiameterConnectionMap.h"
DiameterConnectionMap::DiameterConnectionMap() {
// TODO Auto-generated constructor stub
}
DiameterConnectionMap::~DiameterConnectionMap() {
// TODO Auto-generated destructor stub
}
DiameterConnection *DiameterConnectionMap::findConnectionFor(cMessage *msg) {
SCTPCommand *ind = dynamic_cast<SCTPCommand *>(msg->getControlInfo());
if (!ind)
opp_error("DiameterConnectionMap: findConnectionFor(): no SCTPCommand control info in message (not from SCTP?)");
int assocId = ind->getAssocId();
ConnMap::iterator i = connMap.find(assocId);
ASSERT(i == connMap.end() || i->first == i->second->getConnectionId());
return (i == connMap.end()) ? NULL : i->second;
}
void DiameterConnectionMap::addConnection(DiameterConnection *conn) {
ASSERT(connMap.find(conn->getConnectionId()) == connMap.end());
connMap[conn->getConnectionId()] = conn;
}
DiameterConnection *DiameterConnectionMap::removeConnection(DiameterConnection *conn) {
ConnMap::iterator i = connMap.find(conn->getConnectionId());
if (i != connMap.end())
connMap.erase(i);
printConnectionMap();
return conn;
}
/*
void DiameterConnectionMap::deleteConnections()
{
for (ConnMap::iterator i = connMap.begin(); i != connMap.end(); ++i)
delete i->second;
}
*/
void DiameterConnectionMap::printConnectionMap() {
EV << "=====================================================================\n"
<< "Connection Map:\n"
<< "-------------------------------------------------------------------------------\n"
<< "Conn Id\t| Local Addr\t| Local Port\t| Remote Addr\t| Remote Port\n"
<< "---------------------------------------------------------------------\n";
for (ConnMap::iterator i = connMap.begin(); i != connMap.end(); ++i)
EV << (i->second)->getConnectionId() << endl;// << "\t| " << (i->second)->getLocalAddresses().at(0) << "\t| " << "" << "\t| " << "" << "\t| " << "" << endl;
EV << "=====================================================================\n";
}
//
// Copyright (C) 2012 Calin Cerchez
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#ifndef DIAMETERCONNECTIONMAP_H_
#define DIAMETERCONNECTIONMAP_H_
#include "DiameterConnection.h"
class DiameterConnectionMap {
private:
typedef std::map<int,DiameterConnection*> ConnMap;
ConnMap connMap;
public:
DiameterConnectionMap();
virtual ~DiameterConnectionMap();
DiameterConnection *findConnectionFor(cMessage *msg);
void addConnection(DiameterConnection *conn);
DiameterConnection *removeConnection(DiameterConnection *conn);
unsigned int size() {return connMap.size();}
// void deleteConnections();
void printConnectionMap();
};
#endif /* DIAMETERCONNECTIONMAP_H_ */
//
// Copyright (C) 2012 Calin Cerchez
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "DiameterPeerTable.h"
DiameterPeerTable::DiameterPeerTable() {
// TODO Auto-generated constructor stub
}
DiameterPeerTable::~DiameterPeerTable() {
// TODO Auto-generated destructor stub
}
DiameterPeer *DiameterPeerTable::findPeer(std::string dFQDN, std::string dRealm) {
if (dRealm == "") {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if ((peer->dFQDN.find(dFQDN)) != std::string::npos)
return peer;
}
} else {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if ((peer->dFQDN == dFQDN) && (peer->dRealm == dRealm))
return peer;
}
}
return NULL;
}
DiameterPeer *DiameterPeerTable::findPeer(unsigned applId) {
for (unsigned i = 0; i < peers.size(); i++) {
DiameterPeer *peer = peers[i];
if (peer->appl->applId == applId)
return peer;
}
return NULL;
}
void DiameterPeerTable::erase(unsigned start, unsigned end) {
PeerTable::iterator first = peers.begin() + start;
PeerTable::iterator last = peers.begin() + end;
PeerTable::iterator i = first;
for (;i != last; ++i)
delete *i;
peers.erase(first, last);
}
void DiameterPeerTable::print() {
EV << "=====================================================================\n"
<< "Diameter Peer Table:\n";
for (unsigned int i = 0; i < peers.size(); i++) {
EV << "DiameterPeer nr. " << i << ":{\n";
DiameterPeer *peer = peers.at(i);
EV << "\torigFQDN:" << peer->oFQDN << endl;
EV << "\tdestFQDN:" << peer->dFQDN << endl;
EV << "\tstate:" << peer->getStateName() << endl;
if (peer->appl) {
EV << "\tappl:{\n";
EV << "\t\tapplId:" << peer->appl->applId << endl;
EV << "\t\tvendorId:" << peer->appl->vendorId << endl;
EV << "}\n";
}
EV << "}\n";
}
EV << "=====================================================================\n";
}
//
// Copyright (C) 2012 Calin Cerchez
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#ifndef DIAMETERPEERTABLE_H_
#define DIAMETERPEERTABLE_H_
#include "DiameterPeer.h"
class DiameterPeerTable {
private:
typedef std::vector<DiameterPeer*>PeerTable;
PeerTable peers;
public:
DiameterPeerTable();
virtual ~DiameterPeerTable();
void push_back(DiameterPeer *peer) { peers.push_back(peer); }
void erase(unsigned start, unsigned end);
void print();
DiameterPeer *findPeer(std::string dFQDN, std::string dRealm = "");
DiameterPeer *findPeer(unsigned applId);
DiameterPeer *at(unsigned i) { return peers[i]; }
unsigned size() { return peers.size(); }
};
#endif /* DIAMETERPEERTABLE_H_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册