import org.slf4j.LoggerFactory;
import org.umu.cops.stack.*;
import org.umu.cops.stack.COPSError.ErrorTypes;
+import org.umu.cops.stack.COPSHeader.ClientType;
+import org.umu.cops.stack.COPSHeader.OPCode;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
-import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
Client-type of connecting PEP
*/
- private short _clientType;
+ private ClientType _clientType;
/**
Accounting timer (secs)
* @param clientType COPS Client-type
* @param process Object to perform policy data processing
*/
- public COPSPdpAgent(short clientType, COPSPdpDataProcess process) {
+ public COPSPdpAgent(final ClientType clientType, final COPSPdpDataProcess process) {
_serverPort = WELL_KNOWN_PDP_PORT;
_kaTimer = KA_TIMER_VALUE;
_acctTimer = ACCT_TIMER_VALUE;
* @param clientType COPS Client-type
* @param process Object to perform policy data processing
*/
- public COPSPdpAgent(int port, short clientType, COPSPdpDataProcess process) {
+ public COPSPdpAgent(final int port, final ClientType clientType, final COPSPdpDataProcess process) {
_serverPort = port;
_kaTimer = KA_TIMER_VALUE;
return _acctTimer;
}
- /**
- * Gets the connection map
- * @return A <tt>Hashtable</tt> holding the connection map
- */
- public Hashtable getConnectionMap() {
- return new Hashtable(_connectionMap);
- }
-
/**
* Gets the client-type
* @return The client-type
*/
- public short getClientType() {
+ public ClientType getClientType() {
return _clientType;
}
* @throws COPSException
* @throws IOException
*/
- public void disconnect (String pepID, COPSError error)
- throws COPSException, IOException {
-
- COPSPdpConnection pdpConn = _connectionMap.get(pepID);
-
- COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, _clientType);
- COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();
- closeMsg.add(cHdr);
- if (error != null)
- closeMsg.add(error);
-
+ public void disconnect(final String pepID, final COPSError error) throws COPSException, IOException {
+ final COPSPdpConnection pdpConn = _connectionMap.get(pepID);
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType, error, null, null);
closeMsg.writeData(pdpConn.getSocket());
pdpConn.close();
}
// We're waiting for an OPN message
try {
- COPSMsg msg = COPSTransceiver.receiveMsg(socket);
- if (msg.getHeader().isAClientOpen()) {
+ final COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+ if (msg.getHeader().getOpCode().equals(OPCode.OPN)) {
handleClientOpenMsg(socket, msg);
} else {
// COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);
* @throws COPSException
* @throws IOException
*/
- private void handleClientOpenMsg(Socket conn, COPSMsg msg)
- throws COPSException, IOException {
- COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
- COPSPepId pepId = cMsg.getPepId();
+ private void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+ final COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
+ final COPSPepId pepId = cMsg.getPepId();
// Validate Client Type
- if (msg.getHeader().getClientType() != _clientType) {
+ if (msg.getHeader().getClientType().equals(_clientType)) {
// Unsupported client type
- COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, msg.getHeader().getClientType());
- COPSError err = new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA);
- COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();
- closeMsg.add(cHdr);
- closeMsg.add(err);
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
// PEPId is mandatory
if (pepId == null) {
// Mandatory COPS object missing
- COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, msg.getHeader().getClientType());
- COPSError err = new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA);
- COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();
- closeMsg.add(cHdr);
- closeMsg.add(err);
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
(cMsg.getIntegrity() != null)) {
// Unsupported objects
- COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, msg.getHeader().getClientType());
- COPSError err = new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA);
- COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();
- closeMsg.add(cHdr);
- closeMsg.add(err);
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
}
// Connection accepted
- COPSHeader ahdr = new COPSHeader(COPSHeader.COPS_OP_CAT, msg.getHeader().getClientType());
- COPSKATimer katimer = new COPSKATimer(_kaTimer);
- COPSAcctTimer acctTimer = new COPSAcctTimer(_acctTimer);
- COPSClientAcceptMsg acceptMsg = new COPSClientAcceptMsg();
- acceptMsg.add(ahdr);
- acceptMsg.add(katimer) ;
- if (_acctTimer != 0) acceptMsg.add(acctTimer);
+ final COPSKATimer katimer = new COPSKATimer(_kaTimer);
+ final COPSClientAcceptMsg acceptMsg;
+ if (_acctTimer != 0) acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, null, null);
+ else acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer,
+ new COPSAcctTimer(_acctTimer), null);
acceptMsg.writeData(conn);
- COPSPdpConnection pdpConn = new COPSPdpConnection(pepId,conn,_process);
+ final COPSPdpConnection pdpConn = new COPSPdpConnection(pepId,conn,_process);
pdpConn.setKaTimer(_kaTimer);
if (_acctTimer != 0) pdpConn.setAccTimer(_acctTimer);
new Thread(pdpConn).start();