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