+ * Attempts to create a gate against a CMTS, validates the results then attempts to delete it.
+ * @param service - the service used to connect to a CMTS for issuing requests
+ * @param scnName - the service class name (aka. gate name)
+ * @param srcAddr - the address to the CMTS subnet?
+ * @param dstAddr - the destination address
+ * @param direction - the gate direction
+ * @param cmAddrInet - the address to the cable modem to which the gate will be assigned
+ * @param gatePath - the path to the gate
+ * @param expGateSetMsgStart - the expected start of the gate set return message to be validated against
+ */
+ private void addRemoveValidateGate(final PCMMService service, final String scnName, final Ipv4Address srcAddr,
+ final Ipv4Address dstAddr, final ServiceFlowDirection direction,
+ final InetAddress cmAddrInet, final String gatePath,
+ final String expGateSetMsgStart) {
+ connectToCmts(service);
+ addAndValidateGate(service, scnName, srcAddr, dstAddr, direction, cmAddrInet, gatePath, expGateSetMsgStart);
+ deleteGate(service, gatePath);
+ }
+
+ private void addInvalidGate(final PCMMService service, final String scnName, final Ipv4Address srcAddr,
+ final Ipv4Address dstAddr, final ServiceFlowDirection direction,
+ final InetAddress cmAddrInet, final String gatePath,
+ final String expGateSetMsgStart) {
+ connectToCmts(service);
+ final int numRequestsBefore = service.gateRequests.size();
+ addAndValidateGate(service, scnName, srcAddr, dstAddr, direction, cmAddrInet, gatePath, expGateSetMsgStart);
+ assertEquals(numRequestsBefore, service.gateRequests.size());
+ }
+
+ private void connectToCmts(final PCMMService service) {
+ final String message = service.addCcap();
+ Assert.assertNotNull(message);
+ final String expectedMsg = "200 OK - CCAP " + ccapId + " connected @ "
+ + ccap.getConnection().getIpAddress().getIpv4Address().getValue()
+ + ":" + ccap.getConnection().getPort().getValue();
+ Assert.assertEquals(expectedMsg, message);
+ Assert.assertNotNull(service.ccapClient.pcmmPdp.getClientHandle());
+ }
+
+ /**
+ * Attempts to create a gate against a CMTS and validates the results.
+ * @param service - the service used to connect to a CMTS for issuing requests
+ * @param scnName - the service class name (aka. gate name)
+ * @param srcAddr - the address to the CMTS subnet?
+ * @param dstAddr - the destination address
+ * @param direction - the gate direction
+ * @param cmAddrInet - the address to the cable modem to which the gate will be assigned
+ * @param gatePath - the path to the gate
+ * @param expGateSetMsgStart - the expected start of the gate set return message to be validated against
+ */
+ private void addAndValidateGate(final PCMMService service, final String scnName, final Ipv4Address srcAddr,
+ final Ipv4Address dstAddr, final ServiceFlowDirection direction,
+ final InetAddress cmAddrInet, final String gatePath,
+ final String expGateSetMsgStart) {
+ final Gate gate = makeGateObj(scnName, srcAddr, direction, dstAddr);
+
+// final String gateSetMsg = service.sendGateSet(gatePath, cmAddrInet, gate, direction);
+// Assert.assertNotNull(gateSetMsg);
+// Assert.assertTrue(gateSetMsg, gateSetMsg.startsWith(expGateSetMsgStart));
+
+ // TODO update this method for the new GateSendStatus object
+ PCMMService.GateSendStatus status = service.sendGateSet(gatePath, cmAddrInet, gate);
+ Assert.assertNotNull(status);
+ assertThat(status.getMessage(), startsWith(expGateSetMsgStart));
+
+
+ // TODO - add validation to the PCMMGateReq contained within the map
+ if (status.didSucceed()) {
+ Assert.assertTrue((service.gateRequests.containsKey(gatePath)));
+ Assert.assertNotNull(service.gateRequests.get(gatePath));
+ }
+ }
+
+ /**
+ * Attempts to delete a gate
+ * @param service - the service used to connect to a CMTS for issuing requests
+ * @param gatePath - the path to the gate
+ */
+ private boolean deleteGate(final PCMMService service, final String gatePath) {
+ final boolean out = service.sendGateDelete(gatePath);
+
+ // Wait up to 1 sec for response to be processed
+ final long start = System.currentTimeMillis();
+ while (1000 < System.currentTimeMillis() - start) {
+ if (service.gateRequests.size() == 0) break;
+ }
+ Assert.assertNull(service.gateRequests.get(gatePath));
+ return out;
+ }
+
+ /**
+ * Creates a mock Ccap object that can be used for connecting to a CMTS