Added FlowSpec Traffic Profile feature
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / PCMMServiceTest.java
index 650ae3367ecaa4c0be4a517deecfee5c60ffeaa3..b34d758cc5d7aa04f1fa681034626bc1ce5e850c 100644 (file)
@@ -1,10 +1,17 @@
 /*
  * (c) 2015 Cable Television Laboratories, Inc.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
 package org.opendaylight.controller.packetcable.provider;
 
 import static junit.framework.TestCase.assertEquals;
+
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -25,28 +32,36 @@ import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ServiceClassName;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ServiceFlowDirection;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TosByte;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TpProtocol;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmId;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.Connection;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.Classifiers;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.QosClassifierChoice;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.classifier.Classifier;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gate.spec.GateSpec;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.traffic.profile.TrafficProfile;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.ServiceClassName;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.ServiceFlowDirection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.TosByte;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.TpProtocol;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.ccap.attributes.AmId;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.ccap.attributes.Connection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.ccaps.Ccap;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.Classifiers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.ClassifierContainer;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.classifier.container.classifier.choice.QosClassifierChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.classifier.Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.gate.spec.GateSpec;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.flow.spec.profile.FlowSpecProfile;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.TrafficProfile;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.TrafficProfileBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.TrafficProfileChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.FlowSpecChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.FlowSpecChoiceBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.ServiceClassNameChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.traffic.profile.traffic.profile.traffic.profile.choice.ServiceClassNameChoiceBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.serviceclass.name.profile.ServiceClassNameProfile;
 import org.pcmm.PCMMPdpAgent;
-import org.pcmm.gates.IGateSpec.Direction;
 import org.pcmm.gates.IPCMMGate;
 import org.pcmm.rcd.IPCMMClient;
 import org.pcmm.rcd.impl.CMTS;
+import org.pcmm.rcd.impl.CMTSConfig;
 import org.umu.cops.stack.COPSClientSI;
 import org.umu.cops.stack.COPSContext;
 import org.umu.cops.stack.COPSContext.RType;
@@ -120,33 +135,33 @@ public class PCMMServiceTest {
     public void setup() throws IOException {
         srcAddr = new Ipv4Address("10.10.10.0");
         dstAddr = new Ipv4Address("10.32.99.99");
+        invalidCmAddrInet = InetAddress.getByAddress(new byte[] {99, 99, 99, 99});
 
         if (realCmts) {
             cmAddrInet = InetAddress.getByAddress(new byte[] {10, 32, 110, (byte)172});
-            invalidCmAddrInet = InetAddress.getByAddress(new byte[] {99, 99, 99, 99});
+
 
             // Use me when testing against a CMTS or emulator not running in the same JVM
             cmtsAddr = new Ipv4Address("10.32.10.3");
             ccap = makeCcapObj(PCMMPdpAgent.WELL_KNOWN_PDP_PORT, cmtsAddr, ccapId);
         } else {
             cmAddrInet = InetAddress.getByAddress(new byte[] {10, 32, 110, (byte)180});
-            invalidCmAddrInet = InetAddress.getByAddress(new byte[] {99, 99, 99, 99});
 
             // Use me for automated testing and the CMTS emulator running in the same JVM
             cmtsAddr = new Ipv4Address("127.0.0.1");
 
-            final Set<String> upGate = new HashSet<>();
-            upGate.add("extrm_up");
-            final Set<String> dnGate = new HashSet<>();
-            dnGate.add("extrm_dn");
-            final Map<Direction, Set<String>> gates = new HashMap<>();
-            gates.put(Direction.UPSTREAM, upGate);
-            gates.put(Direction.DOWNSTREAM, dnGate);
+            final Set<String> upSCN = new HashSet<>();
+            upSCN.add("extrm_up");
+            final Set<String> dnSCN = new HashSet<>();
+            dnSCN.add("extrm_dn");
 
             final Map<String, Boolean> cmStatus = new HashMap<>();
             cmStatus.put(cmAddrInet.getHostAddress(), true);
             cmStatus.put(invalidCmAddrInet.getHostAddress(), false);
-            icmts = new CMTS(gates, cmStatus);
+
+            CMTSConfig config = new CMTSConfig(0, (short)4, upSCN, dnSCN, cmStatus);
+
+            icmts = new CMTS(config);
             icmts.startServer();
 
             ccap = makeCcapObj(icmts.getPort(), cmtsAddr, ccapId);
@@ -250,7 +265,7 @@ public class PCMMServiceTest {
     public void testAddAndRemoveInvalidCmAddrUpGate() throws Exception {
         // TODO - fix cmts emulator
         final String expectedMsgStart = "404 Not Found - sendGateSet for " + ccapId + '/' + gatePath
-                + " returned error - Error Code: 13 Error Subcode : 0  Invalid SubscriberID";
+                + " returned error - Error Code: 13 Subcode: 0  Invalid SubscriberID";
         addInvalidGate(service, "extrm_up", srcAddr, dstAddr, ServiceFlowDirection.Us, invalidCmAddrInet, gatePath,
                 expectedMsgStart);
     }
@@ -258,7 +273,7 @@ public class PCMMServiceTest {
     @Test
     public void testAddInvalidScnUpGate() throws Exception {
         final String expectedMsgStart = "404 Not Found - sendGateSet for " + ccapId + '/' + gatePath
-                + " returned error - Error Code: 11 Error Subcode : 0  Undefined Service Class Name";
+                + " returned error - Error Code: 11 Subcode: 0  Undefined Service Class Name";
         addInvalidGate(service, "extrm_up_invalid", srcAddr, dstAddr, ServiceFlowDirection.Us, cmAddrInet, gatePath,
                 expectedMsgStart);
     }
@@ -266,7 +281,7 @@ public class PCMMServiceTest {
     @Test
     public void testAddInvalidScnDownGate() throws Exception {
         final String expectedMsgStart = "404 Not Found - sendGateSet for " + ccapId + '/' + gatePath
-                + " returned error - Error Code: 11 Error Subcode : 0  Undefined Service Class Name";
+                + " returned error - Error Code: 11 Subcode: 0  Undefined Service Class Name";
         addInvalidGate(service, "extrm_dn_invalid", srcAddr, dstAddr, ServiceFlowDirection.Ds, cmAddrInet, gatePath,
                 expectedMsgStart);
     }
@@ -362,10 +377,11 @@ public class PCMMServiceTest {
 //        Assert.assertNotNull(gateSetMsg);
 //        Assert.assertTrue(gateSetMsg, gateSetMsg.startsWith(expGateSetMsgStart));
 
-        // TODO update this method for the new GateSetStatus object
-        PCMMService.GateSetStatus status = service.sendGateSet(gatePath, cmAddrInet, gate, direction);
+        // TODO update this method for the new GateSendStatus object
+        PCMMService.GateSendStatus status = service.sendGateSet(gatePath, cmAddrInet, gate);
         Assert.assertNotNull(status);
-        Assert.assertTrue(status.getMessage().startsWith(expGateSetMsgStart));
+        assertThat(status.getMessage(), startsWith(expGateSetMsgStart));
+
 
         // TODO - add validation to the PCMMGateReq contained within the map
         if (status.didSucceed()) {
@@ -433,10 +449,16 @@ public class PCMMServiceTest {
         when(gateSpec.getDirection()).thenReturn(direction);
         // TODO - make sure to write a test when this value is not null
         when(gateSpec.getDscpTosOverwrite()).thenReturn(null);
+
+        // TODO - refactor to add flowspec profile testing as well
         final TrafficProfile trafficProfile = mock(TrafficProfile.class);
-        final ServiceClassName scn = mock(ServiceClassName.class);
-        when(scn.getValue()).thenReturn(scnValue);
-        when(trafficProfile.getServiceClassName()).thenReturn(scn);
+        final ServiceClassNameChoice serviceClassNameChoice = mock(ServiceClassNameChoice.class);
+        final ServiceClassNameProfile serviceClassNameProfile = mock(ServiceClassNameProfile.class);
+        final ServiceClassName serviceClassName = mock(ServiceClassName.class);
+        when(serviceClassName.getValue()).thenReturn(scnValue);
+        when(serviceClassNameProfile.getServiceClassName()).thenReturn(serviceClassName);
+        when(serviceClassNameChoice.getServiceClassNameProfile()).thenReturn(serviceClassNameProfile);
+        when(trafficProfile.getTrafficProfileChoice()).thenReturn(serviceClassNameChoice);
         when(gate.getTrafficProfile()).thenReturn(trafficProfile);
 
         // TODO - write tests when this is null and ExtClassifier or Ipv6Classifier objects are not null
@@ -481,7 +503,8 @@ public class PCMMServiceTest {
         gateBuilder.setAmId(ccap.getAmId());
         gateBuilder.setSubscriberId(addrSubId);
         // force gateSpec.Direction to align with SCN direction
-        final ServiceClassName scn = gateReq.getTrafficProfile().getServiceClassName();
+        final ServiceClassName scn =
+            ((ServiceClassNameChoice)gateReq.getTrafficProfile().getTrafficProfileChoice()).getServiceClassNameProfile().getServiceClassName();
         if (scn != null) {
             gateBuilder.setGateSpec(gateReq.getGateSpec(), direction);
         } else {