[ONOS-6933] Support packet request for different device scheme

Change-Id: If9658838c35b4d425f414c6d5c275c364e15e1a6
This commit is contained in:
Yi Tseng 2017-08-16 14:00:37 -07:00 committed by Thomas Vachuska
parent f43b3d5bb1
commit 809b5d71fe
4 changed files with 29 additions and 13 deletions

View File

@ -89,7 +89,13 @@ public class DefaultDriver implements Driver {
// Merge the properties. // Merge the properties.
ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
properties.putAll(this.properties).putAll(other.properties()); properties.putAll(other.properties());
// remove duplicated properties from this driver and merge
this.properties().entrySet().stream()
.filter(e -> !other.properties().containsKey(e.getKey()))
.forEach(properties::put);
List<Driver> completeParents = new ArrayList<>(); List<Driver> completeParents = new ArrayList<>();
if (parents != null) { if (parents != null) {

View File

@ -16,7 +16,6 @@
package org.onosproject.net.packet.impl; package org.onosproject.net.packet.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Component;
@ -33,6 +32,8 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent; import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener; import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService; import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.Driver;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.TrafficTreatment;
@ -62,7 +63,6 @@ import org.slf4j.Logger;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -89,6 +89,7 @@ public class PacketManager
private static final String ERROR_NULL_SELECTOR = "Selector cannot be null"; private static final String ERROR_NULL_SELECTOR = "Selector cannot be null";
private static final String ERROR_NULL_APP_ID = "Application ID cannot be null"; private static final String ERROR_NULL_APP_ID = "Application ID cannot be null";
private static final String ERROR_NULL_DEVICE_ID = "Device ID cannot be null"; private static final String ERROR_NULL_DEVICE_ID = "Device ID cannot be null";
private static final String SUPPORT_PACKET_REQUEST_PROPERTY = "supportPacketRequest";
private final PacketStoreDelegate delegate = new InternalStoreDelegate(); private final PacketStoreDelegate delegate = new InternalStoreDelegate();
@ -101,6 +102,9 @@ public class PacketManager
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService; protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketStore store; protected PacketStore store;
@ -258,11 +262,6 @@ public class PacketManager
} }
} }
/**
* Set of DeviceId scheme which supports packet requests.
*/
private static final Set<String> SUPPORTED = ImmutableSet.of("of");
/** /**
* Pushes a packet request flow rule to all devices. * Pushes a packet request flow rule to all devices.
* *
@ -271,8 +270,9 @@ public class PacketManager
private void pushToAllDevices(PacketRequest request) { private void pushToAllDevices(PacketRequest request) {
log.debug("Pushing packet request {} to all devices", request); log.debug("Pushing packet request {} to all devices", request);
for (Device device : deviceService.getDevices()) { for (Device device : deviceService.getDevices()) {
// TODO properly test capability via driver, defining behaviour Driver driver = driverService.getDriver(device.id());
if (SUPPORTED.contains(device.id().uri().getScheme())) { if (driver != null &&
Boolean.parseBoolean(driver.getProperty(SUPPORT_PACKET_REQUEST_PROPERTY))) {
pushRule(device, request); pushRule(device, request);
} }
} }
@ -446,12 +446,20 @@ public class PacketManager
eventHandlingExecutor.execute(() -> { eventHandlingExecutor.execute(() -> {
try { try {
Device device = event.subject(); Device device = event.subject();
Driver driver = driverService.getDriver(device.id());
if (driver == null) {
return;
}
if (!Boolean.parseBoolean(driver.getProperty(SUPPORT_PACKET_REQUEST_PROPERTY))) {
return;
}
if (!deviceService.isAvailable(event.subject().id())) {
return;
}
switch (event.type()) { switch (event.type()) {
case DEVICE_ADDED: case DEVICE_ADDED:
case DEVICE_AVAILABILITY_CHANGED: case DEVICE_AVAILABILITY_CHANGED:
if (deviceService.isAvailable(event.subject().id())) { pushRulesToDevice(device);
pushRulesToDevice(device);
}
break; break;
default: default:
break; break;

View File

@ -21,6 +21,7 @@
impl="org.onosproject.driver.pipeline.DefaultSingleTablePipeline"/> impl="org.onosproject.driver.pipeline.DefaultSingleTablePipeline"/>
<behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
impl="org.onosproject.driver.handshaker.DefaultSwitchHandshaker"/> impl="org.onosproject.driver.handshaker.DefaultSwitchHandshaker"/>
<property name="supportPacketRequest">true</property>
</driver> </driver>
<driver name="ovs" extends="default" <driver name="ovs" extends="default"
manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*">

View File

@ -24,6 +24,7 @@
impl="org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable"/> impl="org.onosproject.drivers.p4runtime.P4RuntimeFlowRuleProgrammable"/>
<behaviour api="org.onosproject.net.group.GroupProgrammable" <behaviour api="org.onosproject.net.group.GroupProgrammable"
impl="org.onosproject.drivers.p4runtime.P4RuntimeGroupProgrammable"/> impl="org.onosproject.drivers.p4runtime.P4RuntimeGroupProgrammable"/>
<property name="supportPacketRequest">true</property>
</driver> </driver>
</drivers> </drivers>