7 import org.pcmm.gates.*;
8 import org.pcmm.gates.IGateSpec.DSCPTOS;
9 import org.pcmm.gates.IGateSpec.Direction;
10 import org.pcmm.gates.impl.*;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.umu.cops.prpdp.COPSPdpException;
14 import org.umu.cops.stack.*;
15 import org.umu.cops.stack.COPSClientSI.CSIType;
16 import org.umu.cops.stack.COPSContext.RType;
17 import org.umu.cops.stack.COPSDecision.Command;
18 import org.umu.cops.stack.COPSDecision.DecisionFlag;
20 import java.io.IOException;
21 import java.net.InetAddress;
22 import java.net.Socket;
23 import java.net.UnknownHostException;
28 * Example of an UNSOLICITED decision
30 * <Gate Control Command> = <COPS Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI Data>
32 * <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
33 * <PDP-Config> | <Synch-Request> | <Msg-Receipt>
34 * <Gate-Set> = <Decision Header> <TransactionID> <AMID> <SubscriberID> [<GateID>] <GateSpec>
35 * <Traffic Profile> <classifier> [<classifier...>] [<Event Generation Info>]
36 * [<Volume-Based Usage Limit>] [<Time-Based Usage Limit>][<Opaque Data>] [<UserID>]
40 * COPS message transceiver class for provisioning connections at the PDP side.
42 public class PCMMPdpMsgSender {
44 public final static Logger logger = LoggerFactory.getLogger(PCMMPdpMsgSender.class);
47 * Socket connected to PEP
49 protected Socket _sock;
52 * COPS client-type that identifies the policy client
54 protected short _clientType;
57 * COPS client handle used to uniquely identify a particular PEP's request
60 protected COPSHandle _handle;
65 protected short _transactionID;
66 protected short _classifierID;
67 // XXX - this does not need to be here
68 protected int _gateID;
71 * Creates a PCMMPdpMsgSender
80 public PCMMPdpMsgSender(short clientType, COPSHandle clientHandle,
83 _handle = clientHandle;
84 _clientType = clientType;
91 public PCMMPdpMsgSender(short clientType, short tID,
92 COPSHandle clientHandle, Socket sock) {
94 _handle = clientHandle;
95 _clientType = clientType;
102 * Gets the client handle
104 * @return Client's <tt>COPSHandle</tt>
106 public COPSHandle getClientHandle() {
111 * Gets the client-type
113 * @return Client-type value
115 public short getClientType() {
120 * Gets the transaction-id
122 * @return transaction-id value
124 public short getTransactionID() {
125 return _transactionID;
130 * Sends a PCMM GateSet COPS Decision message
132 * @param gate - the gate to set
133 * @throws COPSPdpException
135 public void sendGateSet(IPCMMGate gate)
136 throws COPSPdpException {
137 // Common Header with the same ClientType as the request
139 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
141 // Client Handle with the same clientHandle as the request
142 final COPSHandle handle = new COPSHandle(getClientHandle().getId());
143 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
144 ITransactionID trID = new TransactionID();
146 // set transaction ID to gate set
147 trID.setGateCommandType(ITransactionID.GateSet);
148 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
149 trID.setTransactionIdentifier(_transactionID);
151 gate.setTransactionID(trID);
154 // new pcmm specific clientsi
155 // TODO - determine if NAMED is correct.
156 COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(gate.getData(), 0, gate.getData().length));
158 decisionMsg.add(hdr);
159 decisionMsg.add(handle);
160 // Decisions (no flags supplied)
162 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
163 COPSDecision install = new COPSDecision(Command.INSTALL, DecisionFlag.REQERROR);
164 decisionMsg.addDecision(install, cntxt);
165 decisionMsg.add(clientSD); // setting up the gate
168 decisionMsg.dump(System.out);
169 } catch (IOException unae) {
170 System.out.println("Error dumping " + unae.getMessage());
174 } catch (COPSException e) {
175 logger.error("Error making Msg", e);
178 // ** Send the GateSet Decision
181 decisionMsg.writeData(_sock);
182 } catch (IOException e) {
183 logger.error("Failed to send the decision, reason: ", e);
189 * Sends a PCMM GateSet COPS Decision message
191 * @param num - parameter used to set the traffic rate
192 * @throws COPSPdpException
194 public void sendGateSetDemo(int num) throws COPSPdpException {
196 // Common Header with the same ClientType as the request
198 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
200 // Client Handle with the same clientHandle as the request
201 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
203 IPCMMGate gate = new PCMMGateReq();
204 ITransactionID trID = new TransactionID();
206 IAMID amid = new AMID();
207 ISubscriberID subscriberID = new SubscriberID();
208 IGateSpec gateSpec = new GateSpec();
209 IClassifier classifier = new Classifier();
210 IExtendedClassifier eclassifier = new ExtendedClassifier();
211 final int trafficRate;
214 trafficRate = PCMMGlobalConfig.DefaultBestEffortTrafficRate;
216 trafficRate = PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
218 ITrafficProfile trafficProfile = new BestEffortService(
219 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
220 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
221 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
222 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
223 .setMaximumTrafficBurst(
224 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
225 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
226 .setRequestTransmissionPolicy(
227 PCMMGlobalConfig.BETransmissionPolicy);
228 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
229 .setMaximumSustainedTrafficRate(
231 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
232 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
234 ((BestEffortService) trafficProfile).getReservedEnvelop()
235 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
236 ((BestEffortService) trafficProfile).getReservedEnvelop()
237 .setMaximumTrafficBurst(
238 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
239 ((BestEffortService) trafficProfile).getReservedEnvelop()
240 .setRequestTransmissionPolicy(
241 PCMMGlobalConfig.BETransmissionPolicy);
242 ((BestEffortService) trafficProfile).getReservedEnvelop()
243 .setMaximumSustainedTrafficRate(
245 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
246 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
249 ((BestEffortService) trafficProfile).getCommittedEnvelop()
250 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
251 ((BestEffortService) trafficProfile).getCommittedEnvelop()
252 .setMaximumTrafficBurst(
253 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
254 ((BestEffortService) trafficProfile).getCommittedEnvelop()
255 .setRequestTransmissionPolicy(
256 PCMMGlobalConfig.BETransmissionPolicy);
257 ((BestEffortService) trafficProfile).getCommittedEnvelop()
258 .setMaximumSustainedTrafficRate(
260 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
261 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
265 final COPSHandle handle = new COPSHandle(getClientHandle().getId());
267 // set transaction ID to gate set
268 trID.setGateCommandType(ITransactionID.GateSet);
269 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
270 trID.setTransactionIdentifier(_transactionID);
272 amid.setApplicationType((short) 1);
273 amid.setApplicationMgrTag((short) 1);
274 gateSpec.setDirection(Direction.UPSTREAM);
275 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
276 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
277 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
278 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
279 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
281 // XXX - if the version major is less than 4 we need to use Classifier
283 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
284 eclassifier.setProtocol(IClassifier.Protocol.TCP);
286 InetAddress subIP = InetAddress
287 .getByName(PCMMGlobalConfig.SubscriberID);
288 InetAddress srcIP = InetAddress
289 .getByName(PCMMGlobalConfig.srcIP);
290 InetAddress dstIP = InetAddress
291 .getByName(PCMMGlobalConfig.dstIP);
292 InetAddress mask = InetAddress.getByName("0.0.0.0");
293 subscriberID.setSourceIPAddress(subIP);
294 eclassifier.setSourceIPAddress(srcIP);
295 eclassifier.setDestinationIPAddress(dstIP);
296 eclassifier.setIPDestinationMask(mask);
297 eclassifier.setIPSourceMask(mask);
298 } catch (UnknownHostException unae) {
299 logger.error("Error getByName", unae);
301 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
302 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
303 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
304 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
305 eclassifier.setActivationState((byte) 0x01);
306 // check if we have a stored value of classifierID else we just
309 // eclassifier.setClassifierID((short) 0x01);
310 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
311 .random() * hashCode() : _classifierID));
313 // eclassifier.setClassifierID((short) 1);
315 eclassifier.setAction((byte) 0x00);
316 // XXX - temp default until Gate Modify is hacked in
317 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
318 eclassifier.setPriority((byte) 65);
321 classifier.setProtocol(IClassifier.Protocol.TCP);
323 InetAddress subIP = InetAddress
324 .getByName(PCMMGlobalConfig.SubscriberID);
325 InetAddress srcIP = InetAddress
326 .getByName(PCMMGlobalConfig.srcIP);
327 InetAddress dstIP = InetAddress
328 .getByName(PCMMGlobalConfig.dstIP);
329 subscriberID.setSourceIPAddress(subIP);
330 classifier.setSourceIPAddress(srcIP);
331 classifier.setDestinationIPAddress(dstIP);
332 } catch (UnknownHostException unae) {
333 logger.error("Error getByName", unae);
335 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
336 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
339 gate.setTransactionID(trID);
341 gate.setSubscriberID(subscriberID);
342 gate.setGateSpec(gateSpec);
343 gate.setTrafficProfile(trafficProfile);
344 gate.setClassifier(eclassifier);
346 byte[] data = gate.getData();
348 // new pcmm specific clientsi
349 COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
351 decisionMsg.add(hdr);
352 decisionMsg.add(handle);
353 // Decisions (no flags supplied)
355 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
356 COPSDecision install = new COPSDecision(Command.INSTALL, DecisionFlag.REQERROR);
357 decisionMsg.addDecision(install, cntxt);
358 decisionMsg.add(clientSD); // setting up the gate
361 decisionMsg.dump(System.out);
362 } catch (IOException unae) {
363 System.out.println("Error dumping " + unae.getMessage());
367 } catch (COPSException e) {
368 logger.error("Error making Msg", e);
371 // ** Send the GateSet Decision
374 decisionMsg.writeData(_sock);
375 } catch (IOException e) {
376 logger.error("Failed to send the decision, reason: ", e);
381 * Sends a PCMM GateSet COPS Decision message
383 * @throws COPSPdpException
385 public void sendGateSetBestEffortWithExtendedClassifier() throws COPSPdpException {
386 // Common Header with the same ClientType as the request
388 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
390 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
392 IPCMMGate gate = new PCMMGateReq();
393 ITransactionID trID = new TransactionID();
395 IAMID amid = new AMID();
396 ISubscriberID subscriberID = new SubscriberID();
397 IGateSpec gateSpec = new GateSpec();
398 IClassifier classifier = new Classifier();
399 IExtendedClassifier eclassifier = new ExtendedClassifier();
401 // XXX check if other values should be provided
403 ITrafficProfile trafficProfile = new BestEffortService(
404 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
405 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
406 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
407 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
408 .setMaximumTrafficBurst(
409 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
410 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
411 .setRequestTransmissionPolicy(
412 PCMMGlobalConfig.BETransmissionPolicy);
413 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
414 .setMaximumSustainedTrafficRate(
415 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
416 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
418 ((BestEffortService) trafficProfile).getReservedEnvelop()
419 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
420 ((BestEffortService) trafficProfile).getReservedEnvelop()
421 .setMaximumTrafficBurst(
422 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
423 ((BestEffortService) trafficProfile).getReservedEnvelop()
424 .setRequestTransmissionPolicy(
425 PCMMGlobalConfig.BETransmissionPolicy);
426 ((BestEffortService) trafficProfile).getReservedEnvelop()
427 .setMaximumSustainedTrafficRate(
428 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
429 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
432 ((BestEffortService) trafficProfile).getCommittedEnvelop()
433 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
434 ((BestEffortService) trafficProfile).getCommittedEnvelop()
435 .setMaximumTrafficBurst(
436 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
437 ((BestEffortService) trafficProfile).getCommittedEnvelop()
438 .setRequestTransmissionPolicy(
439 PCMMGlobalConfig.BETransmissionPolicy);
440 ((BestEffortService) trafficProfile).getCommittedEnvelop()
441 .setMaximumSustainedTrafficRate(
442 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
443 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
447 // Client Handle with the same clientHandle as the request
448 final COPSHandle handle = new COPSHandle(getClientHandle().getId());
450 // set transaction ID to gate set
451 trID.setGateCommandType(ITransactionID.GateSet);
452 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
453 trID.setTransactionIdentifier(_transactionID);
455 amid.setApplicationType((short) 1);
456 amid.setApplicationMgrTag((short) 1);
457 gateSpec.setDirection(Direction.UPSTREAM);
458 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
459 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
460 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
461 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
462 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
464 // XXX - if the version major is less than 4 we need to use Classifier
466 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
467 eclassifier.setProtocol(IClassifier.Protocol.TCP);
469 InetAddress subIP = InetAddress
470 .getByName(PCMMGlobalConfig.SubscriberID);
471 InetAddress srcIP = InetAddress
472 .getByName(PCMMGlobalConfig.srcIP);
473 InetAddress dstIP = InetAddress
474 .getByName(PCMMGlobalConfig.dstIP);
475 InetAddress mask = InetAddress.getByName("0.0.0.0");
476 subscriberID.setSourceIPAddress(subIP);
477 eclassifier.setSourceIPAddress(srcIP);
478 eclassifier.setDestinationIPAddress(dstIP);
479 eclassifier.setIPDestinationMask(mask);
480 eclassifier.setIPSourceMask(mask);
481 } catch (UnknownHostException unae) {
482 logger.error("Error getByName", unae);
484 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
485 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
486 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
487 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
488 eclassifier.setActivationState((byte) 0x01);
489 // check if we have a stored value of classifierID else we just
492 // eclassifier.setClassifierID((short) 0x01);
493 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
494 .random() * hashCode() : _classifierID));
496 // eclassifier.setClassifierID((short) 1);
498 eclassifier.setAction((byte) 0x00);
499 // XXX - temp default until Gate Modify is hacked in
500 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
501 eclassifier.setPriority((byte) 65);
504 classifier.setProtocol(IClassifier.Protocol.TCP);
506 InetAddress subIP = InetAddress
507 .getByName(PCMMGlobalConfig.SubscriberID);
508 InetAddress srcIP = InetAddress
509 .getByName(PCMMGlobalConfig.srcIP);
510 InetAddress dstIP = InetAddress
511 .getByName(PCMMGlobalConfig.dstIP);
512 subscriberID.setSourceIPAddress(subIP);
513 classifier.setSourceIPAddress(srcIP);
514 classifier.setDestinationIPAddress(dstIP);
515 } catch (UnknownHostException unae) {
516 logger.error("Error getByName", unae);
518 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
519 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
522 gate.setTransactionID(trID);
524 gate.setSubscriberID(subscriberID);
525 gate.setGateSpec(gateSpec);
526 gate.setTrafficProfile(trafficProfile);
527 gate.setClassifier(eclassifier);
529 byte[] data = gate.getData();
531 // new pcmm specific clientsi
532 COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
534 decisionMsg.add(hdr);
535 decisionMsg.add(handle);
536 // Decisions (no flags supplied)
538 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
539 COPSDecision install = new COPSDecision(Command.INSTALL, DecisionFlag.REQERROR);
540 decisionMsg.addDecision(install, cntxt);
541 decisionMsg.add(clientSD); // setting up the gate
544 decisionMsg.dump(System.out);
545 } catch (IOException unae) {
546 System.out.println("Error dumping " + unae.getMessage());
550 } catch (COPSException e) {
551 logger.error("Error making Msg", e);
554 // ** Send the GateSet Decision
557 decisionMsg.writeData(_sock);
558 } catch (IOException e) {
559 logger.error("Failed to send the decision", e);
565 public boolean handleGateReport(Socket socket) throws COPSPdpException {
567 // waits for the gate-set-ack or error
568 COPSMsg responseMsg = COPSTransceiver.receiveMsg(socket);
569 if (responseMsg.getHeader().isAReport()) {
570 logger.info("processing received report from CMTS");
571 COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
572 if (reportMsg.getClientSI().size() == 0) {
575 COPSClientSI clientSI = (COPSClientSI) reportMsg.getClientSI()
577 IPCMMGate responseGate = new PCMMGateReq(clientSI.getData()
579 if (responseGate.getTransactionID() != null
580 && responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
581 logger.info("the CMTS has sent a Gate-Set-Ack response");
582 // here CMTS responded that he acknowledged the Gate-Set
583 // TODO do further check of Gate-Set-Ack GateID etc...
584 _gateID = responseGate.getGateID().getGateID();
591 } catch (Exception e) { // COPSException, IOException
592 throw new COPSPdpException("Error COPSTransceiver.receiveMsg");
598 * Sends a PCMM GateSet COPS Decision message
600 * @throws COPSPdpException
602 public void sendGateSet() throws COPSPdpException {
603 // Common Header with the same ClientType as the request
605 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
607 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
609 IPCMMGate gate = new PCMMGateReq();
610 ITransactionID trID = new TransactionID();
612 IAMID amid = new AMID();
613 ISubscriberID subscriberID = new SubscriberID();
614 IGateSpec gateSpec = new GateSpec();
615 IClassifier classifier = new Classifier();
616 // XXX check if other values should be provided
617 ITrafficProfile trafficProfile = new BestEffortService(
618 BestEffortService.DEFAULT_ENVELOP);
619 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
620 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
621 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
622 .setMaximumTrafficBurst(
623 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
624 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
625 .setRequestTransmissionPolicy(
626 PCMMGlobalConfig.BETransmissionPolicy);
628 // Client Handle with the same clientHandle as the request
629 final COPSHandle handle = new COPSHandle(getClientHandle().getId());
630 // byte[] content = "1234".getBytes();
632 // handle.setId(new COPSData(content, 0, content.length));
634 // set transaction ID to gate set
635 trID.setGateCommandType(ITransactionID.GateSet);
636 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
637 trID.setTransactionIdentifier(_transactionID);
639 amid.setApplicationType((short) 1);
640 amid.setApplicationMgrTag((short) 1);
641 gateSpec.setDirection(Direction.UPSTREAM);
642 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
643 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
644 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
645 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
646 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
649 * ((DOCSISServiceClassNameTrafficProfile) trafficProfile)
650 * .setServiceClassName("S_up");
653 classifier.setProtocol(IClassifier.Protocol.TCP);
655 InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
656 InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
657 InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
658 subscriberID.setSourceIPAddress(subIP);
659 classifier.setSourceIPAddress(srcIP);
660 classifier.setDestinationIPAddress(dstIP);
661 } catch (UnknownHostException unae) {
662 logger.error("Error getByName", unae);
664 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
665 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
667 gate.setTransactionID(trID);
669 gate.setSubscriberID(subscriberID);
670 gate.setGateSpec(gateSpec);
671 gate.setTrafficProfile(trafficProfile);
672 gate.setClassifier(classifier);
674 byte[] data = gate.getData();
676 // new pcmm specific clientsi
677 COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
680 decisionMsg.add(hdr);
681 decisionMsg.add(handle);
682 // Decisions (no flags supplied)
684 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
685 COPSDecision install = new COPSDecision(Command.INSTALL, DecisionFlag.REQERROR);
686 decisionMsg.addDecision(install, cntxt);
687 decisionMsg.add(clientSD); // setting up the gate
690 decisionMsg.dump(System.out);
691 } catch (IOException unae) {
692 System.out.println("Error dumping " + unae.getMessage());
696 } catch (COPSException e) {
697 logger.error("Error making Msg", e);
700 // ** Send the GateSet Decision
703 decisionMsg.writeData(_sock);
704 } catch (IOException e) {
705 logger.error("Failed to send the decision", e);
711 * Sends a message asking that the request state be deleted
713 * @throws COPSPdpException
715 public void sendGateDelete(int gID) throws COPSPdpException {
717 * Example of an UNSOLICITED decision <Gate Control Command> = <COPS
718 * Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI
719 * Data> <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
720 * <PDP-Config> | <Synch-Request> | <Msg-Receipt> <Gate-Delete> =
721 * <Decision Header> <TransactionID> <AMID> <SubscriberID> <GateID>
723 // Common Header with the same ClientType as the request
724 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
726 // Client Handle with the same clientHandle as the request
727 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
729 IPCMMGate gate = new PCMMGateReq();
730 ITransactionID trID = new TransactionID();
732 IAMID amid = new AMID();
733 ISubscriberID subscriberID = new SubscriberID();
734 IGateID gateID = new GateID();
736 final COPSHandle handle = new COPSHandle(getClientHandle().getId());
738 // set transaction ID to gate set
739 trID.setGateCommandType(ITransactionID.GateDelete);
740 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
741 trID.setTransactionIdentifier(_transactionID);
743 amid.setApplicationType((short) 1);
744 amid.setApplicationMgrTag((short) 1);
745 gateID.setGateID(gID);
748 InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
749 subscriberID.setSourceIPAddress(subIP);
750 } catch (UnknownHostException unae) {
751 logger.error("Error getByName", unae);
754 gate.setTransactionID(trID);
756 gate.setSubscriberID(subscriberID);
757 gate.setGateID(gateID);
760 byte[] data = gate.getData();
762 // new pcmm specific clientsi
763 COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
765 decisionMsg.add(hdr);
766 decisionMsg.add(handle);
767 // Decisions (no flags supplied)
769 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
770 COPSDecision install = new COPSDecision(Command.INSTALL, DecisionFlag.REQERROR);
771 decisionMsg.addDecision(install, cntxt);
772 decisionMsg.add(clientSD); // setting up the gate
775 decisionMsg.dump(System.out);
776 } catch (IOException unae) {
777 System.out.println("Error dumping " + unae.getMessage());
781 } catch (COPSException e) {
782 logger.error("Error making Msg", e);
785 // ** Send the GateDelete Decision
788 decisionMsg.writeData(_sock);
789 // decisionMsg.writeData(socket_id);
790 } catch (IOException e) {
791 logger.error("Failed to send the decision", e);
796 * Sends a request asking that a new request state be created
798 * @throws COPSPdpException
800 public void sendOpenNewRequestState() throws COPSPdpException {
802 * <Decision Message> ::= <Common Header: Flag UNSOLICITED> <Client
803 * Handle> *(<Decision>) [<Integrity>] <Decision> ::= <Context>
804 * <Decision: Flags> <Decision: Flags> ::= Install Request-State
807 // Common Header with the same ClientType as the request (default
809 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
811 // Client Handle with the same clientHandle as the request
812 final COPSHandle clienthandle = new COPSHandle(_handle.getId());
816 COPSContext cntxt = new COPSContext(RType.CONFIG, (short) 0);
818 COPSDecision dec = new COPSDecision(Command.INSTALL, DecisionFlag.REQSTATE);
819 COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
821 decisionMsg.add(hdr);
822 decisionMsg.add(clienthandle);
823 decisionMsg.addDecision(dec, cntxt);
824 } catch (COPSException e) {
825 throw new COPSPdpException("Error making Msg");
829 decisionMsg.writeData(_sock);
830 } catch (IOException e) {
831 throw new COPSPdpException(
832 "Failed to send the open new request state, reason: "
838 * Sends a message asking for a COPS sync operation
840 * @throws COPSPdpException
842 public void sendGateInfo() throws COPSPdpException {
844 * <Gate-Info> ::= <Common Header> [<Client Handle>] [<Integrity>]
847 // Common Header with the same ClientType as the request
848 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_SSQ, getClientType());
850 // Client Handle with the same clientHandle as the request
851 final COPSHandle clienthandle = new COPSHandle(_handle.getId());
853 COPSSyncStateMsg msg = new COPSSyncStateMsg();
856 msg.add(clienthandle);
857 } catch (Exception e) {
858 throw new COPSPdpException("Error making Msg");
862 msg.writeData(_sock);
863 } catch (IOException e) {
864 throw new COPSPdpException(
865 "Failed to send the GateInfo request, reason: "
871 * Sends a message asking for a COPS sync operation
873 * @throws COPSPdpException
875 public void sendSyncRequest() throws COPSPdpException {
877 * <Synchronize State Request> ::= <Common Header> [<Client Handle>]
881 // Common Header with the same ClientType as the request
882 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_SSQ, getClientType());
884 // Client Handle with the same clientHandle as the request
885 final COPSHandle clienthandle = new COPSHandle(_handle.getId());
887 COPSSyncStateMsg msg = new COPSSyncStateMsg();
890 msg.add(clienthandle);
891 } catch (Exception e) {
892 throw new COPSPdpException("Error making Msg");
896 msg.writeData(_sock);
897 } catch (IOException e) {
898 throw new COPSPdpException(
899 "Failed to send the sync state request, reason: "
904 public void sendSyncRequestState() throws COPSPdpException {
907 public void sendDeleteRequestState() throws COPSPdpException {