Merge changes If0630105,I9d2d5e61,I1cea2a32,Icc05b6a7,Ic57eb4f8, ...
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / rcd / impl / PCMMPolicyServer.java
1 /**
2  * @header@
3  */
4 package org.pcmm.rcd.impl;
5
6 import org.pcmm.PCMMConstants;
7 import org.pcmm.PCMMGlobalConfig;
8 import org.pcmm.PCMMProperties;
9 import org.pcmm.gates.*;
10 import org.pcmm.gates.IGateSpec.DSCPTOS;
11 import org.pcmm.gates.IGateSpec.Direction;
12 import org.pcmm.gates.impl.*;
13 import org.pcmm.messages.IMessage.MessageProperties;
14 import org.pcmm.messages.impl.MessageFactory;
15 import org.pcmm.objects.MMVersionInfo;
16 import org.pcmm.rcd.IPCMMPolicyServer;
17 import org.pcmm.utils.PCMMException;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.umu.cops.prpdp.COPSPdpConnection;
21 import org.umu.cops.prpdp.COPSPdpDataProcess;
22 import org.umu.cops.stack.*;
23 import org.umu.cops.stack.COPSDecision.Command;
24 import org.umu.cops.stack.COPSHeader.OPCode;
25
26 import java.io.IOException;
27 import java.net.InetAddress;
28 import java.net.Socket;
29 import java.net.UnknownHostException;
30 import java.util.Properties;
31
32 /**
33  * PCMM policy server
34  */
35 public class PCMMPolicyServer extends AbstractPCMMServer implements IPCMMPolicyServer {
36
37     public final static Logger logger = LoggerFactory.getLogger(PCMMPolicyServer.class);
38
39     /**
40      * since PCMMPolicyServer can connect to multiple CMTS (PEP) we need to
41      * manage each connection in a separate thread.
42      */
43
44     public PCMMPolicyServer() {
45         super();
46     }
47
48     /*
49      * (non-Javadoc)
50      *
51      * @see
52      * org.pcmm.rcd.IPCMMPolicyServer#requestCMTSConnection(java.lang.String)
53      */
54     public IPSCMTSClient requestCMTSConnection(String host) {
55         try {
56             InetAddress address = InetAddress.getByName(host);
57             return requestCMTSConnection(address);
58         } catch (UnknownHostException e) {
59             logger.error(e.getMessage());
60         }
61         return null;
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see
68      * org.pcmm.rcd.IPCMMPolicyServer#requestCMTSConnection(java.net.InetAddress
69      * )
70      */
71     public IPSCMTSClient requestCMTSConnection(InetAddress host) {
72         IPSCMTSClient client = new PSCMTSClient();
73         try {
74             if (client.tryConnect(host, PCMMProperties.get(PCMMConstants.PCMM_PORT, Integer.class))) {
75                 boolean endNegotiation = false;
76                 while (!endNegotiation) {
77                     logger.debug("waiting for OPN message from CMTS");
78                     COPSMsg opnMessage = client.readMessage();
79                     // Client-Close
80                     if (opnMessage.getHeader().getOpCode().equals(OPCode.CC)) {
81                         COPSError error = ((COPSClientCloseMsg) opnMessage).getError();
82                         logger.debug("CMTS requetsed Client-Close");
83                         throw new PCMMException(new PCMMError((short)error.getErrCode().ordinal(),
84                                 (short)error.getErrSubCode().ordinal()));
85                     } else // Client-Open
86                     {
87                         if (opnMessage.getHeader().getOpCode().equals(OPCode.OPN)) {
88                             logger.debug("OPN message received from CMTS");
89                             COPSClientOpenMsg opn = (COPSClientOpenMsg) opnMessage;
90                             if (opn.getClientSI() == null) {
91                                 throw new COPSException("CMTS shoud have sent MM version info in Client-Open message");
92                             } else {
93                                 // set the version info
94                                 MMVersionInfo vInfo = new MMVersionInfo(opn.getClientSI().getData().getData());
95                                 client.setVersionInfo(vInfo);
96                                 logger.debug(
97                                         "CMTS sent MMVersion info : major:" + vInfo.getMajorVersionNB() + "  minor:" +
98                                                 vInfo.getMinorVersionNB()); //
99                                 if (client.getVersionInfo().getMajorVersionNB() ==
100                                         client.getVersionInfo().getMinorVersionNB()) {
101                                     // send a CC since CMTS has exhausted all
102                                     // protocol selection attempts
103                                     throw new COPSException("CMTS exhausted all protocol selection attempts");
104                                 }
105                             }
106                             // send CAT response
107                             Properties prop = new Properties();
108                             logger.debug("send CAT to the CMTS ");
109                             COPSMsg catMsg = MessageFactory.getInstance().create(OPCode.CAT, prop);
110                             client.sendRequest(catMsg);
111                             // wait for REQ msg
112                             COPSMsg reqMsg = client.readMessage();
113                             // Client-Close
114                             if (reqMsg.getHeader().getOpCode().equals(OPCode.CC)) {
115                                 COPSError error = ((COPSClientCloseMsg) opnMessage).getError();
116                                 logger.debug("CMTS requetsed Client-Close");
117                                 throw new PCMMException(new PCMMError((short)error.getErrCode().ordinal(),
118                                         (short)error.getErrSubCode().ordinal()));
119                             } else // Request
120                             {
121                                 if (reqMsg.getHeader().getOpCode().equals(OPCode.REQ)) {
122                                     logger.debug("Received REQ message form CMTS");
123                                     // end connection attempts
124                                     COPSReqMsg req = (COPSReqMsg) reqMsg;
125                                     // set the client handle to be used later by the
126                                     // gate-set
127                                     client.setClientHandle(req.getClientHandle().getId().str());
128                                     COPSPdpDataProcess processor = null;
129                                     COPSPdpConnection copsPdpConnection = new COPSPdpConnection(opn.getPepId(),
130                                             ((AbstractPCMMClient) client).getSocket(), processor);
131                                     copsPdpConnection
132                                             .setKaTimer(((COPSClientAcceptMsg) catMsg).getKATimer().getTimerVal());
133                                     pool.schedule(pool.adapt(copsPdpConnection));
134                                     endNegotiation = true;
135                                 } else {
136                                     throw new COPSException("Can't understand request");
137                                 }
138                             }
139                         } else {
140                             throw new COPSException("Can't understand request");
141                         }
142                     }
143                 }
144             }
145             // else raise exception.
146         } catch (Exception e) {
147             logger.error(e.getMessage());
148             // no need to keep connection.
149             client.disconnect();
150             return null;
151         }
152         return client;
153     }
154
155     @Override
156     protected IPCMMClientHandler getPCMMClientHandler(Socket socket) {
157         // TODO Auto-generated method stub
158         return null;
159     }
160
161     /**
162      * @see {@link IPSCMTSClient}
163      */
164     /* public */static class PSCMTSClient extends AbstractPCMMClient implements IPSCMTSClient {
165         /**
166          * Transaction id is
167          */
168         private short transactionID;
169         private short classifierID;
170         private int gateID;
171
172         public PSCMTSClient() {
173             super();
174             logger.info("Client " + getClass() + hashCode() + " crated and started");
175         }
176
177         public PSCMTSClient(Socket socket) {
178             setSocket(socket);
179         }
180
181         public boolean gateSet() {
182             logger.debug("Sending Gate-Set message");
183             if (!isConnected()) {
184                 throw new IllegalArgumentException("Not connected");
185             }
186             // XXX check if other values should be provided
187             //
188             ITrafficProfile trafficProfile = buildTrafficProfile();
189             // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
190             ITransactionID trID = new TransactionID();
191             // set transaction ID to gate set
192             trID.setGateCommandType(ITransactionID.GateSet);
193             transactionID = (transactionID == 0 ? (short) (Math.random() * hashCode()) : transactionID);
194             trID.setTransactionIdentifier(transactionID);
195             // AMID
196             IAMID amid = getAMID();
197             // GATE SPEC
198             IGateSpec gateSpec = getGateSpec();
199             ISubscriberID subscriberID = new SubscriberID();
200             // Classifier if MM version <4, Extended Classifier else
201             IClassifier eclassifier = getClassifier(subscriberID);
202
203             IPCMMGate gate = new PCMMGateReq();
204             gate.setTransactionID(trID);
205             gate.setAMID(amid);
206             gate.setSubscriberID(subscriberID);
207             gate.setGateSpec(gateSpec);
208             gate.setTrafficProfile(trafficProfile);
209             gate.setClassifier(eclassifier);
210             byte[] data = gate.getData();
211
212             // configure message properties
213             Properties prop = new Properties();
214             prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
215             prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
216             prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
217             prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
218             COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
219             // ** Send the GateSet Decision
220             // **
221             sendRequest(decisionMsg);
222             // TODO check on this ?
223             // waits for the gate-set-ack or error
224             COPSMsg responseMsg = readMessage();
225             if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
226                 logger.info("processing received report from CMTS");
227                 COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
228                 if (reportMsg.getClientSI() == null) {
229                     logger.debug("CMTS responded with an empty SI");
230                     return false;
231                 }
232                 COPSClientSI clientSI = reportMsg.getClientSI();
233                 IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
234                 IPCMMError error = responseGate.getError();
235                 if (error != null) {
236                     logger.error(error.toString());
237                     return false;
238                 }
239                 logger.info("the CMTS has sent TransactionID :" + responseGate.getTransactionID());
240                 if (responseGate.getTransactionID() != null &&
241                         responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
242                     logger.info("the CMTS has sent a Gate-Set-Ack response");
243                     // here CMTS responded that he acknowledged the Gate-Set
244                     // TODO do further check of Gate-Set-Ack GateID etc...
245                     gateID = responseGate.getGateID().getGateID();
246                     return true;
247                 } else {
248                     return false;
249                 }
250             }
251             return false;
252         }
253
254         /*
255          * (non-Javadoc)
256          *
257          * @see org.pcmm.rcd.IPCMMPolicyServer#gateDelete()
258          */
259         @Override
260         public boolean gateDelete() {
261             if (!isConnected()) {
262                 logger.error("Not connected");
263                 return false;
264             }
265             ITransactionID trID = new TransactionID();
266             // set transaction ID to gate set
267             trID.setGateCommandType(ITransactionID.GateDelete);
268             trID.setTransactionIdentifier(transactionID);
269             // AMID
270             IAMID amid = getAMID();
271             // GATE SPEC
272             ISubscriberID subscriberID = new SubscriberID();
273             try {
274                 subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
275             } catch (UnknownHostException e1) {
276                 logger.error(e1.getMessage());
277             }
278
279             IGateID gateIdObj = new GateID();
280             gateIdObj.setGateID(gateID);
281
282             IPCMMGate gate = new PCMMGateReq();
283             gate.setTransactionID(trID);
284             gate.setAMID(amid);
285             gate.setSubscriberID(subscriberID);
286             gate.setGateID(gateIdObj);
287
288             // configure message properties
289             Properties prop = new Properties();
290             prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
291             prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
292             prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
293             byte[] data = gate.getData();
294             prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
295             COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
296             // ** Send the GateSet Decision
297             // **
298             try {
299                 decisionMsg.writeData(getSocket());
300             } catch (IOException e) {
301                 logger.error("Failed to send the decision, reason: " + e.getMessage());
302                 return false;
303             }
304             // waits for the gate-delete-ack or error
305             COPSMsg responseMsg = readMessage();
306             if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
307                 logger.info("processing received report from CMTS");
308                 COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
309                 if (reportMsg.getClientSI() == null) {
310                     return false;
311                 }
312                 COPSClientSI clientSI = reportMsg.getClientSI();
313                 IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
314                 IPCMMError error = responseGate.getError();
315                 if (error != null) {
316                     logger.error(error.toString());
317                     return false;
318                 }
319                 // here CMTS responded that he acknowledged the Gate-delete
320                 // message
321                 ITransactionID responseTransactionID = responseGate.getTransactionID();
322                 if (responseTransactionID != null &&
323                         responseTransactionID.getGateCommandType() == ITransactionID.GateDeleteAck) {
324                     // TODO check : Is this test needed ??
325                     if (responseGate.getGateID().getGateID() == gateID &&
326                             responseTransactionID.getTransactionIdentifier() == transactionID) {
327                         logger.info("the CMTS has sent a Gate-Delete-Ack response");
328                         return true;
329                     }
330                 }
331
332             }
333             return false;
334         }
335
336         /*
337          * (non-Javadoc)
338          *
339          * @see org.pcmm.rcd.IPCMMPolicyServer#gateInfo()
340          */
341         @Override
342         public boolean gateInfo() {
343             if (!isConnected()) {
344                 logger.error("Not connected");
345                 return false;
346             }
347             ITransactionID trID = new TransactionID();
348             // set transaction ID to gate set
349             trID.setGateCommandType(ITransactionID.GateInfo);
350             trID.setTransactionIdentifier(transactionID);
351             // AMID
352             IAMID amid = getAMID();
353             // GATE SPEC
354             ISubscriberID subscriberID = new SubscriberID();
355             try {
356                 subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
357             } catch (UnknownHostException e1) {
358                 logger.error(e1.getMessage());
359             }
360             IGateID gateIdObj = new GateID();
361             gateIdObj.setGateID(gateID);
362
363             IPCMMGate gate = new PCMMGateReq();
364             gate.setTransactionID(trID);
365             gate.setAMID(amid);
366             gate.setSubscriberID(subscriberID);
367             gate.setGateID(gateIdObj);
368
369             // configure message properties
370             Properties prop = new Properties();
371             prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
372             prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
373             prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
374             byte[] data = gate.getData();
375             prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
376             COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
377             // ** Send the GateSet Decision
378             // **
379             try {
380                 decisionMsg.writeData(getSocket());
381             } catch (IOException e) {
382                 logger.error("Failed to send the decision, reason: " + e.getMessage());
383                 return false;
384             }
385             // waits for the gate-Info-ack or error
386             COPSMsg responseMsg = readMessage();
387             if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
388                 logger.info("processing received report from CMTS");
389                 COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
390                 if (reportMsg.getClientSI() == null) {
391                     return false;
392                 }
393                 COPSClientSI clientSI = reportMsg.getClientSI();
394                 IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
395                 IPCMMError error = responseGate.getError();
396                 ITransactionID responseTransactionID = responseGate.getTransactionID();
397                 if (error != null) {
398                     logger.debug(responseTransactionID != null ? responseTransactionID.toString() :
399                             "returned Transaction ID is null");
400                     logger.error(error.toString());
401                     return false;
402                 }
403                 // here CMTS responded that he acknowledged the Gate-Info
404                 // message
405                 /*
406                  * <Gate-Info-Ack> = <ClientSI Header> <TransactionID> <AMID>
407                  * <SubscriberID> <GateID> [<Event Generation Info>] <Gate-Spec>
408                  * <classifier> <classifier...>] <Traffic Profile> <Gate Time
409                  * Info> <Gate Usage Info> [<Volume-Based Usage Limit>] [<PSID>]
410                  * [<Msg-Receipt-Key>] [<UserID>] [<Time-Based Usage Limit>]
411                  * [<Opaque Data>] <GateState> [<SharedResourceID>]
412                  */
413                 if (responseTransactionID != null &&
414                         responseTransactionID.getGateCommandType() == ITransactionID.GateInfoAck) {
415                     // TODO need to implement missing data wrapper
416                     logger.info("TransactionID : " + responseTransactionID.toString());
417                     logger.info("AMID :" + String.valueOf(responseGate.getAMID()));
418                     logger.info("SubscriberID :" + String.valueOf(responseGate.getSubscriberID()));
419                     logger.info("Traffic Profile :" + String.valueOf(responseGate.getTrafficProfile()));
420                     logger.info("Gate Time Info :");
421                     logger.info("Gate Usage Info :");
422                     logger.info("GateState :");
423                     return true;
424                 }
425
426             }
427             return false;
428         }
429
430         /*
431          * (non-Javadoc)
432          *
433          * @see org.pcmm.rcd.IPCMMPolicyServer#synchronize()
434          */
435         @Override
436         public boolean gateSynchronize() {
437             if (!isConnected()) {
438                 logger.error("Not connected");
439                 return false;
440             }
441             ITransactionID trID = new TransactionID();
442             // set transaction ID to gate set
443             trID.setGateCommandType(ITransactionID.SynchRequest);
444             trID.setTransactionIdentifier(transactionID);
445             // AMID
446             IAMID amid = getAMID();
447             // GATE SPEC
448             ISubscriberID subscriberID = new SubscriberID();
449             try {
450                 subscriberID.setSourceIPAddress(InetAddress.getLocalHost());
451             } catch (UnknownHostException e1) {
452                 logger.error(e1.getMessage());
453             }
454             IGateID gateIdObj = new GateID();
455             gateIdObj.setGateID(gateID);
456
457             IPCMMGate gate = new PCMMGateReq();
458             gate.setTransactionID(trID);
459             gate.setAMID(amid);
460             gate.setSubscriberID(subscriberID);
461             gate.setGateID(gateIdObj);
462
463             // configure message properties
464             Properties prop = new Properties();
465             prop.put(MessageProperties.CLIENT_HANDLE, getClientHandle());
466             prop.put(MessageProperties.DECISION_CMD_CODE, Command.INSTALL);
467             prop.put(MessageProperties.DECISION_FLAG, Command.NULL);
468             byte[] data = gate.getData();
469             prop.put(MessageProperties.GATE_CONTROL, new COPSData(data, 0, data.length));
470             COPSMsg decisionMsg = MessageFactory.getInstance().create(OPCode.DEC, prop);
471             // ** Send the GateSet Decision
472             // **
473             try {
474                 decisionMsg.writeData(getSocket());
475             } catch (IOException e) {
476                 logger.error("Failed to send the decision, reason: " + e.getMessage());
477                 return false;
478             }
479             // waits for the gate-Info-ack or error
480             COPSMsg responseMsg = readMessage();
481             if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
482                 logger.info("processing received report from CMTS");
483                 COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
484                 if (reportMsg.getClientSI() == null) {
485                     return false;
486                 }
487                 COPSClientSI clientSI = reportMsg.getClientSI();
488                 IPCMMGate responseGate = new PCMMGateReq(clientSI.getData().getData());
489                 IPCMMError error = responseGate.getError();
490                 ITransactionID responseTransactionID = responseGate.getTransactionID();
491                 if (error != null) {
492                     logger.debug(responseTransactionID != null ? responseTransactionID.toString() :
493                             "returned Transaction ID is null");
494                     logger.error(error.toString());
495                     return false;
496                 }
497                 // here CMTS responded that he acknowledged the Gate-Info
498                 // message
499                 /*
500                  * <Gate-Info-Ack> = <ClientSI Header> <TransactionID> <AMID>
501                  * <SubscriberID> <GateID> [<Event Generation Info>] <Gate-Spec>
502                  * <classifier> <classifier...>] <Traffic Profile> <Gate Time
503                  * Info> <Gate Usage Info> [<Volume-Based Usage Limit>] [<PSID>]
504                  * [<Msg-Receipt-Key>] [<UserID>] [<Time-Based Usage Limit>]
505                  * [<Opaque Data>] <GateState> [<SharedResourceID>]
506                  */
507                 if (responseTransactionID != null &&
508                         responseTransactionID.getGateCommandType() == ITransactionID.SynchReport) {
509                     // TODO need to implement missing data wrapper
510                     logger.info("TransactionID : " + responseTransactionID.toString());
511                     logger.info("AMID :" + String.valueOf(responseGate.getAMID()));
512                     logger.info("SubscriberID :" + String.valueOf(responseGate.getSubscriberID()));
513                     logger.info("Traffic Profile :" + String.valueOf(responseGate.getTrafficProfile()));
514                     logger.info("Gate Time Info :");
515                     logger.info("Gate Usage Info :");
516                     logger.info("GateState :");
517                     return true;
518                 }
519
520             }
521             return false;
522         }
523
524         private IAMID getAMID() {
525             IAMID amid = new AMID();
526             amid.setApplicationType((short) 1);
527             amid.setApplicationMgrTag((short) 1);
528             return amid;
529         }
530
531         private IClassifier getClassifier(ISubscriberID subscriberID) {
532             IClassifier classifier;
533             // if the version major is less than 4 we need to use Classifier
534             if (getVersionInfo().getMajorVersionNB() >= 4) {
535                 classifier = new ExtendedClassifier();
536                 // eclassifier.setProtocol(IClassifier.Protocol.NONE);
537 //                classifier.setProtocol(IClassifier.Protocol.TCP);
538                 try {
539                     InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
540                     InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
541                     InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
542                     InetAddress mask =
543                             InetAddress.getByName(PCMMProperties.get(PCMMConstants.DEFAULT_MASK, String.class));
544                     subscriberID.setSourceIPAddress(subIP);
545                     classifier.setSourceIPAddress(srcIP);
546                     classifier.setDestinationIPAddress(dstIP);
547                     ((IExtendedClassifier) classifier).setIPDestinationMask(mask);
548                     ((IExtendedClassifier) classifier).setIPSourceMask(mask);
549                 } catch (UnknownHostException unae) {
550                     logger.error("Error getByName", unae);
551                 }
552                 ((IExtendedClassifier) classifier).setSourcePortStart(PCMMGlobalConfig.srcPort);
553                 ((IExtendedClassifier) classifier).setSourcePortEnd(PCMMGlobalConfig.srcPort);
554                 ((IExtendedClassifier) classifier).setDestinationPortStart(PCMMGlobalConfig.dstPort);
555                 ((IExtendedClassifier) classifier).setDestinationPortEnd(PCMMGlobalConfig.dstPort);
556                 ((IExtendedClassifier) classifier).setActivationState((byte) 0x01);
557                 /*
558                  * check if we have a stored value of classifierID else we just
559                  * create one eclassifier.setClassifierID((short) 0x01);
560                  */
561                 ((IExtendedClassifier) classifier)
562                         .setClassifierID((short) (classifierID == 0 ? Math.random() * hashCode() : classifierID));
563                 // XXX - testie
564                 // eclassifier.setClassifierID((short) 1);
565                 ((IExtendedClassifier) classifier).setAction((byte) 0x00);
566                 // XXX - temp default until Gate Modify is hacked in
567                 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
568                 classifier.setPriority((byte) 65);
569
570             } else {
571                 classifier = new Classifier();
572 //                classifier.setProtocol(IClassifier.Protocol.TCP);
573                 try {
574                     InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
575                     InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
576                     InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
577                     subscriberID.setSourceIPAddress(subIP);
578                     classifier.setSourceIPAddress(srcIP);
579                     classifier.setDestinationIPAddress(dstIP);
580                 } catch (UnknownHostException unae) {
581                     logger.error("Error getByName", unae);
582                 }
583                 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
584                 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
585             }
586             return classifier;
587         }
588
589         /**
590          * @return GateSpec object
591          */
592         private IGateSpec getGateSpec() {
593             IGateSpec gateSpec = new GateSpec();
594             gateSpec.setDirection(Direction.UPSTREAM);
595             gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
596             gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
597             gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
598             gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
599             gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
600             return gateSpec;
601         }
602
603         /**
604          * creates a traffic profile with 3 envelops (Authorized, Reserved and
605          * Committed).
606          *
607          * @return Traffic profile
608          */
609         private ITrafficProfile buildTrafficProfile() {
610             ITrafficProfile trafficProfile = new BestEffortService(BestEffortService.DEFAULT_ENVELOP);
611             ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
612                     .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
613             ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
614                     .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
615             ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
616                     .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
617             ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
618                     .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
619             // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
620
621             ((BestEffortService) trafficProfile).getReservedEnvelop()
622                     .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
623             ((BestEffortService) trafficProfile).getReservedEnvelop()
624                     .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
625             ((BestEffortService) trafficProfile).getReservedEnvelop()
626                     .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
627             ((BestEffortService) trafficProfile).getReservedEnvelop()
628                     .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
629             // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
630
631             ((BestEffortService) trafficProfile).getCommittedEnvelop()
632                     .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
633             ((BestEffortService) trafficProfile).getCommittedEnvelop()
634                     .setMaximumTrafficBurst(BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
635             ((BestEffortService) trafficProfile).getCommittedEnvelop()
636                     .setRequestTransmissionPolicy(PCMMGlobalConfig.BETransmissionPolicy);
637             ((BestEffortService) trafficProfile).getCommittedEnvelop()
638                     .setMaximumSustainedTrafficRate(PCMMGlobalConfig.DefaultLowBestEffortTrafficRate);
639             return trafficProfile;
640         }
641
642         @Override
643         public short getClassifierId() {
644             return classifierID;
645         }
646
647         @Override
648         public short getTransactionId() {
649             return transactionID;
650         }
651
652         @Override
653         public int getGateId() {
654             return gateID;
655         }
656     }
657
658 }