Committed by
Gerrit Code Review
[ONOS-2287,ONOS-2288]Pcep TunnelProvider implementation
Change-Id: I4184336c200f1060e93be5dc28076ba35f6b98f4
Showing
9 changed files
with
1495 additions
and
34 deletions
... | @@ -85,6 +85,23 @@ public class ConnectPoint { | ... | @@ -85,6 +85,23 @@ public class ConnectPoint { |
85 | } | 85 | } |
86 | 86 | ||
87 | /** | 87 | /** |
88 | + * Returns the identifier of the infrastructure device if the connection | ||
89 | + * point belongs to a network element which is indeed an ip of pcc | ||
90 | + * client identifier. | ||
91 | + * | ||
92 | + * @return network element identifier as a pcc client identifier | ||
93 | + * @throws java.lang.IllegalStateException if connection point is not | ||
94 | + * associated with a pcc client | ||
95 | + */ | ||
96 | + public IpElementId ipElementId() { | ||
97 | + if (elementId instanceof IpElementId) { | ||
98 | + return (IpElementId) elementId; | ||
99 | + } | ||
100 | + throw new IllegalStateException("Connection point not associated " + | ||
101 | + "with an pcc client"); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
88 | * Returns the connection port number. | 105 | * Returns the connection port number. |
89 | * | 106 | * |
90 | * @return port number | 107 | * @return port number | ... | ... |
1 | +package org.onosproject.net; | ||
2 | + | ||
3 | +import java.util.Objects; | ||
4 | +import org.onlab.packet.IpAddress; | ||
5 | +import com.google.common.base.MoreObjects; | ||
6 | + | ||
7 | +/** | ||
8 | + * Represent for a Element ID using ip address. | ||
9 | + */ | ||
10 | +public final class IpElementId extends ElementId { | ||
11 | + | ||
12 | + private final IpAddress ipAddress; | ||
13 | + | ||
14 | + /** | ||
15 | + * Public construction is prohibited. | ||
16 | + * @param ipAddress ip address | ||
17 | + */ | ||
18 | + private IpElementId(IpAddress ipAddress) { | ||
19 | + this.ipAddress = ipAddress; | ||
20 | + } | ||
21 | + | ||
22 | + /** | ||
23 | + * Create a IP Element ID. | ||
24 | + * @param ipAddress IP address | ||
25 | + * @return IpElementId | ||
26 | + */ | ||
27 | + public static IpElementId ipElement(IpAddress ipAddress) { | ||
28 | + return new IpElementId(ipAddress); | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns the ip address. | ||
33 | + * | ||
34 | + * @return ipAddress | ||
35 | + */ | ||
36 | + public IpAddress ipAddress() { | ||
37 | + return ipAddress; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public int hashCode() { | ||
42 | + return Objects.hash(ipAddress); | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public boolean equals(Object obj) { | ||
47 | + if (this == obj) { | ||
48 | + return true; | ||
49 | + } | ||
50 | + if (obj instanceof IpElementId) { | ||
51 | + final IpElementId other = (IpElementId) obj; | ||
52 | + return Objects.equals(this.ipAddress, other.ipAddress); | ||
53 | + } | ||
54 | + return false; | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public String toString() { | ||
59 | + return MoreObjects.toStringHelper(getClass()).add("ipAddress", ipAddress).toString(); | ||
60 | + } | ||
61 | +} |
... | @@ -220,5 +220,4 @@ public class PcepFactoryVer1 implements PcepFactory { | ... | @@ -220,5 +220,4 @@ public class PcepFactoryVer1 implements PcepFactory { |
220 | public PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg() { | 220 | public PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg() { |
221 | return new PcepLabelRangeResvMsgVer1.Builder(); | 221 | return new PcepLabelRangeResvMsgVer1.Builder(); |
222 | } | 222 | } |
223 | - | ||
224 | } | 223 | } | ... | ... |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
2 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | 2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
3 | - <modelVersion>4.0.0</modelVersion> | 3 | + <modelVersion>4.0.0</modelVersion> |
4 | - <parent> | 4 | + <parent> |
5 | - <groupId>org.onosproject</groupId> | 5 | + <groupId>org.onosproject</groupId> |
6 | - <artifactId>onos-pcep-providers</artifactId> | 6 | + <artifactId>onos-pcep-providers</artifactId> |
7 | - <version>1.3.0-SNAPSHOT</version> | 7 | + <version>1.3.0-SNAPSHOT</version> |
8 | - <relativePath>../pom.xml</relativePath> | 8 | + <relativePath>../pom.xml</relativePath> |
9 | - </parent> | 9 | + </parent> |
10 | - <artifactId>onos-pcep-provider-tunnel</artifactId> | 10 | + <artifactId>onos-pcep-provider-tunnel</artifactId> |
11 | - <packaging>bundle</packaging> | 11 | + <packaging>bundle</packaging> |
12 | <description>PCEP-based tunnel provider</description> | 12 | <description>PCEP-based tunnel provider</description> |
13 | - <dependencies> | 13 | + <dependencies> |
14 | - <dependency> | 14 | + <dependency> |
15 | - <groupId>org.onosproject</groupId> | 15 | + <groupId>org.onosproject</groupId> |
16 | - <artifactId>onos-app-pcep-api</artifactId> | 16 | + <artifactId>onos-app-pcep-api</artifactId> |
17 | - </dependency> | 17 | + </dependency> |
18 | - </dependencies> | 18 | + <dependency> |
19 | + <groupId>org.onosproject</groupId> | ||
20 | + <artifactId>onos-pcep-controller-api</artifactId> | ||
21 | + </dependency> | ||
22 | + </dependencies> | ||
19 | </project> | 23 | </project> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 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 java.util.HashMap; | ||
19 | +import java.util.Map; | ||
20 | + | ||
21 | +import org.apache.commons.collections.map.MultiKeyMap; | ||
22 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
23 | +import org.onosproject.incubator.net.tunnel.TunnelProviderService; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +/** | ||
28 | + * Entity to provide tunnel DB and mapping for request/response between CORE to PCEP | ||
29 | + * and PCEP to PCC. | ||
30 | + */ | ||
31 | +public class PcepTunnelApiMapper { | ||
32 | + protected static final Logger log = LoggerFactory.getLogger(PcepTunnelApiMapper.class); | ||
33 | + | ||
34 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | ||
35 | + // Map to store all the tunnel requests. | ||
36 | + private Map<Integer, PcepTunnelData> tunnelRequestQueue; | ||
37 | + //Map to store all core related tunnel requests. | ||
38 | + private Map<TunnelId, PcepTunnelData> coreTunnelRequestQueue; | ||
39 | + //Map to store all the created tunnels. | ||
40 | + private Map<Integer, PcepTunnelData> tunnelDB; | ||
41 | + // Map to store the tunnel ids, given by core and given by pcc. | ||
42 | + private Map<TunnelId, Integer> tunnelIdMap; | ||
43 | + //Map to store all the learnt tunnels. | ||
44 | + private MultiKeyMap pccTunnelDB = new MultiKeyMap(); | ||
45 | + | ||
46 | + TunnelProviderService tunnelApiMapperservice; | ||
47 | + | ||
48 | + /** | ||
49 | + * Default constructor. | ||
50 | + */ | ||
51 | + public PcepTunnelApiMapper() { | ||
52 | + //TODO check if the map need to initialize | ||
53 | + tunnelRequestQueue = new HashMap<Integer, PcepTunnelData>(); | ||
54 | + coreTunnelRequestQueue = new HashMap<TunnelId, PcepTunnelData>(); | ||
55 | + tunnelDB = new HashMap<Integer, PcepTunnelData>(); | ||
56 | + tunnelIdMap = new HashMap<TunnelId, Integer>(); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Add tunnels to tunnel Request queues. | ||
61 | + * | ||
62 | + * @param srpId srp id | ||
63 | + * @param pcepTunnelData pcep tunnel data | ||
64 | + */ | ||
65 | + public void addToTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) { | ||
66 | + tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData); | ||
67 | + log.debug("Tunnel Added to TunnelRequestQueue"); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Map between Tunnel ID and pcc provided Tunnel ID. | ||
72 | + * | ||
73 | + * @param pcepTunnelData pcep tunnel data | ||
74 | + */ | ||
75 | + public void addToTunnelIdMap(PcepTunnelData pcepTunnelData) { | ||
76 | + int value = pcepTunnelData.statefulIpv4IndentifierTlv().getTunnelId() & 0xFFFF; | ||
77 | + tunnelIdMap.put(pcepTunnelData.tunnel().tunnelId(), (new Integer(value))); | ||
78 | + log.debug("Tunnel ID Added to tunnelIdMap"); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Add tunnels to core tunnel request queue. | ||
83 | + * | ||
84 | + * @param pcepTunnelData pcep tunnel data | ||
85 | + */ | ||
86 | + public void addToCoreTunnelRequestQueue(PcepTunnelData pcepTunnelData) { | ||
87 | + coreTunnelRequestQueue.put(pcepTunnelData.tunnel().tunnelId(), pcepTunnelData); | ||
88 | + log.debug("Tunnel Added to CoreTunnelRequestQueue"); | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * Removes tunnels from the core tunnel request queue. | ||
93 | + * | ||
94 | + * @param tunnelId tunnel id | ||
95 | + */ | ||
96 | + public void removeFromCoreTunnelRequestQueue(TunnelId tunnelId) { | ||
97 | + coreTunnelRequestQueue.remove(tunnelId); | ||
98 | + log.debug("Tunnnel create response sent to core and removed from CoreTunnelRequestQueue"); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Handle the report which comes after initiate message. | ||
103 | + * | ||
104 | + * @param srpId srp id | ||
105 | + * @param pcepTunnelData pcep tunnel data | ||
106 | + */ | ||
107 | + public void handleCreateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) { | ||
108 | + | ||
109 | + int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId()); | ||
110 | + tunnelDB.put(new Integer(value), pcepTunnelData); | ||
111 | + tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData); | ||
112 | + log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}" | ||
113 | + + (new Integer(value)).toString()); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Handle report which comes for update message. | ||
118 | + * | ||
119 | + * @param srpId srp id | ||
120 | + * @param pcepTunnelData pcep tunnel data | ||
121 | + */ | ||
122 | + public void handleUpdateTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) { | ||
123 | + if (pcepTunnelData.rptFlag()) { | ||
124 | + pcepTunnelData.setRptFlag(false); | ||
125 | + int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId()); | ||
126 | + tunnelDB.put(new Integer(value), pcepTunnelData); | ||
127 | + tunnelRequestQueue.remove(new Integer(srpId), pcepTunnelData); | ||
128 | + log.debug("Tunnel Added to TunnelDBQueue and removed from TunnelRequestQueue. tunnel id {}" , | ||
129 | + (new Integer(value)).toString()); | ||
130 | + } else { | ||
131 | + pcepTunnelData.setRptFlag(true); | ||
132 | + tunnelRequestQueue.put(new Integer(srpId), pcepTunnelData); | ||
133 | + log.debug("Tunnel updated in TunnelRequestQueue"); | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Handle report for tunnel Release request. | ||
139 | + * | ||
140 | + * @param srpId srp id | ||
141 | + * @param pcepTunnelData pcep tunnel data | ||
142 | + */ | ||
143 | + public void handleRemoveFromTunnelRequestQueue(int srpId, PcepTunnelData pcepTunnelData) { | ||
144 | + | ||
145 | + int value = tunnelIdMap.get(pcepTunnelData.tunnel().tunnelId()); | ||
146 | + tunnelIdMap.remove(pcepTunnelData.tunnel().tunnelId()); | ||
147 | + tunnelDB.remove(new Integer(value)); | ||
148 | + tunnelRequestQueue.remove(srpId); | ||
149 | + log.debug("Tunnel removed from TunnelDBQueue and TunnelRequestQueue"); | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Returns PcepTunnelData from the tunnel request queue. | ||
154 | + * | ||
155 | + * @param srpId srp id | ||
156 | + * @return PcepTunnelData pcep tunnel data | ||
157 | + */ | ||
158 | + public PcepTunnelData getDataFromTunnelRequestQueue(int srpId) { | ||
159 | + return tunnelRequestQueue.get(new Integer(srpId)); | ||
160 | + | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * Returns PcepTunnelData from the tunnel DB. | ||
165 | + * | ||
166 | + * @param tunnelId tunnel id | ||
167 | + * @return PcepTunnelData pcep tunnel data | ||
168 | + */ | ||
169 | + public PcepTunnelData getDataFromTunnelDBQueue(TunnelId tunnelId) { | ||
170 | + int value = tunnelIdMap.get(tunnelId); | ||
171 | + return tunnelDB.get((new Integer(value))); | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Checks whether the tunnel exist in tunnel request queue. | ||
176 | + * | ||
177 | + * @param srpId srp id | ||
178 | + * @return true if tunnel exist in reuest queue, false otherwise | ||
179 | + */ | ||
180 | + public boolean checkFromTunnelRequestQueue(int srpId) { | ||
181 | + boolean retValue = tunnelRequestQueue.containsKey(srpId); | ||
182 | + return retValue; | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Returns whether tunnel exist in tunnel db. | ||
187 | + * | ||
188 | + * @param tunnelId | ||
189 | + * @return true/false | ||
190 | + */ | ||
191 | + public boolean checkFromTunnelDBQueue(TunnelId tunnelId) { | ||
192 | + int value = tunnelIdMap.get(tunnelId); | ||
193 | + boolean retValue = tunnelDB.containsKey((new Integer(value))); | ||
194 | + return retValue; | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
198 | + * Add Learnt tunnels to pcc tunnel DB. | ||
199 | + * | ||
200 | + * @param pcepTunnelData pcep tunnel data | ||
201 | + */ | ||
202 | + public void addPccTunnelDB(PcepTunnelData pcepTunnelData) { | ||
203 | + pccTunnelDB.put(pcepTunnelData.statefulIpv4IndentifierTlv().getTunnelId() & 0xFFFFL, | ||
204 | + pcepTunnelData.statefulIpv4IndentifierTlv().getIpv4IngressAddress(), pcepTunnelData); | ||
205 | + } | ||
206 | +} |
providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelData.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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 java.util.Objects; | ||
19 | + | ||
20 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
21 | +import org.onosproject.net.ElementId; | ||
22 | +import org.onosproject.net.Path; | ||
23 | +import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ||
24 | + | ||
25 | +import com.google.common.base.MoreObjects; | ||
26 | + | ||
27 | +/** | ||
28 | + * To store all tunnel related information from Core and Path computation client. | ||
29 | + */ | ||
30 | +public class PcepTunnelData { | ||
31 | + | ||
32 | + private Tunnel tunnel; | ||
33 | + private Path path; | ||
34 | + private int plspId; | ||
35 | + private ElementId elementId; | ||
36 | + private RequestType requestType; | ||
37 | + private boolean rptFlag; | ||
38 | + | ||
39 | + // data need to store from LSP object | ||
40 | + private boolean lspAFlag; | ||
41 | + private boolean lspDFlag; | ||
42 | + private byte lspOFlag; | ||
43 | + private short tunnelId; | ||
44 | + private int extTunnelId; | ||
45 | + private short lspId; | ||
46 | + private StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv; | ||
47 | + | ||
48 | + /** | ||
49 | + * Default constructor. | ||
50 | + */ | ||
51 | + public PcepTunnelData() { | ||
52 | + this.elementId = null; | ||
53 | + this.tunnel = null; | ||
54 | + this.path = null; | ||
55 | + this.requestType = null; | ||
56 | + this.rptFlag = false; | ||
57 | + this.plspId = 0; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Constructor to initialize Tunnel, Path and Request type. | ||
62 | + * | ||
63 | + * @param tunnel mpls tunnel | ||
64 | + * @param path Path in network | ||
65 | + * @param requestType request type for tunnel | ||
66 | + */ | ||
67 | + public PcepTunnelData(Tunnel tunnel, Path path, RequestType requestType) { | ||
68 | + this.tunnel = tunnel; | ||
69 | + this.path = path; | ||
70 | + this.requestType = requestType; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Constructor to initialize ElemendId, Tunnel, Path and Request type. | ||
75 | + * | ||
76 | + * @param elementId Ip element id | ||
77 | + * @param tunnel mpls tunnel | ||
78 | + * @param path Path in network | ||
79 | + * @param requestType request type for tunnel | ||
80 | + */ | ||
81 | + public PcepTunnelData(ElementId elementId, Tunnel tunnel, Path path, RequestType requestType) { | ||
82 | + this.elementId = elementId; | ||
83 | + this.tunnel = tunnel; | ||
84 | + this.path = path; | ||
85 | + this.requestType = requestType; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Constructor to initialize Tunnel and Request type. | ||
90 | + * | ||
91 | + * @param tunnel Tunnel from core | ||
92 | + * @param requestType request type for tunnel | ||
93 | + */ | ||
94 | + public PcepTunnelData(Tunnel tunnel, RequestType requestType) { | ||
95 | + this.tunnel = tunnel; | ||
96 | + this.requestType = requestType; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Constructor to initialize ElementId, Tunnel and Request type. | ||
101 | + * | ||
102 | + * @param elementId Ip element id | ||
103 | + * @param tunnel mpls tunnel | ||
104 | + * @param requestType request type for tunnel | ||
105 | + */ | ||
106 | + public PcepTunnelData(ElementId elementId, Tunnel tunnel, RequestType requestType) { | ||
107 | + this.elementId = elementId; | ||
108 | + this.tunnel = tunnel; | ||
109 | + this.requestType = requestType; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Sets ip element id. | ||
114 | + * | ||
115 | + * @param elementId Ip element id | ||
116 | + */ | ||
117 | + public void setElementId(ElementId elementId) { | ||
118 | + this.elementId = elementId; | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Sets tunnel. | ||
123 | + * | ||
124 | + * @param tunnel mpls tunnel | ||
125 | + */ | ||
126 | + public void setTunnel(Tunnel tunnel) { | ||
127 | + this.tunnel = tunnel; | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Sets Path. | ||
132 | + * | ||
133 | + * @param path Path in network | ||
134 | + */ | ||
135 | + public void setPath(Path path) { | ||
136 | + this.path = path; | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Request type for tunnel. | ||
141 | + * | ||
142 | + * @param requestType request type for tunnel | ||
143 | + */ | ||
144 | + public void setRequestType(RequestType requestType) { | ||
145 | + this.requestType = requestType; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Sets plspid generated from pcc. | ||
150 | + * | ||
151 | + * @param plspId plsp identifier | ||
152 | + */ | ||
153 | + public void setPlspId(int plspId) { | ||
154 | + this.plspId = plspId; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Sets A flag from lsp object. | ||
159 | + * | ||
160 | + * @param value A flag value | ||
161 | + */ | ||
162 | + public void setLspAFlag(boolean value) { | ||
163 | + this.lspAFlag = value; | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Sets OF flag from lsp object. | ||
168 | + * | ||
169 | + * @param value OF flag value | ||
170 | + */ | ||
171 | + public void setLspOFlag(byte value) { | ||
172 | + this.lspOFlag = value; | ||
173 | + } | ||
174 | + | ||
175 | + /** | ||
176 | + * Sets tunnel id from PCC. | ||
177 | + * | ||
178 | + * @param value tunnel id value | ||
179 | + */ | ||
180 | + public void setTunnelId(short value) { | ||
181 | + this.tunnelId = value; | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Sets extended tunnel id from PCC. | ||
186 | + * | ||
187 | + * @param value extended tunnel id value | ||
188 | + */ | ||
189 | + public void setExtTunnelId(int value) { | ||
190 | + this.extTunnelId = value; | ||
191 | + } | ||
192 | + | ||
193 | + /** | ||
194 | + * Sets lsp id from pcc. | ||
195 | + * | ||
196 | + * @param value lsp id | ||
197 | + */ | ||
198 | + public void setLspId(short value) { | ||
199 | + this.lspId = value; | ||
200 | + } | ||
201 | + | ||
202 | + /** | ||
203 | + * Sets statefulIpv4Identifiers tlv. | ||
204 | + * @param value statefulIpv4Identifiers tlv | ||
205 | + */ | ||
206 | + public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentidiersTlv value) { | ||
207 | + this.statefulIpv4IndentifierTlv = value; | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Sets report flag. | ||
212 | + * | ||
213 | + * @param rptFlag report flag | ||
214 | + */ | ||
215 | + public void setRptFlag(boolean rptFlag) { | ||
216 | + this.rptFlag = rptFlag; | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
220 | + * Sets D flag from lsp object. | ||
221 | + * | ||
222 | + * @param value D flag value | ||
223 | + */ | ||
224 | + public void setLspDFlag(boolean value) { | ||
225 | + this.lspDFlag = value; | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * To get Ip element id. | ||
230 | + * | ||
231 | + * @return Ip elemend id | ||
232 | + */ | ||
233 | + public ElementId elementId() { | ||
234 | + return this.elementId; | ||
235 | + } | ||
236 | + | ||
237 | + /** | ||
238 | + * To get Tunnel. | ||
239 | + * | ||
240 | + * @return tunnel | ||
241 | + */ | ||
242 | + public Tunnel tunnel() { | ||
243 | + return this.tunnel; | ||
244 | + } | ||
245 | + | ||
246 | + /** | ||
247 | + * To get Path. | ||
248 | + * | ||
249 | + * @return path | ||
250 | + */ | ||
251 | + public Path path() { | ||
252 | + return this.path; | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * To get request type. | ||
257 | + * | ||
258 | + * @return request type | ||
259 | + */ | ||
260 | + public RequestType requestType() { | ||
261 | + return this.requestType; | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
265 | + * To get pLspId. | ||
266 | + * | ||
267 | + * @return pLspId | ||
268 | + */ | ||
269 | + public int plspId() { | ||
270 | + return this.plspId; | ||
271 | + } | ||
272 | + | ||
273 | + /** | ||
274 | + * To get A flag. | ||
275 | + * | ||
276 | + * @return A flag | ||
277 | + */ | ||
278 | + public boolean lspAFlag() { | ||
279 | + return this.lspAFlag; | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * To get OF flag. | ||
284 | + * | ||
285 | + * @return OF flag | ||
286 | + */ | ||
287 | + public byte lspOFlag() { | ||
288 | + return this.lspOFlag; | ||
289 | + } | ||
290 | + | ||
291 | + /** | ||
292 | + * To get tunnel id. | ||
293 | + * | ||
294 | + * @return tunnel id | ||
295 | + */ | ||
296 | + public short tunnelId() { | ||
297 | + return this.tunnelId; | ||
298 | + } | ||
299 | + | ||
300 | + /** | ||
301 | + * To get extended tunnel id. | ||
302 | + * | ||
303 | + * @return extended tunnel id | ||
304 | + */ | ||
305 | + public int extTunnelId() { | ||
306 | + return this.extTunnelId; | ||
307 | + } | ||
308 | + | ||
309 | + /** | ||
310 | + * To get pLspId. | ||
311 | + * | ||
312 | + * @return pLspId | ||
313 | + */ | ||
314 | + public short lspId() { | ||
315 | + return this.lspId; | ||
316 | + } | ||
317 | + | ||
318 | + /** | ||
319 | + * To get D Flag. | ||
320 | + * | ||
321 | + * @return d flag | ||
322 | + */ | ||
323 | + public boolean lspDFlag() { | ||
324 | + return this.lspDFlag; | ||
325 | + } | ||
326 | + | ||
327 | + /** | ||
328 | + * To get statefulIpv4Indentifier tlv. | ||
329 | + * | ||
330 | + * @return statefulIpv4Indentifier tlv | ||
331 | + */ | ||
332 | + public StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv() { | ||
333 | + return this.statefulIpv4IndentifierTlv; | ||
334 | + } | ||
335 | + | ||
336 | + /** | ||
337 | + * To get report flag. | ||
338 | + * | ||
339 | + * @return report flag | ||
340 | + */ | ||
341 | + public boolean rptFlag() { | ||
342 | + return this.rptFlag; | ||
343 | + } | ||
344 | + | ||
345 | + @Override | ||
346 | + public boolean equals(Object obj) { | ||
347 | + if (this == obj) { | ||
348 | + return true; | ||
349 | + } | ||
350 | + | ||
351 | + if (obj instanceof PcepTunnelData) { | ||
352 | + PcepTunnelData other = (PcepTunnelData) obj; | ||
353 | + return Objects.equals(tunnel, other.tunnel) | ||
354 | + && Objects.equals(path, other.path) | ||
355 | + && Objects.equals(plspId, other.plspId) | ||
356 | + && Objects.equals(elementId, other.elementId) | ||
357 | + && Objects.equals(requestType, other.requestType) | ||
358 | + && Objects.equals(rptFlag, other.rptFlag) | ||
359 | + && Objects.equals(lspAFlag, other.lspAFlag) | ||
360 | + && Objects.equals(lspDFlag, other.lspDFlag) | ||
361 | + && Objects.equals(lspOFlag, other.lspOFlag) | ||
362 | + && Objects.equals(tunnelId, other.tunnelId) | ||
363 | + && Objects.equals(extTunnelId, other.extTunnelId) | ||
364 | + && Objects.equals(lspId, other.lspId) | ||
365 | + && Objects.equals(statefulIpv4IndentifierTlv, other.statefulIpv4IndentifierTlv); | ||
366 | + } | ||
367 | + | ||
368 | + return false; | ||
369 | + } | ||
370 | + | ||
371 | + @Override | ||
372 | + public int hashCode() { | ||
373 | + return Objects.hash(tunnel, path, plspId, elementId, requestType, rptFlag, lspAFlag, | ||
374 | + lspDFlag, lspOFlag, tunnelId, extTunnelId, lspId, statefulIpv4IndentifierTlv); | ||
375 | + } | ||
376 | + | ||
377 | + @Override | ||
378 | + public String toString() { | ||
379 | + return MoreObjects.toStringHelper(getClass()).add("Tunnel", tunnel) | ||
380 | + .add("Path", path).add("PlspId", plspId).add("ElementId", elementId) | ||
381 | + .add("RequestType", requestType).add("RptFlag", rptFlag).add("LspAFlag", lspAFlag) | ||
382 | + .add("LspDFlag", lspDFlag).add("LspOFlag", lspOFlag).add("TunnelId", tunnelId) | ||
383 | + .add("ExtTunnelid", extTunnelId).add("LspId", lspId) | ||
384 | + .add("StatefulIpv4IndentifierTlv", statefulIpv4IndentifierTlv).toString(); | ||
385 | + } | ||
386 | +} |
... | @@ -16,13 +16,18 @@ | ... | @@ -16,13 +16,18 @@ |
16 | package org.onosproject.provider.pcep.tunnel.impl; | 16 | package org.onosproject.provider.pcep.tunnel.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | +import static org.onosproject.net.DefaultAnnotations.EMPTY; | ||
19 | import static org.onosproject.net.DeviceId.deviceId; | 20 | import static org.onosproject.net.DeviceId.deviceId; |
20 | import static org.onosproject.net.PortNumber.portNumber; | 21 | import static org.onosproject.net.PortNumber.portNumber; |
22 | +import static org.onosproject.pcep.api.PcepDpid.uri; | ||
21 | import static org.slf4j.LoggerFactory.getLogger; | 23 | import static org.slf4j.LoggerFactory.getLogger; |
22 | 24 | ||
23 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
26 | +import java.util.Collections; | ||
24 | import java.util.HashMap; | 27 | import java.util.HashMap; |
28 | +import java.util.LinkedList; | ||
25 | import java.util.List; | 29 | import java.util.List; |
30 | +import java.util.ListIterator; | ||
26 | import java.util.Optional; | 31 | import java.util.Optional; |
27 | 32 | ||
28 | import org.apache.felix.scr.annotations.Activate; | 33 | import org.apache.felix.scr.annotations.Activate; |
... | @@ -31,9 +36,12 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -31,9 +36,12 @@ import org.apache.felix.scr.annotations.Deactivate; |
31 | import org.apache.felix.scr.annotations.Reference; | 36 | import org.apache.felix.scr.annotations.Reference; |
32 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 37 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
33 | import org.apache.felix.scr.annotations.Service; | 38 | import org.apache.felix.scr.annotations.Service; |
39 | +import org.onlab.packet.IpAddress; | ||
34 | import org.onosproject.core.DefaultGroupId; | 40 | import org.onosproject.core.DefaultGroupId; |
35 | import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint; | 41 | import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint; |
42 | +import org.onosproject.incubator.net.tunnel.DefaultTunnel; | ||
36 | import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; | 43 | import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; |
44 | +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; | ||
37 | import org.onosproject.incubator.net.tunnel.OpticalLogicId; | 45 | import org.onosproject.incubator.net.tunnel.OpticalLogicId; |
38 | import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; | 46 | import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; |
39 | import org.onosproject.incubator.net.tunnel.Tunnel; | 47 | import org.onosproject.incubator.net.tunnel.Tunnel; |
... | @@ -50,9 +58,11 @@ import org.onosproject.net.DefaultLink; | ... | @@ -50,9 +58,11 @@ import org.onosproject.net.DefaultLink; |
50 | import org.onosproject.net.DefaultPath; | 58 | import org.onosproject.net.DefaultPath; |
51 | import org.onosproject.net.DeviceId; | 59 | import org.onosproject.net.DeviceId; |
52 | import org.onosproject.net.ElementId; | 60 | import org.onosproject.net.ElementId; |
61 | +import org.onosproject.net.IpElementId; | ||
53 | import org.onosproject.net.Link; | 62 | import org.onosproject.net.Link; |
54 | import org.onosproject.net.Path; | 63 | import org.onosproject.net.Path; |
55 | import org.onosproject.net.PortNumber; | 64 | import org.onosproject.net.PortNumber; |
65 | +import org.onosproject.net.SparseAnnotations; | ||
56 | import org.onosproject.net.provider.AbstractProvider; | 66 | import org.onosproject.net.provider.AbstractProvider; |
57 | import org.onosproject.net.provider.ProviderId; | 67 | import org.onosproject.net.provider.ProviderId; |
58 | import org.onosproject.pcep.api.PcepController; | 68 | import org.onosproject.pcep.api.PcepController; |
... | @@ -60,9 +70,34 @@ import org.onosproject.pcep.api.PcepDpid; | ... | @@ -60,9 +70,34 @@ import org.onosproject.pcep.api.PcepDpid; |
60 | import org.onosproject.pcep.api.PcepHopNodeDescription; | 70 | import org.onosproject.pcep.api.PcepHopNodeDescription; |
61 | import org.onosproject.pcep.api.PcepOperator.OperationType; | 71 | import org.onosproject.pcep.api.PcepOperator.OperationType; |
62 | import org.onosproject.pcep.api.PcepTunnel; | 72 | import org.onosproject.pcep.api.PcepTunnel; |
63 | -import org.onosproject.pcep.api.PcepTunnel.PathState; | ||
64 | import org.onosproject.pcep.api.PcepTunnel.PATHTYPE; | 73 | import org.onosproject.pcep.api.PcepTunnel.PATHTYPE; |
74 | +import org.onosproject.pcep.api.PcepTunnel.PathState; | ||
65 | import org.onosproject.pcep.api.PcepTunnelListener; | 75 | import org.onosproject.pcep.api.PcepTunnelListener; |
76 | +import org.onosproject.pcep.controller.PccId; | ||
77 | +import org.onosproject.pcep.controller.PcepClient; | ||
78 | +import org.onosproject.pcep.controller.PcepClientController; | ||
79 | +import org.onosproject.pcep.controller.PcepClientListener; | ||
80 | +import org.onosproject.pcep.controller.PcepEventListener; | ||
81 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
82 | +import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; | ||
83 | +import org.onosproject.pcepio.protocol.PcepAttribute; | ||
84 | +import org.onosproject.pcepio.protocol.PcepBandwidthObject; | ||
85 | +import org.onosproject.pcepio.protocol.PcepEndPointsObject; | ||
86 | +import org.onosproject.pcepio.protocol.PcepEroObject; | ||
87 | +import org.onosproject.pcepio.protocol.PcepInitiateMsg; | ||
88 | +import org.onosproject.pcepio.protocol.PcepLspObject; | ||
89 | +import org.onosproject.pcepio.protocol.PcepMessage; | ||
90 | +import org.onosproject.pcepio.protocol.PcepMsgPath; | ||
91 | +import org.onosproject.pcepio.protocol.PcepReportMsg; | ||
92 | +import org.onosproject.pcepio.protocol.PcepRroObject; | ||
93 | +import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
94 | +import org.onosproject.pcepio.protocol.PcepStateReport; | ||
95 | +import org.onosproject.pcepio.protocol.PcepUpdateMsg; | ||
96 | +import org.onosproject.pcepio.protocol.PcepUpdateRequest; | ||
97 | +import org.onosproject.pcepio.types.IPv4SubObject; | ||
98 | +import org.onosproject.pcepio.types.PcepValueType; | ||
99 | +import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ||
100 | +import org.onosproject.pcepio.types.SymbolicPathNameTlv; | ||
66 | import org.slf4j.Logger; | 101 | import org.slf4j.Logger; |
67 | 102 | ||
68 | import static org.onosproject.pcep.api.PcepDpid.*; | 103 | import static org.onosproject.pcep.api.PcepDpid.*; |
... | @@ -73,14 +108,13 @@ import static org.onosproject.pcep.api.PcepDpid.*; | ... | @@ -73,14 +108,13 @@ import static org.onosproject.pcep.api.PcepDpid.*; |
73 | */ | 108 | */ |
74 | @Component(immediate = true) | 109 | @Component(immediate = true) |
75 | @Service | 110 | @Service |
76 | -public class PcepTunnelProvider extends AbstractProvider | 111 | +public class PcepTunnelProvider extends AbstractProvider implements TunnelProvider { |
77 | - implements TunnelProvider { | ||
78 | 112 | ||
79 | private static final Logger log = getLogger(PcepTunnelProvider.class); | 113 | private static final Logger log = getLogger(PcepTunnelProvider.class); |
80 | private static final long MAX_BANDWIDTH = 99999744; | 114 | private static final long MAX_BANDWIDTH = 99999744; |
81 | private static final long MIN_BANDWIDTH = 64; | 115 | private static final long MIN_BANDWIDTH = 64; |
82 | private static final String BANDWIDTH_UINT = "kbps"; | 116 | private static final String BANDWIDTH_UINT = "kbps"; |
83 | - static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default"; | 117 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
84 | 118 | ||
85 | private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied."; | 119 | private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied."; |
86 | 120 | ||
... | @@ -90,23 +124,30 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -90,23 +124,30 @@ public class PcepTunnelProvider extends AbstractProvider |
90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 124 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
91 | protected PcepController controller; | 125 | protected PcepController controller; |
92 | 126 | ||
127 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
128 | + protected PcepClientController pcepClientController; | ||
93 | TunnelProviderService service; | 129 | TunnelProviderService service; |
94 | 130 | ||
95 | HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); | 131 | HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); |
96 | 132 | ||
97 | - private InnerTunnerProvider listener = new InnerTunnerProvider(); | 133 | + private InnerTunnelProvider listener = new InnerTunnelProvider(); |
134 | + | ||
135 | + protected PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); | ||
136 | + private static final int DEFAULT_BANDWIDTH_VALUE = 10; | ||
98 | 137 | ||
99 | /** | 138 | /** |
100 | * Creates a Tunnel provider. | 139 | * Creates a Tunnel provider. |
101 | */ | 140 | */ |
102 | public PcepTunnelProvider() { | 141 | public PcepTunnelProvider() { |
103 | - super(new ProviderId("default", PROVIDER_ID)); | 142 | + super(new ProviderId("pcep", PROVIDER_ID)); |
104 | } | 143 | } |
105 | 144 | ||
106 | @Activate | 145 | @Activate |
107 | public void activate() { | 146 | public void activate() { |
108 | service = tunnelProviderRegistry.register(this); | 147 | service = tunnelProviderRegistry.register(this); |
109 | controller.addTunnelListener(listener); | 148 | controller.addTunnelListener(listener); |
149 | + pcepClientController.addListener(listener); | ||
150 | + pcepClientController.addEventListener(listener); | ||
110 | log.info("Started"); | 151 | log.info("Started"); |
111 | } | 152 | } |
112 | 153 | ||
... | @@ -114,47 +155,173 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -114,47 +155,173 @@ public class PcepTunnelProvider extends AbstractProvider |
114 | public void deactivate() { | 155 | public void deactivate() { |
115 | tunnelProviderRegistry.unregister(this); | 156 | tunnelProviderRegistry.unregister(this); |
116 | controller.removeTunnelListener(listener); | 157 | controller.removeTunnelListener(listener); |
158 | + pcepClientController.removeListener(listener); | ||
117 | log.info("Stopped"); | 159 | log.info("Stopped"); |
118 | } | 160 | } |
119 | 161 | ||
120 | @Override | 162 | @Override |
121 | public void setupTunnel(Tunnel tunnel, Path path) { | 163 | public void setupTunnel(Tunnel tunnel, Path path) { |
122 | - // TODO Auto-generated method stub | 164 | + if (tunnel.type() != Tunnel.Type.MPLS) { |
165 | + log.error("Tunnel Type MPLS is only supported"); | ||
166 | + return; | ||
167 | + } | ||
123 | 168 | ||
169 | + // check for tunnel end points | ||
170 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
171 | + log.error("Tunnel source or destination is not valid"); | ||
172 | + return; | ||
173 | + } | ||
174 | + | ||
175 | + // Get the pcc client | ||
176 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); | ||
177 | + | ||
178 | + if (!(pc instanceof PcepClient)) { | ||
179 | + log.error("There is no PCC connected with ip addresss {}" | ||
180 | + + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); | ||
181 | + return; | ||
182 | + } | ||
183 | + pcepSetupTunnel(tunnel, path, pc); | ||
124 | } | 184 | } |
125 | 185 | ||
126 | @Override | 186 | @Override |
127 | public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | 187 | public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { |
128 | - // TODO Auto-generated method stub | ||
129 | 188 | ||
189 | + if (tunnel.type() != Tunnel.Type.MPLS) { | ||
190 | + log.error("Tunnel Type MPLS is only supported"); | ||
191 | + return; | ||
192 | + } | ||
193 | + | ||
194 | + if (!(srcElement instanceof IpElementId)) { | ||
195 | + log.error("Element id is not valid"); | ||
196 | + return; | ||
197 | + } | ||
198 | + | ||
199 | + // check for tunnel end points | ||
200 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
201 | + log.error("Tunnel source or destination is not valid"); | ||
202 | + return; | ||
203 | + } | ||
204 | + | ||
205 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); | ||
206 | + | ||
207 | + if (!(pc instanceof PcepClient)) { | ||
208 | + log.error("There is no PCC connected with ip addresss {}" | ||
209 | + + ((IpElementId) srcElement).ipAddress().toString()); | ||
210 | + return; | ||
211 | + } | ||
212 | + pcepSetupTunnel(tunnel, path, pc); | ||
130 | } | 213 | } |
131 | 214 | ||
132 | @Override | 215 | @Override |
133 | public void releaseTunnel(Tunnel tunnel) { | 216 | public void releaseTunnel(Tunnel tunnel) { |
134 | - // TODO Auto-generated method stub | ||
135 | 217 | ||
218 | + if (tunnel.type() != Tunnel.Type.MPLS) { | ||
219 | + log.error("Tunnel Type MPLS is only supported"); | ||
220 | + return; | ||
221 | + } | ||
222 | + | ||
223 | + // check for tunnel end points | ||
224 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
225 | + log.error("Tunnel source or destination is not valid"); | ||
226 | + return; | ||
227 | + } | ||
228 | + | ||
229 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); | ||
230 | + | ||
231 | + if (!(pc instanceof PcepClient)) { | ||
232 | + log.error("There is no PCC connected with ip addresss {}" | ||
233 | + + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); | ||
234 | + return; | ||
235 | + } | ||
236 | + pcepReleaseTunnel(tunnel, pc); | ||
136 | } | 237 | } |
137 | 238 | ||
138 | @Override | 239 | @Override |
139 | public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { | 240 | public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { |
140 | - // TODO Auto-generated method stub | 241 | + if (tunnel.type() != Tunnel.Type.MPLS) { |
242 | + log.error("Tunnel Type MPLS is only supported"); | ||
243 | + return; | ||
244 | + } | ||
245 | + | ||
246 | + if (!(srcElement instanceof IpElementId)) { | ||
247 | + log.error("Element id is not valid"); | ||
248 | + return; | ||
249 | + } | ||
141 | 250 | ||
251 | + // check for tunnel end points | ||
252 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
253 | + log.error("Tunnel source or destination is not valid"); | ||
254 | + return; | ||
255 | + } | ||
256 | + | ||
257 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); | ||
258 | + | ||
259 | + if (!(pc instanceof PcepClient)) { | ||
260 | + log.error("There is no PCC connected with ip addresss {}" | ||
261 | + + ((IpElementId) srcElement).ipAddress().toString()); | ||
262 | + return; | ||
263 | + } | ||
264 | + pcepReleaseTunnel(tunnel, pc); | ||
142 | } | 265 | } |
143 | 266 | ||
144 | @Override | 267 | @Override |
145 | public void updateTunnel(Tunnel tunnel, Path path) { | 268 | public void updateTunnel(Tunnel tunnel, Path path) { |
146 | - // TODO Auto-generated method stub | 269 | + if (tunnel.type() != Tunnel.Type.MPLS) { |
270 | + log.error("Tunnel Type MPLS is only supported"); | ||
271 | + return; | ||
272 | + } | ||
273 | + | ||
274 | + // check for tunnel end points | ||
275 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
276 | + log.error("Tunnel source or destination is not valid"); | ||
277 | + return; | ||
278 | + } | ||
147 | 279 | ||
280 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpTunnelEndPoint) tunnel.src()).ip())); | ||
281 | + | ||
282 | + if (!(pc instanceof PcepClient)) { | ||
283 | + log.error("There is no PCC connected with ip addresss {}" | ||
284 | + + ((IpTunnelEndPoint) tunnel.src()).ip().toString()); | ||
285 | + return; | ||
286 | + } | ||
287 | + pcepUpdateTunnel(tunnel, path, pc); | ||
148 | } | 288 | } |
149 | 289 | ||
150 | @Override | 290 | @Override |
151 | public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | 291 | public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { |
152 | - // TODO Auto-generated method stub | ||
153 | 292 | ||
293 | + if (tunnel.type() != Tunnel.Type.MPLS) { | ||
294 | + log.error("Tunnel Type MPLS is only supported"); | ||
295 | + return; | ||
296 | + } | ||
297 | + | ||
298 | + if (!(srcElement instanceof IpElementId)) { | ||
299 | + log.error("Element id is not valid"); | ||
300 | + return; | ||
301 | + } | ||
302 | + | ||
303 | + // check for tunnel end points | ||
304 | + if (!(tunnel.src() instanceof IpTunnelEndPoint) || !(tunnel.dst() instanceof IpTunnelEndPoint)) { | ||
305 | + log.error("Tunnel source or destination is not valid"); | ||
306 | + return; | ||
307 | + } | ||
308 | + | ||
309 | + PcepClient pc = pcepClientController.getClient(PccId.pccId(((IpElementId) srcElement).ipAddress())); | ||
310 | + | ||
311 | + if (!(pc instanceof PcepClient)) { | ||
312 | + log.error("There is no PCC connected with ip addresss {}" | ||
313 | + + ((IpElementId) srcElement).ipAddress().toString()); | ||
314 | + return; | ||
315 | + } | ||
316 | + pcepUpdateTunnel(tunnel, path, pc); | ||
154 | } | 317 | } |
155 | 318 | ||
156 | @Override | 319 | @Override |
157 | public TunnelId tunnelAdded(TunnelDescription tunnel) { | 320 | public TunnelId tunnelAdded(TunnelDescription tunnel) { |
321 | + if (tunnel.type() == Tunnel.Type.MPLS) { | ||
322 | + pcepTunnelAPIMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); | ||
323 | + return service.tunnelAdded(tunnel); | ||
324 | + } | ||
158 | 325 | ||
159 | long bandwidth = Long | 326 | long bandwidth = Long |
160 | .parseLong(tunnel.annotations().value("bandwidth")); | 327 | .parseLong(tunnel.annotations().value("bandwidth")); |
... | @@ -185,7 +352,7 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -185,7 +352,7 @@ public class PcepTunnelProvider extends AbstractProvider |
185 | PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort, | 352 | PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort, |
186 | dstPort, bandwidth, | 353 | dstPort, bandwidth, |
187 | tunnel.tunnelName() | 354 | tunnel.tunnelName() |
188 | - .value()); | 355 | + .value()); |
189 | 356 | ||
190 | checkNotNull(pcepTunnel, TUNNLE_NOT_NULL); | 357 | checkNotNull(pcepTunnel, TUNNLE_NOT_NULL); |
191 | TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null); | 358 | TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null); |
... | @@ -197,6 +364,11 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -197,6 +364,11 @@ public class PcepTunnelProvider extends AbstractProvider |
197 | 364 | ||
198 | @Override | 365 | @Override |
199 | public void tunnelRemoved(TunnelDescription tunnel) { | 366 | public void tunnelRemoved(TunnelDescription tunnel) { |
367 | + if (tunnel.type() == Tunnel.Type.MPLS) { | ||
368 | + pcepTunnelAPIMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); | ||
369 | + service.tunnelRemoved(tunnel); | ||
370 | + } | ||
371 | + | ||
200 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); | 372 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); |
201 | checkNotNull(tunnelOld, "The tunnel id is not exsited."); | 373 | checkNotNull(tunnelOld, "The tunnel id is not exsited."); |
202 | if (tunnelOld.type() != Tunnel.Type.VLAN) { | 374 | if (tunnelOld.type() != Tunnel.Type.VLAN) { |
... | @@ -215,6 +387,10 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -215,6 +387,10 @@ public class PcepTunnelProvider extends AbstractProvider |
215 | 387 | ||
216 | @Override | 388 | @Override |
217 | public void tunnelUpdated(TunnelDescription tunnel) { | 389 | public void tunnelUpdated(TunnelDescription tunnel) { |
390 | + if (tunnel.type() == Tunnel.Type.MPLS) { | ||
391 | + pcepTunnelAPIMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); | ||
392 | + service.tunnelUpdated(tunnel); | ||
393 | + } | ||
218 | 394 | ||
219 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); | 395 | Tunnel tunnelOld = tunnelQueryById(tunnel.id()); |
220 | if (tunnelOld.type() != Tunnel.Type.VLAN) { | 396 | if (tunnelOld.type() != Tunnel.Type.VLAN) { |
... | @@ -380,7 +556,6 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -380,7 +556,6 @@ public class PcepTunnelProvider extends AbstractProvider |
380 | * @return corresponding tunnel id of the a tunnel key. | 556 | * @return corresponding tunnel id of the a tunnel key. |
381 | */ | 557 | */ |
382 | private TunnelId getTunnelId(String tunnelKey) { | 558 | private TunnelId getTunnelId(String tunnelKey) { |
383 | - | ||
384 | for (String key : tunnelMap.keySet()) { | 559 | for (String key : tunnelMap.keySet()) { |
385 | if (key.equals(tunnelKey)) { | 560 | if (key.equals(tunnelKey)) { |
386 | return tunnelMap.get(key); | 561 | return tunnelMap.get(key); |
... | @@ -405,11 +580,274 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -405,11 +580,274 @@ public class PcepTunnelProvider extends AbstractProvider |
405 | 580 | ||
406 | } | 581 | } |
407 | 582 | ||
408 | - private class InnerTunnerProvider implements PcepTunnelListener { | 583 | + /** |
584 | + * Creates list of hops for ERO object from Path. | ||
585 | + * | ||
586 | + * @param path network path | ||
587 | + * @return list of ipv4 subobjects | ||
588 | + */ | ||
589 | + private LinkedList<PcepValueType> createPcepPath(Path path) { | ||
590 | + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
591 | + List<Link> listLink = path.links(); | ||
592 | + ConnectPoint source = null; | ||
593 | + ConnectPoint destination = null; | ||
594 | + IpAddress ipDstAddress = null; | ||
595 | + IpAddress ipSrcAddress = null; | ||
596 | + PcepValueType subObj = null; | ||
597 | + | ||
598 | + for (Link link : listLink) { | ||
599 | + source = link.src(); | ||
600 | + if (!(source.equals(destination))) { | ||
601 | + //set IPv4SubObject for ERO object | ||
602 | + ipSrcAddress = source.ipElementId().ipAddress(); | ||
603 | + subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); | ||
604 | + llSubObjects.add(subObj); | ||
605 | + } | ||
606 | + | ||
607 | + destination = link.dst(); | ||
608 | + ipDstAddress = destination.ipElementId().ipAddress(); | ||
609 | + subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); | ||
610 | + llSubObjects.add(subObj); | ||
611 | + } | ||
612 | + return llSubObjects; | ||
613 | + } | ||
614 | + | ||
615 | + /** | ||
616 | + * Creates PcInitiated lsp request list for setup tunnel. | ||
617 | + * | ||
618 | + * @param tunnel mpls tunnel | ||
619 | + * @param path network path | ||
620 | + * @param pc pcep client | ||
621 | + * @param srpId unique id for pcep message | ||
622 | + * @return list of PcInitiatedLspRequest | ||
623 | + * @throws PcepParseException while building pcep objects fails | ||
624 | + */ | ||
625 | + LinkedList<PcInitiatedLspRequest> createPcInitiatedLspReqList(Tunnel tunnel, Path path, | ||
626 | + PcepClient pc, int srpId) | ||
627 | + throws PcepParseException { | ||
628 | + PcepValueType tlv; | ||
629 | + LinkedList<PcepValueType> llSubObjects = createPcepPath(path); | ||
630 | + | ||
631 | + if (null == llSubObjects || 0 == llSubObjects.size()) { | ||
632 | + log.error("There is no link information to create tunnel"); | ||
633 | + return null; | ||
634 | + } | ||
635 | + | ||
636 | + //build SRP object | ||
637 | + PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build(); | ||
638 | + | ||
639 | + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | ||
640 | + LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>(); | ||
641 | + // set LSP identifiers TLV | ||
642 | + tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), | ||
643 | + (short) 0, (short) 0, 0, | ||
644 | + (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); | ||
645 | + llOptionalTlv.add(tlv); | ||
646 | + //set SymbolicPathNameTlv of LSP object | ||
647 | + tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); | ||
648 | + llOptionalTlv.add(tlv); | ||
649 | + | ||
650 | + //build LSP object | ||
651 | + PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setOFlag((byte) 0).setPlspId(0) | ||
652 | + .setOptionalTlv(llOptionalTlv).build(); | ||
653 | + | ||
654 | + //build ENDPOINTS object | ||
655 | + PcepEndPointsObject endpointsobj = pc.factory().buildEndPointsObject() | ||
656 | + .setSourceIpAddress(((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()) | ||
657 | + .setDestIpAddress(((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()) | ||
658 | + .setPFlag(true).build(); | ||
659 | + | ||
660 | + //build ERO object | ||
661 | + PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build(); | ||
662 | + | ||
663 | + int iBandwidth = DEFAULT_BANDWIDTH_VALUE; | ||
664 | + if (null != tunnel.annotations().value("bandwidth")) { | ||
665 | + iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth")); | ||
666 | + } | ||
667 | + // build bandwidth object | ||
668 | + PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build(); | ||
669 | + // build pcep attribute | ||
670 | + PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build(); | ||
671 | + | ||
672 | + PcInitiatedLspRequest initiateLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj) | ||
673 | + .setLspObject(lspobj).setEndPointsObject(endpointsobj).setEroObject(eroobj) | ||
674 | + .setPcepAttribute(pcepAttribute).build(); | ||
675 | + llPcInitiatedLspRequestList.add(initiateLspRequest); | ||
676 | + return llPcInitiatedLspRequestList; | ||
677 | + } | ||
678 | + | ||
679 | + /** | ||
680 | + * To send initiate tunnel message to pcc. | ||
681 | + * | ||
682 | + * @param tunnel mpls tunnel info | ||
683 | + * @param path explicit route for the tunnel | ||
684 | + * @param pc pcep client to send message | ||
685 | + */ | ||
686 | + private void pcepSetupTunnel(Tunnel tunnel, Path path, PcepClient pc) { | ||
687 | + try { | ||
688 | + int srpId = SrpIdGenerators.create(); | ||
689 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.CREATE); | ||
690 | + | ||
691 | + pcepTunnelAPIMapper.addToCoreTunnelRequestQueue(pcepTunnelData); | ||
692 | + | ||
693 | + LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = createPcInitiatedLspReqList(tunnel, path, | ||
694 | + pc, srpId); | ||
695 | + if (null == llPcInitiatedLspRequestList || 0 == llPcInitiatedLspRequestList.size()) { | ||
696 | + log.error("Failed to create PcInitiatedLspRequestList"); | ||
697 | + return; | ||
698 | + } | ||
699 | + | ||
700 | + //build PCInitiate message | ||
701 | + PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg() | ||
702 | + .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList) | ||
703 | + .build(); | ||
704 | + | ||
705 | + pc.sendMessage(Collections.singletonList(pcInitiateMsg)); | ||
706 | + | ||
707 | + pcepTunnelAPIMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); | ||
708 | + } catch (PcepParseException e) { | ||
709 | + log.error("PcepParseException occurred while processing setup tunnel {}", e.getMessage()); | ||
710 | + } | ||
711 | + } | ||
712 | + | ||
713 | + /** | ||
714 | + * To send Release tunnel message to pcc. | ||
715 | + * | ||
716 | + * @param tunnel mpls tunnel info | ||
717 | + * @param pc pcep client to send message | ||
718 | + */ | ||
719 | + private void pcepReleaseTunnel(Tunnel tunnel, PcepClient pc) { | ||
720 | + try { | ||
721 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, RequestType.DELETE); | ||
722 | + pcepTunnelAPIMapper.addToCoreTunnelRequestQueue(pcepTunnelData); | ||
723 | + int srpId = SrpIdGenerators.create(); | ||
724 | + TunnelId tunnelId = tunnel.tunnelId(); | ||
725 | + int plspId = 0; | ||
726 | + StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv = null; | ||
727 | + | ||
728 | + if (!(pcepTunnelAPIMapper.checkFromTunnelDBQueue(tunnelId))) { | ||
729 | + log.error("Tunnel doesnot exists. Tunnel id {}" + tunnelId.toString()); | ||
730 | + return; | ||
731 | + } else { | ||
732 | + PcepTunnelData pcepTunnelDbData = pcepTunnelAPIMapper.getDataFromTunnelDBQueue(tunnelId); | ||
733 | + plspId = pcepTunnelDbData.plspId(); | ||
734 | + statefulIpv4IndentifierTlv = pcepTunnelDbData.statefulIpv4IndentifierTlv(); | ||
735 | + } | ||
736 | + // build srp object | ||
737 | + PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true).build(); | ||
738 | + | ||
739 | + PcepValueType tlv; | ||
740 | + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | ||
741 | + LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>(); | ||
742 | + | ||
743 | + if (null != statefulIpv4IndentifierTlv) { | ||
744 | + tlv = statefulIpv4IndentifierTlv; | ||
745 | + } else { | ||
746 | + tlv = new StatefulIPv4LspIdentidiersTlv(( | ||
747 | + ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), | ||
748 | + (short) 0, (short) 0, 0, | ||
749 | + (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); | ||
750 | + } | ||
751 | + llOptionalTlv.add(tlv); | ||
752 | + tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); | ||
753 | + llOptionalTlv.add(tlv); | ||
754 | + // build lsp object, set r flag as false to delete the tunnel | ||
755 | + PcepLspObject lspobj = pc.factory().buildLspObject().setRFlag(false).setPlspId(plspId) | ||
756 | + .setOptionalTlv(llOptionalTlv).build(); | ||
757 | + | ||
758 | + PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest().setSrpObject(srpobj) | ||
759 | + .setLspObject(lspobj).build(); | ||
760 | + | ||
761 | + llPcInitiatedLspRequestList.add(releaseLspRequest); | ||
762 | + | ||
763 | + PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg() | ||
764 | + .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build(); | ||
765 | + | ||
766 | + pc.sendMessage(Collections.singletonList(pcInitiateMsg)); | ||
767 | + | ||
768 | + pcepTunnelAPIMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); | ||
769 | + } catch (PcepParseException e) { | ||
770 | + log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage()); | ||
771 | + } | ||
772 | + } | ||
773 | + | ||
774 | + /** | ||
775 | + * To send Update tunnel request message to pcc. | ||
776 | + * | ||
777 | + * @param tunnel mpls tunnel info | ||
778 | + * @param path explicit route for the tunnel | ||
779 | + * @param pc pcep client to send message | ||
780 | + */ | ||
781 | + private void pcepUpdateTunnel(Tunnel tunnel, Path path, PcepClient pc) { | ||
782 | + try { | ||
783 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE); | ||
784 | + pcepTunnelAPIMapper.addToCoreTunnelRequestQueue(pcepTunnelData); | ||
785 | + int srpId = SrpIdGenerators.create(); | ||
786 | + TunnelId tunnelId = tunnel.tunnelId(); | ||
787 | + PcepValueType tlv; | ||
788 | + int plspId = 0; | ||
789 | + | ||
790 | + LinkedList<PcepValueType> llSubObjects = createPcepPath(path); | ||
791 | + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>(); | ||
792 | + LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>(); | ||
793 | + | ||
794 | + //build SRP object | ||
795 | + PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build(); | ||
796 | + | ||
797 | + if (!(pcepTunnelAPIMapper.checkFromTunnelDBQueue(tunnelId))) { | ||
798 | + log.error("Tunnel doesnot exists in DB"); | ||
799 | + return; | ||
800 | + } else { | ||
801 | + PcepTunnelData pcepTunnelDBData = pcepTunnelAPIMapper.getDataFromTunnelDBQueue(tunnelId); | ||
802 | + plspId = pcepTunnelDBData.plspId(); | ||
803 | + } | ||
804 | + | ||
805 | + tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()), | ||
806 | + (short) 0, (short) 0, 0, | ||
807 | + (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt())); | ||
808 | + llOptionalTlv.add(tlv); | ||
809 | + | ||
810 | + if (tunnel.tunnelName().value() != null) { | ||
811 | + tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes()); | ||
812 | + llOptionalTlv.add(tlv); | ||
813 | + } | ||
814 | + | ||
815 | + // build lsp object | ||
816 | + PcepLspObject lspobj = pc.factory().buildLspObject().setAFlag(true).setPlspId(plspId) | ||
817 | + .setOptionalTlv(llOptionalTlv).build(); | ||
818 | + // build ero object | ||
819 | + PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build(); | ||
820 | + | ||
821 | + int iBandwidth = DEFAULT_BANDWIDTH_VALUE; | ||
822 | + if (null != tunnel.annotations().value("bandwidth")) { | ||
823 | + iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth")); | ||
824 | + } | ||
825 | + // build bandwidth object | ||
826 | + PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build(); | ||
827 | + // build pcep attribute | ||
828 | + PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute().setBandwidthObject(bandwidthObject).build(); | ||
829 | + // build pcep msg path | ||
830 | + PcepMsgPath msgPath = pc.factory().buildPcepMsgPath().setEroObject(eroobj).setPcepAttribute(pcepAttribute) | ||
831 | + .build(); | ||
832 | + | ||
833 | + PcepUpdateRequest updateRequest = pc.factory().buildPcepUpdateRequest().setSrpObject(srpobj) | ||
834 | + .setLspObject(lspobj).setMsgPath(msgPath).build(); | ||
835 | + | ||
836 | + llUpdateRequestList.add(updateRequest); | ||
837 | + | ||
838 | + PcepUpdateMsg pcUpdateMsg = pc.factory().buildUpdateMsg().setUpdateRequestList(llUpdateRequestList).build(); | ||
839 | + | ||
840 | + pc.sendMessage(Collections.singletonList(pcUpdateMsg)); | ||
841 | + pcepTunnelAPIMapper.addToTunnelRequestQueue(srpId, pcepTunnelData); | ||
842 | + } catch (PcepParseException e) { | ||
843 | + log.error("PcepParseException occurred while processing release tunnel {}", e.getMessage()); | ||
844 | + } | ||
845 | + } | ||
846 | + | ||
847 | + private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener { | ||
409 | 848 | ||
410 | @Override | 849 | @Override |
411 | public void handlePCEPTunnel(PcepTunnel pcepTunnel) { | 850 | public void handlePCEPTunnel(PcepTunnel pcepTunnel) { |
412 | - | ||
413 | TunnelDescription tunnel = null; | 851 | TunnelDescription tunnel = null; |
414 | // instance and id identify a tunnel together | 852 | // instance and id identify a tunnel together |
415 | String tunnelKey = String.valueOf(pcepTunnel.getInstance()) | 853 | String tunnelKey = String.valueOf(pcepTunnel.getInstance()) |
... | @@ -442,9 +880,263 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -442,9 +880,263 @@ public class PcepTunnelProvider extends AbstractProvider |
442 | 880 | ||
443 | default: | 881 | default: |
444 | log.error("Invalid tunnel operation"); | 882 | log.error("Invalid tunnel operation"); |
883 | + } | ||
884 | + } | ||
885 | + | ||
886 | + @Override | ||
887 | + public void handleMessage(PccId pccId, PcepMessage msg) { | ||
888 | + try { | ||
889 | + log.debug("tunnel provider handle message {}", msg.getType().toString()); | ||
890 | + switch (msg.getType()) { | ||
891 | + case REPORT: | ||
892 | + int srpId = 0; | ||
893 | + LinkedList<PcepStateReport> llStateReportList = null; | ||
894 | + llStateReportList = ((PcepReportMsg) msg).getStateReportList(); | ||
895 | + ListIterator<PcepStateReport> listIterator = llStateReportList.listIterator(); | ||
896 | + PcepSrpObject srpObj = null; | ||
897 | + PcepLspObject lspObj = null; | ||
898 | + while (listIterator.hasNext()) { | ||
899 | + PcepStateReport stateRpt = listIterator.next(); | ||
900 | + srpObj = stateRpt.getSrpObject(); | ||
901 | + lspObj = stateRpt.getLspObject(); | ||
902 | + | ||
903 | + if (srpObj instanceof PcepSrpObject) { | ||
904 | + srpId = srpObj.getSrpID(); | ||
905 | + } | ||
906 | + | ||
907 | + log.debug("Plsp ID in handle message " + lspObj.getPlspId()); | ||
908 | + log.debug("SRP ID in handle message " + srpId); | ||
909 | + | ||
910 | + if (!(pcepTunnelAPIMapper.checkFromTunnelRequestQueue(srpId))) { | ||
911 | + | ||
912 | + // Check the sync status | ||
913 | + if (lspObj.getSFlag()) { | ||
914 | + handleSyncReport(stateRpt); | ||
915 | + } else if (!pcepClientController.getClient(pccId).isSyncComplete()) { | ||
916 | + // sync is done | ||
917 | + pcepClientController.getClient(pccId).setIsSyncComplete(true); | ||
918 | + } | ||
919 | + continue; | ||
920 | + } | ||
921 | + | ||
922 | + handleReportMessage(srpId, lspObj); | ||
923 | + } | ||
924 | + break; | ||
925 | + | ||
926 | + default: | ||
927 | + log.debug("Received unsupported message type {}", msg.getType().toString()); | ||
928 | + } | ||
929 | + } catch (Exception e) { | ||
930 | + log.error("Exception occured while processing report message {}", e.getMessage()); | ||
931 | + } | ||
932 | + } | ||
933 | + | ||
934 | + /** | ||
935 | + * Handles report message for setup/update/delete tunnel request. | ||
936 | + * | ||
937 | + * @param srpId unique identifier for pcep message | ||
938 | + * @param lspObj lsp object | ||
939 | + */ | ||
940 | + private void handleReportMessage(int srpId, PcepLspObject lspObj) { | ||
941 | + ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); | ||
942 | + PcepTunnelData pcepTunnelData = pcepTunnelAPIMapper.getDataFromTunnelRequestQueue(srpId); | ||
943 | + SparseAnnotations annotations = (SparseAnnotations) pcepTunnelData.tunnel().annotations(); | ||
944 | + | ||
945 | + // store the values required from report message | ||
946 | + pcepTunnelData.setPlspId(lspObj.getPlspId()); | ||
947 | + pcepTunnelData.setLspAFlag(lspObj.getAFlag()); | ||
948 | + pcepTunnelData.setLspOFlag(lspObj.getOFlag()); | ||
949 | + pcepTunnelData.setLspDFlag(lspObj.getDFlag()); | ||
950 | + | ||
951 | + StatefulIPv4LspIdentidiersTlv ipv4LspTlv = null; | ||
952 | + ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); | ||
953 | + while (listTlvIterator.hasNext()) { | ||
954 | + PcepValueType tlv = listTlvIterator.next(); | ||
955 | + if (tlv.getType() == StatefulIPv4LspIdentidiersTlv.TYPE) { | ||
956 | + ipv4LspTlv = (StatefulIPv4LspIdentidiersTlv) tlv; | ||
957 | + break; | ||
958 | + } | ||
959 | + } | ||
960 | + if (null != ipv4LspTlv) { | ||
961 | + pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspTlv); | ||
962 | + } | ||
963 | + | ||
964 | + Path path = pcepTunnelData.path(); | ||
965 | + Tunnel tunnel = pcepTunnelData.tunnel(); | ||
966 | + DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), | ||
967 | + tunnel.dst(), tunnel.type(), tunnel.groupId(), | ||
968 | + providerId, tunnel.tunnelName(), path, | ||
969 | + annotations); | ||
970 | + | ||
971 | + if (RequestType.CREATE == pcepTunnelData.requestType()) { | ||
972 | + log.debug("Report received for create request"); | ||
973 | + | ||
974 | + pcepTunnelAPIMapper.handleCreateTunnelRequestQueue(srpId, pcepTunnelData); | ||
975 | + if (0 == lspObj.getOFlag()) { | ||
976 | + log.warn("The tunnel is in down state"); | ||
977 | + } | ||
978 | + tunnelAdded(td); | ||
979 | + } | ||
980 | + if (RequestType.DELETE == pcepTunnelData.requestType()) { | ||
981 | + log.debug("Report received for delete request"); | ||
982 | + pcepTunnelAPIMapper.handleRemoveFromTunnelRequestQueue(srpId, pcepTunnelData); | ||
983 | + tunnelRemoved(td); | ||
984 | + } | ||
985 | + | ||
986 | + if (RequestType.UPDATE == pcepTunnelData.requestType()) { | ||
987 | + log.debug("Report received for update request"); | ||
988 | + pcepTunnelData.setRptFlag(true); | ||
989 | + pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData); | ||
990 | + pcepTunnelAPIMapper.handleUpdateTunnelRequestQueue(srpId, pcepTunnelData); | ||
991 | + | ||
992 | + if (0 == lspObj.getOFlag()) { | ||
993 | + log.warn("The tunnel is in down state"); | ||
994 | + } | ||
995 | + if (!(pcepTunnelAPIMapper.checkFromTunnelRequestQueue(srpId))) { | ||
996 | + tunnelUpdated(td); | ||
997 | + } | ||
998 | + } | ||
999 | + } | ||
1000 | + | ||
1001 | + /** | ||
1002 | + * Handles sync report received from pcc. | ||
1003 | + * | ||
1004 | + * @param stateRpt pcep state report | ||
1005 | + */ | ||
1006 | + private void handleSyncReport(PcepStateReport stateRpt) { | ||
1007 | + PcepLspObject lspObj = stateRpt.getLspObject(); | ||
1008 | + PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); | ||
1009 | + checkNotNull(msgPath); | ||
1010 | + PcepRroObject rroObj = msgPath.getRroObject(); | ||
1011 | + checkNotNull(rroObj); | ||
1012 | + int bandwidth = 0; | ||
1013 | + | ||
1014 | + log.debug("Handle Sync report received from PCC."); | ||
1015 | + | ||
1016 | + if (0 == lspObj.getOFlag()) { | ||
1017 | + log.warn("The PCC reported tunnel is in down state"); | ||
1018 | + } | ||
1019 | + log.debug("Sync report received"); | ||
445 | 1020 | ||
1021 | + if (null != msgPath.getBandwidthObject()) { | ||
1022 | + bandwidth = msgPath.getBandwidthObject().getBandwidth(); | ||
446 | } | 1023 | } |
447 | 1024 | ||
1025 | + buildAndStorePcepTunnelData(lspObj, rroObj, bandwidth); | ||
1026 | + } | ||
1027 | + | ||
1028 | + /** | ||
1029 | + * To build Path in network from RRO object. | ||
1030 | + * | ||
1031 | + * @param rroObj rro object | ||
1032 | + * @param providerId provider id | ||
1033 | + * @return path object | ||
1034 | + */ | ||
1035 | + private Path buildPathFromRroObj(PcepRroObject rroObj, ProviderId providerId) { | ||
1036 | + checkNotNull(rroObj); | ||
1037 | + List<Link> links = new ArrayList<Link>(); | ||
1038 | + LinkedList<PcepValueType> llSubObj = rroObj.getSubObjects(); | ||
1039 | + if (0 == llSubObj.size()) { | ||
1040 | + log.error("RRO in report message does not have hop information"); | ||
1041 | + } | ||
1042 | + ListIterator<PcepValueType> tlvIterator = llSubObj.listIterator(); | ||
1043 | + | ||
1044 | + ConnectPoint src = null; | ||
1045 | + ConnectPoint dst = null; | ||
1046 | + boolean isSrcSet = false; | ||
1047 | + while (tlvIterator.hasNext()) { | ||
1048 | + PcepValueType subObj = tlvIterator.next(); | ||
1049 | + switch (subObj.getType()) { | ||
1050 | + | ||
1051 | + case IPv4SubObject.TYPE: | ||
1052 | + | ||
1053 | + IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj; | ||
1054 | + if (!isSrcSet) { | ||
1055 | + IpAddress srcIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); | ||
1056 | + src = new ConnectPoint(IpElementId.ipElement(srcIp), PortNumber.portNumber(0)); | ||
1057 | + isSrcSet = true; | ||
1058 | + } else { | ||
1059 | + IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); | ||
1060 | + dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0)); | ||
1061 | + Link link = new DefaultLink(providerId, src, dst, Link.Type.DIRECT, EMPTY); | ||
1062 | + links.add(link); | ||
1063 | + src = dst; | ||
1064 | + } | ||
1065 | + break; | ||
1066 | + default: | ||
1067 | + // the other sub objects are not required | ||
1068 | + } | ||
1069 | + } | ||
1070 | + return new DefaultPath(providerId, links, 0, EMPTY); | ||
1071 | + } | ||
1072 | + | ||
1073 | + /** | ||
1074 | + * To build pcepTunnelData and informs core about the pcc reported tunnel. | ||
1075 | + * | ||
1076 | + * @param lspObj pcep lsp object | ||
1077 | + * @param rroObj pcep rro object | ||
1078 | + * @param bandwidth bandwidth of tunnel | ||
1079 | + */ | ||
1080 | + private void buildAndStorePcepTunnelData(PcepLspObject lspObj, PcepRroObject rroObj, | ||
1081 | + int bandwidth) { | ||
1082 | + | ||
1083 | + ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); | ||
1084 | + | ||
1085 | + // StatefulIPv4LspIdentidiersTlv in LSP object will have the source and destination address. | ||
1086 | + StatefulIPv4LspIdentidiersTlv lspIdenTlv = null; | ||
1087 | + SymbolicPathNameTlv pathNameTlv = null; | ||
1088 | + LinkedList<PcepValueType> llOptionalTlv = lspObj.getOptionalTlv(); | ||
1089 | + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); | ||
1090 | + while (listIterator.hasNext()) { | ||
1091 | + PcepValueType tlv = listIterator.next(); | ||
1092 | + switch (tlv.getType()) { | ||
1093 | + case StatefulIPv4LspIdentidiersTlv.TYPE: | ||
1094 | + lspIdenTlv = (StatefulIPv4LspIdentidiersTlv) tlv; | ||
1095 | + break; | ||
1096 | + case SymbolicPathNameTlv.TYPE: | ||
1097 | + pathNameTlv = (SymbolicPathNameTlv) tlv; | ||
1098 | + break; | ||
1099 | + default: | ||
1100 | + // currently this tlv is not required | ||
1101 | + } | ||
1102 | + } | ||
1103 | + | ||
1104 | + IpTunnelEndPoint tunnelEndPointSrc; | ||
1105 | + tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(lspIdenTlv.getIpv4IngressAddress())); | ||
1106 | + IpTunnelEndPoint tunnelEndPointDst; | ||
1107 | + tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(lspIdenTlv.getIpv4EgressAddress())); | ||
1108 | + | ||
1109 | + Path path = buildPathFromRroObj(rroObj, providerId); | ||
1110 | + | ||
1111 | + SparseAnnotations annotations = DefaultAnnotations.builder() | ||
1112 | + .set("bandwidth", (new Integer(bandwidth)).toString()) | ||
1113 | + .build(); | ||
1114 | + | ||
1115 | + DefaultTunnelDescription td = new DefaultTunnelDescription(null, tunnelEndPointSrc, | ||
1116 | + tunnelEndPointDst, Tunnel.Type.MPLS, | ||
1117 | + new DefaultGroupId(0), providerId, | ||
1118 | + TunnelName.tunnelName(pathNameTlv.toString()), | ||
1119 | + path, annotations); | ||
1120 | + TunnelId tId = tunnelAdded(td); | ||
1121 | + | ||
1122 | + Tunnel tunnel = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, Tunnel.Type.MPLS, | ||
1123 | + new DefaultGroupId(0), tId, | ||
1124 | + TunnelName.tunnelName(pathNameTlv.toString()), path, annotations); | ||
1125 | + | ||
1126 | + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.LSP_STATE_RPT); | ||
1127 | + pcepTunnelData.setStatefulIpv4IndentifierTlv(lspIdenTlv); | ||
1128 | + pcepTunnelAPIMapper.addPccTunnelDB(pcepTunnelData); | ||
1129 | + pcepTunnelAPIMapper.addToTunnelIdMap(pcepTunnelData); | ||
1130 | + } | ||
1131 | + | ||
1132 | + @Override | ||
1133 | + public void clientConnected(PccId pccId) { | ||
1134 | + // TODO | ||
1135 | + } | ||
1136 | + | ||
1137 | + @Override | ||
1138 | + public void clientDisconnected(PccId pccId) { | ||
1139 | + // TODO | ||
448 | } | 1140 | } |
449 | } | 1141 | } |
450 | 1142 | ||
... | @@ -452,5 +1144,4 @@ public class PcepTunnelProvider extends AbstractProvider | ... | @@ -452,5 +1144,4 @@ public class PcepTunnelProvider extends AbstractProvider |
452 | public Tunnel tunnelQueryById(TunnelId tunnelId) { | 1144 | public Tunnel tunnelQueryById(TunnelId tunnelId) { |
453 | return service.tunnelQueryById(tunnelId); | 1145 | return service.tunnelQueryById(tunnelId); |
454 | } | 1146 | } |
455 | - | ||
456 | } | 1147 | } | ... | ... |
providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/RequestType.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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 | +/** | ||
19 | + * Enum of request types between pcc and pcep. | ||
20 | + */ | ||
21 | +public enum RequestType { | ||
22 | + /** | ||
23 | + * Specifies the request type for PCC is to create new tunnel. | ||
24 | + */ | ||
25 | + CREATE, | ||
26 | + | ||
27 | + /** | ||
28 | + * Specifies the request type for PCC is to update existing tunnel. | ||
29 | + */ | ||
30 | + UPDATE, | ||
31 | + | ||
32 | + /** | ||
33 | + * Specifies the request type for PCC is to delete existing tunnel. | ||
34 | + */ | ||
35 | + DELETE, | ||
36 | + | ||
37 | + /** | ||
38 | + * Specifies the request type for PCC to report existing tunnel. | ||
39 | + */ | ||
40 | + LSP_STATE_RPT; | ||
41 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/SrpIdGenerators.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 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.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import java.util.concurrent.atomic.AtomicInteger; | ||
21 | + | ||
22 | +import org.slf4j.Logger; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unique Srp Id generator for pcep messages. | ||
26 | + */ | ||
27 | +public final class SrpIdGenerators { | ||
28 | + | ||
29 | + private static final Logger log = getLogger(SrpIdGenerators.class); | ||
30 | + private static final AtomicInteger SRP_ID_GEN = new AtomicInteger(); | ||
31 | + private static final int MAX_SRP_ID = 0x7FFFFFFF; | ||
32 | + private static int srpId; | ||
33 | + | ||
34 | + /** | ||
35 | + * Default constructor. | ||
36 | + */ | ||
37 | + private SrpIdGenerators() { | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Get the next srp id. | ||
42 | + * | ||
43 | + * @return srp id | ||
44 | + */ | ||
45 | + public static int create() { | ||
46 | + do { | ||
47 | + if (srpId >= MAX_SRP_ID) { | ||
48 | + if (SRP_ID_GEN.get() >= MAX_SRP_ID) { | ||
49 | + SRP_ID_GEN.set(0); | ||
50 | + } | ||
51 | + } | ||
52 | + srpId = SRP_ID_GEN.incrementAndGet(); | ||
53 | + } while (srpId > MAX_SRP_ID); | ||
54 | + return srpId; | ||
55 | + } | ||
56 | +} |
-
Please register or login to post a comment