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 | |
| 18 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 19 | import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | import static org.hamcrest.core.Is.is; |
| 21 | import static org.hamcrest.core.IsNot.not; |
| 22 | import static org.hamcrest.Matchers.nullValue; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 23 | |
| 24 | import java.io.IOException; |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.List; |
| 27 | |
| 28 | import org.junit.After; |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 29 | import org.junit.Before; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 30 | import org.junit.Test; |
| 31 | import org.onlab.packet.IpAddress; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 32 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 33 | import org.onosproject.core.DefaultGroupId; |
| 34 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 35 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 36 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 37 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 38 | import org.onosproject.incubator.net.tunnel.TunnelName; |
| 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.DefaultLink; |
| 41 | import org.onosproject.net.DefaultPath; |
| 42 | import org.onosproject.net.IpElementId; |
| 43 | import org.onosproject.net.Link; |
| 44 | import org.onosproject.net.Path; |
| 45 | import org.onosproject.net.PortNumber; |
| 46 | import org.onosproject.net.provider.ProviderId; |
| 47 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 48 | /** |
| 49 | * Test for PCEP setup tunnel. |
| 50 | */ |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 51 | public class PcepSetupTunnelProviderTest { |
| 52 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 53 | public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
| 54 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 55 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 56 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 57 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 58 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 59 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 60 | @Before |
| 61 | public void setUp() throws IOException { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 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(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 68 | } |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 69 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 70 | /** |
| 71 | * Send PcInitiate message to PCC. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testCasePcepSetupTunnel() { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 75 | Tunnel tunnel; |
| 76 | Path path; |
| 77 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 78 | List<Link> links = new ArrayList<Link>(); |
| 79 | IpAddress srcIp = IpAddress.valueOf(0xC010101); |
| 80 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 81 | |
| 82 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 83 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 84 | |
| 85 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 86 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 87 | |
| 88 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 89 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 90 | |
| 91 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 92 | |
| 93 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 94 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 95 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 96 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 97 | links.add(link); |
| 98 | |
| 99 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 100 | |
| 101 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 102 | new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), |
| 103 | path, EMPTY); |
| 104 | |
| 105 | tunnelProvider.setupTunnel(tunnel, path); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 106 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Doesn't send PCInitiate message because PCC doesn't supports PCInitiate and stateful capability. |
| 111 | */ |
| 112 | @Test |
| 113 | public void testCasePcepSetupTunnel2() { |
| 114 | Tunnel tunnel; |
| 115 | Path path; |
| 116 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 117 | List<Link> links = new ArrayList<Link>(); |
| 118 | IpAddress srcIp = IpAddress.valueOf(0xC010103); |
| 119 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 120 | |
| 121 | IpAddress dstIp = IpAddress.valueOf(0xC010102); |
| 122 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 123 | |
| 124 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 125 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 126 | |
| 127 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 128 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 129 | |
| 130 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 131 | |
| 132 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 133 | |
| 134 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 135 | .type(Link.Type.DIRECT).build(); |
| 136 | links.add(link); |
| 137 | |
| 138 | path = new DefaultPath(pid, links, 10, EMPTY); |
| 139 | |
| 140 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 141 | new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), |
| 142 | path, EMPTY); |
| 143 | |
| 144 | tunnelProvider.setupTunnel(tunnel, path); |
| 145 | assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @After |
| 149 | public void tearDown() throws IOException { |
| 150 | tunnelProvider.deactivate(); |
| 151 | tunnelProvider.controller = null; |
| 152 | tunnelProvider.pcepClientController = null; |
| 153 | tunnelProvider.tunnelProviderRegistry = null; |
| 154 | } |
| 155 | } |