Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.pcep.tunnel.impl; |
| 17 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.nullValue; |
| 20 | import static org.hamcrest.core.IsNot.not; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 21 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 22 | import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING; |
Avantika-Huawei | fc10dca | 2016-06-10 16:13:55 +0530 | [diff] [blame] | 23 | import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 24 | |
| 25 | import java.io.IOException; |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
| 29 | import org.junit.After; |
| 30 | import org.junit.Test; |
| 31 | import org.onlab.packet.IpAddress; |
| 32 | import org.onosproject.core.DefaultGroupId; |
| 33 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 34 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 35 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 37 | import org.onosproject.incubator.net.tunnel.TunnelName; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 38 | import org.onosproject.mastership.MastershipServiceAdapter; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 39 | import org.onosproject.net.Annotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 40 | import org.onosproject.net.ConnectPoint; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 41 | import org.onosproject.net.DefaultAnnotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 42 | import org.onosproject.net.DefaultLink; |
| 43 | import org.onosproject.net.DefaultPath; |
| 44 | import org.onosproject.net.IpElementId; |
| 45 | import org.onosproject.net.Link; |
| 46 | import org.onosproject.net.Path; |
| 47 | import org.onosproject.net.PortNumber; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 48 | import org.onosproject.net.device.DeviceServiceAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 49 | import org.onosproject.net.provider.ProviderId; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 50 | import org.onosproject.pcep.controller.ClientCapability; |
| 51 | import org.onosproject.pcep.controller.PccId; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 52 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 53 | |
| 54 | public class PcepTunnelProviderTest { |
| 55 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 56 | private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 57 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 58 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 59 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 60 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 61 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 62 | private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter(); |
| 63 | private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 64 | |
| 65 | @Test |
| 66 | public void testCasePcepSetupTunnel() { |
| 67 | |
| 68 | tunnelProvider.tunnelProviderRegistry = registry; |
| 69 | tunnelProvider.pcepClientController = controller; |
| 70 | tunnelProvider.controller = ctl; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 71 | tunnelProvider.deviceService = deviceService; |
| 72 | tunnelProvider.mastershipService = mastershipService; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 73 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 74 | tunnelProvider.tunnelService = tunnelService; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 75 | tunnelProvider.activate(); |
| 76 | |
| 77 | Tunnel tunnel; |
| 78 | Path path; |
| 79 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 80 | List<Link> links = new ArrayList<>(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 81 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 82 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 83 | |
| 84 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 85 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 86 | |
| 87 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 88 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 89 | |
| 90 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 91 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 92 | |
| 93 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 94 | |
| 95 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 96 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 97 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 98 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 99 | links.add(link); |
| 100 | |
| 101 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 102 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 103 | Annotations annotations = DefaultAnnotations.builder() |
| 104 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 105 | .build(); |
| 106 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 107 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 108 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 109 | path, annotations); |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 110 | controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability( |
| 111 | new ClientCapability(true, true, true, true, true)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 112 | |
| 113 | tunnelProvider.setupTunnel(tunnel, path); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 114 | |
| 115 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @After |
| 119 | public void tearDown() throws IOException { |
| 120 | tunnelProvider.deactivate(); |
| 121 | tunnelProvider.controller = null; |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 122 | tunnelProvider.deviceService = null; |
| 123 | tunnelProvider.mastershipService = null; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 124 | tunnelProvider.pcepClientController = null; |
| 125 | tunnelProvider.tunnelProviderRegistry = null; |
| 126 | } |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 127 | } |