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.COPSContext.RType;
16 import org.umu.cops.stack.COPSDecision.Command;
17 import org.umu.cops.stack.COPSDecision.DecisionFlag;
18 import org.umu.cops.stack.COPSHeader.OPCode;
19 import org.umu.cops.stack.COPSObjHeader.CType;
21 import java.io.IOException;
22 import java.net.InetAddress;
23 import java.net.Socket;
24 import java.net.UnknownHostException;
25 import java.util.HashMap;
26 import java.util.HashSet;
33 * Example of an UNSOLICITED decision
35 * <Gate Control Command> = <COPS Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI Data>
37 * <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
38 * <PDP-Config> | <Synch-Request> | <Msg-Receipt>
39 * <Gate-Set> = <Decision Header> <TransactionID> <AMID> <SubscriberID> [<GateID>] <GateSpec>
40 * <Traffic Profile> <classifier> [<classifier...>] [<Event Generation Info>]
41 * [<Volume-Based Usage Limit>] [<Time-Based Usage Limit>][<Opaque Data>] [<UserID>]
45 * COPS message transceiver class for provisioning connections at the PDP side.
47 public class PCMMPdpMsgSender {
49 public final static Logger logger = LoggerFactory.getLogger(PCMMPdpMsgSender.class);
52 * Socket connected to PEP
54 protected Socket _sock;
57 * COPS client-type that identifies the policy client
59 protected short _clientType;
62 * COPS client handle used to uniquely identify a particular PEP's request
65 protected COPSHandle _handle;
70 protected short _transactionID;
71 protected short _classifierID;
72 // XXX - this does not need to be here
73 protected int _gateID;
76 * Creates a PCMMPdpMsgSender
85 public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
87 _handle = clientHandle;
88 _clientType = clientType;
95 public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
98 _handle = clientHandle;
99 _clientType = clientType;
100 _transactionID = tID;
106 * Gets the client handle
108 * @return Client's <tt>COPSHandle</tt>
110 public COPSHandle getClientHandle() {
115 * Gets the client-type
117 * @return Client-type value
119 public short getClientType() {
124 * Gets the transaction-id
126 * @return transaction-id value
128 public short getTransactionID() {
129 return _transactionID;
134 * Sends a PCMM GateSet COPS Decision message
135 * @param gate - the gate
136 * @throws COPSPdpException
138 public void sendGateSet(final IPCMMGate gate) throws COPSPdpException {
139 final ITransactionID trID = new TransactionID();
141 // set transaction ID to gate set
142 trID.setGateCommandType(ITransactionID.GateSet);
143 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
144 trID.setTransactionIdentifier(_transactionID);
146 gate.setTransactionID(trID);
149 // new pcmm specific clientsi
150 final byte[] data = gate.getData();
151 // Common Header with the same ClientType as the request
152 // Client Handle with the same clientHandle as the request
154 final Set<COPSDecision> decisionSet = new HashSet<>();
155 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
156 new COPSData(data, 0, data.length)));
157 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
158 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
160 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
162 // new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
163 // new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
164 // ** Send the GateSet Decision
167 decisionMsg.writeData(_sock);
168 } catch (IOException e) {
169 logger.error("Failed to send the decision", e);
175 * Sends a PCMM GateSet COPS Decision message
177 * @param num - the number
178 * @throws COPSPdpException
180 public void sendGateSetDemo(int num) throws COPSPdpException {
181 final IPCMMGate gate = new PCMMGateReq();
182 final ITransactionID trID = new TransactionID();
183 final IAMID amid = new AMID();
184 final ISubscriberID subscriberID = new SubscriberID();
185 final IGateSpec gateSpec = new GateSpec();
186 final IClassifier classifier = new Classifier();
187 final IExtendedClassifier eclassifier = new ExtendedClassifier();
188 final int trafficRate;
190 trafficRate = PCMMGlobalConfig.DefaultBestEffortTrafficRate;
192 trafficRate = PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
194 final ITrafficProfile trafficProfile = new BestEffortService(
195 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
196 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
197 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
198 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
199 .setMaximumTrafficBurst(
200 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
201 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
202 .setRequestTransmissionPolicy(
203 PCMMGlobalConfig.BETransmissionPolicy);
204 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
205 .setMaximumSustainedTrafficRate(
207 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
208 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
210 ((BestEffortService) trafficProfile).getReservedEnvelop()
211 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
212 ((BestEffortService) trafficProfile).getReservedEnvelop()
213 .setMaximumTrafficBurst(
214 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
215 ((BestEffortService) trafficProfile).getReservedEnvelop()
216 .setRequestTransmissionPolicy(
217 PCMMGlobalConfig.BETransmissionPolicy);
218 ((BestEffortService) trafficProfile).getReservedEnvelop()
219 .setMaximumSustainedTrafficRate(
221 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
222 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
225 ((BestEffortService) trafficProfile).getCommittedEnvelop()
226 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
227 ((BestEffortService) trafficProfile).getCommittedEnvelop()
228 .setMaximumTrafficBurst(
229 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
230 ((BestEffortService) trafficProfile).getCommittedEnvelop()
231 .setRequestTransmissionPolicy(
232 PCMMGlobalConfig.BETransmissionPolicy);
233 ((BestEffortService) trafficProfile).getCommittedEnvelop()
234 .setMaximumSustainedTrafficRate(
236 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
237 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
241 // set transaction ID to gate set
242 trID.setGateCommandType(ITransactionID.GateSet);
243 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
244 trID.setTransactionIdentifier(_transactionID);
246 amid.setApplicationType((short) 1);
247 amid.setApplicationMgrTag((short) 1);
248 gateSpec.setDirection(Direction.UPSTREAM);
249 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
250 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
251 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
252 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
253 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
255 // XXX - if the version major is less than 4 we need to use Classifier
256 // TODO - Use some variable here or remove...
258 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
259 eclassifier.setProtocol(IClassifier.Protocol.TCP);
261 InetAddress subIP = InetAddress
262 .getByName(PCMMGlobalConfig.SubscriberID);
263 InetAddress srcIP = InetAddress
264 .getByName(PCMMGlobalConfig.srcIP);
265 InetAddress dstIP = InetAddress
266 .getByName(PCMMGlobalConfig.dstIP);
267 InetAddress mask = InetAddress.getByName("0.0.0.0");
268 subscriberID.setSourceIPAddress(subIP);
269 eclassifier.setSourceIPAddress(srcIP);
270 eclassifier.setDestinationIPAddress(dstIP);
271 eclassifier.setIPDestinationMask(mask);
272 eclassifier.setIPSourceMask(mask);
273 } catch (UnknownHostException unae) {
274 logger.error("Error getByName", unae);
276 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
277 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
278 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
279 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
280 eclassifier.setActivationState((byte) 0x01);
281 // check if we have a stored value of classifierID else we just
284 // eclassifier.setClassifierID((short) 0x01);
285 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
286 .random() * hashCode() : _classifierID));
288 // eclassifier.setClassifierID((short) 1);
290 eclassifier.setAction((byte) 0x00);
291 // XXX - temp default until Gate Modify is hacked in
292 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
293 eclassifier.setPriority((byte) 65);
296 classifier.setProtocol(IClassifier.Protocol.TCP);
298 InetAddress subIP = InetAddress
299 .getByName(PCMMGlobalConfig.SubscriberID);
300 InetAddress srcIP = InetAddress
301 .getByName(PCMMGlobalConfig.srcIP);
302 InetAddress dstIP = InetAddress
303 .getByName(PCMMGlobalConfig.dstIP);
304 subscriberID.setSourceIPAddress(subIP);
305 classifier.setSourceIPAddress(srcIP);
306 classifier.setDestinationIPAddress(dstIP);
307 } catch (UnknownHostException unae) {
308 logger.error("Error getByName", unae);
310 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
311 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
314 gate.setTransactionID(trID);
316 gate.setSubscriberID(subscriberID);
317 gate.setGateSpec(gateSpec);
318 gate.setTrafficProfile(trafficProfile);
319 gate.setClassifier(eclassifier);
321 final byte[] data = gate.getData();
323 final Set<COPSDecision> decisionSet = new HashSet<>();
324 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
325 new COPSData(data, 0, data.length)));
326 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
327 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
329 // Common Header with the same ClientType as the request
330 // Client Handle with the same clientHandle as the request
331 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
332 new COPSHandle(getClientHandle().getId()), decisionMap, null);
333 // new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
334 // new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length))); TODO - what does the value of 4 mean here???
336 // ** Send the GateSet Decision
339 decisionMsg.writeData(_sock);
340 } catch (IOException e) {
341 logger.error("Failed to send the decision", e);
346 * Sends a PCMM GateSet COPS Decision message
347 * @throws COPSPdpException
349 public void sendGateSetBestEffortWithExtendedClassifier() throws COPSPdpException {
350 final IPCMMGate gate = new PCMMGateReq();
351 final ITransactionID trID = new TransactionID();
352 final IAMID amid = new AMID();
353 final ISubscriberID subscriberID = new SubscriberID();
354 final IGateSpec gateSpec = new GateSpec();
355 final IClassifier classifier = new Classifier();
356 final IExtendedClassifier eclassifier = new ExtendedClassifier();
358 // XXX check if other values should be provided
360 final ITrafficProfile trafficProfile = new BestEffortService(
361 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
362 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
363 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
364 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
365 .setMaximumTrafficBurst(
366 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
367 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
368 .setRequestTransmissionPolicy(
369 PCMMGlobalConfig.BETransmissionPolicy);
370 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
371 .setMaximumSustainedTrafficRate(
372 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
373 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
375 ((BestEffortService) trafficProfile).getReservedEnvelop()
376 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
377 ((BestEffortService) trafficProfile).getReservedEnvelop()
378 .setMaximumTrafficBurst(
379 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
380 ((BestEffortService) trafficProfile).getReservedEnvelop()
381 .setRequestTransmissionPolicy(
382 PCMMGlobalConfig.BETransmissionPolicy);
383 ((BestEffortService) trafficProfile).getReservedEnvelop()
384 .setMaximumSustainedTrafficRate(
385 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
386 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
389 ((BestEffortService) trafficProfile).getCommittedEnvelop()
390 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
391 ((BestEffortService) trafficProfile).getCommittedEnvelop()
392 .setMaximumTrafficBurst(
393 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
394 ((BestEffortService) trafficProfile).getCommittedEnvelop()
395 .setRequestTransmissionPolicy(
396 PCMMGlobalConfig.BETransmissionPolicy);
397 ((BestEffortService) trafficProfile).getCommittedEnvelop()
398 .setMaximumSustainedTrafficRate(
399 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
400 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
404 // set transaction ID to gate set
405 trID.setGateCommandType(ITransactionID.GateSet);
406 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
407 trID.setTransactionIdentifier(_transactionID);
409 amid.setApplicationType((short) 1);
410 amid.setApplicationMgrTag((short) 1);
411 gateSpec.setDirection(Direction.UPSTREAM);
412 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
413 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
414 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
415 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
416 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
418 // XXX - if the version major is less than 4 we need to use Classifier
420 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
421 eclassifier.setProtocol(IClassifier.Protocol.TCP);
423 InetAddress subIP = InetAddress
424 .getByName(PCMMGlobalConfig.SubscriberID);
425 InetAddress srcIP = InetAddress
426 .getByName(PCMMGlobalConfig.srcIP);
427 InetAddress dstIP = InetAddress
428 .getByName(PCMMGlobalConfig.dstIP);
429 InetAddress mask = InetAddress.getByName("0.0.0.0");
430 subscriberID.setSourceIPAddress(subIP);
431 eclassifier.setSourceIPAddress(srcIP);
432 eclassifier.setDestinationIPAddress(dstIP);
433 eclassifier.setIPDestinationMask(mask);
434 eclassifier.setIPSourceMask(mask);
435 } catch (UnknownHostException unae) {
436 logger.error("Error getByName", unae);
438 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
439 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
440 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
441 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
442 eclassifier.setActivationState((byte) 0x01);
443 // check if we have a stored value of classifierID else we just
446 // eclassifier.setClassifierID((short) 0x01);
447 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
448 .random() * hashCode() : _classifierID));
450 // eclassifier.setClassifierID((short) 1);
452 eclassifier.setAction((byte) 0x00);
453 // XXX - temp default until Gate Modify is hacked in
454 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
455 eclassifier.setPriority((byte) 65);
458 classifier.setProtocol(IClassifier.Protocol.TCP);
460 InetAddress subIP = InetAddress
461 .getByName(PCMMGlobalConfig.SubscriberID);
462 InetAddress srcIP = InetAddress
463 .getByName(PCMMGlobalConfig.srcIP);
464 InetAddress dstIP = InetAddress
465 .getByName(PCMMGlobalConfig.dstIP);
466 subscriberID.setSourceIPAddress(subIP);
467 classifier.setSourceIPAddress(srcIP);
468 classifier.setDestinationIPAddress(dstIP);
469 } catch (UnknownHostException unae) {
470 logger.error("Error getByName", unae);
472 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
473 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
476 gate.setTransactionID(trID);
478 gate.setSubscriberID(subscriberID);
479 gate.setGateSpec(gateSpec);
480 gate.setTrafficProfile(trafficProfile);
481 gate.setClassifier(eclassifier);
483 byte[] data = gate.getData();
485 final Set<COPSDecision> decisionSet = new HashSet<>();
486 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
487 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
488 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
490 // Common Header with the same ClientType as the request
491 // Client Handle with the same clientHandle as the request
492 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
494 // new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
495 // new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null)); TODO - what does the value of 4 mean here???
497 // ** Send the GateSet Decision
500 decisionMsg.writeData(_sock);
501 } catch (IOException e) {
502 logger.error("Failed to send the decision", e);
508 public boolean handleGateReport(final Socket socket) throws COPSPdpException {
510 // waits for the gate-set-ack or error
511 final COPSMsg responseMsg = COPSTransceiver.receiveMsg(socket);
512 if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
513 logger.info("processing received report from CMTS");
514 final COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
515 if (reportMsg.getClientSI() == null) {
518 final IPCMMGate responseGate = new PCMMGateReq(reportMsg.getClientSI().getData().getData());
519 if (responseGate.getTransactionID() != null
520 && responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
521 logger.info("the CMTS has sent a Gate-Set-Ack response");
522 // here CMTS responded that he acknowledged the Gate-Set
523 // TODO do further check of Gate-Set-Ack GateID etc...
524 _gateID = responseGate.getGateID().getGateID();
531 } catch (Exception e) { // COPSException, IOException
532 throw new COPSPdpException("Error COPSTransceiver.receiveMsg");
538 * Sends a PCMM GateSet COPS Decision message
540 * @throws COPSPdpException
542 public void sendGateSet() throws COPSPdpException {
543 // Common Header with the same ClientType as the request
545 final IPCMMGate gate = new PCMMGateReq();
546 final ITransactionID trID = new TransactionID();
548 final IAMID amid = new AMID();
549 final ISubscriberID subscriberID = new SubscriberID();
550 final IGateSpec gateSpec = new GateSpec();
551 final IClassifier classifier = new Classifier();
552 // XXX check if other values should be provided
553 final ITrafficProfile trafficProfile = new BestEffortService(
554 BestEffortService.DEFAULT_ENVELOP);
555 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
556 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
557 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
558 .setMaximumTrafficBurst(
559 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
560 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
561 .setRequestTransmissionPolicy(
562 PCMMGlobalConfig.BETransmissionPolicy);
564 // byte[] content = "1234".getBytes();
566 // handle.setId(new COPSData(content, 0, content.length));
568 // set transaction ID to gate set
569 trID.setGateCommandType(ITransactionID.GateSet);
570 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
571 trID.setTransactionIdentifier(_transactionID);
573 amid.setApplicationType((short) 1);
574 amid.setApplicationMgrTag((short) 1);
575 gateSpec.setDirection(Direction.UPSTREAM);
576 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
577 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
578 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
579 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
580 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
583 * ((DOCSISServiceClassNameTrafficProfile) trafficProfile)
584 * .setServiceClassName("S_up");
587 classifier.setProtocol(IClassifier.Protocol.TCP);
589 InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
590 InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
591 InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
592 subscriberID.setSourceIPAddress(subIP);
593 classifier.setSourceIPAddress(srcIP);
594 classifier.setDestinationIPAddress(dstIP);
595 } catch (UnknownHostException unae) {
596 logger.error("Error getByName", unae);
598 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
599 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
601 gate.setTransactionID(trID);
603 gate.setSubscriberID(subscriberID);
604 gate.setGateSpec(gateSpec);
605 gate.setTrafficProfile(trafficProfile);
606 gate.setClassifier(classifier);
608 final byte[] data = gate.getData();
610 final Set<COPSDecision> decisionSet = new HashSet<>();
611 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL,
612 DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
613 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
614 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
616 // Client Handle with the same clientHandle as the request
617 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
618 new COPSHandle(getClientHandle().getId()), decisionMap, null);
619 // new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
620 // new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
622 // ** Send the GateSet Decision
625 decisionMsg.writeData(_sock);
626 } catch (IOException e) {
627 logger.error("Failed to send the decision", e);
633 * Sends a message asking that the request state be deleted
635 * @throws COPSPdpException
637 public void sendGateDelete(int gID) throws COPSPdpException {
639 * Example of an UNSOLICITED decision <Gate Control Command> = <COPS
640 * Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI
641 * Data> <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
642 * <PDP-Config> | <Synch-Request> | <Msg-Receipt> <Gate-Delete> =
643 * <Decision Header> <TransactionID> <AMID> <SubscriberID> <GateID>
645 // Common Header with the same ClientType as the request
646 final IPCMMGate gate = new PCMMGateReq();
647 final ITransactionID trID = new TransactionID();
649 final IAMID amid = new AMID();
650 final ISubscriberID subscriberID = new SubscriberID();
651 final IGateSpec gateSpec = new GateSpec();
652 final IGateID gateID = new GateID();
654 // set transaction ID to gate set
655 trID.setGateCommandType(ITransactionID.GateDelete);
656 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
657 trID.setTransactionIdentifier(_transactionID);
659 amid.setApplicationType((short) 1);
660 amid.setApplicationMgrTag((short) 1);
661 gateID.setGateID(gID);
664 InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
665 subscriberID.setSourceIPAddress(subIP);
666 } catch (UnknownHostException unae) {
667 logger.error("Error getByName", unae);
670 gate.setTransactionID(trID);
672 gate.setSubscriberID(subscriberID);
673 gate.setGateID(gateID);
676 final byte[] data = gate.getData();
678 final Set<COPSDecision> decisionSet = new HashSet<>();
679 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
680 new COPSData(data, 0, data.length)));
681 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
682 decisionMap.put(new COPSContext(RType.CONFIG, (short) 0), decisionSet);
684 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
685 new COPSHandle(getClientHandle().getId()), decisionMap, null);
686 // new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
687 // new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
689 // ** Send the GateDelete Decision
692 decisionMsg.writeData(_sock);
693 // decisionMsg.writeData(socket_id);
694 } catch (IOException e) {
695 logger.error("Failed to send the decision", e);
700 * Sends a request asking that a new request state be created
702 * @throws COPSPdpException
704 public void sendOpenNewRequestState() throws COPSPdpException {
706 * <Decision Message> ::= <Common Header: Flag UNSOLICITED> <Client
707 * Handle> *(<Decision>) [<Integrity>] <Decision> ::= <Context>
708 * <Decision: Flags> <Decision: Flags> ::= Install Request-State
711 final Set<COPSDecision> decisionSet = new HashSet<>();
712 decisionSet.add(new COPSDecision(Command.INSTALL, DecisionFlag.REQSTATE));
713 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
714 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
716 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), new COPSHandle(_handle.getId()),
720 decisionMsg.writeData(_sock);
721 } catch (IOException e) {
722 throw new COPSPdpException(
723 "Failed to send the open new request state, reason: "
729 * Sends a message asking for a COPS sync operation
731 * @throws COPSPdpException
733 public void sendGateInfo() throws COPSPdpException {
735 * <Gate-Info> ::= <Common Header> [<Client Handle>] [<Integrity>]
737 final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
739 msg.writeData(_sock);
740 } catch (IOException e) {
741 throw new COPSPdpException(
742 "Failed to send the GateInfo request, reason: "
748 * Sends a message asking for a COPS sync operation
750 * @throws COPSPdpException
752 public void sendSyncRequest() throws COPSPdpException {
754 * <Synchronize State Request> ::= <Common Header> [<Client Handle>]
758 // Client Handle with the same clientHandle as the request
759 final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
761 msg.writeData(_sock);
762 } catch (IOException e) {
763 throw new COPSPdpException(
764 "Failed to send the sync state request, reason: "
769 public void sendSyncRequestState() throws COPSPdpException {
772 public void sendDeleteRequestState() throws COPSPdpException {