[ONOS-4163] Provider side changes to support stateful PCE and PCECC

Change-Id: I0a57ed1d1e505a2e94921fd5f5d92426a105ad12
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
index 23a2213..2c9961f 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
@@ -20,6 +20,7 @@
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNot.not;
 import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,7 +37,9 @@
 import org.onosproject.incubator.net.tunnel.Tunnel;
 import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
 import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DefaultPath;
 import org.onosproject.net.IpElementId;
@@ -44,8 +47,11 @@
 import org.onosproject.net.Path;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.provider.ProviderId;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
 
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
 /**
  * Test for PCEP update tunnel.
  */
@@ -78,7 +84,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xD010101);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -101,14 +107,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for updating tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -126,7 +136,7 @@
         Tunnel tunnel;
         Path path;
         ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
-        List<Link> links = new ArrayList<Link>();
+        List<Link> links = new ArrayList<>();
         IpAddress srcIp = IpAddress.valueOf(0xC010103);
         IpElementId srcElementId = IpElementId.ipElement(srcIp);
 
@@ -149,14 +159,18 @@
 
         path = new DefaultPath(pid, links, 20, EMPTY);
 
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+                .build();
+
         tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
                                    new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
-                                   path, EMPTY);
+                                   path, annotations);
 
         // for updating tunnel tunnel should exist in db
         PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
         pcepTunnelData.setPlspId(1);
-        StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
         pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
         tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
 
@@ -166,6 +180,110 @@
         assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
     }
 
+    /**
+     * Sends update message to PCC for SR based tunnel.
+     */
+    @Test
+    public void testCasePcepUpdateSrTunnel() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xD010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xD010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for updating tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.updateTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
+    /**
+     * Sends update message to PCC for tunnel without signalling and without SR.
+     */
+    @Test
+    public void testCasePcepUpdateTunnelWithoutSigSr() {
+        Tunnel tunnel;
+        Path path;
+        ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+        List<Link> links = new ArrayList<>();
+        IpAddress srcIp = IpAddress.valueOf(0xD010101);
+        IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+        IpAddress dstIp = IpAddress.valueOf(0xD010102);
+        IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+        IpTunnelEndPoint ipTunnelEndPointSrc;
+        ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+        IpTunnelEndPoint ipTunnelEndPointDst;
+        ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+        ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+        ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+        Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+                .type(Link.Type.DIRECT).build();
+        links.add(link);
+
+        path = new DefaultPath(pid, links, 20, EMPTY);
+
+        Annotations annotations = DefaultAnnotations.builder()
+                .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+                .build();
+
+        tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+                                   new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+                                   path, annotations);
+
+        // for updating tunnel tunnel should exist in db
+        PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+        pcepTunnelData.setPlspId(1);
+        StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+        pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+        tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+        tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+        tunnelProvider.updateTunnel(tunnel, path);
+        assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+    }
+
     @After
     public void tearDown() throws IOException {
         tunnelProvider.deactivate();