Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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; |
| 19 | |
| 20 | import java.io.IOException; |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import org.junit.After; |
| 25 | import org.junit.Test; |
| 26 | import org.onlab.packet.IpAddress; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 27 | import org.onosproject.cfg.ComponentConfigAdapter; |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 28 | import org.onosproject.core.DefaultGroupId; |
| 29 | import org.onosproject.incubator.net.tunnel.DefaultTunnel; |
| 30 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 31 | import org.onosproject.incubator.net.tunnel.Tunnel; |
| 32 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 33 | import org.onosproject.incubator.net.tunnel.TunnelName; |
| 34 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.DefaultLink; |
| 36 | import org.onosproject.net.DefaultPath; |
| 37 | import org.onosproject.net.IpElementId; |
| 38 | import org.onosproject.net.Link; |
| 39 | import org.onosproject.net.Path; |
| 40 | import org.onosproject.net.PortNumber; |
| 41 | import org.onosproject.net.provider.ProviderId; |
| 42 | import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; |
| 43 | |
| 44 | |
| 45 | public class PcepReleaseTunnelProviderTest { |
| 46 | |
| 47 | static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
| 48 | PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
| 49 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
| 50 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
| 51 | private final PcepControllerAdapter ctl = new PcepControllerAdapter(); |
| 52 | private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 53 | private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 54 | |
| 55 | @Test |
| 56 | public void testCasePcepReleaseTunnel() { |
| 57 | tunnelProvider.tunnelProviderRegistry = registry; |
| 58 | tunnelProvider.pcepClientController = controller; |
| 59 | tunnelProvider.controller = ctl; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 60 | tunnelProvider.tunnelService = tunnelService; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 61 | tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; |
chengfan | 2fff70f | 2015-08-24 18:20:19 -0500 | [diff] [blame] | 62 | tunnelProvider.cfgService = new ComponentConfigAdapter(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 63 | tunnelProvider.activate(); |
| 64 | |
| 65 | Tunnel tunnel; |
| 66 | Path path; |
| 67 | List<Link> links = new ArrayList<Link>(); |
| 68 | |
| 69 | ProviderId pid = new ProviderId("pcep", PROVIDER_ID); |
| 70 | |
| 71 | IpAddress srcIp = IpAddress.valueOf(0xB6024E20); |
| 72 | IpElementId srcElementId = IpElementId.ipElement(srcIp); |
| 73 | |
| 74 | IpAddress dstIp = IpAddress.valueOf(0xB6024E21); |
| 75 | IpElementId dstElementId = IpElementId.ipElement(dstIp); |
| 76 | |
| 77 | IpTunnelEndPoint ipTunnelEndPointSrc; |
| 78 | ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 79 | |
| 80 | IpTunnelEndPoint ipTunnelEndPointDst; |
| 81 | ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); |
| 82 | |
| 83 | ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); |
| 84 | |
| 85 | ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); |
| 86 | |
Ray Milkey | 2693bda | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 87 | Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) |
| 88 | .type(Link.Type.DIRECT).build(); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 89 | links.add(link); |
| 90 | |
| 91 | path = new DefaultPath(pid, links, 20, EMPTY); |
| 92 | |
| 93 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
| 94 | new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), |
| 95 | path, EMPTY); |
| 96 | |
| 97 | // for releasing tunnel tunnel should exist in db |
| 98 | PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE); |
| 99 | pcepTunnelData.setPlspId(1); |
| 100 | StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4); |
| 101 | pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 102 | tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 103 | |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 104 | tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); |
Phanendra Manda | 972ee9e | 2015-08-21 19:08:20 +0530 | [diff] [blame] | 105 | |
| 106 | tunnelProvider.releaseTunnel(tunnel); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | @After |
| 111 | public void tearDown() throws IOException { |
| 112 | tunnelProvider.deactivate(); |
| 113 | tunnelProvider.controller = null; |
| 114 | tunnelProvider.pcepClientController = null; |
| 115 | tunnelProvider.tunnelProviderRegistry = null; |
| 116 | } |
| 117 | } |