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; |
| 23 | import static org.onosproject.provider.pcep.tunnel.impl.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; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 38 | import org.onosproject.net.Annotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 39 | import org.onosproject.net.ConnectPoint; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 40 | import org.onosproject.net.DefaultAnnotations; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 41 | import org.onosproject.net.DefaultLink; |
| 42 | import org.onosproject.net.DefaultPath; |
| 43 | import org.onosproject.net.IpElementId; |
| 44 | import org.onosproject.net.Link; |
| 45 | import org.onosproject.net.Path; |
| 46 | import org.onosproject.net.PortNumber; |
| 47 | import org.onosproject.net.provider.ProviderId; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 48 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 49 | |
| 50 | public class PcepTunnelProviderTest { |
| 51 | |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 52 | private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame] | 53 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 54 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 55 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 56 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 57 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 58 | |
| 59 | @Test |
| 60 | public void testCasePcepSetupTunnel() { |
| 61 | |
| 62 | tunnelProvider.tunnelProviderRegistry = registry; |
| 63 | tunnelProvider.pcepClientController = controller; |
| 64 | tunnelProvider.controller = ctl; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 65 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 66 | tunnelProvider.tunnelService = tunnelService; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 67 | tunnelProvider.activate(); |
| 68 | |
| 69 | Tunnel tunnel; |
| 70 | Path path; |
| 71 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 72 | List<Link> links = new ArrayList<>(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 73 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 74 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 75 | |
| 76 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 77 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 78 | |
| 79 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 80 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 81 | |
| 82 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 83 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 84 | |
| 85 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 86 | |
| 87 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 88 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 89 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 90 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 91 | links.add(link); |
| 92 | |
| 93 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 94 | |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 95 | Annotations annotations = DefaultAnnotations.builder() |
| 96 | .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) |
| 97 | .build(); |
| 98 | |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 99 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
Brian Stanke | 9a10897 | 2016-04-11 15:25:17 -0400 | [diff] [blame] | 100 | new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 101 | path, annotations); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 102 | |
| 103 | tunnelProvider.setupTunnel(tunnel, path); |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 104 | |
| 105 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @After |
| 109 | public void tearDown() throws IOException { |
| 110 | tunnelProvider.deactivate(); |
| 111 | tunnelProvider.controller = null; |
| 112 | tunnelProvider.pcepClientController = null; |
| 113 | tunnelProvider.tunnelProviderRegistry = null; |
| 114 | } |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 115 | } |