Fix Bug 6299 and formatting issues 17/44317/2
authorMufaddal Makati <m.makati@cablelabs.com>
Thu, 18 Aug 2016 20:29:23 +0000 (14:29 -0600)
committerMufaddal Makati <m.makati@cablelabs.com>
Wed, 24 Aug 2016 17:03:35 +0000 (11:03 -0600)
- Fixed bug - https://bugs.opendaylight.org/show_bug.cgi?id=6299
- Fixed tabs and spacing issue

Change-Id: Ifc42607ba8f4019de05284971c9d979c024d28bf
Signed-off-by: Mufaddal Makati <m.makati@cablelabs.com>
packetcable-policy-server/src/main/java/org/opendaylight/controller/packetcable/provider/PCMMGateReqBuilder.java
packetcable-policy-server/src/main/java/org/opendaylight/controller/packetcable/provider/PacketcableProvider.java

index 472e481dce22871982405a1139b2996c0aabb709..f3d4b791b1e1dde5b85cb98e521c1543ea44ecb4 100644 (file)
@@ -70,7 +70,7 @@ public class PCMMGateReqBuilder {
 
     public PCMMGateReq build() {
         return new PCMMGateReq(amid, subscriberID, transactionID, gateSpec, trafficProfile, classifiers,
-                       gateID, error, gateState, gateTimeInfo, gateUsageInfo);
+                gateID, error, gateState, gateTimeInfo, gateUsageInfo);
     }
 
     public void setAmId(final AmId qosAmId) {
@@ -168,33 +168,33 @@ public class PCMMGateReqBuilder {
         byte tosMask = (byte)0x0;
         short srcPort = (short) 0;
         short dstPort = (short) 0;
-        byte priority = (byte) 64;
-        //byte priority = index.byteValue();
-        
+        //byte priority = (byte) 64;
+        byte priority = (byte) (64+index);
+
         // Legacy classifier
-        
+
         // Protocol -- zero is match any
         if (qosClassifier.getProtocol() != null) {
             protocol = Protocol.valueOf(qosClassifier.getProtocol().getValue().shortValue());
         } else {
             protocol = Protocol.NONE;
         }
-        
-         // IP Addresss and mask wildcards - addr byte 0 for no match (or match anything)
-        
+
+        // IP Addresss and mask wildcards - addr byte 0 for no match (or match anything)
+
         Inet4Address srcAddress = (Inet4Address) getByName("0.0.0.0");
-        
+
         if (qosClassifier.getSrcIp() != null) {
-               srcAddress = (Inet4Address) getByName(qosClassifier.getSrcIp().getValue());
+            srcAddress = (Inet4Address) getByName(qosClassifier.getSrcIp().getValue());
         }
-        
+
         Inet4Address dstAddress = (Inet4Address) getByName("0.0.0.0");
-        
+
         if (qosClassifier.getDstIp() != null) {
             dstAddress = (Inet4Address) getByName(qosClassifier.getDstIp().getValue());
         }
-        
-        
+
+
         if (qosClassifier.getSrcPort() != null) {
             srcPort = qosClassifier.getSrcPort().getValue().shortValue();
         }
@@ -212,12 +212,12 @@ public class PCMMGateReqBuilder {
         }
         // push the classifier to the gate request
         classifiers.add(new org.pcmm.gates.impl.Classifier(protocol, tosOverwrite, tosMask, srcAddress, dstAddress, srcPort,
-                        dstPort, priority));
+                dstPort, priority));
     }
