chengfan
Committed by Gerrit Code Review

implement OchPort,OduCltPort,OmsPort

Change-Id: I26425c87a52d2d6d3f7d64357d728e475ef6b10d
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.pcep.api; 16 package org.onosproject.pcep.api;
17 17
18 +import org.onosproject.net.Port;
19 +
18 /** 20 /**
19 * Abstraction of a network infrastructure link. 21 * Abstraction of a network infrastructure link.
20 */ 22 */
...@@ -118,17 +120,17 @@ public interface PcepLink extends PcepOperator { ...@@ -118,17 +120,17 @@ public interface PcepLink extends PcepOperator {
118 public PcepDpid linkDstDeviceId(); 120 public PcepDpid linkDstDeviceId();
119 121
120 /** 122 /**
121 - * Returns the source port number of a link. 123 + * Returns the source port of a link.
122 * 124 *
123 * @return port number 125 * @return port number
124 */ 126 */
125 - public long linkSrcPort(); 127 + public Port linkSrcPort();
126 128
127 /** 129 /**
128 - * Returns the destination port number of a link. 130 + * Returns the destination port of a link.
129 * 131 *
130 * @return port number 132 * @return port number
131 */ 133 */
132 - public long linkDstPort(); 134 + public Port linkDstPort();
133 135
134 } 136 }
......
...@@ -15,15 +15,6 @@ ...@@ -15,15 +15,6 @@
15 */ 15 */
16 package org.onosproject.provider.pcep.topology.impl; 16 package org.onosproject.provider.pcep.topology.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull;
19 -import static org.onosproject.net.DeviceId.deviceId;
20 -import static org.onosproject.pcep.api.PcepDpid.uri;
21 -
22 -import java.util.ArrayList;
23 -import java.util.HashSet;
24 -import java.util.List;
25 -import java.util.Set;
26 -
27 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
28 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
29 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
...@@ -37,10 +28,12 @@ import org.onosproject.net.ConnectPoint; ...@@ -37,10 +28,12 @@ import org.onosproject.net.ConnectPoint;
37 import org.onosproject.net.DefaultAnnotations; 28 import org.onosproject.net.DefaultAnnotations;
38 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
39 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
40 -import org.onosproject.net.Link;
41 import org.onosproject.net.Link.Type; 31 import org.onosproject.net.Link.Type;
42 import org.onosproject.net.MastershipRole; 32 import org.onosproject.net.MastershipRole;
43 -import org.onosproject.net.PortNumber; 33 +import org.onosproject.net.OchPort;
34 +import org.onosproject.net.OduCltPort;
35 +import org.onosproject.net.OmsPort;
36 +import org.onosproject.net.Port;
44 import org.onosproject.net.device.DefaultDeviceDescription; 37 import org.onosproject.net.device.DefaultDeviceDescription;
45 import org.onosproject.net.device.DefaultPortDescription; 38 import org.onosproject.net.device.DefaultPortDescription;
46 import org.onosproject.net.device.DeviceDescription; 39 import org.onosproject.net.device.DeviceDescription;
...@@ -48,6 +41,9 @@ import org.onosproject.net.device.DeviceProvider; ...@@ -48,6 +41,9 @@ import org.onosproject.net.device.DeviceProvider;
48 import org.onosproject.net.device.DeviceProviderRegistry; 41 import org.onosproject.net.device.DeviceProviderRegistry;
49 import org.onosproject.net.device.DeviceProviderService; 42 import org.onosproject.net.device.DeviceProviderService;
50 import org.onosproject.net.device.DeviceService; 43 import org.onosproject.net.device.DeviceService;
44 +import org.onosproject.net.device.OchPortDescription;
45 +import org.onosproject.net.device.OduCltPortDescription;
46 +import org.onosproject.net.device.OmsPortDescription;
51 import org.onosproject.net.device.PortDescription; 47 import org.onosproject.net.device.PortDescription;
52 import org.onosproject.net.link.DefaultLinkDescription; 48 import org.onosproject.net.link.DefaultLinkDescription;
53 import org.onosproject.net.link.LinkDescription; 49 import org.onosproject.net.link.LinkDescription;
...@@ -68,6 +64,14 @@ import org.onosproject.pcep.api.PcepSwitchListener; ...@@ -68,6 +64,14 @@ import org.onosproject.pcep.api.PcepSwitchListener;
68 import org.slf4j.Logger; 64 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory; 65 import org.slf4j.LoggerFactory;
70 66
67 +import java.util.ArrayList;
68 +import java.util.HashMap;
69 +import java.util.List;
70 +
71 +import static com.google.common.base.Preconditions.checkNotNull;
72 +import static org.onosproject.net.DeviceId.deviceId;
73 +import static org.onosproject.pcep.api.PcepDpid.uri;
74 +
71 /** 75 /**
72 * Provider which uses an PCEP controller to detect network infrastructure 76 * Provider which uses an PCEP controller to detect network infrastructure
73 * topology. 77 * topology.
...@@ -109,8 +113,8 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -109,8 +113,8 @@ public class PcepTopologyProvider extends AbstractProvider
109 113
110 private DeviceProviderService deviceProviderService; 114 private DeviceProviderService deviceProviderService;
111 private LinkProviderService linkProviderService; 115 private LinkProviderService linkProviderService;
112 - // List<Long> srcportList = new ArrayList<Long>(); 116 +
113 - HashSet<Long> portSet = new HashSet<>(); 117 + private HashMap<Long, List<PortDescription>> portMap = new HashMap<>();
114 private InternalLinkProvider listener = new InternalLinkProvider(); 118 private InternalLinkProvider listener = new InternalLinkProvider();
115 119
116 @Activate 120 @Activate
...@@ -129,36 +133,50 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -129,36 +133,50 @@ public class PcepTopologyProvider extends AbstractProvider
129 controller.removeLinkListener(listener); 133 controller.removeLinkListener(listener);
130 } 134 }
131 135
132 - private List<PortDescription> buildPortDescriptions(List<Long> ports, 136 + private List<PortDescription> buildPortDescriptions(PcepDpid dpid,
137 + Port port,
133 PortType portType) { 138 PortType portType) {
134 - final List<PortDescription> portDescs = new ArrayList<>(); 139 +
135 - for (long port : ports) { 140 + List<PortDescription> portList;
136 - portDescs.add(buildPortDescription(port, portType)); 141 +
142 + if (portMap.containsKey(dpid.value())) {
143 + portList = portMap.get(dpid.value());
144 + } else {
145 + portList = new ArrayList<>();
146 + }
147 + if (port != null && portType != null) {
148 + portList.add(buildPortDescription(port, portType));
137 } 149 }
138 - return portDescs;
139 - }
140 150
141 - private PortDescription buildPortDescription(long port, PortType portType) { 151 + portMap.put(dpid.value(), portList);
142 - final PortNumber portNo = PortNumber.portNumber(port); 152 + return portList;
143 - final boolean enabled = true;
144 - DefaultAnnotations extendedAttributes = DefaultAnnotations.builder()
145 - .set("portType", String.valueOf(portType)).build();
146 - return new DefaultPortDescription(portNo, enabled, extendedAttributes);
147 } 153 }
148 154
149 - private DefaultAnnotations buildLinkAnnotations(PcepLink linkDesc) { 155 + private PortDescription buildPortDescription(Port port, PortType portType) {
150 - DefaultAnnotations extendedAttributes = DefaultAnnotations 156 + PortDescription portDescription;
151 - .builder() 157 +
152 - .set("subType", String.valueOf(linkDesc.linkSubType())) 158 + switch (portType) {
153 - .set("workState", linkDesc.linkState()) 159 + case OCH_PORT:
154 - .set("distance", String.valueOf(linkDesc.linkDistance())) 160 + OchPort ochp = (OchPort) port;
155 - .set("capType", linkDesc.linkCapacityType().toLowerCase()) 161 + portDescription = new OchPortDescription(ochp.number(), ochp.isEnabled(),
156 - .set("avail_" + linkDesc.linkCapacityType().toLowerCase(), 162 + ochp.signalType(), ochp.isTunable(),
157 - String.valueOf(linkDesc.linkAvailValue())) 163 + ochp.lambda());
158 - .set("max_" + linkDesc.linkCapacityType().toLowerCase(), 164 + break;
159 - String.valueOf(linkDesc.linkMaxValue())).build(); 165 + case ODU_PORT:
160 - 166 + OduCltPort odup = (OduCltPort) port;
161 - return extendedAttributes; 167 + portDescription = new OduCltPortDescription(odup.number(), odup.isEnabled(),
168 + odup.signalType());
169 + break;
170 + case OMS_PORT:
171 + OmsPort op = (OmsPort) port;
172 + portDescription = new OmsPortDescription(op.number(), op.isEnabled(), op.minFrequency(),
173 + op.maxFrequency(), op.grid());
174 + break;
175 + default:
176 + portDescription = new DefaultPortDescription(port.number(), port.isEnabled());
177 + break;
178 + }
179 + return portDescription;
162 } 180 }
163 181
164 /** 182 /**
...@@ -169,109 +187,82 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -169,109 +187,82 @@ public class PcepTopologyProvider extends AbstractProvider
169 */ 187 */
170 private LinkDescription buildLinkDescription(PcepLink pceLink) { 188 private LinkDescription buildLinkDescription(PcepLink pceLink) {
171 LinkDescription ld; 189 LinkDescription ld;
172 - 190 + checkNotNull(pceLink);
173 DeviceId srcDeviceID = deviceId(uri(pceLink.linkSrcDeviceID())); 191 DeviceId srcDeviceID = deviceId(uri(pceLink.linkSrcDeviceID()));
174 DeviceId dstDeviceID = deviceId(uri(pceLink.linkDstDeviceId())); 192 DeviceId dstDeviceID = deviceId(uri(pceLink.linkDstDeviceId()));
175 193
176 - if (deviceService.getDevice(srcDeviceID) == null
177 - || deviceService.getDevice(dstDeviceID) == null) {
178 - log.info("the device of the link is not exited" + srcDeviceID
179 - + dstDeviceID);
180 - return null;
181 - }
182 - // update port info
183 - long srcPort = pceLink.linkSrcPort();
184 - portSet.add(srcPort);
185 - List<Long> srcportList = new ArrayList<Long>();
186 - srcportList.addAll(portSet);
187 deviceProviderService 194 deviceProviderService
188 .updatePorts(srcDeviceID, 195 .updatePorts(srcDeviceID,
189 - buildPortDescriptions(srcportList, 196 + buildPortDescriptions(pceLink.linkSrcDeviceID(),
190 - pceLink.portType())); 197 + pceLink.linkSrcPort(), pceLink.portType()));
191 198
192 - ConnectPoint src = new ConnectPoint(srcDeviceID, 199 + deviceProviderService
193 - PortNumber.portNumber(pceLink 200 + .updatePorts(dstDeviceID,
194 - .linkSrcPort())); 201 + buildPortDescriptions(pceLink.linkDstDeviceId(),
202 + pceLink.linkDstPort(), pceLink.portType()));
195 203
196 - ConnectPoint dst = new ConnectPoint(dstDeviceID, 204 + ConnectPoint src = new ConnectPoint(srcDeviceID, pceLink.linkSrcPort().number());
197 - PortNumber.portNumber(pceLink
198 - .linkDstPort()));
199 - DefaultAnnotations extendedAttributes = buildLinkAnnotations(pceLink);
200 205
206 + ConnectPoint dst = new ConnectPoint(dstDeviceID, pceLink.linkDstPort().number());
207 +
208 + DefaultAnnotations extendedAttributes = DefaultAnnotations
209 + .builder()
210 + .set("subType", String.valueOf(pceLink.linkSubType()))
211 + .set("workState", pceLink.linkState())
212 + .set("distance", String.valueOf(pceLink.linkDistance()))
213 + .set("capType", pceLink.linkCapacityType().toLowerCase())
214 + .set("avail_" + pceLink.linkCapacityType().toLowerCase(),
215 + String.valueOf(pceLink.linkAvailValue()))
216 + .set("max_" + pceLink.linkCapacityType().toLowerCase(),
217 + String.valueOf(pceLink.linkMaxValue())).build();
201 // construct the link 218 // construct the link
202 - ld = new DefaultLinkDescription(src, dst, Type.OPTICAL, 219 + ld = new DefaultLinkDescription(src, dst, Type.OPTICAL, extendedAttributes);
203 - extendedAttributes);
204 return ld; 220 return ld;
205 } 221 }
206 222
207 - private void processLinkUpdate(LinkDescription linkDescription) {
208 -
209 - // dst changed, delete the original link,if the dst device is not in
210 - // other links ,delete it.
211 - if (linkService.getLink(linkDescription.src(), linkDescription.dst()) == null) {
212 - // in face,one src one link
213 - Set<Link> links = linkService
214 - .getIngressLinks(linkDescription.src());
215 - for (Link link : links) {
216 - linkProviderService.linkVanished((LinkDescription) link);
217 - if (linkService.getDeviceLinks(link.dst().deviceId()).size() == 0) {
218 - deviceProviderService.deviceDisconnected(link.dst()
219 - .deviceId());
220 - }
221 - }
222 -
223 - }
224 - linkProviderService.linkDetected(linkDescription);
225 -
226 - }
227 -
228 private class InternalLinkProvider 223 private class InternalLinkProvider
229 implements PcepSwitchListener, PcepLinkListener { 224 implements PcepSwitchListener, PcepLinkListener {
230 225
231 @Override 226 @Override
232 public void switchAdded(PcepDpid dpid) { 227 public void switchAdded(PcepDpid dpid) {
233 - // TODO Auto-generated method stub
234 -
235 if (deviceProviderService == null) { 228 if (deviceProviderService == null) {
236 return; 229 return;
237 } 230 }
238 - DeviceId devicdId = deviceId(uri(dpid)); 231 + DeviceId deviceId = deviceId(uri(dpid));
239 PcepSwitch sw = controller.getSwitch(dpid); 232 PcepSwitch sw = controller.getSwitch(dpid);
240 checkNotNull(sw, "device should not null."); 233 checkNotNull(sw, "device should not null.");
241 // The default device type is switch. 234 // The default device type is switch.
242 ChassisId cId = new ChassisId(dpid.value()); 235 ChassisId cId = new ChassisId(dpid.value());
243 - Device.Type deviceType = null; 236 + Device.Type deviceType;
244 237
245 switch (sw.getDeviceType()) { 238 switch (sw.getDeviceType()) {
246 - case ROADM: 239 + case ROADM:
247 - deviceType = Device.Type.ROADM; 240 + deviceType = Device.Type.ROADM;
248 - break; 241 + break;
249 - case OTN: 242 + case OTN:
250 - deviceType = Device.Type.SWITCH; 243 + deviceType = Device.Type.SWITCH;
251 - break; 244 + break;
252 - case ROUTER: 245 + case ROUTER:
253 - deviceType = Device.Type.ROUTER; 246 + deviceType = Device.Type.ROUTER;
254 - break; 247 + break;
255 - default: 248 + default:
256 - deviceType = Device.Type.OTHER; 249 + deviceType = Device.Type.OTHER;
257 } 250 }
258 251
259 DeviceDescription description = new DefaultDeviceDescription( 252 DeviceDescription description = new DefaultDeviceDescription(
260 - devicdId.uri(), 253 + deviceId.uri(),
261 - deviceType, 254 + deviceType,
262 - sw.manufacturerDescription(), 255 + sw.manufacturerDescription(),
263 - sw.hardwareDescription(), 256 + sw.hardwareDescription(),
264 - sw.softwareDescription(), 257 + sw.softwareDescription(),
265 - sw.serialNumber(), 258 + sw.serialNumber(),
266 - cId); 259 + cId);
267 - deviceProviderService.deviceConnected(devicdId, description); 260 + deviceProviderService.deviceConnected(deviceId, description);
268 261
269 } 262 }
270 263
271 @Override 264 @Override
272 public void switchRemoved(PcepDpid dpid) { 265 public void switchRemoved(PcepDpid dpid) {
273 - // TODO Auto-generated method stub
274 -
275 if (deviceProviderService == null || linkProviderService == null) { 266 if (deviceProviderService == null || linkProviderService == null) {
276 return; 267 return;
277 } 268 }
...@@ -296,19 +287,17 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -296,19 +287,17 @@ public class PcepTopologyProvider extends AbstractProvider
296 return; 287 return;
297 } 288 }
298 switch (operType) { 289 switch (operType) {
299 - case ADD: 290 + case ADD:
300 - linkProviderService.linkDetected(ld); 291 + case UPDATE:
301 - break; 292 + linkProviderService.linkDetected(ld);
302 - case UPDATE: 293 + break;
303 - processLinkUpdate(ld);
304 - break;
305 294
306 - case DELETE: 295 + case DELETE:
307 - linkProviderService.linkVanished(ld); 296 + linkProviderService.linkVanished(ld);
308 - break; 297 + break;
309 298
310 - default: 299 + default:
311 - break; 300 + break;
312 301
313 } 302 }
314 } 303 }
......