-/**
- * @header@
+/*
+ * Copyright (c) 2014, 2015 Cable Television Laboratories, Inc. and others. 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.messages.impl;
import org.pcmm.messages.IMessage.MessageProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.COPSError.ErrorTypes;
+import org.umu.cops.stack.COPSHeader.OPCode;
+import org.umu.cops.stack.COPSObjHeader.CType;
import java.net.InetAddress;
-import java.util.Properties;
+import java.util.*;
/**
*
*
* @see pcmm.messages.IMessageFactory#create(pcmm.messages.MessageType)
*/
- public COPSMsg create(final byte messageType) {
+ public COPSMsg create(final OPCode messageType) {
return create(messageType, new Properties());
}
* @see org.pcmm.messages.IMessageFactory#create(org.pcmm.messages.IMessage.
* MessageType, java.util.Properties)
*/
- public COPSMsg create(final byte messageType, final Properties properties) {
+ public COPSMsg create(final OPCode messageType, final Properties properties) {
logger.info("Creating message of type - " + messageType);
// return new PCMMMessage(messageType, content);
switch (messageType) {
- case COPSHeader.COPS_OP_OPN:
+ case OPN:
return createOPNMessage(properties);
- case COPSHeader.COPS_OP_REQ:
+ case REQ:
return createREQMessage(properties);
- case COPSHeader.COPS_OP_CAT:
+ case CAT:
return createCATMessage(properties);
- case COPSHeader.COPS_OP_CC:
+ case CC:
return createCCMessage(properties);
- case COPSHeader.COPS_OP_DEC:
+ case DEC:
return createDECMessage(properties);
- case COPSHeader.COPS_OP_DRQ:
+ case DRQ:
break;
- case COPSHeader.COPS_OP_KA:
+ case KA:
return createKAMessage(properties);
- case COPSHeader.COPS_OP_RPT:
+ case RPT:
break;
- case COPSHeader.COPS_OP_SSC:
+ case SSC:
break;
- case COPSHeader.COPS_OP_SSQ:
+ case SSQ:
break;
}
return null;
* @return - the message
*/
protected COPSMsg createDECMessage(final Properties prop) {
- final COPSDecisionMsg msg = new COPSDecisionMsg();
+
// ===common part between all gate control messages
- final COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, IPCMMClient.CLIENT_TYPE);
+ // final COPSHeader hdr = new COPSHeader(OPCode.DEC, IPCMMClient.CLIENT_TYPE);
// handle
// context
- final COPSContext context = new COPSContext(COPSContext.CONFIG, (short) 0);
// decision
- final COPSDecision decision = new COPSDecision();
+ // TODO - the old command and flag codes are not congruent with the ones described in COPSDecision
+ // TODO - what is the correct client type to be using here???
+/*
if (prop.get(MessageProperties.DECISION_CMD_CODE) != null)
decision.setCmdCode((byte) prop.get(MessageProperties.DECISION_CMD_CODE));
if (prop.get(MessageProperties.DECISION_FLAG) != null)
decision.setFlags((short) prop.get(MessageProperties.DECISION_FLAG));
+*/
- final COPSClientSI si = new COPSClientSI(COPSObjHeader.COPS_DEC, (byte) 4);
+ final COPSData data;
if (prop.get(MessageProperties.GATE_CONTROL) != null)
- si.setData((COPSData) prop.get(MessageProperties.GATE_CONTROL));
- try {
- msg.add(hdr);
- final COPSHandle handle;
- if (prop.get(MessageProperties.CLIENT_HANDLE) != null) {
- handle = new COPSHandle(new COPSData((String) prop.get(MessageProperties.CLIENT_HANDLE)));
- }
- else {
- // TODO - This smells wrong to have a null handle ID
- handle = new COPSHandle(null);
- }
- msg.add(handle);
- msg.addDecision(decision, context);
- msg.add(si);
+ data = (COPSData) prop.get(MessageProperties.GATE_CONTROL);
+ else
+ data = null;
- // TODO - determine why this block has been commented out
- // try {
- // msg.dump(System.out);
- // } catch (IOException unae) {
- // }
+ // TODO - Need to determine is SIGNALED is the correct default CSIType
+ // Decided that CSI object is not what should be encapsulated by the COPSDecisionMsg, therefore placing
+ // data into the COPSDecision object located in the decisionMap
+ // final COPSClientSI si = new COPSClientSI(CSIType.SIGNALED, data);
- } catch (final COPSException e) {
- logger.error(e.getMessage());
+ final COPSHandle handle;
+ if (prop.get(MessageProperties.CLIENT_HANDLE) != null) {
+ handle = new COPSHandle(new COPSData((String) prop.get(MessageProperties.CLIENT_HANDLE)));
}
+ else {
+ // TODO - This smells wrong to have a null handle ID
+ handle = new COPSHandle(null);
+ }
+ final Set<COPSDecision> decisionSet = new HashSet<>();
+ decisionSet.add(new COPSDecision(CType.DEF, Command.NULL, DecisionFlag.NA, data));
+ final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+ decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+
+ final COPSDecisionMsg msg = new COPSDecisionMsg(IPCMMClient.CLIENT_TYPE, handle, decisionMap, null, null);
+
+ // TODO - determine why this block has been commented out
+ // try {
+ // msg.dump(System.out);
+ // } catch (IOException unae) {
+ // }
return msg;
}
* @return COPS message
*/
protected COPSMsg createOPNMessage(final Properties prop) {
- final COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_OPN, IPCMMClient.CLIENT_TYPE);
- final COPSPepId pepId = new COPSPepId();
// version infor object
short majorVersion = MMVersionInfo.DEFAULT_MAJOR_VERSION_INFO;
short minorVersion = MMVersionInfo.DEFAULT_MINOR_VERSION_INFO;
if (prop.get(MessageProperties.MM_MINOR_VERSION_INFO) != null)
minorVersion = (Short) prop.get(MessageProperties.MM_MINOR_VERSION_INFO);
// Mandatory MM version.
- final COPSClientSI clientSI = new COPSClientSI((byte) 1);
byte[] versionInfo = new MMVersionInfo(majorVersion, minorVersion).getAsBinaryArray();
- clientSI.setData(new COPSData(versionInfo, 0, versionInfo.length));
- final COPSClientOpenMsg msg = new COPSClientOpenMsg();
+ final COPSClientSI clientSI = new COPSClientSI(CSIType.SIGNALED, new COPSData(versionInfo, 0, versionInfo.length));
try {
final COPSData d;
if (prop.get(MessageProperties.PEP_ID) != null)
d = new COPSData((String) prop.get(MessageProperties.PEP_ID));
else
d = new COPSData(InetAddress.getLocalHost().getHostName());
- pepId.setData(d);
- msg.add(hdr);
- msg.add(pepId);
- msg.add(clientSI);
+ final COPSPepId pepId = new COPSPepId(d);
+ return new COPSClientOpenMsg(IPCMMClient.CLIENT_TYPE, pepId, clientSI, null, null);
} catch (Exception e) {
logger.error("Error creating OPN message", e);
}
- return msg;
+
+ // TODO - this probably should not return null and throw an exception instead
+ return null;
}
/**
* @return COPS message
*/
protected COPSMsg createCATMessage(final Properties prop) {
- final COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_CAT, IPCMMClient.CLIENT_TYPE);
+ // TODO - determine what the first constructor parameter really should be???
final COPSKATimer katimer;
if (prop.get(MessageProperties.KA_TIMER) != null)
- katimer = new COPSKATimer((short) prop.get(MessageProperties.KA_TIMER));
+ katimer = new COPSKATimer((short)prop.get(MessageProperties.KA_TIMER));
else
katimer = new COPSKATimer(KA_TIMER_VALUE);
+ // TODO - determine what the first constructor parameter really should be???
final COPSAcctTimer acctTimer;
if (prop.get(MessageProperties.ACCEPT_TIMER) != null)
acctTimer = new COPSAcctTimer((short) prop.get(MessageProperties.ACCEPT_TIMER));
else
acctTimer = new COPSAcctTimer(ACCT_TIMER_VALUE);
- final COPSClientAcceptMsg acceptMsg = new COPSClientAcceptMsg();
- try {
- acceptMsg.add(hdr);
- acceptMsg.add(katimer);
- if (acctTimer.getTimerVal() != 0)
- acceptMsg.add(acctTimer);
- } catch (COPSException e) {
- logger.error(e.getMessage());
- }
- return acceptMsg;
+ if (acctTimer.getTimerVal() != 0)
+ return new COPSClientAcceptMsg(IPCMMClient.CLIENT_TYPE, katimer, acctTimer, null);
+ else return new COPSClientAcceptMsg(IPCMMClient.CLIENT_TYPE, katimer, null, null);
}
/**
* @return COPS message
*/
protected COPSMsg createCCMessage(final Properties prop) {
- final COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_CC, IPCMMClient.CLIENT_TYPE);
final COPSError err;
if (prop.get(MessageProperties.ERR_MESSAGE) != null) {
- short code = (short) 0;
- final short error = (short) prop.get(MessageProperties.ERR_MESSAGE);
+ ErrorTypes code = ErrorTypes.NA;
+ final ErrorTypes error = (ErrorTypes) prop.get(MessageProperties.ERR_MESSAGE);
if (prop.get(MessageProperties.ERR_MESSAGE_SUB_CODE) != null)
- code = (short) prop.get(MessageProperties.ERR_MESSAGE_SUB_CODE);
- err = new COPSError(error, code);
+ code = (ErrorTypes) prop.get(MessageProperties.ERR_MESSAGE_SUB_CODE);
+ err = new COPSError(COPSError.ERROR_CODE_TO_TYPE.get(error.ordinal()),
+ COPSError.ERROR_CODE_TO_TYPE.get(code.ordinal()));
} else
- err = new COPSError(COPSError.COPS_ERR_UNKNOWN, (short) 0);
+ err = new COPSError(ErrorTypes.UNKNOWN, ErrorTypes.NA);
- final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg();
- try {
- closeMsg.add(cHdr);
- closeMsg.add(err);
- } catch (COPSException e) {
- logger.error(e.getMessage());
- }
- return closeMsg;
+ return new COPSClientCloseMsg(IPCMMClient.CLIENT_TYPE, err, null, null);
}
/**
* @return Request message
*/
protected COPSMsg createREQMessage(final Properties prop) {
- final COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_REQ, IPCMMClient.CLIENT_TYPE);
- final COPSReqMsg req = new COPSReqMsg();
-
final short rType;
if (prop.get(MessageProperties.R_TYPE) != null)
rType = (Short) prop.get(MessageProperties.R_TYPE);
mType = (Short) prop.get(MessageProperties.M_TYPE);
else mType = ICMTS.DEFAULT_M_TYPE;
- final COPSContext copsContext = new COPSContext(rType, mType);
+ final COPSContext copsContext = new COPSContext(COPSContext.VAL_TO_RTYPE.get((int)rType), mType);
final COPSHandle copsHandle;
if (prop.get(MessageProperties.CLIENT_HANDLE) != null)
copsHandle = new COPSHandle(new COPSData((String) prop.get(MessageProperties.CLIENT_HANDLE)));
else
// just a random handle
copsHandle = new COPSHandle(new COPSData("" + Math.random() * 82730));
- try {
- req.add(cHdr);
- req.add(copsContext);
- req.add(copsHandle);
- } catch (COPSException e) {
- logger.error(e.getMessage());
- }
- return req;
+
+ return new COPSReqMsg(IPCMMClient.CLIENT_TYPE, copsHandle, copsContext, null, null, null, null, null);
}
/**
* TODO - Why is there a timer being instantiated but never used?
*/
protected COPSMsg createKAMessage(final Properties prop) {
- final COPSHeader cHdr = new COPSHeader(COPSHeader.COPS_OP_KA, (short) 0);
- final COPSKAMsg kaMsg = new COPSKAMsg();
+ // TODO - determine why this isn't really doing anything
+ return new COPSKAMsg(null);
+/*
final COPSKATimer timer;
if (prop.get(MessageProperties.KA_TIMER) != null)
- timer = new COPSKATimer((Short) prop.get(MessageProperties.KA_TIMER));
+ timer = new COPSKATimer((short)0, (Short) prop.get(MessageProperties.KA_TIMER));
else
timer = new COPSKATimer();
- try {
- kaMsg.add(cHdr);
- } catch (COPSException e) {
- logger.error(e.getMessage());
- }
- return kaMsg;
+*/
}
}