-    
+
     private void addExtClassifier(final Short index, final ExtClassifier qosExtClassifier) {
         // Extended classifier
-        final byte priority = (byte) 64;
+        final byte priority = (byte) (index+64);
         final ActivationState activationState = ActivationState.ACTIVE;
         // Protocol -- zero is match any
         final Protocol protocol;
@@ -281,25 +281,25 @@ public class PCMMGateReqBuilder {
         Inet4Address srcIpAddr = (Inet4Address) getByName("0.0.0.0");
 
         if (qosExtClassifier.getSrcIp() != null) {
-               srcIpAddr = getInet4Address(qosExtClassifier.getSrcIp());
+            srcIpAddr = getInet4Address(qosExtClassifier.getSrcIp());
         }
-        
+
         Inet4Address dstIpAddr = (Inet4Address) getByName("0.0.0.0");
         if (qosExtClassifier.getDstIp() != null) {
-               dstIpAddr = getInet4Address(qosExtClassifier.getDstIp());
+            dstIpAddr = getInet4Address(qosExtClassifier.getDstIp());
         }
-        
+
         //mask
         Inet4Address srcIpMask = (Inet4Address) getByName("255.255.255.255");
         if (qosExtClassifier.getSrcIpMask() != null) {
-               srcIpMask = getInet4Address(qosExtClassifier.getSrcIpMask());
+            srcIpMask = getInet4Address(qosExtClassifier.getSrcIpMask());
         }
-        
+
         Inet4Address dstIpMask = (Inet4Address) getByName("255.255.255.255");
         if (qosExtClassifier.getDstIpMask() != null) {
-               dstIpMask = getInet4Address(qosExtClassifier.getDstIpMask());
+            dstIpMask = getInet4Address(qosExtClassifier.getDstIpMask());
         }
-        
+
         // TODO - find out what the classifier ID should really be. It was never getting set previously
         final short classifierId = (short)index;
 
@@ -339,7 +339,7 @@ public class PCMMGateReqBuilder {
         // TODO - try to make these two variables immutable
         byte srcPrefixLen = (byte) 128;
         Inet6Address srcAddress = (Inet6Address) getByName("0::0");
-        
+
         if (qosIpv6Classifier.getSrcIp6() != null) {
             String[] parts = qosIpv6Classifier.getSrcIp6().getValue().split("/");
             String Ipv6AddressStr = parts[0];
@@ -414,15 +414,15 @@ public class PCMMGateReqBuilder {
             tcMask = qosIpv6Classifier.getTcHigh().getValue().byteValue();
         else if (qosIpv6Classifier.getTcLow() != null) tcMask = (byte) 0xff;
         else tcMask = (byte) 0x00;
-        
+
         FlowLabel flowLabelFlag = FlowLabel.IRRELEVANT;
         int flowLabelId = 0;
-        
+
         if (qosIpv6Classifier.getFlowLabel() != null) {
-               flowLabelFlag = FlowLabel.VALID;
-               flowLabelId = qosIpv6Classifier.getFlowLabel().intValue();
+            flowLabelFlag = FlowLabel.VALID;
+            flowLabelId = qosIpv6Classifier.getFlowLabel().intValue();
         }
-        
+
 
         // TODO - find out what the classifier ID should really be. It was never getting set previously
         final short classifierId = (short)index;
@@ -432,7 +432,7 @@ public class PCMMGateReqBuilder {
 
         // push the IPv6 classifier to the gate request
         classifiers.add(
-                new org.pcmm.gates.impl.IPv6Classifier(srcAddress, dstAddress, srcPortBegin, dstPortBegin, (byte) 64,
+                new org.pcmm.gates.impl.IPv6Classifier(srcAddress, dstAddress, srcPortBegin, dstPortBegin, (byte) (index+64),
                         srcPortEnd, dstPortEnd, classifierId, ActivationState.ACTIVE, action, flowLabelFlag, tcLow,
                         tcHigh, tcMask, flowLabelId, nextHdr, srcPrefixLen, dstPrefLen));
     }
index 1bbf5b283d63eb75887f53cac290d61413a5c4d3..3fae8074f4415cb2f97f6efb91ba8e6cdeb911ac 100644 (file)
@@ -151,8 +151,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
     @Override
     public void onSessionInitiated(ProviderContext session) {
         logger.info("Packetcable Session Initiated");
-        logger.info("logging levels: error={}, warn={}, info={}, debug={}, trace={}", logger.isErrorEnabled(),
-                logger.isWarnEnabled(), logger.isInfoEnabled(), logger.isDebugEnabled(), logger.isTraceEnabled());
+        logger.info("logging levels: error={}, warn={}, info={}, debug={}, trace={}", logger.isErrorEnabled(), logger.isWarnEnabled(), logger.isInfoEnabled(), logger.isDebugEnabled(), logger.isTraceEnabled());
 
         dataBroker = session.getSALService(DataBroker.class);
 
@@ -303,7 +302,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
     // ValidationException does not need to be thrown again
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
     private <T extends DataObject> void saveErrors(@Nonnull Map<InstanceIdentifier<T>, ValidationException> errorMap,
-            @Nonnull Map<InstanceIdentifier<T>, T> dataMap) {
+                                                   @Nonnull Map<InstanceIdentifier<T>, T> dataMap) {
 
         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
 
@@ -611,7 +610,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
 
         @Override
         protected void handleUpdatedData(final Map<InstanceIdentifier<Ccap>, Ccap> updatedCcaps,
-                final Map<InstanceIdentifier<Ccap>, Ccap> originalCcaps) {
+                                         final Map<InstanceIdentifier<Ccap>, Ccap> originalCcaps) {
 
             // TODO actually support updates
 
@@ -644,7 +643,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
 
         @Override
         protected void handleRemovedData(final Set<InstanceIdentifier<Ccap>> removedCcapPaths,
-                final Map<InstanceIdentifier<Ccap>, Ccap> originalCcaps) {
+                                         final Map<InstanceIdentifier<Ccap>, Ccap> originalCcaps) {
 
             for (InstanceIdentifier<Ccap> iid : removedCcapPaths) {
                 final Ccap nukedCcap = originalCcaps.get(iid);
@@ -803,7 +802,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
         }
 
         private void saveGateError(@Nonnull final InstanceIdentifier<Gate> gateIID, @Nonnull final String gatePathStr,
-                @Nonnull final String error) {
+                                   @Nonnull final String error) {
             checkNotNull(gateIID);
             checkNotNull(error);
 
@@ -822,7 +821,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
 
         @Override
         protected void handleUpdatedData(final Map<InstanceIdentifier<Gate>, Gate> updatedData,
-                final Map<InstanceIdentifier<Gate>, Gate> originalData) {
+                                         final Map<InstanceIdentifier<Gate>, Gate> originalData) {
             // TODO actually support updates
 
             // update operation not allowed -- restore the original config object and complain
@@ -852,7 +851,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
 
         @Override
         protected void handleRemovedData(final Set<InstanceIdentifier<Gate>> removedPaths,
-                final Map<InstanceIdentifier<Gate>, Gate> originalData) {
+                                         final Map<InstanceIdentifier<Gate>, Gate> originalData) {
 
             for (final InstanceIdentifier<Gate> removedGateIID : removedPaths) {
 
@@ -870,8 +869,7 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
                     final PCMMService service = pcmmServiceMap.get(thisCcap.getCcapId());
                     if (service != null) {
                         service.sendGateDelete(gatePathStr);
-                        logger.info("onDataChanged(): removed QoS gate {} for {}/{}/{}: ", gateId, ccapId, gatePathStr,
-                                thisGate);
+                        logger.info("onDataChanged(): removed QoS gate {} for {}/{}/{}: ", gateId, ccapId, gatePathStr,thisGate);
                     } else {
                         logger.warn("Unable to send to locate PCMMService to send gate delete message with CCAP - "
                                 + thisCcap);
@@ -1241,82 +1239,111 @@ public class PacketcableProvider implements BindingAwareProvider, AutoCloseable,
                 rpcResponse = gatePathStr + ": Subscriber ID not provided; gate poll not performed";
             } else {
                 //poll all gates for the appId
+                PollAllGatesForApp pollAllGatesForApp = new PollAllGatesForApp(appIid,app);
+                Thread t = new Thread(pollAllGatesForApp);
+                t.start();
+                rpcResponse = appKey.getAppId() + "/: gate subtree poll in progress";
+            }
+        }
 
-                Subscribers subs = app.getSubscribers();
+        DateAndTime rpcDateAndTime = getNowTimeStamp();
 
-                logger.info("qospollgates subscribers: " + subs.toString());
+        QosPollGatesOutputBuilder outputBuilder = new QosPollGatesOutputBuilder().setTimestamp(rpcDateAndTime)
+                .setResponse(rpcResponse)
+                .setGate(gateOutputBuilder.build());
+        return Futures.immediateFuture(RpcResultBuilder.success(outputBuilder.build()).build());
+    }
+    private class PollAllGatesForApp implements Runnable {
 
-                List<Subscriber> subList = subs.getSubscriber();
-                logger.info("qospollgates subList: " + subList.toString());
-                for (Subscriber sub : subList) {
+        private InstanceIdentifier <App> appIid;
+        private App app;
 
-                    //generate active subIid
-                    subscriberId = sub.getSubscriberId();
-                    InstanceIdentifier<Subscriber> subIid = appIid.builder()
-                            .child(Subscribers.class)
-                            .child(Subscriber.class, new SubscriberKey(subscriberId))
-                            .build();
+        private PollAllGatesForApp (InstanceIdentifier <App> appIid, App app) {
+            this.app = app;
+            this.appIid = appIid;
+        }
 
-                    List<Gate> gateList = sub.getGates().getGate();
-                    for (Gate gate : gateList) {
-                        //logger.info("qospollgates active gate: "+gate);
+        @Override
+        public void run() {
 
-                        //generate active gateIid
-                        gateId = gate.getGateId();
-                        InstanceIdentifier<Gate> gateIid =
-                                subIid.builder().child(Gates.class).child(Gate.class, new GateKey(gateId)).build();
+            org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.qos.poll.gates.output.GateBuilder gateOutputBuilder =
+                    new org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.qos.poll.gates.output.GateBuilder();
 
-                        opsGate = readGateFromOperationalDatastore(gateIid);
-                        opsCopsGateId = opsGate.getCopsGateId();
-                        //generate active gatePathStr
-                        gatePathStr = appKey.getAppId() + "/" + subscriberId + "/" + gateId;
-                        if ((!Objects.equals(opsCopsGateId, "")) && (!Objects.equals(opsCopsGateId, null))) {
-                            ccapId = findCcapForSubscriberId(getInetAddress(subscriberId)).getCcapId();
-                            PCMMService pcmmService = pcmmServiceMap.get(ccapId);
-                            //is the CCAP socket open?
-                            if (!pcmmService.getPcmmPdpSocket() && pcmmService.getPcmmCcapClientIsConnected()) {
-                                PCMMService.GateSendStatus status = pcmmService.sendGateInfo(gatePathStr);
-                                DateAndTime gateDateAndTime = getNowTimeStamp();
-                                gateOutputError = Collections.singletonList(status.getMessage());
+            GateBuilder gateBuilder = new GateBuilder();
 
+            //generate appKey
+            AppKey appKey = InstanceIdentifier.keyOf(appIid);
 
-                                gateBuilder.setGateId(gateId)
-                                        .setGatePath(gatePathStr)
-                                        .setCcapId(ccapId)
-                                        .setCopsGateState(
-                                                status.getCopsGateState() + "/" + status.getCopsGateStateReason())
-                                        .setCopsGateTimeInfo(status.getCopsGateTimeInfo())
-                                        .setCopsGateUsageInfo(status.getCopsGateUsageInfo())
-                                        .setCopsGateId(status.getCopsGateId())
-                                        .setError(gateOutputError)
-                                        .setTimestamp(gateDateAndTime);
+            Subscribers subs = app.getSubscribers();
+            logger.info("qospollgates subscribers: " + subs.toString());
 
-                                mdsalUtils.put(LogicalDatastoreType.OPERATIONAL, gateIid, gateBuilder.build());
-                            } else {
-                                logger.info(
-                                        "qospollgates: {}: CCAP socket is down or client disconnected; gate poll not performed",
-                                        ccapId);
-                            }
+            List<Subscriber> subList = subs.getSubscriber();
+            logger.info("qospollgates subList: " + subList.toString());
+
+            for (Subscriber sub : subList) {
+                //generate active subIid
+                String subscriberId = sub.getSubscriberId();
+                InstanceIdentifier<Subscriber> subIid = appIid.builder()
+                        .child(Subscribers.class)
+                        .child(Subscriber.class, new SubscriberKey(subscriberId))
+                        .build();
+
+                List<Gate> gateList = sub.getGates().getGate();
+
+                for (Gate gate : gateList) {
+                    //logger.info("qospollgates active gate: "+gate);
+
+                    //generate active gateIid
+                    String gateId = gate.getGateId();
+                    InstanceIdentifier<Gate> gateIid =
+                            subIid.builder().child(Gates.class).child(Gate.class, new GateKey(gateId)).build();
+
+
+                    Gate opsGate = readGateFromOperationalDatastore(gateIid);
+                    String opsCopsGateId = opsGate.getCopsGateId();
+                    //generate active gatePathStr
+                    String gatePathStr = appKey.getAppId() + "/" + subscriberId + "/" + gateId;
+
+                    if ((!Objects.equals(opsCopsGateId, "")) && (!Objects.equals(opsCopsGateId, null))) {
+                        String ccapId = findCcapForSubscriberId(getInetAddress(subscriberId)).getCcapId();
+                        PCMMService pcmmService = pcmmServiceMap.get(ccapId);
+                        //is the CCAP socket open?
+                        if (!pcmmService.getPcmmPdpSocket() && pcmmService.getPcmmCcapClientIsConnected()) {
+                            PCMMService.GateSendStatus status = pcmmService.sendGateInfo(gatePathStr);
+                            DateAndTime gateDateAndTime = getNowTimeStamp();
+                            List<String> gateOutputError = Collections.singletonList(status.getMessage());
+
+
+                            gateBuilder.setGateId(gateId)
+                                    .setGatePath(gatePathStr)
+                                    .setCcapId(ccapId)
+                                    .setCopsGateState(
+                                            status.getCopsGateState() + "/" + status.getCopsGateStateReason())
+                                    .setCopsGateTimeInfo(status.getCopsGateTimeInfo())
+                                    .setCopsGateUsageInfo(status.getCopsGateUsageInfo())
+                                    .setCopsGateId(status.getCopsGateId())
+                                    .setError(gateOutputError)
+                                    .setTimestamp(gateDateAndTime);
+
+                            mdsalUtils.put(LogicalDatastoreType.OPERATIONAL, gateIid, gateBuilder.build());
                         } else {
-                            //TODO define what happens if a gate is not active.. is nothing ok
-                            logger.info("qospollgates: {}: gate not active; gate poll not performed", gatePathStr);
+                            logger.info(
+                                    "qospollgates: {}: CCAP socket is down or client disconnected; gate poll not performed",
+                                    ccapId);
                         }
+                    } else {
+                        //TODO define what happens if a gate is not active.. is nothing ok
+                        logger.info("qospollgates: {}: gate not active; gate poll not performed", gatePathStr);
                     }
                 }
-                rpcResponse = appKey.getAppId() + "/: gate subtree poll in progress";
             }
         }
 
-        DateAndTime rpcDateAndTime = getNowTimeStamp();
-
-        QosPollGatesOutputBuilder outputBuilder = new QosPollGatesOutputBuilder().setTimestamp(rpcDateAndTime)
-                .setResponse(rpcResponse)
-                .setGate(gateOutputBuilder.build());
-        return Futures.immediateFuture(RpcResultBuilder.success(outputBuilder.build()).build());
     }
 
+
     private DateAndTime getNowTimeStamp() {
         DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
         return new DateAndTime(dateFormat.format(new Date()));
     }
-}
+}
\ No newline at end of file