Saurav Das

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
...@@ -23,6 +23,7 @@ import org.onosproject.core.ApplicationId; ...@@ -23,6 +23,7 @@ import org.onosproject.core.ApplicationId;
23 import org.onosproject.net.ConnectPoint; 23 import org.onosproject.net.ConnectPoint;
24 import org.onosproject.net.flow.DefaultTrafficSelector; 24 import org.onosproject.net.flow.DefaultTrafficSelector;
25 import org.onosproject.net.flow.DefaultTrafficTreatment; 25 import org.onosproject.net.flow.DefaultTrafficTreatment;
26 +import org.onosproject.net.flow.FlowRule;
26 import org.onosproject.net.flow.TrafficSelector; 27 import org.onosproject.net.flow.TrafficSelector;
27 import org.onosproject.net.flow.TrafficTreatment; 28 import org.onosproject.net.flow.TrafficTreatment;
28 import org.onosproject.net.packet.DefaultOutboundPacket; 29 import org.onosproject.net.packet.DefaultOutboundPacket;
...@@ -73,7 +74,7 @@ public class TunnellingConnectivityManager { ...@@ -73,7 +74,7 @@ public class TunnellingConnectivityManager {
73 selector.matchTcpSrc(BGP_PORT); 74 selector.matchTcpSrc(BGP_PORT);
74 75
75 packetService.requestPackets(selector.build(), PacketPriority.CONTROL, 76 packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
76 - appId); 77 + appId, FlowRule.Type.ACL);
77 78
78 selector = DefaultTrafficSelector.builder(); 79 selector = DefaultTrafficSelector.builder();
79 80
...@@ -83,7 +84,7 @@ public class TunnellingConnectivityManager { ...@@ -83,7 +84,7 @@ public class TunnellingConnectivityManager {
83 selector.matchTcpDst(BGP_PORT); 84 selector.matchTcpDst(BGP_PORT);
84 85
85 packetService.requestPackets(selector.build(), PacketPriority.CONTROL, 86 packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
86 - appId); 87 + appId, FlowRule.Type.ACL);
87 } 88 }
88 89
89 public void stop() { 90 public void stop() {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.packet; 16 package org.onosproject.net.packet;
17 17
18 import org.onosproject.core.ApplicationId; 18 import org.onosproject.core.ApplicationId;
19 +import org.onosproject.net.flow.FlowRule;
19 import org.onosproject.net.flow.TrafficSelector; 20 import org.onosproject.net.flow.TrafficSelector;
20 21
21 /** 22 /**
...@@ -58,6 +59,22 @@ public interface PacketService { ...@@ -58,6 +59,22 @@ public interface PacketService {
58 void requestPackets(TrafficSelector selector, PacketPriority priority, 59 void requestPackets(TrafficSelector selector, PacketPriority priority,
59 ApplicationId appId); 60 ApplicationId appId);
60 61
62 + /**
63 + * Requests that packets matching the given selector are punted from the
64 + * dataplane to the controller. Clients of the PacketService should use
65 + * this call to hint at the tableType in the dataplane valid for the selector.
66 + *
67 + * @param selector the traffic selector used to match packets
68 + * @param priority the priority of the rule
69 + * @param appId the application ID of the requester
70 + * @param tableType the abstract table Type in the dataplane where flowrules
71 + * should be inserted to punt the selector packets to the
72 + * control plane
73 + */
74 + void requestPackets(TrafficSelector selector, PacketPriority priority,
75 + ApplicationId appId, FlowRule.Type tableType);
76 +
77 +
61 // TODO add API to allow applications to revoke requests when they deactivate 78 // TODO add API to allow applications to revoke requests when they deactivate
62 79
63 /** 80 /**
......
...@@ -88,12 +88,14 @@ implements PacketService, PacketProviderRegistry { ...@@ -88,12 +88,14 @@ implements PacketService, PacketProviderRegistry {
88 private final TrafficSelector selector; 88 private final TrafficSelector selector;
89 private final PacketPriority priority; 89 private final PacketPriority priority;
90 private final ApplicationId appId; 90 private final ApplicationId appId;
91 + private final FlowRule.Type tableType;
91 92
92 public PacketRequest(TrafficSelector selector, PacketPriority priority, 93 public PacketRequest(TrafficSelector selector, PacketPriority priority,
93 - ApplicationId appId) { 94 + ApplicationId appId, FlowRule.Type tableType) {
94 this.selector = selector; 95 this.selector = selector;
95 this.priority = priority; 96 this.priority = priority;
96 this.appId = appId; 97 this.appId = appId;
98 + this.tableType = tableType;
97 } 99 }
98 100
99 public TrafficSelector selector() { 101 public TrafficSelector selector() {
...@@ -108,6 +110,10 @@ implements PacketService, PacketProviderRegistry { ...@@ -108,6 +110,10 @@ implements PacketService, PacketProviderRegistry {
108 return appId; 110 return appId;
109 } 111 }
110 112
113 + public FlowRule.Type tableType() {
114 + return tableType;
115 + }
116 +
111 @Override 117 @Override
112 public boolean equals(Object o) { 118 public boolean equals(Object o) {
113 if (this == o) { 119 if (this == o) {
...@@ -170,7 +176,22 @@ implements PacketService, PacketProviderRegistry { ...@@ -170,7 +176,22 @@ implements PacketService, PacketProviderRegistry {
170 checkNotNull(appId, "Application ID cannot be null"); 176 checkNotNull(appId, "Application ID cannot be null");
171 177
172 PacketRequest request = 178 PacketRequest request =
173 - new PacketRequest(selector, priority, appId); 179 + new PacketRequest(selector, priority, appId, FlowRule.Type.DEFAULT);
180 +
181 + packetRequests.add(request);
182 + pushToAllDevices(request);
183 + }
184 +
185 + @Override
186 + public void requestPackets(TrafficSelector selector, PacketPriority priority,
187 + ApplicationId appId, FlowRule.Type tableType) {
188 + checkNotNull(selector, "Selector cannot be null");
189 + checkNotNull(appId, "Application ID cannot be null");
190 + checkNotNull(tableType, "Table Type cannot be null. For requesting packets +"
191 + + "without table hints, use other methods in the packetService API");
192 +
193 + PacketRequest request =
194 + new PacketRequest(selector, priority, appId, tableType);
174 195
175 packetRequests.add(request); 196 packetRequests.add(request);
176 pushToAllDevices(request); 197 pushToAllDevices(request);
...@@ -204,7 +225,7 @@ implements PacketService, PacketProviderRegistry { ...@@ -204,7 +225,7 @@ implements PacketService, PacketProviderRegistry {
204 treatment, 225 treatment,
205 request.priority().priorityValue(), 226 request.priority().priorityValue(),
206 request.appId(), 227 request.appId(),
207 - 0, true); 228 + 0, true, request.tableType());
208 229
209 flowService.applyFlowRules(flow); 230 flowService.applyFlowRules(flow);
210 } 231 }
......
...@@ -47,6 +47,7 @@ import org.onosproject.net.Port; ...@@ -47,6 +47,7 @@ import org.onosproject.net.Port;
47 import org.onosproject.net.PortNumber; 47 import org.onosproject.net.PortNumber;
48 import org.onosproject.net.device.DeviceListener; 48 import org.onosproject.net.device.DeviceListener;
49 import org.onosproject.net.device.DeviceServiceAdapter; 49 import org.onosproject.net.device.DeviceServiceAdapter;
50 +import org.onosproject.net.flow.FlowRule;
50 import org.onosproject.net.flow.TrafficSelector; 51 import org.onosproject.net.flow.TrafficSelector;
51 import org.onosproject.net.flow.instructions.Instruction; 52 import org.onosproject.net.flow.instructions.Instruction;
52 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; 53 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
...@@ -266,6 +267,12 @@ public class HostMonitorTest { ...@@ -266,6 +267,12 @@ public class HostMonitorTest {
266 public void requestPackets(TrafficSelector selector, 267 public void requestPackets(TrafficSelector selector,
267 PacketPriority priority, ApplicationId appId) { 268 PacketPriority priority, ApplicationId appId) {
268 } 269 }
270 +
271 + @Override
272 + public void requestPackets(TrafficSelector selector,
273 + PacketPriority priority, ApplicationId appId,
274 + FlowRule.Type tableType) {
275 + }
269 } 276 }
270 277
271 class TestDeviceService extends DeviceServiceAdapter { 278 class TestDeviceService extends DeviceServiceAdapter {
......
...@@ -51,6 +51,7 @@ import org.onosproject.net.Port; ...@@ -51,6 +51,7 @@ import org.onosproject.net.Port;
51 import org.onosproject.net.PortNumber; 51 import org.onosproject.net.PortNumber;
52 import org.onosproject.net.device.DeviceListener; 52 import org.onosproject.net.device.DeviceListener;
53 import org.onosproject.net.device.DeviceService; 53 import org.onosproject.net.device.DeviceService;
54 +import org.onosproject.net.flow.FlowRule;
54 import org.onosproject.net.flow.TrafficSelector; 55 import org.onosproject.net.flow.TrafficSelector;
55 import org.onosproject.net.flow.instructions.Instruction; 56 import org.onosproject.net.flow.instructions.Instruction;
56 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; 57 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
...@@ -592,5 +593,11 @@ public class ProxyArpManagerTest { ...@@ -592,5 +593,11 @@ public class ProxyArpManagerTest {
592 public void requestPackets(TrafficSelector selector, 593 public void requestPackets(TrafficSelector selector,
593 PacketPriority priority, ApplicationId appId) { 594 PacketPriority priority, ApplicationId appId) {
594 } 595 }
596 +
597 + @Override
598 + public void requestPackets(TrafficSelector selector,
599 + PacketPriority priority, ApplicationId appId,
600 + FlowRule.Type tableType) {
601 + }
595 } 602 }
596 } 603 }
......
...@@ -61,6 +61,7 @@ import org.onosproject.net.HostLocation; ...@@ -61,6 +61,7 @@ import org.onosproject.net.HostLocation;
61 import org.onosproject.net.device.DeviceEvent; 61 import org.onosproject.net.device.DeviceEvent;
62 import org.onosproject.net.device.DeviceListener; 62 import org.onosproject.net.device.DeviceListener;
63 import org.onosproject.net.device.DeviceServiceAdapter; 63 import org.onosproject.net.device.DeviceServiceAdapter;
64 +import org.onosproject.net.flow.FlowRule;
64 import org.onosproject.net.flow.TrafficSelector; 65 import org.onosproject.net.flow.TrafficSelector;
65 import org.onosproject.net.flow.TrafficTreatment; 66 import org.onosproject.net.flow.TrafficTreatment;
66 import org.onosproject.net.host.HostDescription; 67 import org.onosproject.net.host.HostDescription;
...@@ -287,6 +288,12 @@ public class HostLocationProviderTest { ...@@ -287,6 +288,12 @@ public class HostLocationProviderTest {
287 public void requestPackets(TrafficSelector selector, 288 public void requestPackets(TrafficSelector selector,
288 PacketPriority priority, ApplicationId appId) { 289 PacketPriority priority, ApplicationId appId) {
289 } 290 }
291 +
292 + @Override
293 + public void requestPackets(TrafficSelector selector,
294 + PacketPriority priority, ApplicationId appId,
295 + FlowRule.Type tableType) {
296 + }
290 } 297 }
291 298
292 299
......
...@@ -73,7 +73,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -73,7 +73,7 @@ import static org.slf4j.LoggerFactory.getLogger;
73 public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { 73 public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
74 74
75 private static final String PROP_USE_BDDP = "useBDDP"; 75 private static final String PROP_USE_BDDP = "useBDDP";
76 - 76 + private static final String PROP_DISABLE_LD = "disableLinkDiscovery";
77 private static final String PROP_LLDP_SUPPRESSION = "lldpSuppression"; 77 private static final String PROP_LLDP_SUPPRESSION = "lldpSuppression";
78 78
79 private static final String DEFAULT_LLDP_SUPPRESSION_CONFIG = "../config/lldp_suppression.json"; 79 private static final String DEFAULT_LLDP_SUPPRESSION_CONFIG = "../config/lldp_suppression.json";
...@@ -99,14 +99,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -99,14 +99,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
99 99
100 private ScheduledExecutorService executor; 100 private ScheduledExecutorService executor;
101 101
102 - @Property(name = PROP_USE_BDDP, boolValue = true, 102 + @Property(name = PROP_USE_BDDP, label = "use BDDP for link discovery")
103 - label = "use BDDP for link discovery")
104 private boolean useBDDP = true; 103 private boolean useBDDP = true;
105 104
105 + @Property(name = PROP_DISABLE_LD, label = "permanently disable link discovery")
106 + private boolean disableLD = false;
107 +
106 private static final long INIT_DELAY = 5; 108 private static final long INIT_DELAY = 5;
107 private static final long DELAY = 5; 109 private static final long DELAY = 5;
108 110
109 - @Property(name = PROP_LLDP_SUPPRESSION, value = DEFAULT_LLDP_SUPPRESSION_CONFIG, 111 + @Property(name = PROP_LLDP_SUPPRESSION,
110 label = "Path to LLDP suppression configuration file") 112 label = "Path to LLDP suppression configuration file")
111 private String filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG; 113 private String filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG;
112 114
...@@ -128,11 +130,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -128,11 +130,16 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
128 } 130 }
129 131
130 @Activate 132 @Activate
131 - public void activate() { 133 + public void activate(ComponentContext context) {
132 appId = 134 appId =
133 coreService.registerApplication("org.onosproject.provider.lldp"); 135 coreService.registerApplication("org.onosproject.provider.lldp");
134 136
135 - loadSuppressionRules(); 137 + // to load configuration at startup
138 + modified(context);
139 + if (disableLD) {
140 + log.info("Link Discovery has been permanently disabled by configuration");
141 + return;
142 + }
136 143
137 providerService = providerRegistry.register(this); 144 providerService = providerRegistry.register(this);
138 deviceService.addListener(listener); 145 deviceService.addListener(listener);
...@@ -170,6 +177,9 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -170,6 +177,9 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
170 177
171 @Deactivate 178 @Deactivate
172 public void deactivate() { 179 public void deactivate() {
180 + if (disableLD) {
181 + return;
182 + }
173 executor.shutdownNow(); 183 executor.shutdownNow();
174 for (LinkDiscovery ld : discoverers.values()) { 184 for (LinkDiscovery ld : discoverers.values()) {
175 ld.stop(); 185 ld.stop();
...@@ -186,21 +196,22 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -186,21 +196,22 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
186 @Modified 196 @Modified
187 public void modified(ComponentContext context) { 197 public void modified(ComponentContext context) {
188 if (context == null) { 198 if (context == null) {
199 + loadSuppressionRules();
189 return; 200 return;
190 } 201 }
191 @SuppressWarnings("rawtypes") 202 @SuppressWarnings("rawtypes")
192 Dictionary properties = context.getProperties(); 203 Dictionary properties = context.getProperties();
193 204
194 - String s = (String) properties.get(PROP_USE_BDDP); 205 + String s = (String) properties.get(PROP_DISABLE_LD);
195 - if (Strings.isNullOrEmpty(s)) { 206 + if (!Strings.isNullOrEmpty(s)) {
196 - useBDDP = true; 207 + disableLD = Boolean.valueOf(s);
197 - } else { 208 + }
209 + s = (String) properties.get(PROP_USE_BDDP);
210 + if (!Strings.isNullOrEmpty(s)) {
198 useBDDP = Boolean.valueOf(s); 211 useBDDP = Boolean.valueOf(s);
199 } 212 }
200 s = (String) properties.get(PROP_LLDP_SUPPRESSION); 213 s = (String) properties.get(PROP_LLDP_SUPPRESSION);
201 - if (Strings.isNullOrEmpty(s)) { 214 + if (!Strings.isNullOrEmpty(s)) {
202 - filePath = DEFAULT_LLDP_SUPPRESSION_CONFIG;
203 - } else {
204 filePath = s; 215 filePath = s;
205 } 216 }
206 217
...@@ -210,6 +221,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -210,6 +221,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
210 private void loadSuppressionRules() { 221 private void loadSuppressionRules() {
211 SuppressionRulesStore store = new SuppressionRulesStore(filePath); 222 SuppressionRulesStore store = new SuppressionRulesStore(filePath);
212 try { 223 try {
224 + log.info("Reading suppression rules from {}", filePath);
213 rules = store.read(); 225 rules = store.read();
214 } catch (IOException e) { 226 } catch (IOException e) {
215 log.info("Failed to load {}, using built-in rules", filePath); 227 log.info("Failed to load {}, using built-in rules", filePath);
......
...@@ -55,6 +55,7 @@ import org.onosproject.net.PortNumber; ...@@ -55,6 +55,7 @@ import org.onosproject.net.PortNumber;
55 import org.onosproject.net.device.DeviceEvent; 55 import org.onosproject.net.device.DeviceEvent;
56 import org.onosproject.net.device.DeviceListener; 56 import org.onosproject.net.device.DeviceListener;
57 import org.onosproject.net.device.DeviceServiceAdapter; 57 import org.onosproject.net.device.DeviceServiceAdapter;
58 +import org.onosproject.net.flow.FlowRule;
58 import org.onosproject.net.flow.TrafficSelector; 59 import org.onosproject.net.flow.TrafficSelector;
59 import org.onosproject.net.flow.TrafficTreatment; 60 import org.onosproject.net.flow.TrafficTreatment;
60 import org.onosproject.net.link.LinkDescription; 61 import org.onosproject.net.link.LinkDescription;
...@@ -116,7 +117,7 @@ public class LLDPLinkProviderTest { ...@@ -116,7 +117,7 @@ public class LLDPLinkProviderTest {
116 provider.masterService = masterService; 117 provider.masterService = masterService;
117 118
118 119
119 - provider.activate(); 120 + provider.activate(null);
120 } 121 }
121 122
122 @Test 123 @Test
...@@ -211,6 +212,7 @@ public class LLDPLinkProviderTest { ...@@ -211,6 +212,7 @@ public class LLDPLinkProviderTest {
211 212
212 } 213 }
213 214
215 + @SuppressWarnings(value = { "unused" })
214 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) { 216 private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) {
215 return new DeviceEvent(type, deviceService.getDevice(did), 217 return new DeviceEvent(type, deviceService.getDevice(did),
216 deviceService.getPort(did, port)); 218 deviceService.getPort(did, port));
...@@ -400,6 +402,12 @@ public class LLDPLinkProviderTest { ...@@ -400,6 +402,12 @@ public class LLDPLinkProviderTest {
400 public void requestPackets(TrafficSelector selector, 402 public void requestPackets(TrafficSelector selector,
401 PacketPriority priority, ApplicationId appId) { 403 PacketPriority priority, ApplicationId appId) {
402 } 404 }
405 +
406 + @Override
407 + public void requestPackets(TrafficSelector selector,
408 + PacketPriority priority, ApplicationId appId,
409 + FlowRule.Type tableType) {
410 + }
403 } 411 }
404 412
405 private class TestDeviceService extends DeviceServiceAdapter { 413 private class TestDeviceService extends DeviceServiceAdapter {
......
1 +# Sample configuration for link discovery
2 +# Note that the current file location (onos/tools/package/etc) is required for packaging onos and launching it in another location.
3 +# If you are launching onos locally, this configuration file would be placed at: $(KARAF_ROOT)/etc
4 +
5 +#
6 +# Disable Link Dicovery Permanently (Note: changing this property at runtime will have NO effect)
7 +# WARNING: This should only be used for special projects like bgprouter, where ONOS is controlling
8 +# a single switch
9 +#
10 +#disableLinkDiscovery = true
11 +
12 +#
13 +# Enable Broadcast Discovery Protocol (EthType=0x8942)
14 +#
15 +#useBDDP = false
16 +
17 +#
18 +# Disable LLDP's received from specific devices
19 +# Details of the devices are in the file configured below
20 +#
21 +#lldpSuppression = ../config/lldp_suppresion.json