blob: ee55362eba73b0dcab0cd32339e540ab721a7c64 [file] [log] [blame]
Phanendra Manda37b97fb2015-08-15 02:04:24 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Phanendra Manda37b97fb2015-08-15 02:04:24 +05303 *
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 java.util.HashMap;
19import java.util.Map;
20
Phanendra Manda37b97fb2015-08-15 02:04:24 +053021import org.onosproject.incubator.net.tunnel.TunnelId;
22import org.onosproject.incubator.net.tunnel.TunnelProviderService;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26/**
27 * Entity to provide tunnel DB and mapping for request/response between CORE to PCEP
28 * and PCEP to PCC.
29 */
30public class PcepTunnelApiMapper {
Ray Milkey9c9cde42018-01-12 14:22:06 -080031 private static final Logger log = LoggerFactory.getLogger(PcepTunnelApiMapper.class);
Phanendra Manda37b97fb2015-08-15 02:04:24 +053032
33 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
34 // Map to store all the tunnel requests.
35 private Map<Integer, PcepTunnelData> tunnelRequestQueue;
36 //Map to store all core related tunnel requests.
37 private Map<TunnelId, PcepTunnelData> coreTunnelRequestQueue;
38 //Map to store all the created tunnels.
39 private Map<Integer, PcepTunnelData> tunnelDB;
40 // Map to store the tunnel ids, given by core and given by pcc.
41 private Map<TunnelId, Integer> tunnelIdMap;
Phanendra Manda37b97fb2015-08-15 02:04:24 +053042
43 TunnelProviderService tunnelApiMapperservice;
44
45 /**
46 * Default constructor.
47 */
48 public PcepTunnelApiMapper() {
49 //TODO check if the map need to initialize
50 tunnelRequestQueue = new HashMap<Integer, PcepTunnelData>();
51 coreTunnelRequestQueue = new HashMap<TunnelId, PcepTunnelData>();
52 tunnelDB = new HashMap<Integer, PcepTunnelData>();
53 tunnelIdMap = new HashMap<TunnelId, Integer>();
54 }
55
56 /**
57 * Add tunnels to tunnel Request queues.
58 *
59 * @param srpId srp id
60 * @param pcepTunnelData pcep tunnel data
61 */
62 public void addToTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
63 tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData);
64 log.debug("Tunnel Added to TunnelRequestQueue");
65 }
66
67 /**
68 * Map between Tunnel ID and pcc provided Tunnel ID.
69 *
70 * @param pcepTunnelData pcep tunnel data
71 */
72 public void addToTunnelIdMap(PcepTunnelData pcepTunnelData) {
73 int value = pcepTunnelData.statefulIpv4IndentifierTlv().getTunnelId() & 0xFFFF;
74 tunnelIdMap.put(pcepTunnelData.tunnel().tunnelId(), (new Integer(value)));
75 log.debug("Tunnel ID Added to tunnelIdMap");
76 }
77
78 /**
79 * Add tunnels to core tunnel request queue.
80 *
81 * @param pcepTunnelData pcep tunnel data
82 */
83 public void addToCoreTunnelRequestQueue(PcepTunnelData pcepTunnelData) {
84 coreTunnelRequestQueue.put(pcepTunnelData.tunnel().tunnelId(), pcepTunnelData);
85 log.debug("Tunnel Added to CoreTunnelRequestQueue");
86 }
87
88 /**
89 * Removes tunnels from the core tunnel request queue.
90 *
91 * @param tunnelId tunnel id
92 */
93 public void removeFromCoreTunnelRequestQueue(TunnelId tunnelId) {
94 coreTunnelRequestQueue.remove(tunnelId);
95 log.debug("Tunnnel create response sent to core and removed from CoreTunnelRequestQueue");
96 }
97
98 /**
99 * Handle the report which comes after initiate message.
100 *
101 * @param srpId srp id
102 * @param pcepTunnelData pcep tunnel data
103 */
104 public void handleCreateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
105
106 int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
107 tunnelDB.put(new Integer(value), pcepTunnelData);
108 tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData);
109 log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}"
110 + (new Integer(value)).toString());
111 }
112
113 /**
114 * Handle report which comes for update message.
115 *
116 * @param srpId srp id
117 * @param pcepTunnelData pcep tunnel data
118 */
119 public void handleUpdateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
120 if (pcepTunnelData.rptFlag()) {
121 pcepTunnelData.setRptFlag(false);
122 int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
123 tunnelDB.put(new Integer(value), pcepTunnelData);
124 tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData);
Jian Li68c4fc42016-01-11 16:07:03 -0800125 log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}",
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530126 (new Integer(value)).toString());
127 } else {
128 pcepTunnelData.setRptFlag(true);
129 tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData);
130 log.debug("Tunnel updated in TunnelRequestQueue");
131 }
132 }
133
134 /**
135 * Handle report for tunnel Release request.
136 *
137 * @param srpId srp id
138 * @param pcepTunnelData pcep tunnel data
139 */
140 public void handleRemoveFromTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) {
141
142 int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId());
143 tunnelIdMap.remove(pcepTunnelData.tunnel().tunnelId());
144 tunnelDB.remove(new Integer(value));
145 tunnelRequestQueue.remove(srpId);
146 log.debug("Tunnel removed from TunnelDBQueue and TunnelRequestQueue");
147 }
148
149 /**
150 * Returns PcepTunnelData from the tunnel request queue.
151 *
152 * @param srpId srp id
153 * @return PcepTunnelData pcep tunnel data
154 */
155 public PcepTunnelData getDataFromTunnelRequestQueue(int srpId) {
156 return tunnelRequestQueue.get(new Integer(srpId));
157
158 }
159
160 /**
161 * Returns PcepTunnelData from the tunnel DB.
162 *
163 * @param tunnelId tunnel id
164 * @return PcepTunnelData pcep tunnel data
165 */
166 public PcepTunnelData getDataFromTunnelDBQueue(TunnelId tunnelId) {
167 int value = tunnelIdMap.get(tunnelId);
168 return tunnelDB.get((new Integer(value)));
169 }
170
171 /**
172 * Checks whether the tunnel exist in tunnel request queue.
173 *
174 * @param srpId srp id
175 * @return true if tunnel exist in reuest queue, false otherwise
176 */
177 public boolean checkFromTunnelRequestQueue(int srpId) {
178 boolean retValue = tunnelRequestQueue.containsKey(srpId);
179 return retValue;
180 }
181
182 /**
183 * Returns whether tunnel exist in tunnel db.
184 *
Phanendra Manda51fb9c22015-09-01 16:17:41 +0530185 * @param tunnelId tunnel id
186 * @return true/false if the tunnel exists in the tunnel db
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530187 */
188 public boolean checkFromTunnelDBQueue(TunnelId tunnelId) {
189 int value = tunnelIdMap.get(tunnelId);
190 boolean retValue = tunnelDB.containsKey((new Integer(value)));
191 return retValue;
192 }
Phanendra Manda37b97fb2015-08-15 02:04:24 +0530193}