mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 09:51:38 +02:00
Couple of changes for the BGP Router project:
1. Link Discovery can be turned off completely via configuration 2. PacketService allows applications to hint at table_type when registering for packets Change-Id: I89f0bbf84dce1b449db5af19868f83503c44f750
This commit is contained in:
parent
26647a675f
commit
c313c405b2
@ -23,6 +23,7 @@ import org.onosproject.core.ApplicationId;
|
||||
import org.onosproject.net.ConnectPoint;
|
||||
import org.onosproject.net.flow.DefaultTrafficSelector;
|
||||
import org.onosproject.net.flow.DefaultTrafficTreatment;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
import org.onosproject.net.flow.TrafficTreatment;
|
||||
import org.onosproject.net.packet.DefaultOutboundPacket;
|
||||
@ -73,7 +74,7 @@ public class TunnellingConnectivityManager {
|
||||
selector.matchTcpSrc(BGP_PORT);
|
||||
|
||||
packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
|
||||
appId);
|
||||
appId, FlowRule.Type.ACL);
|
||||
|
||||
selector = DefaultTrafficSelector.builder();
|
||||
|
||||
@ -83,7 +84,7 @@ public class TunnellingConnectivityManager {
|
||||
selector.matchTcpDst(BGP_PORT);
|
||||
|
||||
packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
|
||||
appId);
|
||||
appId, FlowRule.Type.ACL);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.onosproject.net.packet;
|
||||
|
||||
import org.onosproject.core.ApplicationId;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
|
||||
/**
|
||||
@ -58,6 +59,22 @@ public interface PacketService {
|
||||
void requestPackets(TrafficSelector selector, PacketPriority priority,
|
||||
ApplicationId appId);
|
||||
|
||||
/**
|
||||
* Requests that packets matching the given selector are punted from the
|
||||
* dataplane to the controller. Clients of the PacketService should use
|
||||
* this call to hint at the tableType in the dataplane valid for the selector.
|
||||
*
|
||||
* @param selector the traffic selector used to match packets
|
||||
* @param priority the priority of the rule
|
||||
* @param appId the application ID of the requester
|
||||
* @param tableType the abstract table Type in the dataplane where flowrules
|
||||
* should be inserted to punt the selector packets to the
|
||||
* control plane
|
||||
*/
|
||||
void requestPackets(TrafficSelector selector, PacketPriority priority,
|
||||
ApplicationId appId, FlowRule.Type tableType);
|
||||
|
||||
|
||||
// TODO add API to allow applications to revoke requests when they deactivate
|
||||
|
||||
/**
|
||||
|
@ -88,12 +88,14 @@ implements PacketService, PacketProviderRegistry {
|
||||
private final TrafficSelector selector;
|
||||
private final PacketPriority priority;
|
||||
private final ApplicationId appId;
|
||||
private final FlowRule.Type tableType;
|
||||
|
||||
public PacketRequest(TrafficSelector selector, PacketPriority priority,
|
||||
ApplicationId appId) {
|
||||
ApplicationId appId, FlowRule.Type tableType) {
|
||||
this.selector = selector;
|
||||
this.priority = priority;
|
||||
this.appId = appId;
|
||||
this.tableType = tableType;
|
||||
}
|
||||
|
||||
public TrafficSelector selector() {
|
||||
@ -108,6 +110,10 @@ implements PacketService, PacketProviderRegistry {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public FlowRule.Type tableType() {
|
||||
return tableType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@ -170,7 +176,22 @@ implements PacketService, PacketProviderRegistry {
|
||||
checkNotNull(appId, "Application ID cannot be null");
|
||||
|
||||
PacketRequest request =
|
||||
new PacketRequest(selector, priority, appId);
|
||||
new PacketRequest(selector, priority, appId, FlowRule.Type.DEFAULT);
|
||||
|
||||
packetRequests.add(request);
|
||||
pushToAllDevices(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPackets(TrafficSelector selector, PacketPriority priority,
|
||||
ApplicationId appId, FlowRule.Type tableType) {
|
||||
checkNotNull(selector, "Selector cannot be null");
|
||||
checkNotNull(appId, "Application ID cannot be null");
|
||||
checkNotNull(tableType, "Table Type cannot be null. For requesting packets +"
|
||||
+ "without table hints, use other methods in the packetService API");
|
||||
|
||||
PacketRequest request =
|
||||
new PacketRequest(selector, priority, appId, tableType);
|
||||
|
||||
packetRequests.add(request);
|
||||
pushToAllDevices(request);
|
||||
@ -204,7 +225,7 @@ implements PacketService, PacketProviderRegistry {
|
||||
treatment,
|
||||
request.priority().priorityValue(),
|
||||
request.appId(),
|
||||
0, true);
|
||||
0, true, request.tableType());
|
||||
|
||||
flowService.applyFlowRules(flow);
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import org.onosproject.net.Port;
|
||||
import org.onosproject.net.PortNumber;
|
||||
import org.onosproject.net.device.DeviceListener;
|
||||
import org.onosproject.net.device.DeviceServiceAdapter;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
import org.onosproject.net.flow.instructions.Instruction;
|
||||
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
|
||||
@ -266,6 +267,12 @@ public class HostMonitorTest {
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId,
|
||||
FlowRule.Type tableType) {
|
||||
}
|
||||
}
|
||||
|
||||
class TestDeviceService extends DeviceServiceAdapter {
|
||||
|
@ -51,6 +51,7 @@ import org.onosproject.net.Port;
|
||||
import org.onosproject.net.PortNumber;
|
||||
import org.onosproject.net.device.DeviceListener;
|
||||
import org.onosproject.net.device.DeviceService;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
import org.onosproject.net.flow.instructions.Instruction;
|
||||
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
|
||||
@ -592,5 +593,11 @@ public class ProxyArpManagerTest {
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId,
|
||||
FlowRule.Type tableType) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ import org.onosproject.net.HostLocation;
|
||||
import org.onosproject.net.device.DeviceEvent;
|
||||
import org.onosproject.net.device.DeviceListener;
|
||||
import org.onosproject.net.device.DeviceServiceAdapter;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
import org.onosproject.net.flow.TrafficTreatment;
|
||||
import org.onosproject.net.host.HostDescription;
|
||||
@ -287,6 +288,12 @@ public class HostLocationProviderTest {
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId,
|
||||
FlowRule.Type tableType) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ import static org.slf4j.LoggerFactory.getLogger;
|
||||
public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
|
||||
private static final String PROP_USE_BDDP = "useBDDP";
|
||||
|
||||
private static final String PROP_DISABLE_LD = "disableLinkDiscovery";
|
||||
private static final String PROP_LLDP_SUPPRESSION = "lldpSuppression";
|
||||
|
||||
private static final String DEFAULT_LLDP_SUPPRESSION_CONFIG = "../config/lldp_suppression.json";
|
||||
@ -99,14 +99,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Property(name = PROP_USE_BDDP, boolValue = true,
|
||||
label = "use BDDP for link discovery")
|
||||
@Property(name = PROP_USE_BDDP, label = "use BDDP for link discovery")
|
||||
private boolean useBDDP = true;
|
||||
|
||||
@Property(name = PROP_DISABLE_LD, label = "permanently disable link discovery")
|
||||
private boolean disableLD = false;
|
||||
|
||||
private static final long INIT_DELAY = 5;
|
||||
private static final long DELAY = 5;
|
||||
|
||||
@Property(name = PROP_LLDP_SUPPRESSION, value = DEFAULT_LLDP_SUPPRESSION_CONFIG,
|
||||
@Property(name = PROP_LLDP_SUPPRESSION,
|
||||
label = "Path to LLDP suppression configuration file")
|
||||
private String filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG;
|
||||
|
||||
@ -128,11 +130,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
}
|
||||
|
||||
@Activate
|
||||
public void activate() {
|
||||
public void activate(ComponentContext context) {
|
||||
appId =
|
||||
coreService.registerApplication("org.onosproject.provider.lldp");
|
||||
|
||||
loadSuppressionRules();
|
||||
// to load configuration at startup
|
||||
modified(context);
|
||||
if (disableLD) {
|
||||
log.info("Link Discovery has been permanently disabled by configuration");
|
||||
return;
|
||||
}
|
||||
|
||||
providerService = providerRegistry.register(this);
|
||||
deviceService.addListener(listener);
|
||||
@ -170,6 +177,9 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
if (disableLD) {
|
||||
return;
|
||||
}
|
||||
executor.shutdownNow();
|
||||
for (LinkDiscovery ld : discoverers.values()) {
|
||||
ld.stop();
|
||||
@ -186,21 +196,22 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
@Modified
|
||||
public void modified(ComponentContext context) {
|
||||
if (context == null) {
|
||||
loadSuppressionRules();
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
Dictionary properties = context.getProperties();
|
||||
|
||||
String s = (String) properties.get(PROP_USE_BDDP);
|
||||
if (Strings.isNullOrEmpty(s)) {
|
||||
useBDDP = true;
|
||||
} else {
|
||||
String s = (String) properties.get(PROP_DISABLE_LD);
|
||||
if (!Strings.isNullOrEmpty(s)) {
|
||||
disableLD = Boolean.valueOf(s);
|
||||
}
|
||||
s = (String) properties.get(PROP_USE_BDDP);
|
||||
if (!Strings.isNullOrEmpty(s)) {
|
||||
useBDDP = Boolean.valueOf(s);
|
||||
}
|
||||
s = (String) properties.get(PROP_LLDP_SUPPRESSION);
|
||||
if (Strings.isNullOrEmpty(s)) {
|
||||
filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG;
|
||||
} else {
|
||||
if (!Strings.isNullOrEmpty(s)) {
|
||||
filePath = s;
|
||||
}
|
||||
|
||||
@ -210,6 +221,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
|
||||
private void loadSuppressionRules() {
|
||||
SuppressionRulesStore store = new SuppressionRulesStore(filePath);
|
||||
try {
|
||||
log.info("Reading suppression rules from {}", filePath);
|
||||
rules = store.read();
|
||||
} catch (IOException e) {
|
||||
log.info("Failed to load {}, using built-in rules", filePath);
|
||||
|
@ -55,6 +55,7 @@ import org.onosproject.net.PortNumber;
|
||||
import org.onosproject.net.device.DeviceEvent;
|
||||
import org.onosproject.net.device.DeviceListener;
|
||||
import org.onosproject.net.device.DeviceServiceAdapter;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
import org.onosproject.net.flow.TrafficTreatment;
|
||||
import org.onosproject.net.link.LinkDescription;
|
||||
@ -116,7 +117,7 @@ public class LLDPLinkProviderTest {
|
||||
provider.masterService = masterService;
|
||||
|
||||
|
||||
provider.activate();
|
||||
provider.activate(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -211,6 +212,7 @@ public class LLDPLinkProviderTest {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings(value = { "unused" })
|
||||
private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) {
|
||||
return new DeviceEvent(type, deviceService.getDevice(did),
|
||||
deviceService.getPort(did, port));
|
||||
@ -400,6 +402,12 @@ public class LLDPLinkProviderTest {
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestPackets(TrafficSelector selector,
|
||||
PacketPriority priority, ApplicationId appId,
|
||||
FlowRule.Type tableType) {
|
||||
}
|
||||
}
|
||||
|
||||
private class TestDeviceService extends DeviceServiceAdapter {
|
||||
|
@ -0,0 +1,21 @@
|
||||
# Sample configuration for link discovery
|
||||
# Note that the current file location (onos/tools/package/etc) is required for packaging onos and launching it in another location.
|
||||
# If you are launching onos locally, this configuration file would be placed at: $(KARAF_ROOT)/etc
|
||||
|
||||
#
|
||||
# Disable Link Dicovery Permanently (Note: changing this property at runtime will have NO effect)
|
||||
# WARNING: This should only be used for special projects like bgprouter, where ONOS is controlling
|
||||
# a single switch
|
||||
#
|
||||
#disableLinkDiscovery = true
|
||||
|
||||
#
|
||||
# Enable Broadcast Discovery Protocol (EthType=0x8942)
|
||||
#
|
||||
#useBDDP = false
|
||||
|
||||
#
|
||||
# Disable LLDP's received from specific devices
|
||||
# Details of the devices are in the file configured below
|
||||
#
|
||||
#lldpSuppression = ../config/lldp_suppresion.json
|
Loading…
x
Reference in New Issue
Block a user