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;
19 import org.umu.cops.stack.COPSHeader.OPCode;
20 import org.umu.cops.stack.COPSObjHeader.CNum;
21 import org.umu.cops.stack.COPSObjHeader.CType;
23 import java.io.IOException;
24 import java.net.InetAddress;
25 import java.net.Socket;
26 import java.net.UnknownHostException;
27 import java.util.HashMap;
28 import java.util.HashSet;
35 * Example of an UNSOLICITED decision
37 * <Gate Control Command> = <COPS Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI Data>
39 * <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
40 * <PDP-Config> | <Synch-Request> | <Msg-Receipt>
41 * <Gate-Set> = <Decision Header> <TransactionID> <AMID> <SubscriberID> [<GateID>] <GateSpec>
42 * <Traffic Profile> <classifier> [<classifier...>] [<Event Generation Info>]
43 * [<Volume-Based Usage Limit>] [<Time-Based Usage Limit>][<Opaque Data>] [<UserID>]
47 * COPS message transceiver class for provisioning connections at the PDP side.
49 public class PCMMPdpMsgSender {
51 public final static Logger logger = LoggerFactory.getLogger(PCMMPdpMsgSender.class);
54 * Socket connected to PEP
56 protected final Socket _sock;
59 * COPS client-type that identifies the policy client
61 protected final short _clientType;
64 * COPS client handle used to uniquely identify a particular PEP's request
67 protected final COPSHandle _handle;
72 protected short _transactionID;
73 protected final short _classifierID;
74 // XXX - this does not need to be here
75 protected IGateID _gateID;
78 * Creates a PCMMPdpMsgSender
87 public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock)
88 throws COPSPdpException {
89 this(clientType, (short)0, clientHandle, sock);
92 public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
93 final Socket sock) throws COPSPdpException {
94 if (clientHandle == null) throw new COPSPdpException("Client handle must not be null");
95 if (sock == null) throw new COPSPdpException("Socket must not be null");
97 _handle = clientHandle;
98 _clientType = clientType;
105 * Gets the client-type
107 * @return Client-type value
109 public short getClientType() {
114 * Gets the transaction-id
116 * @return transaction-id value
118 public short getTransactionID() {
119 return _transactionID;
125 * @return the gate-id value
127 public IGateID getGateID() {
132 * Sends a PCMM GateSet COPS Decision message
133 * @param gate - the gate
134 * @throws COPSPdpException
136 public void sendGateSet(final IPCMMGate gate) throws COPSPdpException {
137 final ITransactionID trID = new TransactionID();
139 // set transaction ID to gate set
140 trID.setGateCommandType(ITransactionID.GateSet);
141 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
142 trID.setTransactionIdentifier(_transactionID);
144 gate.setTransactionID(trID);
145 // retain the transactionId to gate request mapping for gateID recovery after response
146 // see PCMMPdpReqStateMan.processReport()
147 final Short trIDnum = trID.getTransactionIdentifier();
148 logger.info("Adding gate to cache - " + gate + " with key - " + trIDnum);
149 PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
151 // new pcmm specific clientsi
152 final byte[] data = gate.getData();
153 // Common Header with the same ClientType as the request
154 // Client Handle with the same clientHandle as the request
156 final Set<COPSDecision> decisionSet = new HashSet<>();
157 decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
158 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
159 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
161 final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
163 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
164 decisionMap, null, clientSD);
166 // ** Send the GateSet Decision
168 decisionMsg.writeData(_sock);
169 } catch (IOException e) {
170 logger.error("Failed to send the decision", e);
176 * Sends a PCMM GateSet COPS Decision message
178 * @param num - the number
179 * @throws COPSPdpException
181 public void sendGateSetDemo(int num) throws COPSPdpException {
182 final IPCMMGate gate = new PCMMGateReq();
183 final ITransactionID trID = new TransactionID();
184 final IAMID amid = new AMID();
185 final ISubscriberID subscriberID = new SubscriberID();
186 final IGateSpec gateSpec = new GateSpec();
187 final IClassifier classifier = new Classifier();
188 final IExtendedClassifier eclassifier = new ExtendedClassifier();
189 final int trafficRate;
191 trafficRate = PCMMGlobalConfig.DefaultBestEffortTrafficRate;
193 trafficRate = PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
195 final ITrafficProfile trafficProfile = new BestEffortService(
196 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
197 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
198 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
199 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
200 .setMaximumTrafficBurst(
201 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
202 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
203 .setRequestTransmissionPolicy(
204 PCMMGlobalConfig.BETransmissionPolicy);
205 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
206 .setMaximumSustainedTrafficRate(
208 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
209 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
211 ((BestEffortService) trafficProfile).getReservedEnvelop()
212 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
213 ((BestEffortService) trafficProfile).getReservedEnvelop()
214 .setMaximumTrafficBurst(
215 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
216 ((BestEffortService) trafficProfile).getReservedEnvelop()
217 .setRequestTransmissionPolicy(
218 PCMMGlobalConfig.BETransmissionPolicy);
219 ((BestEffortService) trafficProfile).getReservedEnvelop()
220 .setMaximumSustainedTrafficRate(
222 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
223 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
226 ((BestEffortService) trafficProfile).getCommittedEnvelop()
227 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
228 ((BestEffortService) trafficProfile).getCommittedEnvelop()
229 .setMaximumTrafficBurst(
230 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
231 ((BestEffortService) trafficProfile).getCommittedEnvelop()
232 .setRequestTransmissionPolicy(
233 PCMMGlobalConfig.BETransmissionPolicy);
234 ((BestEffortService) trafficProfile).getCommittedEnvelop()
235 .setMaximumSustainedTrafficRate(
237 // PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
238 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
242 // set transaction ID to gate set
243 trID.setGateCommandType(ITransactionID.GateSet);
244 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
245 trID.setTransactionIdentifier(_transactionID);
247 amid.setApplicationType((short) 1);
248 amid.setApplicationMgrTag((short) 1);
249 gateSpec.setDirection(Direction.UPSTREAM);
250 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
251 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
252 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
253 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
254 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
256 // XXX - if the version major is less than 4 we need to use Classifier
257 // TODO - Use some variable here or remove...
259 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
260 // eclassifier.setProtocol(IClassifier.Protocol.TCP);
262 InetAddress subIP = InetAddress
263 .getByName(PCMMGlobalConfig.SubscriberID);
264 InetAddress srcIP = InetAddress
265 .getByName(PCMMGlobalConfig.srcIP);
266 InetAddress dstIP = InetAddress
267 .getByName(PCMMGlobalConfig.dstIP);
268 InetAddress mask = InetAddress.getByName("0.0.0.0");
269 subscriberID.setSourceIPAddress(subIP);
270 eclassifier.setSourceIPAddress(srcIP);
271 eclassifier.setDestinationIPAddress(dstIP);
272 eclassifier.setIPDestinationMask(mask);
273 eclassifier.setIPSourceMask(mask);
274 } catch (UnknownHostException unae) {
275 logger.error("Error getByName", unae);
277 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
278 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
279 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
280 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
281 eclassifier.setActivationState((byte) 0x01);
282 // check if we have a stored value of classifierID else we just
285 // eclassifier.setClassifierID((short) 0x01);
286 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
287 .random() * hashCode() : _classifierID));
289 // eclassifier.setClassifierID((short) 1);
291 eclassifier.setAction((byte) 0x00);
292 // XXX - temp default until Gate Modify is hacked in
293 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
294 eclassifier.setPriority((byte) 65);
297 // classifier.setProtocol(IClassifier.Protocol.TCP);
299 InetAddress subIP = InetAddress
300 .getByName(PCMMGlobalConfig.SubscriberID);
301 InetAddress srcIP = InetAddress
302 .getByName(PCMMGlobalConfig.srcIP);
303 InetAddress dstIP = InetAddress
304 .getByName(PCMMGlobalConfig.dstIP);
305 subscriberID.setSourceIPAddress(subIP);
306 classifier.setSourceIPAddress(srcIP);
307 classifier.setDestinationIPAddress(dstIP);
308 } catch (UnknownHostException unae) {
309 logger.error("Error getByName", unae);
311 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
312 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
315 gate.setTransactionID(trID);
317 gate.setSubscriberID(subscriberID);
318 gate.setGateSpec(gateSpec);
319 gate.setTrafficProfile(trafficProfile);
320 gate.setClassifier(eclassifier);
322 final byte[] data = gate.getData();
324 final Set<COPSDecision> decisionSet = new HashSet<>();
325 decisionSet.add(new COPSDecision(CType.NA, Command.INSTALL, DecisionFlag.REQERROR));
326 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
327 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
328 final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
330 // Common Header with the same ClientType as the request
331 // Client Handle with the same clientHandle as the request
332 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
333 new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
335 // ** Send the GateSet Decision
338 decisionMsg.writeData(_sock);
339 } catch (IOException e) {
340 logger.error("Failed to send the decision", e);
345 * Sends a PCMM GateSet COPS Decision message
346 * @throws COPSPdpException
348 public void sendGateSetBestEffortWithExtendedClassifier() throws COPSPdpException {
349 final IPCMMGate gate = new PCMMGateReq();
350 final ITransactionID trID = new TransactionID();
351 final IAMID amid = new AMID();
352 final ISubscriberID subscriberID = new SubscriberID();
353 final IGateSpec gateSpec = new GateSpec();
354 final IClassifier classifier = new Classifier();
355 final IExtendedClassifier eclassifier = new ExtendedClassifier();
357 // XXX check if other values should be provided
359 final ITrafficProfile trafficProfile = new BestEffortService(
360 (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
361 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
362 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
363 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
364 .setMaximumTrafficBurst(
365 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
366 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
367 .setRequestTransmissionPolicy(
368 PCMMGlobalConfig.BETransmissionPolicy);
369 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
370 .setMaximumSustainedTrafficRate(
371 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
372 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
374 ((BestEffortService) trafficProfile).getReservedEnvelop()
375 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
376 ((BestEffortService) trafficProfile).getReservedEnvelop()
377 .setMaximumTrafficBurst(
378 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
379 ((BestEffortService) trafficProfile).getReservedEnvelop()
380 .setRequestTransmissionPolicy(
381 PCMMGlobalConfig.BETransmissionPolicy);
382 ((BestEffortService) trafficProfile).getReservedEnvelop()
383 .setMaximumSustainedTrafficRate(
384 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
385 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
388 ((BestEffortService) trafficProfile).getCommittedEnvelop()
389 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
390 ((BestEffortService) trafficProfile).getCommittedEnvelop()
391 .setMaximumTrafficBurst(
392 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
393 ((BestEffortService) trafficProfile).getCommittedEnvelop()
394 .setRequestTransmissionPolicy(
395 PCMMGlobalConfig.BETransmissionPolicy);
396 ((BestEffortService) trafficProfile).getCommittedEnvelop()
397 .setMaximumSustainedTrafficRate(
398 PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
399 // PCMMGlobalConfig.DefaultBestEffortTrafficRate);
403 // set transaction ID to gate set
404 trID.setGateCommandType(ITransactionID.GateSet);
405 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
406 trID.setTransactionIdentifier(_transactionID);
408 amid.setApplicationType((short) 1);
409 amid.setApplicationMgrTag((short) 1);
410 gateSpec.setDirection(Direction.UPSTREAM);
411 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
412 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
413 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
414 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
415 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
417 // XXX - if the version major is less than 4 we need to use Classifier
419 //eclassifier.setProtocol(IClassifier.Protocol.NONE);
420 // eclassifier.setProtocol(IClassifier.Protocol.TCP);
422 InetAddress subIP = InetAddress
423 .getByName(PCMMGlobalConfig.SubscriberID);
424 InetAddress srcIP = InetAddress
425 .getByName(PCMMGlobalConfig.srcIP);
426 InetAddress dstIP = InetAddress
427 .getByName(PCMMGlobalConfig.dstIP);
428 InetAddress mask = InetAddress.getByName("0.0.0.0");
429 subscriberID.setSourceIPAddress(subIP);
430 eclassifier.setSourceIPAddress(srcIP);
431 eclassifier.setDestinationIPAddress(dstIP);
432 eclassifier.setIPDestinationMask(mask);
433 eclassifier.setIPSourceMask(mask);
434 } catch (UnknownHostException unae) {
435 logger.error("Error getByName", unae);
437 eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
438 eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
439 eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
440 eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
441 eclassifier.setActivationState((byte) 0x01);
442 // check if we have a stored value of classifierID else we just
445 // eclassifier.setClassifierID((short) 0x01);
446 eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
447 .random() * hashCode() : _classifierID));
449 // eclassifier.setClassifierID((short) 1);
451 eclassifier.setAction((byte) 0x00);
452 // XXX - temp default until Gate Modify is hacked in
453 // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
454 eclassifier.setPriority((byte) 65);
457 // classifier.setProtocol(IClassifier.Protocol.TCP);
459 InetAddress subIP = InetAddress
460 .getByName(PCMMGlobalConfig.SubscriberID);
461 InetAddress srcIP = InetAddress
462 .getByName(PCMMGlobalConfig.srcIP);
463 InetAddress dstIP = InetAddress
464 .getByName(PCMMGlobalConfig.dstIP);
465 subscriberID.setSourceIPAddress(subIP);
466 classifier.setSourceIPAddress(srcIP);
467 classifier.setDestinationIPAddress(dstIP);
468 } catch (UnknownHostException unae) {
469 logger.error("Error getByName", unae);
471 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
472 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
475 gate.setTransactionID(trID);
477 gate.setSubscriberID(subscriberID);
478 gate.setGateSpec(gateSpec);
479 gate.setTrafficProfile(trafficProfile);
480 gate.setClassifier(eclassifier);
482 byte[] data = gate.getData();
484 final Set<COPSDecision> decisionSet = new HashSet<>();
485 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR));
486 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
487 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
488 final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
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(_handle.getId()),
493 decisionMap, null, clientSD);
495 // ** Send the GateSet Decision
498 decisionMsg.writeData(_sock);
499 } catch (IOException e) {
500 logger.error("Failed to send the decision", e);
506 public boolean handleGateReport(final Socket socket) throws COPSPdpException {
508 // waits for the gate-set-ack or error
509 final COPSMsg responseMsg = COPSTransceiver.receiveMsg(socket);
510 if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
511 logger.info("processing received report from CMTS");
512 final COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
513 if (reportMsg.getClientSI() == null) {
516 final IPCMMGate responseGate = new PCMMGateReq(reportMsg.getClientSI().getData().getData());
517 if (responseGate.getTransactionID() != null
518 && responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
519 logger.info("the CMTS has sent a Gate-Set-Ack response");
520 // here CMTS responded that he acknowledged the Gate-Set
521 // TODO do further check of Gate-Set-Ack GateID etc...
522 _gateID = responseGate.getGateID();
529 } catch (Exception e) { // COPSException, IOException
530 throw new COPSPdpException("Error COPSTransceiver.receiveMsg", e);
536 * Sends a PCMM GateSet COPS Decision message
538 * @throws COPSPdpException
540 public void sendGateSet() throws COPSPdpException {
541 // Common Header with the same ClientType as the request
543 final IPCMMGate gate = new PCMMGateReq();
544 final ITransactionID trID = new TransactionID();
546 final IAMID amid = new AMID();
547 final ISubscriberID subscriberID = new SubscriberID();
548 final IGateSpec gateSpec = new GateSpec();
549 final IClassifier classifier = new Classifier();
550 // XXX check if other values should be provided
551 final ITrafficProfile trafficProfile = new BestEffortService(
552 BestEffortService.DEFAULT_ENVELOP);
553 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
554 .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
555 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
556 .setMaximumTrafficBurst(
557 BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
558 ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
559 .setRequestTransmissionPolicy(
560 PCMMGlobalConfig.BETransmissionPolicy);
562 // byte[] content = "1234".getBytes();
564 // handle.setId(new COPSData(content, 0, content.length));
566 // set transaction ID to gate set
567 trID.setGateCommandType(ITransactionID.GateSet);
568 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
569 trID.setTransactionIdentifier(_transactionID);
571 amid.setApplicationType((short) 1);
572 amid.setApplicationMgrTag((short) 1);
573 gateSpec.setDirection(Direction.UPSTREAM);
574 gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
575 gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
576 gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
577 gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
578 gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
581 * ((DOCSISServiceClassNameTrafficProfile) trafficProfile)
582 * .setServiceClassName("S_up");
585 // classifier.setProtocol(IClassifier.Protocol.TCP);
587 InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
588 InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
589 InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
590 subscriberID.setSourceIPAddress(subIP);
591 classifier.setSourceIPAddress(srcIP);
592 classifier.setDestinationIPAddress(dstIP);
593 } catch (UnknownHostException unae) {
594 logger.error("Error getByName", unae);
596 classifier.setSourcePort(PCMMGlobalConfig.srcPort);
597 classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
599 gate.setTransactionID(trID);
601 gate.setSubscriberID(subscriberID);
602 gate.setGateSpec(gateSpec);
603 gate.setTrafficProfile(trafficProfile);
604 gate.setClassifier(classifier);
606 final byte[] data = gate.getData();
608 final Set<COPSDecision> decisionSet = new HashSet<>();
609 decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR));
610 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
611 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
613 final COPSClientSI clientSD = new COPSClientSI(CSIType.NAMED, new COPSData(data, 0, data.length));
615 // Client Handle with the same clientHandle as the request
616 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
617 new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
619 // ** Send the GateSet Decision
622 decisionMsg.writeData(_sock);
623 } catch (IOException e) {
624 logger.error("Failed to send the decision", e);
629 * Sends a message asking that the request state be deleted
631 * @throws COPSPdpException
633 public void sendGateDelete(final IPCMMGate gate) throws COPSPdpException {
634 // set transaction ID to gate set
635 final ITransactionID trID = new TransactionID();
636 trID.setGateCommandType(ITransactionID.GateDelete);
637 _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
638 trID.setTransactionIdentifier(_transactionID);
639 gate.setTransactionID(trID);
641 Short trIDnum = trID.getTransactionIdentifier();
642 PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
644 // gateDelete only requires AMID, subscriberID, and gateID
645 // remove the gateSpec, traffic profile, and classifiers from original gate request
646 gate.setGateSpec(null);
647 gate.setTrafficProfile(null);
648 gate.setClassifier(null);
649 // clear the error object
653 final byte[] data = gate.getData();
654 final Set<COPSDecision> decisionSet = new HashSet<>();
655 decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
656 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
657 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
658 final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
660 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
661 new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
663 // ** Send the GateDelete Decision
666 decisionMsg.writeData(_sock);
667 // decisionMsg.writeData(socket_id);
668 } catch (IOException e) {
669 logger.error("Failed to send the decision", e);
674 * Sends a request asking that a new request state be created
676 * @throws COPSPdpException
678 public void sendOpenNewRequestState() throws COPSPdpException {
680 * <Decision Message> ::= <Common Header: Flag UNSOLICITED> <Client
681 * Handle> *(<Decision>) [<Integrity>] <Decision> ::= <Context>
682 * <Decision: Flags> <Decision: Flags> ::= Install Request-State
685 final Set<COPSDecision> decisionSet = new HashSet<>();
686 decisionSet.add(new COPSDecision(Command.INSTALL, DecisionFlag.REQSTATE));
687 final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
688 decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
690 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), new COPSHandle(_handle.getId()),
691 decisionMap, null, null);
694 decisionMsg.writeData(_sock);
695 } catch (IOException e) {
696 throw new COPSPdpException("Failed to send the open new request state", e);
701 * Sends a message asking for a COPS sync operation
703 * @throws COPSPdpException
705 public void sendGateInfo() throws COPSPdpException {
707 * <Gate-Info> ::= <Common Header> [<Client Handle>] [<Integrity>]
709 final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
711 msg.writeData(_sock);
712 } catch (IOException e) {
713 throw new COPSPdpException("Failed to send the GateInfo request", e);
718 * Sends a message asking for a COPS sync operation
720 * @throws COPSPdpException
722 public void sendSyncRequest() throws COPSPdpException {
724 * <Synchronize State Request> ::= <Common Header> [<Client Handle>]
728 // Client Handle with the same clientHandle as the request
729 final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
731 msg.writeData(_sock);
732 } catch (IOException e) {
733 throw new COPSPdpException("Failed to send the sync state request", e);
737 public void sendSyncRequestState() throws COPSPdpException {
740 public void sendDeleteRequestState() throws COPSPdpException {