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 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.nullValue; |
| 20 | import static org.hamcrest.core.Is.is; |
| 21 | import static org.hamcrest.core.IsNot.not; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 22 | import static org.onosproject.net.DefaultAnnotations.EMPTY; |
| 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 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; |
| 48 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 49 | /** |
| 50 | * Test for PCEP update tunnel. |
| 51 | */ |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 52 | public class PcepUpdateTunnelProviderTest { |
| 53 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 54 | public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
| 55 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 56 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 57 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 58 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
| 59 | private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 60 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
| 61 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 62 | @Before |
| 63 | public void setUp() throws IOException { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 64 | tunnelProvider.tunnelProviderRegistry = registry; |
| 65 | tunnelProvider.pcepClientController = controller; |
| 66 | tunnelProvider.controller = ctl; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 67 | tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 68 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
| 69 | tunnelProvider.tunnelService = tunnelService; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 70 | tunnelProvider.activate(); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 71 | } |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 72 | |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 73 | /** |
| 74 | * Send update message to PCC. |
| 75 | */ |
| 76 | @Test |
| 77 | public void testCasePcepUpdateTunnel() { |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 78 | Tunnel tunnel; |
| 79 | Path path; |
| 80 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 81 | List<Link> links = new ArrayList<Link>(); |
| 82 | IpAddress srcIp = IpAddress.valueOf(0xD010101); |
| 83 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 84 | |
| 85 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 86 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 87 | |
| 88 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 89 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 90 | |
| 91 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 92 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 93 | |
| 94 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 95 | |
| 96 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 97 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 98 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 99 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 100 | links.add(link); |
| 101 | |
| 102 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 103 | |
| 104 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 105 | new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), |
| 106 | path, EMPTY); |
| 107 | |
| 108 | // for updating tunnel tunnel should exist in db |
| 109 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 110 | pcepTunnelData.setPlspId(1); |
| 111 | StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4); |
| 112 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 113 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 114 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 115 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 116 | |
| 117 | tunnelProvider.updateTunnel(tunnel, path); |
Priyanka B | d2b2888 | 2016-04-04 16:57:04 +0530 | [diff] [blame^] | 118 | assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Doesn't send update message because PCC doesn't supports PCE stateful capability. |
| 123 | */ |
| 124 | @Test |
| 125 | public void testCasePcepUpdateTunnel2() { |
| 126 | Tunnel tunnel; |
| 127 | Path path; |
| 128 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 129 | List<Link> links = new ArrayList<Link>(); |
| 130 | IpAddress srcIp = IpAddress.valueOf(0xC010103); |
| 131 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 132 | |
| 133 | IpAddress dstIp = IpAddress.valueOf(0xD010102); |
| 134 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 135 | |
| 136 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 137 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 138 | |
| 139 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 140 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 141 | |
| 142 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 143 | |
| 144 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 145 | |
| 146 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 147 | .type(Link.Type.DIRECT).build(); |
| 148 | links.add(link); |
| 149 | |
| 150 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 151 | |
| 152 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 153 | new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), |
| 154 | path, EMPTY); |
| 155 | |
| 156 | // for updating tunnel tunnel should exist in db |
| 157 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); |
| 158 | pcepTunnelData.setPlspId(1); |
| 159 | StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4); |
| 160 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
| 161 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
| 162 | |
| 163 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
| 164 | |
| 165 | tunnelProvider.updateTunnel(tunnel, path); |
| 166 | assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @After |
| 170 | public void tearDown() throws IOException { |
| 171 | tunnelProvider.deactivate(); |
| 172 | tunnelProvider.controller = null; |
| 173 | tunnelProvider.pcepClientController = null; |
| 174 | tunnelProvider.tunnelProviderRegistry = null; |
| 175 | } |
| 176 | } |