package org.pcmm;
+import org.pcmm.gates.IPCMMGate;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * TODO - Remove all uses of this class which is evil as it contains environmental settings
+ */
public class PCMMGlobalConfig {
// System
public static int Debug = 0;
public static int getGateID2() {
return GateID2;
}
+
+ /**
+ * Global TransactionId to Gate Request map allows recovery of CCAP GateIds
+ * TODO - need to find a better means to store shared state.
+ */
+
+ public static Map<Short, IPCMMGate> transactionGateMap = new ConcurrentHashMap<>();
}
/*
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
/**
* Core PDP agent for provisioning
*/
public class PCMMPdpAgent extends COPSPdpAgent {
- public final static Logger logger = LoggerFactory.getLogger(PCMMPdpAgent.class);
+ private static final Logger logger = LoggerFactory.getLogger(PCMMPdpAgent.class);
/** Well-known port for PCMM */
public static final int WELL_KNOWN_PDP_PORT = 3918;
- private COPSPepId _pepId;
- private String _pepIdString;
/**
* PEP host name
*/
- private String psHost;
+ private final String psHost;
/**
* PEP port
*/
- private int psPort;
-
- private Socket socket;
+ private final int psPort;
/**
* Policy data processing object
*/
- private PCMMPdpDataProcess _process;
- private COPSHandle _handle;
-// private short _transactionID;
-
- /**
- * Temporary until can refactor PdpAgent classes
- */
- @Deprecated
- private final Map<String, PCMMPdpConnection> _connectionMap;
+ private final PCMMPdpDataProcess _process;
+ // Next two attributes are initialized when connected
/**
- * Creates a PDP Agent
- *
- * @param clientType
- * COPS Client-type
- * @param process
- * Object to perform policy data processing
+ * The Socket connection to the PEP
*/
- public PCMMPdpAgent(short clientType, PCMMPdpDataProcess process) {
- this(clientType, null, WELL_KNOWN_PDP_PORT, process);
- }
+ private transient Socket socket;
+ private transient COPSHandle _handle;
/**
* Creates a PDP Agent
*
- * @param clientType
- * COPS Client-type
- * @param psHost
- * Host to connect to
- * @param psPort
- * Port to connect to
- * @param process
- * Object to perform policy data processing
+ * @param clientType - COPS Client-type
+ * @param psHost - Host to connect to
+ * @param psPort - Port to connect to
+ * @param process - Object to perform policy data processing
*/
- public PCMMPdpAgent(short clientType, String psHost, int psPort, PCMMPdpDataProcess process) {
+ public PCMMPdpAgent(final short clientType, final String psHost, final int psPort,
+ final PCMMPdpDataProcess process) {
super(psPort, clientType, null);
this._process = process;
this.psHost = psHost;
- this._connectionMap = new ConcurrentHashMap<>();
+ this.psPort = psPort;
}
/**
/**
* Connects to a PDP
*
- * @param psHost
- * CMTS host name
- * @param psPort
- * CMTS port
* @return <tt>true</tt> if PDP accepts the connection; <tt>false</tt>
* otherwise
* @throws java.net.UnknownHostException
* @throws java.io.IOException
* @throws COPSException
- * @throws COPSPdpException
*/
- public boolean connect(String psHost, int psPort) throws IOException, COPSException, COPSPdpException {
-
- this.psHost = psHost;
- this.psPort = psPort;
+ public boolean connect() throws IOException, COPSException, COPSPdpException {
// Create Socket and send OPN
- InetAddress addr = InetAddress.getByName(psHost);
- try {
- socket = new Socket(addr, psPort);
- } catch (IOException e) {
- logger.error("Error creating socket connection", e);
- return (false);
- }
- logger.info("PDP Socket Opened");
+ final InetAddress addr = InetAddress.getByName(psHost);
+ // caller will catch IOExceptions
+ socket = new Socket(addr, psPort);
+ logger.debug("{} {}", getClass().getName(), "PDP Socket Opened");
+ // COPSDebug.err(getClass().getName(), "PDP Socket Opened");
// Loop through for Incoming messages
// server infinite loop
// We're waiting for an message
try {
- logger.info("PDP COPSTransceiver.receiveMsg");
- COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+ logger.debug("Waiting to receiveMsg");
+ final COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+ logger.debug("Message received of type - " + msg.getHeader().getOpCode());
if (msg.getHeader().getOpCode().equals(OPCode.OPN)) {
- logger.info("PDP msg.getHeader().isAClientOpen");
handleClientOpenMsg(socket, msg);
} else {
try {
socket.close();
} catch (Exception ex) {
- logger.error("Unexpected exception closing socket", ex);
+ logger.error("Unexpected error closing socket", ex);
}
}
- } catch (Exception e) { // COPSException, IOException
+ } catch (Exception e) {
+ logger.error("Unexpected error handing client open message", e);
try {
socket.close();
} catch (Exception ex) {
- logger.error("Unexpected exception closing socket", ex);
+ logger.error("Unexpected error closing socket", ex);
}
return true;
}
return false;
}
- /**
- * Handles a COPS client-open message
- *
- * @param conn
- * Socket to the PEP
- * @param msg
- * <tt>COPSMsg</tt> holding the client-open message
- * @throws COPSException
- * @throws IOException
- */
- private void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+ // TODO - remove and let super handle after DataProcess & PdpConnection classes are properly refactored
+ @Override
+ public void disconnect (final String pepID, final COPSError error) throws COPSException, IOException {
+ final PCMMPdpConnection pdpConn = (PCMMPdpConnection) _connectionMap.get(pepID);
+ if (pdpConn != null) {
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(), error, null, null);
+ closeMsg.writeData(pdpConn.getSocket());
+ pdpConn.close();
+ }
+
+ final Thread thread = threadMap.remove(pepID);
+ if (thread != null) thread.interrupt();
+ }
+
+ @Override
+ protected void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+ logger.info("Processing client open message");
final COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
- final COPSPepId pepId = cMsg.getPepId();
+ _pepId = cMsg.getPepId();
// Validate Client Type
+ // TODO - Need to fix this logic. Currently the client type being set is the CCAP AMID.type mapped to the
+ // enumeration's ordinal value
+/*
if (msg.getHeader().getClientType() != getClientType()) {
// Unsupported client type
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Unexpected error writing COPS data", unae);
+ logger.error("Unexpected error writing data", unae);
}
throw new COPSException("Unsupported client type");
}
+*/
// PEPId is mandatory
- if (pepId == null) {
+ if (_pepId == null) {
// Mandatory COPS object missing
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Unexpected error writing COPS data", unae);
+ logger.error("Unexpected error closing socket", unae);
}
throw new COPSException("Mandatory COPS object missing (PEPId)");
}
- setPepId(pepId);
+
// Support
if ((cMsg.getClientSI() != null) ) {
final MMVersionInfo _mminfo = new MMVersionInfo(cMsg.getClientSI().getData().getData());
- logger.info("CMTS sent MMVersion info : major:" + _mminfo.getMajorVersionNB() + " minor:" +
+ logger.debug("CMTS sent MMVersion info : major:" + _mminfo.getMajorVersionNB() + " minor:" +
_mminfo.getMinorVersionNB());
} else {
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ // Unsupported objects
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Unexpected error writing COPS data", unae);
+ logger.error("Unexpected error writing data", unae);
}
throw new COPSException("Unsupported objects (PdpAddress, Integrity)");
*/
// Connection accepted
- final COPSKATimer katimer = new COPSKATimer(getKaTimer());
- final COPSAcctTimer acctTimer = new COPSAcctTimer(getAcctTimer());
final COPSClientAcceptMsg acceptMsg;
if (getAcctTimer() != 0)
- acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, acctTimer, null);
+ acceptMsg = new COPSClientAcceptMsg(getClientType(), new COPSKATimer(getKaTimer()),
+ new COPSAcctTimer(getAcctTimer()), null);
else
- acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, null, null);
-
+ acceptMsg = new COPSClientAcceptMsg(getClientType(), new COPSKATimer(getKaTimer()), null, null);
acceptMsg.writeData(conn);
// XXX - handleRequestMsg
try {
- logger.info("PDP COPSTransceiver.receiveMsg");
- COPSMsg rmsg = COPSTransceiver.receiveMsg(socket);
+ logger.debug("handleClientOpenMsg() - Waiting to receive message");
+ final COPSMsg rmsg = COPSTransceiver.receiveMsg(socket);
+ logger.debug("Received message of type - " + rmsg.getHeader().getOpCode());
// Client-Close
if (rmsg.getHeader().getOpCode().equals(OPCode.CC)) {
- logger.info("Client close description - " + ((COPSClientCloseMsg) rmsg).getError().getDescription());
+ System.out.println(((COPSClientCloseMsg) rmsg)
+ .getError().getDescription());
// close the socket
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Unexpected exception writing COPS data", unae);
+ logger.error("Unexpected error writing data", unae);
}
throw new COPSException("CMTS requetsed Client-Close");
} else {
_handle = rMsg.getClientHandle();
} else
throw new COPSException("Can't understand request");
-
}
} catch (Exception e) { // COPSException, IOException
- throw new COPSException("Error COPSTransceiver.receiveMsg");
+ throw new COPSException("Error COPSTransceiver.receiveMsg", e);
}
- logger.info("PDPCOPSConnection");
- PCMMPdpConnection pdpConn = new PCMMPdpConnection(pepId, conn, _process);
+ logger.debug("PDPCOPSConnection");
+ final PCMMPdpConnection pdpConn = new PCMMPdpConnection(_pepId, conn, _process);
pdpConn.setKaTimer(getKaTimer());
if (getAcctTimer() != 0)
pdpConn.setAccTimer(getAcctTimer());
// XXX - handleRequestMsg
// XXX - check handle is valid
- PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(getClientType(), _handle.getId().str());
- pdpConn.getReqStateMans().put(_handle.getId().str(),man);
+ final PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(getClientType(), _handle.getId().str());
+ pdpConn.addStateMan(_handle.getId().str(), man);
man.setDataProcess(_process);
try {
man.initRequestState(conn);
} catch (COPSPdpException unae) {
- logger.error("Error initializing the state manager's request state");
+ logger.error("Unexpected error initializing state", unae);
}
// XXX - End handleRequestMsg
- logger.info("PDP Thread(pdpConn).start");
- new Thread(pdpConn).start();
- _connectionMap.put(pepId.getData().str(), pdpConn);
- }
+ logger.info("Starting PDP connection thread to - " + psHost);
- /**
- * @return the _psHost
- */
- public String getPsHost() {
- return psHost;
- }
-
- /**
- * TODO - make the host immutable
- * @param _psHost
- * the _psHost to set
- */
- @Deprecated
- public void setPsHost(String _psHost) {
- this.psHost = _psHost;
+ // TODO - store the thread reference so it is possible to manage.
+ final Thread thread = new Thread(pdpConn, "Agent for - " + psHost);
+ thread.start();
+ threadMap.put(_pepId.getData().str(), thread);
+ _connectionMap.put(_pepId.getData().str(), pdpConn);
}
- /**
- * @return the _psPort
- */
- public int getPsPort() {
- return psPort;
- }
-
- /**
- * TODO - make the port immutable
- * @param _psPort
- * the _psPort to set
- */
- @Deprecated
- public void setPsPort(int _psPort) {
- this.psPort = _psPort;
- }
-
- /**
- * @return the socket
- */
public Socket getSocket() {
return socket;
}
-
- /**
- * TODO - Ensure socket is not overly transient
- * @param socket
- * the socket to set
- */
- @Deprecated
- public void setSocket(Socket socket) {
- this.socket = socket;
- }
-
- /**
- * @return the _process
- */
public PCMMPdpDataProcess getProcess() {
return _process;
}
-
- /**
- * @param _process
- * the _process to set
- */
- public void setProcess(PCMMPdpDataProcess _process) {
- this._process = _process;
- }
-
- /**
- * Gets the client handle
- * @return Client's <tt>COPSHandle</tt>
- */
public COPSHandle getClientHandle() {
return _handle;
}
-
- /**
- * Gets the PepId
- * @return <tt>COPSPepId</tt>
- */
- public COPSPepId getPepId() {
- return _pepId;
- }
-
public String getPepIdString() {
- return _pepIdString;
+ return _pepId.getData().str();
}
- /**
- * Sets the PepId
- * TODO - make PEP ID and the associate string immutable or remove altogether
- * @param pepId - COPSPepId
- */
- @Deprecated
- public void setPepId(COPSPepId pepId) {
- _pepId = pepId;
- _pepIdString = pepId.getData().str();
- }
/*
* (non-Javadoc)
*
}
+
import org.slf4j.LoggerFactory;
import org.umu.cops.prpdp.COPSPdpException;
import org.umu.cops.stack.*;
-import org.umu.cops.stack.COPSHeader.OPCode;
import java.io.IOException;
import java.net.Socket;
_process = process;
}
+ public void addStateMan(final String key, final PCMMPdpReqStateMan man) {
+ _managerMap.put(key, man);
+ }
+
/**
* Sets the keep-alive timer value
* @param kaTimer Keep-alive timer value (secs)
* Main loop
*/
public void run () {
+ logger.info("Starting socket listener.");
Date _lastSendKa = new Date();
_lastRecKa = new Date();
try {
while (!_sock.isClosed()) {
if (_sock.getInputStream().available() != 0) {
+ logger.info("Waiting to process socket messages");
processMessage(_sock);
+ logger.info("Message processed");
_lastRecKa = new Date();
}
if ((cTime - _startTime) > ((_kaTimer*3/4)*1000)) {
// TODO - determine what is the client type to be used here?
final COPSKAMsg msg = new COPSKAMsg(null);
+ logger.info("Sending KA message to CCAP");
COPSTransceiver.sendMsg(msg, _sock);
+ logger.info("Sent KA message gto CCAP");
_lastSendKa = new Date();
}
}
try {
Thread.sleep(500);
} catch (Exception e) {
- logger.error("Unexpected exception while sleeping", e);
+ logger.info("Shutting down", e);
+ break;
}
}
private void processMessage(final Socket conn) throws COPSPdpException, COPSException, IOException {
final COPSMsg msg = COPSTransceiver.receiveMsg(conn);
- if (msg.getHeader().getOpCode().equals(OPCode.CC)) {
- handleClientCloseMsg(conn, msg);
- } else if (msg.getHeader().getOpCode().equals(OPCode.KA)) {
- handleKeepAliveMsg(conn, msg);
- } else if (msg.getHeader().getOpCode().equals(OPCode.REQ)) {
- handleRequestMsg(conn, msg);
- } else if (msg.getHeader().getOpCode().equals(OPCode.RPT)) {
- handleReportMsg(conn, msg);
- } else if (msg.getHeader().getOpCode().equals(OPCode.DRQ)) {
- handleDeleteRequestMsg(conn, msg);
- } else if (msg.getHeader().getOpCode().equals(OPCode.SSQ)) {
- handleSyncComplete(conn, msg);
- } else {
- throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");
+ logger.info("Processing message received of type - " + msg.getHeader().getOpCode());
+
+ switch (msg.getHeader().getOpCode()) {
+ case CC:
+ handleClientCloseMsg(conn, msg);
+ break;
+ case KA:
+ handleKeepAliveMsg(conn, msg);
+ break;
+ case REQ:
+ handleRequestMsg(conn, msg);
+ break;
+ case RPT:
+ handleReportMsg(conn, msg);
+ break;
+ case DRQ:
+ handleDeleteRequestMsg(conn, msg);
+ break;
+ case SSQ:
+ handleSyncComplete(conn, msg);
+ break;
+ default:
+ throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");
}
}
private void handleClientCloseMsg(Socket conn, COPSMsg msg) {
COPSClientCloseMsg cMsg = (COPSClientCloseMsg) msg;
_error = cMsg.getError();
+ logger.info("Closing client with error - " + _error.getDescription());
try {
// Support
if (cMsg.getIntegrity() != null) {
import org.slf4j.LoggerFactory;
import org.umu.cops.prpdp.COPSPdpException;
import org.umu.cops.stack.*;
+import org.umu.cops.stack.COPSClientSI.CSIType;
import org.umu.cops.stack.COPSContext.RType;
import org.umu.cops.stack.COPSDecision.Command;
import org.umu.cops.stack.COPSDecision.DecisionFlag;
import org.umu.cops.stack.COPSHeader.OPCode;
+import org.umu.cops.stack.COPSObjHeader.CNum;
import org.umu.cops.stack.COPSObjHeader.CType;
import java.io.IOException;
/**
* Socket connected to PEP
*/
- protected Socket _sock;
+ protected final Socket _sock;
/**
* COPS client-type that identifies the policy client
*/
- protected short _clientType;
+ protected final short _clientType;
/**
* COPS client handle used to uniquely identify a particular PEP's request
* for a client-type
*/
- protected COPSHandle _handle;
+ protected final COPSHandle _handle;
/**
*
*/
protected short _transactionID;
- protected short _classifierID;
+ protected final short _classifierID;
// XXX - this does not need to be here
- protected int _gateID;
+ protected IGateID _gateID;
/**
* Creates a PCMMPdpMsgSender
* @param sock
* Socket to the PEP
*/
- public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
- // COPS Handle
- _handle = clientHandle;
- _clientType = clientType;
-
- _transactionID = 0;
- _classifierID = 0;
- _sock = sock;
+ public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock)
+ throws COPSPdpException {
+ this(clientType, (short)0, clientHandle, sock);
}
public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
- final Socket sock) {
+ final Socket sock) throws COPSPdpException {
+ if (clientHandle == null) throw new COPSPdpException("Client handle must not be null");
+ if (sock == null) throw new COPSPdpException("Socket must not be null");
// COPS Handle
_handle = clientHandle;
_clientType = clientType;
_sock = sock;
}
- /**
- * Gets the client handle
- *
- * @return Client's <tt>COPSHandle</tt>
- */
- public COPSHandle getClientHandle() {
- return _handle;
- }
-
/**
* Gets the client-type
*
return _transactionID;
}
+ /**
+ * Gets the gate-id
+ *
+ * @return the gate-id value
+ */
+ public IGateID getGateID() {
+ return _gateID;
+ }
/**
* Sends a PCMM GateSet COPS Decision message
trID.setTransactionIdentifier(_transactionID);
gate.setTransactionID(trID);
-
+ // retain the transactionId to gate request mapping for gateID recovery after response
+ // see PCMMPdpReqStateMan.processReport()
+ final Short trIDnum = trID.getTransactionIdentifier();
+ logger.info("Adding gate to cache - " + gate + " with key - " + trIDnum);
+ PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
// new pcmm specific clientsi
final byte[] data = gate.getData();
// Client Handle with the same clientHandle as the request
final Set<COPSDecision> decisionSet = new HashSet<>();
- decisionSet.add(
- new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+ decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
- final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
- decisionMap, null, null);
+ final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
+
+ final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
+ decisionMap, null, clientSD);
+
// ** Send the GateSet Decision
- // **
try {
decisionMsg.writeData(_sock);
} catch (IOException e) {
// TODO - Use some variable here or remove...
if (true) {
//eclassifier.setProtocol(IClassifier.Protocol.NONE);
- eclassifier.setProtocol(IClassifier.Protocol.TCP);
+// eclassifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress
.getByName(PCMMGlobalConfig.SubscriberID);
eclassifier.setPriority((byte) 65);
} else {
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress
.getByName(PCMMGlobalConfig.SubscriberID);
final byte[] data = gate.getData();
final Set<COPSDecision> decisionSet = new HashSet<>();
- decisionSet.add(
- new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+ decisionSet.add(new COPSDecision(CType.NA, Command.INSTALL, DecisionFlag.REQERROR));
final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+ final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
// Common Header with the same ClientType as the request
// Client Handle with the same clientHandle as the request
final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
- new COPSHandle(getClientHandle().getId()), decisionMap, null, null);
+ new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
// ** Send the GateSet Decision
// **
// XXX - if the version major is less than 4 we need to use Classifier
if (true) {
//eclassifier.setProtocol(IClassifier.Protocol.NONE);
- eclassifier.setProtocol(IClassifier.Protocol.TCP);
+// eclassifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress
.getByName(PCMMGlobalConfig.SubscriberID);
eclassifier.setPriority((byte) 65);
} else {
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress
.getByName(PCMMGlobalConfig.SubscriberID);
byte[] data = gate.getData();
final Set<COPSDecision> decisionSet = new HashSet<>();
- decisionSet.add(
- new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+ decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR));
final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+ final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
// Common Header with the same ClientType as the request
// Client Handle with the same clientHandle as the request
- final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
- decisionMap, null, null);
+ final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
+ decisionMap, null, clientSD);
// ** Send the GateSet Decision
// **
logger.info("the CMTS has sent a Gate-Set-Ack response");
// here CMTS responded that he acknowledged the Gate-Set
// TODO do further check of Gate-Set-Ack GateID etc...
- _gateID = responseGate.getGateID().getGateID();
+ _gateID = responseGate.getGateID();
return true;
} else {
return false;
}
return false;
} catch (Exception e) { // COPSException, IOException
- throw new COPSPdpException("Error COPSTransceiver.receiveMsg");
+ throw new COPSPdpException("Error COPSTransceiver.receiveMsg", e);
}
}
* .setServiceClassName("S_up");
*/
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
final byte[] data = gate.getData();
final Set<COPSDecision> decisionSet = new HashSet<>();
- decisionSet.add(
- new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+ decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR));
final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+ final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
+
// Client Handle with the same clientHandle as the request
final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
- new COPSHandle(getClientHandle().getId()), decisionMap, null, null);
+ new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
// ** Send the GateSet Decision
// **
} catch (IOException e) {
logger.error("Failed to send the decision", e);
}
-
}
/**
*
* @throws COPSPdpException
*/
- public void sendGateDelete(int gID) throws COPSPdpException {
- /*
- * Example of an UNSOLICITED decision <Gate Control Command> = <COPS
- * Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI
- * Data> <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
- * <PDP-Config> | <Synch-Request> | <Msg-Receipt> <Gate-Delete> =
- * <Decision Header> <TransactionID> <AMID> <SubscriberID> <GateID>
- */
- // Common Header with the same ClientType as the request
- final IPCMMGate gate = new PCMMGateReq();
- final ITransactionID trID = new TransactionID();
-
- final IAMID amid = new AMID();
- final ISubscriberID subscriberID = new SubscriberID();
- final IGateID gateID = new GateID();
-
+ public void sendGateDelete(final IPCMMGate gate) throws COPSPdpException {
// set transaction ID to gate set
+ final ITransactionID trID = new TransactionID();
trID.setGateCommandType(ITransactionID.GateDelete);
_transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
trID.setTransactionIdentifier(_transactionID);
+ gate.setTransactionID(trID);
- amid.setApplicationType((short) 1);
- amid.setApplicationMgrTag((short) 1);
- gateID.setGateID(gID);
-
- try {
- InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
- subscriberID.setSourceIPAddress(subIP);
- } catch (UnknownHostException unae) {
- logger.error("Error getByName", unae);
- }
+ Short trIDnum = trID.getTransactionIdentifier();
+ PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
- gate.setTransactionID(trID);
- gate.setAMID(amid);
- gate.setSubscriberID(subscriberID);
- gate.setGateID(gateID);
+ // gateDelete only requires AMID, subscriberID, and gateID
+ // remove the gateSpec, traffic profile, and classifiers from original gate request
+ gate.setGateSpec(null);
+ gate.setTrafficProfile(null);
+ gate.setClassifier(null);
+ // clear the error object
+ gate.setError(null);
// XXX - GateID
final byte[] data = gate.getData();
-
final Set<COPSDecision> decisionSet = new HashSet<>();
- decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
- new COPSData(data, 0, data.length)));
+ decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
- decisionMap.put(new COPSContext(RType.CONFIG, (short) 0), decisionSet);
+ decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+ final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
- new COPSHandle(getClientHandle().getId()), decisionMap, null, null);
+ new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
// ** Send the GateDelete Decision
// **
try {
decisionMsg.writeData(_sock);
} catch (IOException e) {
- throw new COPSPdpException(
- "Failed to send the open new request state, reason: "
- + e.getMessage());
+ throw new COPSPdpException("Failed to send the open new request state", e);
}
}
try {
msg.writeData(_sock);
} catch (IOException e) {
- throw new COPSPdpException(
- "Failed to send the GateInfo request, reason: "
- + e.getMessage());
+ throw new COPSPdpException("Failed to send the GateInfo request", e);
}
}
try {
msg.writeData(_sock);
} catch (IOException e) {
- throw new COPSPdpException(
- "Failed to send the sync state request, reason: "
- + e.getMessage());
+ throw new COPSPdpException("Failed to send the sync state request", e);
}
}
// XXX - Temp
package org.pcmm;
+import org.pcmm.gates.IGateID;
+import org.pcmm.gates.IPCMMGate;
import org.pcmm.gates.ITransactionID;
import org.pcmm.gates.impl.PCMMGateReq;
import org.slf4j.Logger;
*/
public class PCMMPdpReqStateMan {
- public final static Logger logger = LoggerFactory.getLogger(PCMMPdpReqStateMan.class);
+ private final static Logger logger = LoggerFactory.getLogger(PCMMPdpReqStateMan.class);
/**
* Request State created
* Gets the client-type
* @return Client-type value
*/
- public int getClientType() {
+ public short getClientType() {
return _clientType;
}
logger.info("rtypemsg process");
//** Here we must act in accordance with
//** the report received
+
+ // retrieve and remove the transactionId to gate request map entry
+ // see PCMMPdpMsgSender.sendGateSet(IPCMMGate gate)
+ final ITransactionID trID = gateMsg.getTransactionID();
+ final Short trIDnum = trID.getTransactionIdentifier();
+
+ logger.info("Removing gate from cache with key - " + trIDnum);
+ final IPCMMGate gate = PCMMGlobalConfig.transactionGateMap.remove(trIDnum);
+ if (gate != null) {
+ // capture the "error" message if any
+ gate.setError(gateMsg.getError());
+ logger.info("Setting error on gate - " + gateMsg.getError());
+ }else {
+ logger.error("processReport(): gateReq not found for transactionID {}", trIDnum);
+ return;
+ }
+
if (rtypemsg.getReportType().equals(ReportType.SUCCESS)) {
logger.info("rtypemsg success");
_status = ST_REPORT;
+ final IGateID gateID = gateMsg.getGateID();
+ logger.info("Setting gate ID on gate object - " + gateID);
+ gate.setGateID(gateID);
if (_process != null)
_process.successReport(this, gateMsg);
} else {
- if (gateMsg.getTransactionID().getGateCommandType() == ITransactionID.GateDeleteAck) {
- logger.info("GateDeleteAck: GateID = " + gateMsg.getGateID().getGateID());
- if (gateMsg.getGateID().getGateID() == PCMMGlobalConfig.getGateID1())
- PCMMGlobalConfig.setGateID1(0);
- if (gateMsg.getGateID().getGateID() == PCMMGlobalConfig.getGateID2())
- PCMMGlobalConfig.setGateID2(0);
-
- }
- if (gateMsg.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
- logger.info("GateSetAck: GateID = " + gateMsg.getGateID().getGateID());
- if (0 == PCMMGlobalConfig.getGateID1())
- PCMMGlobalConfig.setGateID1(gateMsg.getGateID().getGateID());
- if (0 == PCMMGlobalConfig.getGateID2())
- PCMMGlobalConfig.setGateID2(gateMsg.getGateID().getGateID());
- }
+ final String cmdType;
+ if ( trID.getGateCommandType() == ITransactionID.GateDeleteAck ) {
+ cmdType = "GateDeleteAck";
+ } else if ( trID.getGateCommandType() == ITransactionID.GateSetAck ) {
+ cmdType = "GateSetAck";
+ } else cmdType = null;
+ // capture the gateId from the response message
+ final IGateID gateID = gateMsg.getGateID();
+ logger.info("Setting gate ID on gate object - " + gateID);
+ gate.setGateID(gateID);
+ int gateIdInt = gateID.getGateID();
+ String gateIdHex = String.format("%08x", gateIdInt);
+ logger.info(getClass().getName() + ": " + cmdType + ": GateID = " + gateIdHex);
}
if (rtypemsg.getReportType().equals(ReportType.FAILURE)) {
logger.info("rtypemsg failure");
_process.failReport(this, gateMsg);
else
logger.info("Gate message error - " + gateMsg.getError().toString());
- } else
- if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
+ } else if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
logger.info("rtypemsg account");
_status = ST_ACCT;
if (_process != null)
_process.acctReport(this, gateMsg);
- }
+ }
+
+ // let the waiting gateSet/gateDelete sender proceed
+ // TODO - see PCMMService#processReport() gate.notify(). Should determine a better means to
+ // TODO - handle this synchronization.
+ logger.info("Notify gate request has been updated with ID - " + gate.getGateID());
+ synchronized(gate) {
+ gate.notify();
+ }
+ logger.info("Out processReport");
}
}
package org.pcmm.gates;
-import java.net.InetAddress;
-
import org.pcmm.base.IPCMMBaseObject;
+import java.net.InetAddress;
+
/**
*
*
*/
public interface IClassifier extends IPCMMBaseObject {
- static final short LENGTH = 24;
- static final byte SNUM = 6;
- static final byte STYPE = 1;
+ short LENGTH = 24;
+ byte SNUM = 6;
+ byte STYPE = 1;
- static enum Protocol {
+ enum Protocol {
/*ICMP((short) 1), IGMP((short) 2), */
NONE((short)0), TCP((short) 6), UDP((short) 17);
*
* @return the protocol.
*/
- Protocol getProtocol();
+ short getProtocol();
/**
* @see <a
* href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.txt">protocols</a>
- * @param p
+ * @param p - the protocol value
*/
- void setProtocol(Protocol p);
+ void setProtocol(short p);
/**
* Priority may be used to distinguish between multiple classifiers that
* information regarding the treatment of other objects specified in the Gate
* message.
* </p>
- *
- *
- *
- *
*/
public interface IGateSpec extends IPCMMBaseObject {
- static final byte SNUM = 5;
- static final byte STYPE = 1;
- static final short LENGTH = 16;
+ byte SNUM = 5;
+ byte STYPE = 1;
+ short LENGTH = 16;
/**
* <p>
*
*
*/
- public enum Direction {
+ enum Direction {
UPSTREAM((byte) 1), DOWNSTREAM((byte) 0);
- private Direction(byte value) {
+ Direction(byte value) {
this.value = value;
}
}
}
- };
+ }
/**
*
*/
- public enum DSCPTOS {
+ enum DSCPTOS {
- ENABLE((byte) 1), OVERRIDE((byte) 0);
+ ENABLE((byte) 2), OVERRIDE((byte) 0);
- private DSCPTOS(byte value) {
+ DSCPTOS(byte value) {
this.value = value;
}
private byte value;
- };
+ }
/**
* <p>
/**
*
- * @param dscpTos
+ * @param dscpTos - the object used to overwrite
*/
void setDSCP_TOSOverwrite(DSCPTOS dscpTos);
+ // set the DSCP_TOS value
+ void setDSCP_TOSOverwrite(byte dscpTos);
+
/**
*
* @return DSCP/TOS
/**
*
- * @return
+ * @return - the mask
*/
byte getDSCP_TOSMask();
package org.pcmm.gates;
+import java.net.InetAddress;
+
public interface IIPv6Classifier extends IExtendedClassifier {
- static final short LENGTH = 64;
- static final byte SNUM = 6;
- static final byte STYPE = 3;
+ short LENGTH = 64;
+ byte SNUM = 6;
+ byte STYPE = 3;
+
+ // flags: Flow Label match enable flag
+ void setFlowLabelEnableFlag(byte flag);
+ byte getFlowLabelEnableFlag();
// Tc-low
+ void setTcLow(byte tcLow);
+ byte getTcLow();
+
// Tc-high
+ void setTcHigh(byte tcHigh);
+ byte getTcHigh();
+
// Tc-mask
+ void setTcMask(byte tcHigh);
+ byte getTcMask();
+
// Flow Label
+ void setFlowLabel(Long flowLabel);
+ int getFlowLabel();
+
// Next Header Type
+ void setNextHdr(short nxtHdr);
+ short getNextHdr();
+
// Source Prefix Length
+ void setSourcePrefixLen(byte srcPrefixLen);
+ byte getSourcePrefixLen();
+
// Destination Prefix Length
+ void setDestinationPrefixLen(byte dstPrefixLen);
+ byte getDestinationPrefixLen();
+
// IPv6 Source Address
+ void setSourceIPAddress(InetAddress a);
+ InetAddress getSourceIPAddress();
+
// IPv6 Destination Address
+ void setDestinationIPAddress(InetAddress a);
+ InetAddress getDestinationIPAddress();
+
// Source Port Start
+ short getSourcePortStart();
+ void setSourcePortStart(short p);
+
// Source Port End
+ short getSourcePortEnd();
+ void setSourcePortEnd(short p);
+
// Destination Port Start
+ short getDestinationPortStart();
+ void setDestinationPortStart(short p);
+
// Destination Port End
+ short getDestinationPortEnd();
+ void setDestinationPortEnd(short p);
+
// ClassifierID
+ short getClassifierID();
+ void setClassifierID(short p);
+
// Priority
+ void setPriority(byte p);
+ byte getPriority();
+
// Activation State
- // Action
+ void setActivationState(byte s);
+ byte getActivationState();
+ // Action
+ void setAction(byte a);
+ byte getAction();
}
*/
package org.pcmm.gates.impl;
+import org.pcmm.base.impl.PCMMBaseObject;
+import org.pcmm.gates.IClassifier;
+
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import org.pcmm.base.impl.PCMMBaseObject;
-import org.pcmm.gates.IClassifier;
-
/**
- *
+ * TODO - Cleanup this interface
*/
public class Classifier extends PCMMBaseObject implements IClassifier {
}
/**
- * @param data
+ * @param data - the data to add
*/
public Classifier(byte[] data) {
super(data);
}
/**
- * @param len
- * @param sType
- * @param sNum
+ * @param len - the classifier's length
+ * @param sType - the sType value
+ * @param sNum - the sNum value
*/
public Classifier(short len, byte sType, byte sNum) {
super(len, sType, sNum);
* @see org.pcmm.gates.IClassifier#getProtocol()
*/
@Override
- public Protocol getProtocol() {
- return Protocol.valueOf(getShort((short) 0));
+ public short getProtocol() {
+ return getShort((short) 0);
}
/*
* @see org.pcmm.gates.IClassifier#setProtocol(short)
*/
@Override
- public void setProtocol(Protocol p) {
- setShort(p.getValue(), (short) 0);
+ public void setProtocol(short p) {
+ setShort(p, (short) 0);
}
/*
implements ITrafficProfile {
public static final byte STYPE = 2;
- public static final short LENGTH = 12;
+ public static final short LENGTH = 24;
/**
*
}
/**
- * @param data
+ * @param data - the data bytes to parse
*/
public DOCSISServiceClassNameTrafficProfile(byte[] data) {
super(data);
}
/**
- * @param len
- * @param sType
- * @param sNum
+ * @param len - the classifier's length
+ * @param sType - the sType value
+ * @param sNum - the sNum value
*/
public DOCSISServiceClassNameTrafficProfile(short len, byte sType, byte sNum) {
super(len, sType, sNum);
*/
package org.pcmm.gates.impl;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
import org.pcmm.base.impl.PCMMBaseObject;
import org.pcmm.gates.IExtendedClassifier;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/**
*
*/
}
/**
- * @param data
+ * @param data - the data bytes to parse
*/
public ExtendedClassifier(byte[] data) {
super(data);
}
/**
- * @param len
- * @param sType
- * @param sNum
+ * @param len - the classifier's length
+ * @param sType - the sType value
+ * @param sNum - the sNum value
*/
public ExtendedClassifier(short len, byte sType, byte sNum) {
super(len, sType, sNum);
* @see org.pcmm.gates.IClassifier#getProtocol()
*/
@Override
- public Protocol getProtocol() {
- return Protocol.valueOf(getShort((short) 0));
+ public short getProtocol() {
+ return getShort((short) 0);
}
/*
* @see org.pcmm.gates.IClassifier#setProtocol(short)
*/
@Override
- public void setProtocol(Protocol p) {
- setShort(p.getValue(), (short) 0);
+ public void setProtocol(short p) {
+ setShort(p, (short) 0);
}
/*
*/
public class GateSpec extends PCMMBaseObject implements IGateSpec {
+ // GateSpec flags are Direction (bit 0) and DSCPTOS overwrite enable (bit 1)
+ private byte flags = 0;
+
public GateSpec() {
super(LENGTH, STYPE, SNUM);
}
@Override
public void setDirection(Direction direction) {
- setByte(direction.getValue(), (short) 0);
+ // OR in the Direction flag with the DSCPTOS enable flag
+ flags |= direction.getValue();
+ setByte(flags, (short) 0);
}
@Override
@Override
public void setDSCP_TOSOverwrite(DSCPTOS dscpTos) {
- setByte(dscpTos.getValue(), (short) 1);
+ // OR in the DSCPTOS enable flag with the Direction flag
+ flags |= dscpTos.getValue();
+ setByte(flags, (short) 0);
}
+ @Override
+ public void setDSCP_TOSOverwrite(byte dscpTos) {
+ setByte(dscpTos, (short) 1);
+ }
+
+
@Override
public DSCPTOS getDSCP_TOSOverwrite() {
return DSCPTOS.valueOf(getByte((short) 1));
--- /dev/null
+/**
+
+ * Copyright (c) 2014 CableLabs. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+
+ */
+package org.pcmm.gates.impl;
+
+import org.pcmm.base.impl.PCMMBaseObject;
+import org.pcmm.gates.IIPv6Classifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ *
+ */
+public class IPv6Classifier extends PCMMBaseObject implements
+ IIPv6Classifier {
+
+ private Logger logger = LoggerFactory.getLogger(IPv6Classifier.class);
+
+ public IPv6Classifier() {
+ this(LENGTH, STYPE, SNUM);
+ }
+
+ /**
+ * @param data - the data bytes to parse
+ */
+ public IPv6Classifier(byte[] data) {
+ super(data);
+ }
+
+ /**
+ * @param len - the classifier's length
+ * @param sType - the sType value
+ * @param sNum - the sNum value
+ */
+ public IPv6Classifier(short len, byte sType, byte sNum) {
+ super(len, sType, sNum);
+ }
+
+ // offset:length Field Name: Description
+ // 00:01 Flags: 0000.0001 Flow Label enable match
+ // 01:01 Tc-low
+ // 02:01 Tc-high
+ // 03:01 Tc-mask
+ // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
+ // 08:02 Next Header Type
+ // 10:01 Source Prefix Length
+ // 11:01 Destination Prefix Length
+ // 12:16 IPv6 Source Address
+ // 28:16 IPv6 Destination Address
+ // 44:02 Source Port Start
+ // 46:02 Source Port End
+ // 48:02 Destination Port Start
+ // 50:02 Destination Port End
+ // 52:02 ClassifierID
+ // 54:01 Priority
+ // 55:01 Activation State
+ // 56:01 Action
+ // 57:03 Reserved
+
+ // 00:01 Flags: 0000.0001 Flow Label enable match
+ @Override
+ public void setFlowLabelEnableFlag(byte flag) {
+ setByte(flag, (short) 0);
+ }
+ @Override
+ public byte getFlowLabelEnableFlag() {
+ return getByte((short) 0);
+ }
+
+ // 01:01 Tc-low
+ @Override
+ public void setTcLow(byte tcLow) {
+ setByte(tcLow, (short) 1);
+ }
+ @Override
+ public byte getTcLow() {
+ return getByte((short) 1);
+ }
+
+ // 02:01 Tc-high
+ @Override
+ public void setTcHigh(byte tcHigh) {
+ setByte(tcHigh, (short) 2);
+ }
+ @Override
+ public byte getTcHigh() {
+ return getByte((short) 2);
+ }
+
+ // 03:01 Tc-mask
+ @Override
+ public void setTcMask(byte tcMask) {
+ setByte(tcMask, (short) 3);
+ }
+ @Override
+ public byte getTcMask() {
+ return getByte((short) 3);
+ }
+
+ // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
+ @Override
+ public void setFlowLabel(Long flowLabel) {
+ setInt(flowLabel.intValue(), (short) 4);
+ }
+ @Override
+ public int getFlowLabel() {
+ return getInt((short) 4);
+ }
+
+ // 08:02 Next Header Type
+ @Override
+ public void setNextHdr(short nxtHdr) {
+ setShort(nxtHdr, (short) 8);
+ }
+ @Override
+ public short getNextHdr() {
+ return getShort((short) 8);
+ }
+
+ // 10:01 Source Prefix Length
+ @Override
+ public void setSourcePrefixLen(byte srcPrefixLen) {
+ setByte(srcPrefixLen, (short) 10);
+ }
+ @Override
+ public byte getSourcePrefixLen() {
+ return getByte((short) 10);
+ }
+
+ // 11:01 Destination Prefix Length
+ @Override
+ public void setDestinationPrefixLen(byte dstPrefixLen) {
+ setByte(dstPrefixLen, (short) 11);
+ }
+ @Override
+ public byte getDestinationPrefixLen() {
+ return getByte((short) 11);
+ }
+
+ // 12:16 IPv6 Source Address
+ @Override
+ public void setSourceIPAddress(InetAddress a) {
+ setBytes(a.getAddress(), (short) 12);
+ }
+ @Override
+ public InetAddress getSourceIPAddress() {
+ try {
+ return InetAddress.getByAddress(getBytes((short) 12, (short) 16));
+ } catch (UnknownHostException e) {
+ logger.error("getSourceIPAddress(): Malformed IPv6 address: {}", e.getMessage());
+ }
+ return null;
+ }
+
+ // 28:16 IPv6 Destination Address
+ @Override
+ public void setDestinationIPAddress(InetAddress a) {
+ setBytes(a.getAddress(), (short) 28);
+ }
+ @Override
+ public InetAddress getDestinationIPAddress() {
+ try {
+ return InetAddress.getByAddress(getBytes((short) 28, (short) 16));
+ } catch (UnknownHostException e) {
+ logger.error("getDestinationIPAddress(): Malformed IPv6 address: {}", e.getMessage());
+ }
+ return null;
+ }
+ // 44:02 Source Port Start
+ @Override
+ public short getSourcePortStart() {
+ return getShort((short) 44);
+ }
+ @Override
+ public void setSourcePortStart(short p) {
+ setShort(p, (short) 44);
+ }
+
+ // 46:02 Source Port End
+ @Override
+ public short getSourcePortEnd() {
+ return getShort((short) 46);
+ }
+ @Override
+ public void setSourcePortEnd(short p) {
+ setShort(p, (short) 46);
+ }
+
+ // 48:02 Destination Port Start
+ @Override
+ public short getDestinationPortStart() {
+ return getShort((short) 48);
+ }
+ @Override
+ public void setDestinationPortStart(short p) {
+ setShort(p, (short) 48);
+ }
+
+ // 50:02 Destination Port End
+ @Override
+ public short getDestinationPortEnd() {
+ return getShort((short) 50);
+ }
+ @Override
+ public void setDestinationPortEnd(short p) {
+ setShort(p, (short) 50);
+ }
+
+ // 52:02 ClassifierID
+ @Override
+ public short getClassifierID() {
+ return getShort((short) 52);
+ }
+
+ @Override
+ public void setClassifierID(short p) {
+ setShort(p, (short) 52);
+ }
+
+ // 54:01 Priority
+ @Override
+ public void setPriority(byte p) {
+ setByte(p, (short) 54);
+ }
+ @Override
+ public byte getPriority() {
+ return getByte((short) 54);
+ }
+
+ // 55:01 Activation State
+ @Override
+ public void setActivationState(byte s) {
+ setByte(s, (short) 55);
+ }
+ @Override
+ public byte getActivationState() {
+ return getByte((short) 55);
+ }
+
+ // 56:01 Action
+ @Override
+ public void setAction(byte a) {
+ setByte(a, (short) 56);
+ }
+ @Override
+ public byte getAction() {
+ return getByte((short) 56);
+ }
+
+
+
+ // baggage from IExtendedClassifier
+ // not used in IPv6 classifiers
+ @Override
+ public void setIPSourceMask(InetAddress a) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setIPDestinationMask(InetAddress m) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public InetAddress getIPSourceMask() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public InetAddress getIPDestinationMask() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public short getDestinationPort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setDestinationPort(short p) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public short getSourcePort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setSourcePort(short p) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public short getProtocol() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setProtocol(short p) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public byte getDSCPTOS() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setDSCPTOS(byte v) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public byte getDSCPTOSMask() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setDSCPTOSMask(byte v) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
if (getVersionInfo().getMajorVersionNB() >= 4) {
classifier = new ExtendedClassifier();
// eclassifier.setProtocol(IClassifier.Protocol.NONE);
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
} else {
classifier = new Classifier();
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
try {
InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
*/
public class COPSPdpAgent extends Thread {
- public final static Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class);
+ private static final Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class);
/** Well-known port for COPS */
- public static final int WELL_KNOWN_PDP_PORT = 3288;
+ // public static final int WELL_KNOWN_PDP_PORT = 3288;
/** Default keep-alive timer value (secs) */
public static final short KA_TIMER_VALUE = 30;
/** Default accounting timer value (secs) */
public static final short ACCT_TIMER_VALUE = 0;
/**
- PDP host port
+ * PDP host port
*/
private int _serverPort;
/**
- Client-type of connecting PEP
+ * Client-type of connecting PEP
*/
private short _clientType;
/**
- Accounting timer (secs)
+ * Accounting timer (secs)
*/
private short _acctTimer;
/**
- Keep-alive timer (secs)
+ * Keep-alive timer (secs)
*/
private short _kaTimer;
/**
- Maps a PEP-ID to a connection
+ * The PEP ID
*/
- private final Map<String, COPSPdpConnection> _connectionMap;
+ protected transient COPSPepId _pepId;
+
+ /**
+ * Maps a PEP-ID to a connection
+ * TODO - Refactor COPSPdpConnection to extend PCMMPdpConnection. Until then, the value must remain an Object
+ */
+ protected Map<String, Object> _connectionMap;
// map < String(PEPID), COPSPdpConnection > ConnectionMap;
/**
private COPSPdpDataProcess _process;
/**
- * Creates a PDP Agent
- *
- * @param clientType COPS Client-type
- * @param process Object to perform policy data processing
+ * Holds all of the threads to manage by PEP ID
*/
- public COPSPdpAgent(final short clientType, final COPSPdpDataProcess process) {
- _serverPort = WELL_KNOWN_PDP_PORT;
- _kaTimer = KA_TIMER_VALUE;
- _acctTimer = ACCT_TIMER_VALUE;
-
- _clientType = clientType;
- _connectionMap = new ConcurrentHashMap<>();
- _process = process;
- }
+ protected final Map<String, Thread> threadMap;
/**
* Creates a PDP Agent
_clientType = clientType;
_connectionMap = new ConcurrentHashMap<>();
_process = process;
- }
-
- /**
- * Sets the keep-alive timer value
- * @param kaTimer Keep alive timer value (secs)
- */
- public void setKaTimer (short kaTimer) {
- _kaTimer = kaTimer;
- }
-
- /**
- * Sets the accounting timer value
- * @param acctTimer Accounting timer value (secs)
- */
- public void setAcctTimer (short acctTimer) {
- _acctTimer = acctTimer;
+ this.threadMap = new ConcurrentHashMap<>();
}
/**
* @throws IOException
*/
public void disconnect(final String pepID, final COPSError error) throws COPSException, IOException {
- final COPSPdpConnection pdpConn = _connectionMap.get(pepID);
+ final COPSPdpConnection pdpConn = (COPSPdpConnection)_connectionMap.get(pepID);
final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType, error, null, null);
closeMsg.writeData(pdpConn.getSocket());
pdpConn.close();
* @throws COPSException
* @throws COPSPdpException
*/
- public void sync (String pepID)
- throws COPSException, COPSPdpException {
-
- COPSPdpConnection pdpConn = _connectionMap.get(pepID);
+ public void sync(final String pepID) throws COPSException, COPSPdpException {
+ COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID);
pdpConn.syncAllRequestState();
}
* Removes a PEP from the connection map
* @param pepID PEP-ID of the PEP to be removed
*/
- public void delete (String pepID) {
+ public void delete(final String pepID) {
_connectionMap.remove(pepID);
}
final ServerSocket serverSocket = new ServerSocket (_serverPort);
//Loop through for Incoming messages
-
// server infinite loop
while (true) {
-
// Wait for an incoming connection from a PEP
- Socket socket = serverSocket.accept();
+ final Socket socket = serverSocket.accept();
// COPSDebug.out(getClass().getName(),"New connection accepted " +
// socket.getInetAddress() +
// We're waiting for an OPN message
try {
final COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+ logger.info("Message received - " + msg);
if (msg.getHeader().getOpCode().equals(OPCode.OPN)) {
handleClientOpenMsg(socket, msg);
} else {
- // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);
+ logger.error("Not an open message, closing socket");
try {
socket.close();
} catch (Exception ex) {
- logger.error("Error closing socket", ex);
+ logger.error("Unexpected exception closing socket", ex);
}
}
} catch (Exception e) { // COPSException, IOException
try {
socket.close();
} catch (Exception ex) {
- logger.error("Error closing socket", ex);
+ logger.error("Unexpected exception closing socket", ex);
}
}
}
}
/**
- * Handles a COPS client-open message
- * @param conn Socket to the PEP
- * @param msg <tt>COPSMsg</tt> holding the client-open message
- * @throws COPSException
- * @throws IOException
- */
- private void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+ * Handles a COPS client-open message
+ * @param conn Socket to the PEP
+ * @param msg <tt>COPSMsg</tt> holding the client-open message
+ * @throws COPSException
+ * @throws IOException
+ * TODO - Refactor PCMMPdpAgent#handleClientOpenMsg() as it contains much of this same logic
+ */
+ protected void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
final COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
- final COPSPepId pepId = cMsg.getPepId();
+ _pepId = cMsg.getPepId();
// Validate Client Type
- if (msg.getHeader().getClientType() == _clientType) {
+ if (msg.getHeader().getClientType() != _clientType) {
// Unsupported client type
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Error writing COPS data", unae);
+ logger.error("Unexpected exception writing data", unae);
}
throw new COPSException("Unsupported client type");
}
// PEPId is mandatory
- if (pepId == null) {
+ if (_pepId == null) {
// Mandatory COPS object missing
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Error writing close message", unae);
+ logger.error("Unexpected exception writing data", unae);
}
throw new COPSException("Mandatory COPS object missing (PEPId)");
}
// Support
- if ( (cMsg.getClientSI() != null) ||
- (cMsg.getPdpAddress() != null) ||
- (cMsg.getIntegrity() != null)) {
-
+ if ( (cMsg.getClientSI() != null) || (cMsg.getPdpAddress() != null) || (cMsg.getIntegrity() != null)) {
// Unsupported objects
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+ final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
try {
closeMsg.writeData(conn);
} catch (IOException unae) {
- logger.error("Error writing close message", unae);
+ logger.error("Exception writing data", unae);
}
throw new COPSException("Unsupported objects (ClientSI, PdpAddress, Integrity)");
}
// Connection accepted
- 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,
+ if (_acctTimer != 0)
+ acceptMsg = new COPSClientAcceptMsg(_clientType, new COPSKATimer(_kaTimer),
new COPSAcctTimer(_acctTimer), null);
+ else
+ acceptMsg = new COPSClientAcceptMsg(_clientType, new COPSKATimer(_kaTimer),null, null);
acceptMsg.writeData(conn);
- final 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();
- _connectionMap.put(pepId.getData().str(),pdpConn);
+ _connectionMap.put(_pepId.getData().str(), pdpConn);
}
}
-/*\r
- * Copyright (c) 2004 University of Murcia. All rights reserved.\r
- * --------------------------------------------------------------\r
- * For more information, please see <http://www.umu.euro6ix.org/>.\r
- */\r
-\r
-package org.umu.cops.prpdp;\r
-\r
-/**\r
- * Exception class for PDP errors\r
- *\r
- * @version COPSPdpException.java, v 2.00 2004\r
- *\r
- */\r
-\r
-public class COPSPdpException extends Exception {\r
-\r
- private int rc;\r
- final static int GENERAL_ERROR = 0x00000001;\r
-\r
- /**\r
- * Creates a <tt>COPSPdpException</tt> with the given message.\r
- * @param msg Exception message\r
- */\r
- public COPSPdpException(String msg) {\r
- super(msg);\r
- rc=0;\r
- }\r
-\r
- /**\r
- * Creates a <tt>COPSPdpException</tt> with the given message and return code.\r
- * @param msg Exception message\r
- * @param retCode Return code\r
- */\r
- public COPSPdpException(String msg, int retCode) {\r
- super(msg);\r
- rc = retCode;\r
- }\r
-\r
- /**\r
- * Gets the return code of the exception\r
- * @return Exception's return code\r
- */\r
- public int returnCode() {\r
- return rc;\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2004 University of Murcia. All rights reserved.
+ * --------------------------------------------------------------
+ * For more information, please see <http://www.umu.euro6ix.org/>.
+ */
+
+package org.umu.cops.prpdp;
+
+/**
+ * Exception class for PDP errors
+ *
+ * @version COPSPdpException.java, v 2.00 2004
+ *
+ */
+
+public class COPSPdpException extends Exception {
+
+ private int rc;
+ final static int GENERAL_ERROR = 0x00000001;
+
+ /**
+ * Creates a <tt>COPSPdpException</tt> with the given message.
+ * @param msg Exception message
+ */
+ public COPSPdpException(String msg) {
+ super(msg);
+ rc=0;
+ }
+
+ /**
+ * Creates a <tt>COPSPdpException</tt> with the given message and return code.
+ * @param msg Exception message
+ * @param retCode Return code
+ */
+ public COPSPdpException(String msg, int retCode) {
+ super(msg);
+ rc = retCode;
+ }
+
+ /**
+ * Creates a <tt>COPSPdpException</tt> with the given message and throwable.
+ * @param msg Exception message
+ * @param t the Throwable
+ */
+ public COPSPdpException(String msg, Throwable t) {
+ super(msg, t);
+ }
+
+ /**
+ * Gets the return code of the exception
+ * @return Exception's return code
+ */
+ public int returnCode() {
+ return rc;
+ }
+
+}
*/
package org.opendaylight.controller.packetcable.provider.processors;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeCommittedEnvelope;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeReservedEnvelope;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.SubscriberIdRpcAddFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.TcpMatchRangesAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.TcpMatchRangesRpcAddFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.UdpMatchRangesAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.UdpMatchRangesRpcAddFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.tcp.match.ranges.attributes.TcpMatchRanges;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.udp.match.ranges.attributes.UpdMatchRanges;
import org.pcmm.gates.IClassifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/**
*
* PacketCable data processor
public IClassifier process(Match match) {
ExtendedClassifier classifier = new ExtendedClassifier();
- classifier.setProtocol(IClassifier.Protocol.NONE);
+// classifier.setProtocol(IClassifier.Protocol.NONE);
getUdpMatchRangeValues(match.getAugmentation(UdpMatchRangesRpcAddFlow.class), classifier);
getTcpMatchRangesValues(match.getAugmentation(TcpMatchRangesRpcAddFlow.class), classifier);
SubscriberIdRpcAddFlow subId = match.getAugmentation(SubscriberIdRpcAddFlow.class);
short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
if (tcpRange != null) {
- classifier.setProtocol(IClassifier.Protocol.TCP);
+// classifier.setProtocol(IClassifier.Protocol.TCP);
TcpMatchRanges tcpMatchRanges = tcpRange.getTcpMatchRanges();
PortNumber tcpDestinationPortStart = tcpMatchRanges.getTcpDestinationPortStart();
if (tcpDestinationPortStart != null && tcpDestinationPortStart.getValue() != null)
short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
if (updRange != null) {
- classifier.setProtocol(IClassifier.Protocol.UDP);
+// classifier.setProtocol(IClassifier.Protocol.UDP);
UpdMatchRanges updMatchRanges = updRange.getUpdMatchRanges();
PortNumber udpDestinationPortStart = updMatchRanges.getUdpDestinationPortStart();
if (udpDestinationPortStart != null && udpDestinationPortStart.getValue() != null)