+++ /dev/null
-/**
- @header@
- */
-
-package org.pcmm.rcd;
-
-import java.net.InetAddress;
-
-import org.pcmm.objects.MMVersionInfo;
-import org.pcmm.state.IStateful;
-
-/**
- * <i>PKT-SP-MM-I05-091029 PacketCableTM Specification</i>
- * <p>
- * As discussed in RFC 2753 [11], the policy management framework underlying
- * PacketCable Multimedia is based on the work of the IETF's Resource Allocation
- * Protocol (RAP) working group. Since the Policy Server is situated between the
- * Application Manager and the CMTS, it simultaneously plays a dual role as a
- * "proxy" for AM-initiated session requests and as a "sentry" for defining and
- * enforcing Resource Control Domain policy. As described in [11] and in keeping
- * with the PacketCable 1.x DQoS model, the Policy Server serves as Policy
- * Decision Point (PDP) in relation to the CMTS in that the Policy Server
- * implements MSO-defined authorization and resource-management procedures.
- * Conversely, the Policy Server assumes the role of Policy Enforcement Point
- * (PEP) in relation to the Application Manager as it proxies Gate Control
- * messages to and from the CMTS element. To revisit the interaction scenario,
- * the Application Manager issues policy requests to the Policy Server. The
- * Policy Server acting as a "sentry" for these requests, and applies a set of
- * policy rules that have been pre-provisioned by the MSO. Upon passing the
- * checks, the Policy Server then acts as a "proxy" with respect to the
- * Application Manager and the CMTS, forwarding the policy request and returning
- * any associated response. Each policy request transaction must be processed
- * individually. Policy decisions may be based on a number of factors, such as:
- * <ul>
- * <li>Parameters associated with the request and the status of available
- * resources</li>
- * <li>Identity of the particular client and associated profile information</li>
- * <li>Application parameters</li>
- * <li>Security considerations</li>
- * <li>Time-of-day</li>
- * </ul>
- * The primary functions of the Policy Server include:
- * <ul>
- * <li>A policy decision request mechanism, invoked by Application Managers</li>
- * <li>A policy decision request 'policing' mechanism, enforcing installed
- * Policy Rules</li>
- * <li>A policy decision delivery mechanism, used to install policy decisions on
- * the CMTS</li>
- * <li>A mechanism to allow for the proxying of QoS management messages to the
- * CMTS on behalf of the Application Manager</li>
- * <li>An event recording interface to a Record Keeping Server that is used to
- * log policy requests, which may in turn be correlated with network resource
- * usage records</li>·
- * </ul>
- * Since the Policy Server functions as a proxy between the AM and CMTS elements
- * (with complementary client and server interfaces) some MSOs may elect to
- * deploy multiple layers of Policy Servers and to delegate certain policy
- * decisions among these servers in order to satisfy requirements associated
- * with scalability and fault-tolerance.
- * </p>
- * <p>
- * <i>Stateful & Stateless Policy Servers</i> There are two basic classes of
- * Policy Servers – Stateful and Stateless. A Stateless Policy Server is a
- * slight misnomer since it does maintain enough state to map Application
- * Manager requests to the proper CMTS and maintain COPS session state, while a
- * pure Stateless Policy Server maintains no state on any of the media sessions.
- * Stateful Policy Servers come in several varieties – some participate in
- * admission control and thus monitor the QoS attributes of active media
- * sessions, some leave QoS and admission control to the CMTS but monitor
- * time-based or volume-based service requests from the Application Manager, and
- * some Policy Servers are somewhere between these extremes. The reason there is
- * a variety of Policy Server types is that there is a variety of environments
- * that operators are trying to support. For example, some operators may wish to
- * support PacketCable Multimedia over the same CMTSs that they use for
- * PacketCable telephony, and they may want a single CMS/Policy Server that has
- * a more global view of the network resources being used. On the other hand,
- * some operators may wish to run a PacketCable Multimedia- only environment, or
- * they may utilize simpler CMTS-driven mechanisms for partitioning PacketCable
- * Multimedia and telephony resources. These simpler configurations have more
- * modest requirements on the amount of state that a Policy Server maintains.
- * Policy Server state requirements can also be driven by the level of trust
- * between the Policy Server and Application Manager; a Stateful Policy Server
- * can more readily police Application Manager session control behavior than can
- * a Stateless Policy Server. So a Stateful Policy Server may be more
- * appropriate for operators supporting third party Application Managers. Other
- * operators may rely on economics to enforce their trust relationships with
- * Application Managers, or they may control the Application Managers
- * themselves. In such cases a Stateless Policy Server may be more appropriate.
- * Since it is impossible to categorize all the various components of media
- * session and network QoS state that a Policy Server is maintaining, the
- * protocol is designed to be independent of this complexity. A Stateful Policy
- * Server gleans PacketCable Multimedia media session information from the
- * Application Manager requests it proxies; any other information it requires is
- * gathered via mechanisms that are outside the scope of this specification. The
- * CMTS and the Application Manager make no distinction as to the type of Policy
- * Server to which they are connected, and the protocol is designed in such a
- * manner that the type of Policy Server is transparent to the end point. The
- * type of Policy Server is only of importance to the operator. Since some types
- * of Policy Servers attempt to assist with admission control and may have a
- * larger view of the network and its resources, additional state
- * synchronization issues may arise in design in a network which contains more
- * than one of these types of Policy Servers. It is the responsibility of the
- * operator to ensure that the efforts of these Policy Servers are not
- * undermined by a network that includes other autonomous Policy Servers.
- * </p>
- * <p>
- * <i>Modification of Requests and Responses by Policy Servers</i> Although
- * nominally a part of the Resource Control Domain, the Policy Server can be an
- * intermediary between the Service and the Resource Control Domains, in
- * addition to its normal role of implementing MSO-defined authorization and
- * resource management procedures. In either of these capacities it may modify
- * the incoming request before forwarding it to the CMTS. In acting as an
- * intermediary between the SCD and RCD, the Policy Server may translate fields
- * from formats or scales used in the SCD into formats or scales used in the
- * RCD. For example, the Policy Server may modify the "priority" of a request
- * coming from an Application Manager (especially important to do for an AM
- * outside of the MSO network) so that this priority field uses a consistent
- * scale throughout the operator's RCD. In its capacity as an intermediary, the
- * Policy Server may use bidirectional translation – in other words, it should
- * translate requests from the AM to the CMTS and "untranslate" the responses
- * from the CMTS to the AM. This capability can be supported by stateful policy
- * servers by remembering the original request, and it can be supported by
- * stateless Policy Servers if the translation function is invertible.
- * Modification of certain objects, specifically the Classifier and Traffic
- * Profile objects, may cause operational problems in the originating AM. As
- * such, these objects MUST NOT be modified by the policy server. Aside from
- * these exceptions, all other objects may be policed and modified at the PS's
- * discretion based on provisioned policy rules.
- * </p>
- *
- */
-public interface IPCMMPolicyServer extends IPCMMServer, IStateful {
-
- /**
- * establishes COPS connection with the CMTS
- *
- * @param host
- * : remote host name or ip address
- * @return connected socket.
- */
- IPSCMTSClient requestCMTSConnection(String host);
-
- /**
- * establishes COPS connection with the CMTS
- *
- * @param host
- * : remote ip address‚
- * @return connected socket.
- */
- IPSCMTSClient requestCMTSConnection(InetAddress host);
-
- /**
- * <p>
- * In the PacketCable model, the CMTS (PEP) is the one that listens on the
- * assigned port 3918, and it is the Policy Server that MUST initiate the
- * TCP connection to the CMTS, thus we implement the IPCMMClient interface.
- * </p>
- */
- public static interface IPSCMTSClient extends IPCMMClient {
-
- /**
- *
- * @return Classifier Id.
- */
- short getClassifierId();
-
- /**
- *
- * @return the transaction Id.
- */
- short getTransactionId();
-
- /**
- * Gate id transmitted by the CMTS to the PS.
- *
- * @return the Gate Id.
- */
- int getGateId();
-
- /**
- * initiates a Gate-Set with the CMTS
- *
- * @return
- */
- boolean gateSet();
-
- /**
- * initiates a Gate-Info with the CMTS
- *
- * @return
- */
- boolean gateInfo();
-
- /**
- * initiates a Gate-Delete with the CMTS
- *
- * @return
- */
- boolean gateDelete();
-
- /**
- * sends synch request
- *
- * @return
- */
- boolean gateSynchronize();
-
- /**
- * Sets the value of the multi-media version info.
- *
- * @param MM
- * version info
- */
- void setVersionInfo(MMVersionInfo vInfo);
-
- /**
- *
- * @return MM version info
- */
- MMVersionInfo getVersionInfo();
- }
-}
+++ /dev/null
-/**
- * @header@
- */
-package org.pcmm.rcd.impl;
-
-import org.pcmm.PCMMConstants;
-import org.pcmm.PCMMGlobalConfig;
-import org.pcmm.PCMMProperties;
-import org.pcmm.gates.*;
-import org.pcmm.gates.IGateSpec.DSCPTOS;
-import org.pcmm.gates.IGateSpec.Direction;
-import org.pcmm.gates.impl.*;
-import org.pcmm.messages.IMessage.MessageProperties;
-import org.pcmm.messages.impl.MessageFactory;
-import org.pcmm.objects.MMVersionInfo;
-import org.pcmm.rcd.IPCMMPolicyServer;
-import org.pcmm.utils.PCMMException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.umu.cops.prpdp.COPSPdpConnection;
-import org.umu.cops.prpdp.COPSPdpDataProcess;
-import org.umu.cops.stack.*;
-import org.umu.cops.stack.COPSDecision.Command;
-import org.umu.cops.stack.COPSHeader.OPCode;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.Properties;
-
-/**
- * PCMM policy server
- */
-public class PCMMPolicyServer extends AbstractPCMMServer implements IPCMMPolicyServer {
-
- public final static Logger logger = LoggerFactory.getLogger(PCMMPolicyServer.class);
-
- /**
- * since PCMMPolicyServer can connect to multiple CMTS (PEP) we need to
- * manage each connection in a separate thread.
- */
-
- public PCMMPolicyServer() {
- super();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.pcmm.rcd.IPCMMPolicyServer#requestCMTSConnection(java.lang.String)
- */
- public IPSCMTSClient requestCMTSConnection(String host) {
- try {
- InetAddress address = InetAddress.getByName(host);
- return requestCMTSConnection(address);
- } catch (UnknownHostException e) {
- logger.error(e.getMessage());
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.pcmm.rcd.IPCMMPolicyServer#requestCMTSConnection(java.net.InetAddress
- * )
- */
- public IPSCMTSClient requestCMTSConnection(InetAddress host) {
- IPSCMTSClient client = new PSCMTSClient();
- try {
- if (client.tryConnect(host, PCMMProperties.get(PCMMConstants.PCMM_PORT, Integer.class))) {
- boolean endNegotiation = false;
- while (!endNegotiation) {
- logger.debug("waiting for OPN message from CMTS");
- COPSMsg opnMessage = client.readMessage();
- // Client-Close
- if (opnMessage.getHeader().getOpCode().equals(OPCode.CC)) {
- COPSError error = ((COPSClientCloseMsg) opnMessage).getError();
- logger.debug("CMTS requetsed Client-Close");
- throw new PCMMException(new PCMMError((short)error.getErrCode().ordinal(),
- (short)error.getErrSubCode().ordinal()));
- } else // Client-Open
- {
- if (opnMessage.getHeader().getOpCode().equals(OPCode.OPN)) {
- logger.debug("OPN message received from CMTS");
- COPSClientOpenMsg opn = (COPSClientOpenMsg) opnMessage;
- if (opn.getClientSI() == null) {
- throw new COPSException("CMTS shoud have sent MM version info in Client-Open message");
- } else {
- // set the version info
- MMVersionInfo vInfo = new MMVersionInfo(opn.getClientSI().getData().getData());
- client.setVersionInfo(vInfo);
- logger.debug(
- "CMTS sent MMVersion info : major:" + vInfo.getMajorVersionNB() + " minor:" +
- vInfo.getMinorVersionNB()); //
- if (client.getVersionInfo().getMajorVersionNB() ==
- client.getVersionInfo().getMinorVersionNB()) {
- // send a CC since CMTS has exhausted all
- // protocol selection attempts
- throw new COPSException("CMTS exhausted all protocol selection attempts");
- }
- }
- // send CAT response
- Properties prop = new Properties();
- logger.debug("send CAT to the CMTS ");
- COPSMsg catMsg = MessageFactory.getInstance().create(OPCode.CAT, prop);
- client.sendRequest(catMsg);
- // wait for REQ msg
- COPSMsg reqMsg = client.readMessage();
- // Client-Close
- if (reqMsg.getHeader().getOpCode().equals(OPCode.CC)) {
- COPSError error = ((COPSClientCloseMsg) opnMessage).getError();
- logger.debug("CMTS requetsed Client-Close");
- throw new PCMMException(new PCMMError((short)error.getErrCode().ordinal(),
- (short)error.getErrSubCode().ordinal()));
- } else // Request
- {
- if (reqMsg.getHeader().getOpCode().equals(OPCode.REQ)) {
- logger.debug("Received REQ message form CMTS");
- // end connection attempts
- COPSReqMsg req = (COPSReqMsg) reqMsg;
- // set the client handle to be used later by the
- // gate-set
- client.setClientHandle(req.getClientHandle().getId().str());
- COPSPdpDataProcess processor = null;
- COPSPdpConnection copsPdpConnection = new COPSPdpConnection(opn.getPepId(),
- ((AbstractPCMMClient) client).getSocket(), processor);
- copsPdpConnection
- .setKaTimer(((COPSClientAcceptMsg) catMsg).getKATimer().getTimerVal());
- pool.schedule(pool.adapt(copsPdpConnection));
- endNegotiation = true;
- } else {
- throw new COPSException("Can't understand request");
- }
- }
- } else {
- throw new COPSException("Can't understand request");
- }
- }
- }
- }
- // else raise exception.
- } catch (Exception e) {
- logger.error(e.getMessage());
- // no need to keep connection.
- client.disconnect();
- return null;
- }
- return client;
- }
-
- @Override
- protected IPCMMClientHandler getPCMMClientHandler(Socket socket) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * @see {@link IPSCMTSClient}
- */
- /* public */static class PSCMTSClient extends AbstractPCMMClient implements IPSCMTSClient {
- /**
- * Transaction id is
- */
- private short transactionID;
- private short classifierID;
- private int gateID;
-
- public PSCMTSClient() {
- super();
- logger.info("Client " + getClass() + hashCode() + " crated and started");
- }
-
- public PSCMTSClient(Socket socket) {
- setSocket(socket);
- }
-
- public boolean gateSet() {
- logger.debug("Sending Gate-Set message");
- if (!isConnected()) {
- throw new IllegalArgumentException("Not connected");
- }
- // XXX check if other values should be provided
- //
- ITrafficProfile trafficProfile = buildTrafficProfile();
- // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
- ITransactionID trID = new TransactionID();
- // set transaction ID to gate set
- trID.setGateCommandType(ITransactionID.GateSet);
- transactionID = (transactionID == 0 ? (short) (Math.random() * hashCode()) : transactionID);
- trID.setTransactionIdentifier(transactionID);
- // AMID
- IAMID amid = getAMID();
- // GATE SPEC
- IGateSpec gateSpec = getGateSpec();
- ISubscriberID subscriberID = new SubscriberID();
- // Classifier if MM version <4, Extended Classifier else
- IClassifier eclassifier = getClassifier(subscriberID);
-
- IPCMMGate gate = new PCMMGateReq();
- gate.setTransactionID(trID);
- gate.setAMID(amid);
- gate.setSubscriberID(subscriberID);
- gate.setGateSpec(gateSpec);
- gate.setTrafficProfile(trafficProfile);
- gate.setClassifier(eclassifier);
- byte[] data = gate.getData();
-
- // configure message properties
- Properties prop = new Properties();
- prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
- prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
- prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
- prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
- COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
- // ** Send the GateSet Decision
- // **
- sendRequest(decisionMsg);
- // TODO check on this ?
- // waits for the gate-set-ack or error
- COPSMsg responseMsg = readMessage();
- if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
- logger.info("processing received report from CMTS");
- COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
- if (reportMsg.getClientSI() == null) {
- logger.debug("CMTS responded with an empty SI");
- return false;
- }
- COPSClientSI clientSI = reportMsg.getClientSI();
- IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
- IPCMMError error = responseGate.getError();
- if (error != null) {
- logger.error(error.toString());
- return false;
- }
- logger.info("the CMTS has sent TransactionID :" + responseGate.getTransactionID());
- if (responseGate.getTransactionID() != null &&
- responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
- 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();
- return true;
- } else {
- return false;
- }
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.pcmm.rcd.IPCMMPolicyServer#gateDelete()
- */
- @Override
- public boolean gateDelete() {
- if (!isConnected()) {
- logger.error("Not connected");
- return false;
- }
- ITransactionID trID = new TransactionID();
- // set transaction ID to gate set
- trID.setGateCommandType(ITransactionID.GateDelete);
- trID.setTransactionIdentifier(transactionID);
- // AMID
- IAMID amid = getAMID();
- // GATE SPEC
- ISubscriberID subscriberID = new SubscriberID();
- try {
- subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
- } catch (UnknownHostException e1) {
- logger.error(e1.getMessage());
- }
-
- IGateID gateIdObj = new GateID();
- gateIdObj.setGateID(gateID);
-
- IPCMMGate gate = new PCMMGateReq();
- gate.setTransactionID(trID);
- gate.setAMID(amid);
- gate.setSubscriberID(subscriberID);
- gate.setGateID(gateIdObj);
-
- // configure message properties
- Properties prop = new Properties();
- prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
- prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
- prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
- byte[] data = gate.getData();
- prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
- COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
- // ** Send the GateSet Decision
- // **
- try {
- decisionMsg.writeData(getSocket());
- } catch (IOException e) {
- logger.error("Failed to send the decision, reason: " + e.getMessage());
- return false;
- }
- // waits for the gate-delete-ack or error
- COPSMsg responseMsg = readMessage();
- if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
- logger.info("processing received report from CMTS");
- COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
- if (reportMsg.getClientSI() == null) {
- return false;
- }
- COPSClientSI clientSI = reportMsg.getClientSI();
- IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
- IPCMMError error = responseGate.getError();
- if (error != null) {
- logger.error(error.toString());
- return false;
- }
- // here CMTS responded that he acknowledged the Gate-delete
- // message
- ITransactionID responseTransactionID = responseGate.getTransactionID();
- if (responseTransactionID != null &&
- responseTransactionID.getGateCommandType() == ITransactionID.GateDeleteAck) {
- // TODO check : Is this test needed ??
- if (responseGate.getGateID().getGateID() == gateID &&
- responseTransactionID.getTransactionIdentifier() == transactionID) {
- logger.info("the CMTS has sent a Gate-Delete-Ack response");
- return true;
- }
- }
-
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.pcmm.rcd.IPCMMPolicyServer#gateInfo()
- */
- @Override
- public boolean gateInfo() {
- if (!isConnected()) {
- logger.error("Not connected");
- return false;
- }
- ITransactionID trID = new TransactionID();
- // set transaction ID to gate set
- trID.setGateCommandType(ITransactionID.GateInfo);
- trID.setTransactionIdentifier(transactionID);
- // AMID
- IAMID amid = getAMID();
- // GATE SPEC
- ISubscriberID subscriberID = new SubscriberID();
- try {
- subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
- } catch (UnknownHostException e1) {
- logger.error(e1.getMessage());
- }
- IGateID gateIdObj = new GateID();
- gateIdObj.setGateID(gateID);
-
- IPCMMGate gate = new PCMMGateReq();
- gate.setTransactionID(trID);
- gate.setAMID(amid);
- gate.setSubscriberID(subscriberID);
- gate.setGateID(gateIdObj);
-
- // configure message properties
- Properties prop = new Properties();
- prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
- prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
- prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
- byte[] data = gate.getData();
- prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
- COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
- // ** Send the GateSet Decision
- // **
- try {
- decisionMsg.writeData(getSocket());
- } catch (IOException e) {
- logger.error("Failed to send the decision, reason: " + e.getMessage());
- return false;
- }
- // waits for the gate-Info-ack or error
- COPSMsg responseMsg = readMessage();
- if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
- logger.info("processing received report from CMTS");
- COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
- if (reportMsg.getClientSI() == null) {
- return false;
- }
- COPSClientSI clientSI = reportMsg.getClientSI();
- IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
- IPCMMError error = responseGate.getError();
- ITransactionID responseTransactionID = responseGate.getTransactionID();
- if (error != null) {
- logger.debug(responseTransactionID != null ? responseTransactionID.toString() :
- "returned Transaction ID is null");
- logger.error(error.toString());
- return false;
- }
- // here CMTS responded that he acknowledged the Gate-Info
- // message
- /*
- * <Gate-Info-Ack> = <ClientSI Header> <TransactionID> <AMID>
- * <SubscriberID> <GateID> [<Event Generation Info>] <Gate-Spec>
- * <classifier> <classifier...>] <Traffic Profile> <Gate Time
- * Info> <Gate Usage Info> [<Volume-Based Usage Limit>] [<PSID>]
- * [<Msg-Receipt-Key>] [<UserID>] [<Time-Based Usage Limit>]
- * [<Opaque Data>] <GateState> [<SharedResourceID>]
- */
- if (responseTransactionID != null &&
- responseTransactionID.getGateCommandType() == ITransactionID.GateInfoAck) {
- // TODO need to implement missing data wrapper
- logger.info("TransactionID : " + responseTransactionID.toString());
- logger.info("AMID :" + String.valueOf(responseGate.getAMID()));
- logger.info("SubscriberID :" + String.valueOf(responseGate.getSubscriberID()));
- logger.info("Traffic Profile :" + String.valueOf(responseGate.getTrafficProfile()));
- logger.info("Gate Time Info :");
- logger.info("Gate Usage Info :");
- logger.info("GateState :");
- return true;
- }
-
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.pcmm.rcd.IPCMMPolicyServer#synchronize()
- */
- @Override
- public boolean gateSynchronize() {
- if (!isConnected()) {
- logger.error("Not connected");
- return false;
- }
- ITransactionID trID = new TransactionID();
- // set transaction ID to gate set
- trID.setGateCommandType(ITransactionID.SynchRequest);
- trID.setTransactionIdentifier(transactionID);
- // AMID
- IAMID amid = getAMID();
- // GATE SPEC
- ISubscriberID subscriberID = new SubscriberID();
- try {
- subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
- } catch (UnknownHostException e1) {
- logger.error(e1.getMessage());
- }
- IGateID gateIdObj = new GateID();
- gateIdObj.setGateID(gateID);
-
- IPCMMGate gate = new PCMMGateReq();
- gate.setTransactionID(trID);
- gate.setAMID(amid);
- gate.setSubscriberID(subscriberID);
- gate.setGateID(gateIdObj);
-
- // configure message properties
- Properties prop = new Properties();
- prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
- prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
- prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
- byte[] data = gate.getData();
- prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
- COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
- // ** Send the GateSet Decision
- // **
- try {
- decisionMsg.writeData(getSocket());
- } catch (IOException e) {
- logger.error("Failed to send the decision, reason: " + e.getMessage());
- return false;
- }
- // waits for the gate-Info-ack or error
- COPSMsg responseMsg = readMessage();
- if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
- logger.info("processing received report from CMTS");
- COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
- if (reportMsg.getClientSI() == null) {
- return false;
- }
- COPSClientSI clientSI = reportMsg.getClientSI();
- IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
- IPCMMError error = responseGate.getError();
- ITransactionID responseTransactionID = responseGate.getTransactionID();
- if (error != null) {
- logger.debug(responseTransactionID != null ? responseTransactionID.toString() :
- "returned Transaction ID is null");
- logger.error(error.toString());
- return false;
- }
- // here CMTS responded that he acknowledged the Gate-Info
- // message
- /*
- * <Gate-Info-Ack> = <ClientSI Header> <TransactionID> <AMID>
- * <SubscriberID> <GateID> [<Event Generation Info>] <Gate-Spec>
- * <classifier> <classifier...>] <Traffic Profile> <Gate Time
- * Info> <Gate Usage Info> [<Volume-Based Usage Limit>] [<PSID>]
- * [<Msg-Receipt-Key>] [<UserID>] [<Time-Based Usage Limit>]
- * [<Opaque Data>] <GateState> [<SharedResourceID>]
- */
- if (responseTransactionID != null &&
- responseTransactionID.getGateCommandType() == ITransactionID.SynchReport) {
- // TODO need to implement missing data wrapper
- logger.info("TransactionID : " + responseTransactionID.toString());
- logger.info("AMID :" + String.valueOf(responseGate.getAMID()));
- logger.info("SubscriberID :" + String.valueOf(responseGate.getSubscriberID()));
- logger.info("Traffic Profile :" + String.valueOf(responseGate.getTrafficProfile()));
- logger.info("Gate Time Info :");
- logger.info("Gate Usage Info :");
- logger.info("GateState :");
- return true;
- }
-
- }
- return false;
- }
-
- private IAMID getAMID() {
- IAMID amid = new AMID();
- amid.setApplicationType((short) 1);
- amid.setApplicationMgrTag((short) 1);
- return amid;
- }
-
- private IClassifier getClassifier(ISubscriberID subscriberID) {
- IClassifier classifier;
- // if the version major is less than 4 we need to use Classifier
- if (getVersionInfo().getMajorVersionNB() >= 4) {
- classifier = new ExtendedClassifier();
- // eclassifier.setProtocol(IClassifier.Protocol.NONE);
-// classifier.setProtocol(IClassifier.Protocol.TCP);
- try {
- InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
- InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
- InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
- InetAddress mask =
- InetAddress.getByName(PCMMProperties.get(PCMMConstants.DEFAULT_MASK, String.class));
- subscriberID.setSourceIPAddress(subIP);
- classifier.setSourceIPAddress(srcIP);
- classifier.setDestinationIPAddress(dstIP);
- ((IExtendedClassifier) classifier).setIPDestinationMask(mask);
- ((IExtendedClassifier) classifier).setIPSourceMask(mask);
- } catch (UnknownHostException unae) {
- logger.error("Error getByName", unae);
- }
- ((IExtendedClassifier) classifier).setSourcePortStart(PCMMGlobalConfig.srcPort);
- ((IExtendedClassifier) classifier).setSourcePortEnd(PCMMGlobalConfig.srcPort);
- ((IExtendedClassifier) classifier).setDestinationPortStart(PCMMGlobalConfig.dstPort);
- ((IExtendedClassifier) classifier).setDestinationPortEnd(PCMMGlobalConfig.dstPort);
- ((IExtendedClassifier) classifier).setActivationState((byte) 0x01);
- /*
- * check if we have a stored value of classifierID else we just
- * create one eclassifier.setClassifierID((short) 0x01);
- */
- ((IExtendedClassifier) classifier)
- .setClassifierID((short) (classifierID == 0 ? Math.random() * hashCode() : classifierID));
- // XXX - testie
- // eclassifier.setClassifierID((short) 1);
- ((IExtendedClassifier) classifier).setAction((byte) 0x00);
- // XXX - temp default until Gate Modify is hacked in
- // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
- classifier.setPriority((byte) 65);
-
- } else {
- classifier = new Classifier();
-// classifier.setProtocol(IClassifier.Protocol.TCP);
- try {
- InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
- InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
- InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
- subscriberID.setSourceIPAddress(subIP);
- classifier.setSourceIPAddress(srcIP);
- classifier.setDestinationIPAddress(dstIP);
- } catch (UnknownHostException unae) {
- logger.error("Error getByName", unae);
- }
- classifier.setSourcePort(PCMMGlobalConfig.srcPort);
- classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
- }
- return classifier;
- }
-
- /**
- * @return GateSpec object
- */
- private IGateSpec getGateSpec() {
- IGateSpec gateSpec = new GateSpec();
- gateSpec.setDirection(Direction.UPSTREAM);
- gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
- gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
- gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
- gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
- gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
- return gateSpec;
- }
-
- /**
- * creates a traffic profile with 3 envelops (Authorized, Reserved and
- * Committed).
- *
- * @return Traffic profile
- */
- private ITrafficProfile buildTrafficProfile() {
- ITrafficProfile trafficProfile = new BestEffortService(BestEffortService.DEFAULT_ENVELOP);
- ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
- .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
- ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
- .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
- ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
- .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
- ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
- .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
- // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
- ((BestEffortService) trafficProfile).getReservedEnvelop()
- .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
- ((BestEffortService) trafficProfile).getReservedEnvelop()
- .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
- ((BestEffortService) trafficProfile).getReservedEnvelop()
- .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
- ((BestEffortService) trafficProfile).getReservedEnvelop()
- .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
- // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
- ((BestEffortService) trafficProfile).getCommittedEnvelop()
- .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
- ((BestEffortService) trafficProfile).getCommittedEnvelop()
- .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
- ((BestEffortService) trafficProfile).getCommittedEnvelop()
- .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
- ((BestEffortService) trafficProfile).getCommittedEnvelop()
- .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
- return trafficProfile;
- }
-
- @Override
- public short getClassifierId() {
- return classifierID;
- }
-
- @Override
- public short getTransactionId() {
- return transactionID;
- }
-
- @Override
- public int getGateId() {
- return gateID;
- }
- }
-
-}