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