Committed by
Gerrit Code Review
Interfaces for passing port information from OF switch drivers to DeviceProviders.
Change-Id: I14039f5999c930a211c30138caf81c0513d398e2 Reference: ONOS-1911
Showing
5 changed files
with
140 additions
and
50 deletions
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.driver.handshaker; | 16 | package org.onosproject.driver.handshaker; |
17 | 17 | ||
18 | +import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; | ||
19 | +import org.onosproject.openflow.controller.PortDescPropertyType; | ||
18 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; | 20 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
19 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; | 21 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; |
20 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; | 22 | import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; |
... | @@ -23,28 +25,29 @@ import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; | ... | @@ -23,28 +25,29 @@ import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
23 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; | 25 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply; |
24 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; | 26 | import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest; |
25 | import org.projectfloodlight.openflow.protocol.OFMessage; | 27 | import org.projectfloodlight.openflow.protocol.OFMessage; |
28 | +import org.projectfloodlight.openflow.protocol.OFObject; | ||
26 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 29 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
27 | -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; | ||
28 | -import org.projectfloodlight.openflow.protocol.OFPortOptical; | ||
29 | import org.projectfloodlight.openflow.protocol.OFStatsReply; | 30 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
30 | import org.projectfloodlight.openflow.protocol.OFStatsType; | 31 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
31 | 32 | ||
33 | +import com.google.common.collect.ImmutableList; | ||
34 | +import com.google.common.collect.ImmutableSet; | ||
35 | + | ||
32 | import java.io.IOException; | 36 | import java.io.IOException; |
33 | -import java.util.ArrayList; | ||
34 | -import java.util.Collection; | ||
35 | -import java.util.Collections; | ||
36 | import java.util.List; | 37 | import java.util.List; |
38 | +import java.util.Set; | ||
37 | import java.util.concurrent.atomic.AtomicBoolean; | 39 | import java.util.concurrent.atomic.AtomicBoolean; |
38 | 40 | ||
39 | /** | 41 | /** |
40 | * LINC-OE Optical Emulator switch class. | 42 | * LINC-OE Optical Emulator switch class. |
41 | */ | 43 | */ |
42 | -public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { | 44 | +public class OFOpticalSwitchImplLINC13 |
45 | + extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch { | ||
43 | 46 | ||
44 | private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); | 47 | private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); |
45 | private long barrierXidToWaitFor = -1; | 48 | private long barrierXidToWaitFor = -1; |
46 | 49 | ||
47 | - private OFPortDescStatsReply wPorts; | 50 | + private OFCircuitPortsReply wPorts; |
48 | 51 | ||
49 | @Override | 52 | @Override |
50 | public void startDriverHandshake() { | 53 | public void startDriverHandshake() { |
... | @@ -105,8 +108,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { | ... | @@ -105,8 +108,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
105 | OFStatsReply stats = (OFStatsReply) m; | 108 | OFStatsReply stats = (OFStatsReply) m; |
106 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { | 109 | if (stats.getStatsType() == OFStatsType.EXPERIMENTER) { |
107 | log.warn("LINC-OE : Received stats reply message {}", m); | 110 | log.warn("LINC-OE : Received stats reply message {}", m); |
108 | - processHandshakeOFExperimenterPortDescRequest( | 111 | + wPorts = (OFCircuitPortsReply) m; |
109 | - (OFCircuitPortsReply) m); | ||
110 | driverHandshakeComplete.set(true); | 112 | driverHandshakeComplete.set(true); |
111 | } | 113 | } |
112 | break; | 114 | break; |
... | @@ -124,30 +126,6 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { | ... | @@ -124,30 +126,6 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
124 | 126 | ||
125 | } | 127 | } |
126 | 128 | ||
127 | - private void processHandshakeOFExperimenterPortDescRequest( | ||
128 | - OFCircuitPortsReply sr) { | ||
129 | - Collection<OFPortOptical> entries = sr.getEntries(); | ||
130 | - List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size()); | ||
131 | - for (OFPortOptical entry : entries) { | ||
132 | - log.warn("LINC:OE port message {}", entry.toString()); | ||
133 | - ofPortDescList.add(factory().buildPortDesc(). | ||
134 | - setPortNo(entry.getPortNo()) | ||
135 | - .setConfig(entry.getConfig()) | ||
136 | - .setState(entry.getState()) | ||
137 | - .setHwAddr(entry.getHwAddr()) | ||
138 | - .setName(entry.getName()) | ||
139 | - .build()); | ||
140 | - | ||
141 | - } | ||
142 | - setExperimenterPortDescReply(factory().buildPortDescStatsReply(). | ||
143 | - setEntries(ofPortDescList).build()); | ||
144 | - } | ||
145 | - | ||
146 | - private void setExperimenterPortDescReply(OFPortDescStatsReply reply) { | ||
147 | - wPorts = reply; | ||
148 | - } | ||
149 | - | ||
150 | - | ||
151 | private void sendHandshakeOFExperimenterPortDescRequest() throws | 129 | private void sendHandshakeOFExperimenterPortDescRequest() throws |
152 | IOException { | 130 | IOException { |
153 | // send multi part message for port description for optical switches | 131 | // send multi part message for port description for optical switches |
... | @@ -162,13 +140,13 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { | ... | @@ -162,13 +140,13 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
162 | } | 140 | } |
163 | 141 | ||
164 | @Override | 142 | @Override |
143 | + /** | ||
144 | + * Returns a list of standard (Ethernet) ports. | ||
145 | + * | ||
146 | + * @return List of ports | ||
147 | + */ | ||
165 | public List<OFPortDesc> getPorts() { | 148 | public List<OFPortDesc> getPorts() { |
166 | - List<OFPortDesc> portEntries = new ArrayList<>(); | 149 | + return ImmutableList.copyOf(super.getPorts()); |
167 | - portEntries.addAll(super.getPorts()); | ||
168 | - if (wPorts != null) { | ||
169 | - portEntries.addAll(wPorts.getEntries()); | ||
170 | - } | ||
171 | - return Collections.unmodifiableList(portEntries); | ||
172 | } | 150 | } |
173 | 151 | ||
174 | 152 | ||
... | @@ -182,4 +160,14 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { | ... | @@ -182,4 +160,14 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch { |
182 | return true; | 160 | return true; |
183 | } | 161 | } |
184 | 162 | ||
163 | + @Override | ||
164 | + public List<? extends OFObject> getPortsOf(PortDescPropertyType type) { | ||
165 | + return ImmutableList.copyOf(wPorts.getEntries()); | ||
166 | + } | ||
167 | + | ||
168 | + @Override | ||
169 | + public Set<PortDescPropertyType> getPortTypes() { | ||
170 | + return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT); | ||
171 | + } | ||
172 | + | ||
185 | } | 173 | } | ... | ... |
1 | +package org.onosproject.openflow.controller; | ||
2 | + | ||
3 | +/** | ||
4 | + * Port description property types (OFPPDPT enums) in OF 1.3 <. | ||
5 | + */ | ||
6 | +public enum PortDescPropertyType { | ||
7 | + ETHERNET(0), /* Ethernet port */ | ||
8 | + OPTICAL(1), /* Optical port */ | ||
9 | + OPTICAL_TRANSPORT(2), /* OF1.3 Optical transport extension */ | ||
10 | + PIPELINE_INPUT(2), /* Ingress pipeline */ | ||
11 | + PIPELINE_OUTPUT(3), /* Egress pipeline */ | ||
12 | + RECIRCULATE(4), /* Recirculation */ | ||
13 | + EXPERIMENTER(0xffff); /* Experimenter-implemented */ | ||
14 | + | ||
15 | + private final int value; | ||
16 | + | ||
17 | + PortDescPropertyType(int v) { | ||
18 | + value = v; | ||
19 | + } | ||
20 | + | ||
21 | + public int valueOf() { | ||
22 | + return value; | ||
23 | + } | ||
24 | +} |
1 | +package org.onosproject.openflow.controller; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | +import java.util.Set; | ||
5 | + | ||
6 | +import org.projectfloodlight.openflow.protocol.OFObject; | ||
7 | + | ||
8 | +/** | ||
9 | + * An interface implemented by OpenFlow devices that enables providers to | ||
10 | + * retrieve ports based on port property. | ||
11 | + */ | ||
12 | +public interface WithTypedPorts { | ||
13 | + | ||
14 | + /** | ||
15 | + * Return a list of interfaces (ports) of the type associated with this | ||
16 | + * OpenFlow switch. | ||
17 | + * | ||
18 | + * @param type The port description property type of requested ports | ||
19 | + * @return A potentially empty list of ports. | ||
20 | + */ | ||
21 | + List<? extends OFObject> getPortsOf(PortDescPropertyType type); | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns the port property types supported by the driver implementing this | ||
25 | + * interface. | ||
26 | + * | ||
27 | + * @return A set of port property types | ||
28 | + */ | ||
29 | + Set<PortDescPropertyType> getPortTypes(); | ||
30 | +} |
... | @@ -17,6 +17,7 @@ package org.onosproject.provider.of.device.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.provider.of.device.impl; |
17 | 17 | ||
18 | import com.google.common.collect.Maps; | 18 | import com.google.common.collect.Maps; |
19 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
20 | + | ||
20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
21 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
22 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -44,8 +45,10 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -44,8 +45,10 @@ import org.onosproject.net.provider.ProviderId; |
44 | import org.onosproject.openflow.controller.Dpid; | 45 | import org.onosproject.openflow.controller.Dpid; |
45 | import org.onosproject.openflow.controller.OpenFlowController; | 46 | import org.onosproject.openflow.controller.OpenFlowController; |
46 | import org.onosproject.openflow.controller.OpenFlowEventListener; | 47 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
48 | +import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; | ||
47 | import org.onosproject.openflow.controller.OpenFlowSwitch; | 49 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
48 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; | 50 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
51 | +import org.onosproject.openflow.controller.PortDescPropertyType; | ||
49 | import org.onosproject.openflow.controller.RoleState; | 52 | import org.onosproject.openflow.controller.RoleState; |
50 | import org.onlab.packet.ChassisId; | 53 | import org.onlab.packet.ChassisId; |
51 | import org.projectfloodlight.openflow.protocol.OFFactory; | 54 | import org.projectfloodlight.openflow.protocol.OFFactory; |
... | @@ -53,6 +56,7 @@ import org.projectfloodlight.openflow.protocol.OFMessage; | ... | @@ -53,6 +56,7 @@ import org.projectfloodlight.openflow.protocol.OFMessage; |
53 | import org.projectfloodlight.openflow.protocol.OFPortConfig; | 56 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
54 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 57 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
55 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; | 58 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
59 | +import org.projectfloodlight.openflow.protocol.OFPortOptical; | ||
56 | import org.projectfloodlight.openflow.protocol.OFPortReason; | 60 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
57 | import org.projectfloodlight.openflow.protocol.OFPortState; | 61 | import org.projectfloodlight.openflow.protocol.OFPortState; |
58 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; | 62 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
... | @@ -262,7 +266,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -262,7 +266,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
262 | sw.serialNumber(), | 266 | sw.serialNumber(), |
263 | cId, annotations); | 267 | cId, annotations); |
264 | providerService.deviceConnected(did, description); | 268 | providerService.deviceConnected(did, description); |
265 | - providerService.updatePorts(did, buildPortDescriptions(sw.getPorts())); | 269 | + providerService.updatePorts(did, buildPortDescriptions(sw)); |
266 | 270 | ||
267 | PortStatsCollector psc = new PortStatsCollector( | 271 | PortStatsCollector psc = new PortStatsCollector( |
268 | controller.getSwitch(dpid), POLL_INTERVAL); | 272 | controller.getSwitch(dpid), POLL_INTERVAL); |
... | @@ -290,7 +294,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -290,7 +294,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
290 | } | 294 | } |
291 | DeviceId did = deviceId(uri(dpid)); | 295 | DeviceId did = deviceId(uri(dpid)); |
292 | OpenFlowSwitch sw = controller.getSwitch(dpid); | 296 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
293 | - providerService.updatePorts(did, buildPortDescriptions(sw.getPorts())); | 297 | + providerService.updatePorts(did, buildPortDescriptions(sw)); |
294 | } | 298 | } |
295 | 299 | ||
296 | @Override | 300 | @Override |
... | @@ -333,10 +337,19 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -333,10 +337,19 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
333 | * @param ports the list of ports | 337 | * @param ports the list of ports |
334 | * @return list of portdescriptions | 338 | * @return list of portdescriptions |
335 | */ | 339 | */ |
336 | - private List<PortDescription> buildPortDescriptions(List<OFPortDesc> ports) { | 340 | + private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { |
337 | - final List<PortDescription> portDescs = new ArrayList<>(ports.size()); | 341 | + final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size()); |
338 | - for (OFPortDesc port : ports) { | 342 | + sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port))); |
339 | - portDescs.add(buildPortDescription(port)); | 343 | + if (sw.isOptical()) { |
344 | + OpenFlowOpticalSwitch opsw = (OpenFlowOpticalSwitch) sw; | ||
345 | + opsw.getPortTypes().forEach(type -> { | ||
346 | + LOG.info("ports: {}", opsw.getPortsOf(type)); | ||
347 | + opsw.getPortsOf(type).forEach( | ||
348 | + op -> { | ||
349 | + portDescs.add(buildPortDescription(type, (OFPortOptical) op)); | ||
350 | + } | ||
351 | + ); | ||
352 | + }); | ||
340 | } | 353 | } |
341 | return portDescs; | 354 | return portDescs; |
342 | } | 355 | } |
... | @@ -348,9 +361,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -348,9 +361,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
348 | * @return annotation containing the port name if one is found, | 361 | * @return annotation containing the port name if one is found, |
349 | * null otherwise | 362 | * null otherwise |
350 | */ | 363 | */ |
351 | - private SparseAnnotations makePortNameAnnotation(OFPortDesc port) { | 364 | + private SparseAnnotations makePortNameAnnotation(String port) { |
352 | SparseAnnotations annotations = null; | 365 | SparseAnnotations annotations = null; |
353 | - String portName = Strings.emptyToNull(port.getName()); | 366 | + String portName = Strings.emptyToNull(port); |
354 | if (portName != null) { | 367 | if (portName != null) { |
355 | annotations = DefaultAnnotations.builder() | 368 | annotations = DefaultAnnotations.builder() |
356 | .set(AnnotationKeys.PORT_NAME, portName).build(); | 369 | .set(AnnotationKeys.PORT_NAME, portName).build(); |
... | @@ -359,7 +372,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -359,7 +372,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
359 | } | 372 | } |
360 | 373 | ||
361 | /** | 374 | /** |
362 | - * Build a portDescription from a given port. | 375 | + * Build a portDescription from a given Ethernet port description. |
363 | * | 376 | * |
364 | * @param port the port to build from. | 377 | * @param port the port to build from. |
365 | * @return portDescription for the port. | 378 | * @return portDescription for the port. |
... | @@ -370,11 +383,38 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -370,11 +383,38 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
370 | !port.getState().contains(OFPortState.LINK_DOWN) && | 383 | !port.getState().contains(OFPortState.LINK_DOWN) && |
371 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); | 384 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
372 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; | 385 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
373 | - SparseAnnotations annotations = makePortNameAnnotation(port); | 386 | + SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
374 | return new DefaultPortDescription(portNo, enabled, type, | 387 | return new DefaultPortDescription(portNo, enabled, type, |
375 | portSpeed(port), annotations); | 388 | portSpeed(port), annotations); |
376 | } | 389 | } |
377 | 390 | ||
391 | + /** | ||
392 | + * Build a portDescription from a given a port description describing some | ||
393 | + * Optical port. | ||
394 | + * | ||
395 | + * @param port description property type. | ||
396 | + * @param port the port to build from. | ||
397 | + * @return portDescription for the port. | ||
398 | + */ | ||
399 | + private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port) { | ||
400 | + // Minimally functional fixture. This needs to be fixed as we add better support. | ||
401 | + PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | ||
402 | + boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) | ||
403 | + && !port.getConfig().contains(OFPortConfig.PORT_DOWN); | ||
404 | + SparseAnnotations annotations = makePortNameAnnotation(port.getName()); | ||
405 | + Port.Type type = FIBER; | ||
406 | + | ||
407 | + if (port.getVersion() == OFVersion.OF_13 | ||
408 | + && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { | ||
409 | + // At this point, not much is carried in the optical port message. | ||
410 | + LOG.info("Optical transport port message {}", port.toString()); | ||
411 | + } else { | ||
412 | + // removable once 1.4+ support complete. | ||
413 | + LOG.warn("Unsupported optical port properties"); | ||
414 | + } | ||
415 | + return new DefaultPortDescription(portNo, enabled, type, 0, annotations); | ||
416 | + } | ||
417 | + | ||
378 | private PortDescription buildPortDescription(OFPortStatus status) { | 418 | private PortDescription buildPortDescription(OFPortStatus status) { |
379 | OFPortDesc port = status.getDesc(); | 419 | OFPortDesc port = status.getDesc(); |
380 | if (status.getReason() != OFPortReason.DELETE) { | 420 | if (status.getReason() != OFPortReason.DELETE) { |
... | @@ -382,7 +422,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -382,7 +422,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
382 | } else { | 422 | } else { |
383 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | 423 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
384 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; | 424 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
385 | - SparseAnnotations annotations = makePortNameAnnotation(port); | 425 | + SparseAnnotations annotations = makePortNameAnnotation(port.getName()); |
386 | return new DefaultPortDescription(portNo, false, type, | 426 | return new DefaultPortDescription(portNo, false, type, |
387 | portSpeed(port), annotations); | 427 | portSpeed(port), annotations); |
388 | } | 428 | } | ... | ... |
-
Please register or login to post a comment