[ONOS-2365]Unit test for PcepTunnelProvider
Change-Id: I2903756913225acf43b324da90faa76bd41b6533
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
new file mode 100644
index 0000000..49e2951
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
@@ -0,0 +1,92 @@
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+
+import org.jboss.netty.channel.Channel;
+import org.onosproject.pcep.controller.PccId;
+import org.onosproject.pcep.controller.PcepClient;
+import org.onosproject.pcepio.protocol.PcepFactories;
+import org.onosproject.pcepio.protocol.PcepFactory;
+import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepVersion;
+
+public class PcepClientAdapter implements PcepClient {
+
+ private Channel channel;
+ protected String channelId;
+
+ private boolean connected;
+ private PccId pccId;
+
+ private PcepVersion pcepVersion;
+
+ public void init(PccId pccId, PcepVersion pcepVersion) {
+ this.pccId = pccId;
+ this.pcepVersion = pcepVersion;
+ }
+
+ @Override
+ public final void disconnectClient() {
+ this.channel.close();
+ }
+
+ @Override
+ public final void sendMessage(PcepMessage m) {
+ }
+
+ @Override
+ public final void sendMessage(List<PcepMessage> msgs) {
+ try {
+ PcepMessage pcepMsg = msgs.get(0);
+ assertNotNull("PCEP MSG should be created.", pcepMsg);
+ } catch (RejectedExecutionException e) {
+ throw e;
+ }
+ }
+
+ @Override
+ public final boolean isConnected() {
+ return this.connected;
+ }
+
+ @Override
+ public String channelId() {
+ return channelId;
+ }
+
+ @Override
+ public final PccId getPccId() {
+ return this.pccId;
+ };
+
+ @Override
+ public final String getStringId() {
+ return this.pccId.toString();
+ }
+
+ @Override
+ public final void handleMessage(PcepMessage m) {
+ }
+
+ @Override
+ public boolean isOptical() {
+ return false;
+ }
+
+ @Override
+ public PcepFactory factory() {
+ return PcepFactories.getFactory(pcepVersion);
+ }
+
+ @Override
+ public final boolean isSyncComplete() {
+ return false;
+ }
+
+ @Override
+ public final void setIsSyncComplete(boolean value) {
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
new file mode 100644
index 0000000..74aa590
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
@@ -0,0 +1,189 @@
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.onlab.packet.IpAddress;
+import org.onosproject.pcep.controller.PccId;
+import org.onosproject.pcep.controller.PcepClient;
+import org.onosproject.pcep.controller.PcepClientController;
+import org.onosproject.pcep.controller.PcepClientListener;
+import org.onosproject.pcep.controller.PcepEventListener;
+import org.onosproject.pcep.controller.driver.PcepAgent;
+import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepVersion;
+
+import com.google.common.collect.Sets;
+
+public class PcepClientControllerAdapter implements PcepClientController {
+
+ protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
+ new ConcurrentHashMap<PccId, PcepClient>();
+
+ protected PcepClientAgent agent = new PcepClientAgent();
+ protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
+
+ protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
+
+ @Activate
+ public void activate() {
+ }
+
+ @Deactivate
+ public void deactivate() {
+ }
+
+ @Override
+ public Collection<PcepClient> getClients() {
+ return connectedClients.values();
+ }
+
+ @Override
+ public PcepClient getClient(PccId pccId) {
+ //return connectedClients.get(pccIpAddress);
+ PcepClientAdapter pc = new PcepClientAdapter();
+ pc.init(PccId.pccId(IpAddress.valueOf(0xac000001)), PcepVersion.PCEP_1);
+ return pc;
+ }
+
+ @Override
+ public void addListener(PcepClientListener listener) {
+ if (!pcepClientListener.contains(listener)) {
+ this.pcepClientListener.add(listener);
+ }
+ }
+
+ @Override
+ public void removeListener(PcepClientListener listener) {
+ this.pcepClientListener.remove(listener);
+ }
+
+ @Override
+ public void addEventListener(PcepEventListener listener) {
+ pcepEventListener.add(listener);
+ }
+
+ @Override
+ public void removeEventListener(PcepEventListener listener) {
+ pcepEventListener.remove(listener);
+ }
+
+ @Override
+ public void writeMessage(PccId pccId, PcepMessage msg) {
+ this.getClient(pccId).sendMessage(msg);
+ }
+
+ @Override
+ public void processClientMessage(PccId pccId, PcepMessage msg) {
+
+ PcepClient pc = getClient(pccId);
+
+ switch (msg.getType()) {
+ case NONE:
+ break;
+ case OPEN:
+ break;
+ case KEEP_ALIVE:
+ //log.debug("Sending Keep Alive Message to {" + pccIpAddress.toString() + "}");
+ pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build()));
+ break;
+ case PATH_COMPUTATION_REQUEST:
+ break;
+ case PATH_COMPUTATION_REPLY:
+ break;
+ case NOTIFICATION:
+ break;
+ case ERROR:
+ break;
+ case CLOSE:
+ //log.debug("Sending Close Message to { }", pccIpAddress.toString());
+ pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build()));
+ break;
+ case REPORT:
+ for (PcepEventListener l : pcepEventListener) {
+ l.handleMessage(pccId, msg);
+ }
+ break;
+ case UPDATE:
+ for (PcepEventListener l : pcepEventListener) {
+ l.handleMessage(pccId, msg);
+ }
+ break;
+ case INITIATE:
+ for (PcepEventListener l : pcepEventListener) {
+ l.handleMessage(pccId, msg);
+ }
+ break;
+ case LABEL_UPDATE:
+ break;
+ case MAX:
+ break;
+ case END:
+ break;
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public void closeConnectedClients() {
+ PcepClient pc;
+ for (PccId id : connectedClients.keySet()) {
+ pc = getClient(id);
+ pc.disconnectClient();
+ }
+ }
+
+ /**
+ * Implementation of an Pcep Agent which is responsible for
+ * keeping track of connected clients and the state in which
+ * they are.
+ */
+ public class PcepClientAgent implements PcepAgent {
+
+ @Override
+ public boolean addConnectedClient(PccId pccId, PcepClient pc) {
+
+ if (connectedClients.get(pccId) != null) {
+ return false;
+ } else {
+ connectedClients.put(pccId, pc);
+ for (PcepClientListener l : pcepClientListener) {
+ l.clientConnected(pccId);
+ }
+ return true;
+ }
+ }
+
+ @Override
+ public boolean validActivation(PccId pccId) {
+ if (connectedClients.get(pccId) == null) {
+ //log.error("Trying to activate client but is not in "
+ // + "connected switches: pccIp {}. Aborting ..", pccIpAddress.toString());
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public void removeConnectedClient(PccId pccId) {
+ connectedClients.remove(pccId);
+ for (PcepClientListener l : pcepClientListener) {
+ //log.warn("removal for {}", pccIpAddress.toString());
+ l.clientDisconnected(pccId);
+ }
+ }
+
+ @Override
+ public void processPcepMessage(PccId pccId, PcepMessage m) {
+ processClientMessage(pccId, m);
+ }
+ }
+
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepControllerAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepControllerAdapter.java
new file mode 100644
index 0000000..6aa81f7
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepControllerAdapter.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.pcep.api.PcepController;
+import org.onosproject.pcep.api.PcepDpid;
+import org.onosproject.pcep.api.PcepLinkListener;
+import org.onosproject.pcep.api.PcepSwitch;
+import org.onosproject.pcep.api.PcepSwitchListener;
+import org.onosproject.pcep.api.PcepTunnel;
+import org.onosproject.pcep.api.PcepTunnelListener;
+
+public class PcepControllerAdapter implements PcepController {
+
+ @Override
+ public Iterable<PcepSwitch> getSwitches() {
+ return null;
+ }
+
+ @Override
+ public PcepSwitch getSwitch(PcepDpid did) {
+ return null;
+ }
+
+ @Override
+ public void addListener(PcepSwitchListener listener) {
+
+ }
+
+ @Override
+ public void removeListener(PcepSwitchListener listener) {
+ }
+
+ @Override
+ public void addLinkListener(PcepLinkListener listener) {
+ }
+
+ @Override
+ public void removeLinkListener(PcepLinkListener listener) {
+ }
+
+ @Override
+ public void addTunnelListener(PcepTunnelListener listener) {
+ }
+
+ @Override
+ public void removeTunnelListener(PcepTunnelListener listener) {
+ }
+
+ @Override
+ public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid, long srcPort, long dstPort, long bandwidth,
+ String name) {
+ return null;
+ }
+
+ @Override
+ public Boolean deleteTunnel(String id) {
+ return null;
+ }
+
+ @Override
+ public Boolean updateTunnelBandwidth(String id, long bandwidth) {
+ return null;
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
new file mode 100644
index 0000000..c728aad
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.onosproject.net.DefaultAnnotations.EMPTY;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+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.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.IpElementId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+
+
+public class PcepReleaseTunnelProviderTest {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+ PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+ private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
+ private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+ private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+ private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
+
+ @Test
+ public void testCasePcepReleaseTunnel() {
+ tunnelProvider.tunnelProviderRegistry = registry;
+ tunnelProvider.pcepClientController = controller;
+ tunnelProvider.controller = ctl;
+ tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper;
+ tunnelProvider.activate();
+
+ Tunnel tunnel;
+ Path path;
+ List<Link> links = new ArrayList<Link>();
+
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+
+ IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
+ 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 = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"),
+ path, EMPTY);
+
+ // for releasing tunnel tunnel should exist in db
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
+ pcepTunnelData.setPlspId(1);
+ StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelAPIMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.releaseTunnel(tunnel);
+ }
+
+
+ @After
+ public void tearDown() throws IOException {
+ tunnelProvider.deactivate();
+ tunnelProvider.controller = null;
+ tunnelProvider.pcepClientController = null;
+ tunnelProvider.tunnelProviderRegistry = null;
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
new file mode 100644
index 0000000..e419e22
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.onosproject.net.DefaultAnnotations.EMPTY;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+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.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.IpElementId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+public class PcepSetupTunnelProviderTest {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+ PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+ private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
+ private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+ private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+
+ @Test
+ public void testCasePcepSetupTunnel() {
+
+ tunnelProvider.tunnelProviderRegistry = registry;
+ tunnelProvider.pcepClientController = controller;
+ tunnelProvider.controller = ctl;
+ tunnelProvider.activate();
+
+
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<Link>();
+ IpAddress srcIp = IpAddress.valueOf(0xC010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xC010102);
+ 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 = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 10, EMPTY);
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"),
+ path, EMPTY);
+
+ tunnelProvider.setupTunnel(tunnel, path);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ tunnelProvider.deactivate();
+ tunnelProvider.controller = null;
+ tunnelProvider.pcepClientController = null;
+ tunnelProvider.tunnelProviderRegistry = null;
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
new file mode 100644
index 0000000..7a61bb2
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.onosproject.net.DefaultAnnotations.EMPTY;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+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.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.IpElementId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+
+public class PcepTunnelProviderTest {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+ PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+ private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
+ private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+ private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+
+ @Test
+ public void testCasePcepSetupTunnel() {
+
+ tunnelProvider.tunnelProviderRegistry = registry;
+ tunnelProvider.pcepClientController = controller;
+ tunnelProvider.controller = ctl;
+ tunnelProvider.activate();
+
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<Link>();
+ IpAddress srcIp = IpAddress.valueOf(0xC010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xC010102);
+ 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 = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 10, EMPTY);
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"),
+ path, EMPTY);
+
+ tunnelProvider.setupTunnel(tunnel, path);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ tunnelProvider.deactivate();
+ tunnelProvider.controller = null;
+ tunnelProvider.pcepClientController = null;
+ tunnelProvider.tunnelProviderRegistry = null;
+ }
+}
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
new file mode 100644
index 0000000..a27ba76
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.onosproject.net.DefaultAnnotations.EMPTY;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+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.ConnectPoint;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.DefaultPath;
+import org.onosproject.net.IpElementId;
+import org.onosproject.net.Link;
+import org.onosproject.net.Path;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+
+
+public class PcepUpdateTunnelProviderTest {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+ PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+ private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
+ private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+ private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+ private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
+
+ @Test
+ public void testCasePcepUpdateTunnel() {
+ tunnelProvider.tunnelProviderRegistry = registry;
+ tunnelProvider.pcepClientController = controller;
+ tunnelProvider.controller = ctl;
+ tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper;
+ tunnelProvider.activate();
+
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<Link>();
+ 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 = new DefaultLink(pid, src, dst, Link.Type.DIRECT, EMPTY);
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"),
+ path, EMPTY);
+
+ // 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);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelAPIMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.updateTunnel(tunnel, path);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ tunnelProvider.deactivate();
+ tunnelProvider.controller = null;
+ tunnelProvider.pcepClientController = null;
+ tunnelProvider.tunnelProviderRegistry = null;
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelProviderRegistryAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelProviderRegistryAdapter.java
new file mode 100644
index 0000000..7292d0b
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelProviderRegistryAdapter.java
@@ -0,0 +1,56 @@
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import java.util.Set;
+
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
+import org.onosproject.incubator.net.tunnel.TunnelProviderService;
+import org.onosproject.net.provider.ProviderId;
+
+public class TunnelProviderRegistryAdapter implements TunnelProviderRegistry {
+ TunnelProvider provider;
+
+ @Override
+ public TunnelProviderService register(TunnelProvider provider) {
+ this.provider = provider;
+ return new TestProviderService();
+ }
+
+ @Override
+ public void unregister(TunnelProvider provider) {
+ }
+
+ @Override
+ public Set<ProviderId> getProviders() {
+ return null;
+ }
+
+ private class TestProviderService implements TunnelProviderService {
+
+ @Override
+ public TunnelProvider provider() {
+ return null;
+ }
+
+ @Override
+ public TunnelId tunnelAdded(TunnelDescription tunnel) {
+ return null;
+ }
+
+ @Override
+ public void tunnelRemoved(TunnelDescription tunnel) {
+ }
+
+ @Override
+ public void tunnelUpdated(TunnelDescription tunnel) {
+ }
+
+ @Override
+ public Tunnel tunnelQueryById(TunnelId tunnelId) {
+ return null;
+ }
+ }
+}