Saurav Das
Committed by Gerrit Code Review

Fixes bug where driver gets initialized only when device is available.

More explict handling of versatile forwarding flows in corsa driver.
Moving TunnelConnectivityManager to use flowObjectives instead of flowRules.

Change-Id: If43023f30a6e7a028dfdefbe1ffbcc710a1c7be3
...@@ -161,7 +161,7 @@ public class BgpRouter { ...@@ -161,7 +161,7 @@ public class BgpRouter {
161 connectivityManager = new TunnellingConnectivityManager(appId, 161 connectivityManager = new TunnellingConnectivityManager(appId,
162 configService, 162 configService,
163 packetService, 163 packetService,
164 - flowService); 164 + flowObjectiveService);
165 165
166 icmpHandler = new IcmpHandler(configService, packetService); 166 icmpHandler = new IcmpHandler(configService, packetService);
167 167
...@@ -252,7 +252,7 @@ public class BgpRouter { ...@@ -252,7 +252,7 @@ public class BgpRouter {
252 252
253 flowObjectiveService.forward(deviceId, 253 flowObjectiveService.forward(deviceId,
254 generateRibFlowRule(fibEntry.prefix(), nextId).add()); 254 generateRibFlowRule(fibEntry.prefix(), nextId).add());
255 - log.trace("Sending flow forwarding objective {}->{}", fibEntry, nextId); 255 + log.trace("Sending forwarding objective {} -> nextId:{}", fibEntry, nextId);
256 } 256 }
257 257
258 } 258 }
...@@ -282,8 +282,6 @@ public class BgpRouter { ...@@ -282,8 +282,6 @@ public class BgpRouter {
282 .matchIPDst(prefix) 282 .matchIPDst(prefix)
283 .build(); 283 .build();
284 284
285 -
286 -
287 int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; 285 int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
288 286
289 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder() 287 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
......
...@@ -15,19 +15,21 @@ ...@@ -15,19 +15,21 @@
15 */ 15 */
16 package org.onosproject.bgprouter; 16 package org.onosproject.bgprouter;
17 17
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
18 import org.onlab.packet.Ethernet; 20 import org.onlab.packet.Ethernet;
19 import org.onlab.packet.IPv4; 21 import org.onlab.packet.IPv4;
20 import org.onlab.packet.IpAddress; 22 import org.onlab.packet.IpAddress;
21 import org.onlab.packet.TCP; 23 import org.onlab.packet.TCP;
22 import org.onosproject.core.ApplicationId; 24 import org.onosproject.core.ApplicationId;
23 import org.onosproject.net.ConnectPoint; 25 import org.onosproject.net.ConnectPoint;
24 -import org.onosproject.net.flow.DefaultFlowRule;
25 import org.onosproject.net.flow.DefaultTrafficSelector; 26 import org.onosproject.net.flow.DefaultTrafficSelector;
26 import org.onosproject.net.flow.DefaultTrafficTreatment; 27 import org.onosproject.net.flow.DefaultTrafficTreatment;
27 -import org.onosproject.net.flow.FlowRuleOperations;
28 -import org.onosproject.net.flow.FlowRuleService;
29 import org.onosproject.net.flow.TrafficSelector; 28 import org.onosproject.net.flow.TrafficSelector;
30 import org.onosproject.net.flow.TrafficTreatment; 29 import org.onosproject.net.flow.TrafficTreatment;
30 +import org.onosproject.net.flowobjective.DefaultForwardingObjective;
31 +import org.onosproject.net.flowobjective.FlowObjectiveService;
32 +import org.onosproject.net.flowobjective.ForwardingObjective;
31 import org.onosproject.net.packet.DefaultOutboundPacket; 33 import org.onosproject.net.packet.DefaultOutboundPacket;
32 import org.onosproject.net.packet.OutboundPacket; 34 import org.onosproject.net.packet.OutboundPacket;
33 import org.onosproject.net.packet.PacketContext; 35 import org.onosproject.net.packet.PacketContext;
...@@ -37,6 +39,7 @@ import org.onosproject.routing.config.BgpPeer; ...@@ -37,6 +39,7 @@ import org.onosproject.routing.config.BgpPeer;
37 import org.onosproject.routing.config.BgpSpeaker; 39 import org.onosproject.routing.config.BgpSpeaker;
38 import org.onosproject.routing.config.InterfaceAddress; 40 import org.onosproject.routing.config.InterfaceAddress;
39 import org.onosproject.routing.config.RoutingConfigurationService; 41 import org.onosproject.routing.config.RoutingConfigurationService;
42 +import org.slf4j.Logger;
40 43
41 44
42 /** 45 /**
...@@ -46,23 +49,25 @@ import org.onosproject.routing.config.RoutingConfigurationService; ...@@ -46,23 +49,25 @@ import org.onosproject.routing.config.RoutingConfigurationService;
46 public class TunnellingConnectivityManager { 49 public class TunnellingConnectivityManager {
47 50
48 private static final short BGP_PORT = 179; 51 private static final short BGP_PORT = 179;
49 - 52 + private final Logger log = getLogger(getClass());
50 private final ApplicationId appId; 53 private final ApplicationId appId;
51 54
52 private final BgpSpeaker bgpSpeaker; 55 private final BgpSpeaker bgpSpeaker;
53 56
54 private final PacketService packetService; 57 private final PacketService packetService;
55 private final RoutingConfigurationService configService; 58 private final RoutingConfigurationService configService;
59 + private final FlowObjectiveService flowObjectiveService;
56 60
57 private final BgpProcessor processor = new BgpProcessor(); 61 private final BgpProcessor processor = new BgpProcessor();
58 62
59 public TunnellingConnectivityManager(ApplicationId appId, 63 public TunnellingConnectivityManager(ApplicationId appId,
60 RoutingConfigurationService configService, 64 RoutingConfigurationService configService,
61 PacketService packetService, 65 PacketService packetService,
62 - FlowRuleService flowService) { 66 + FlowObjectiveService flowObjectiveService) {
63 this.appId = appId; 67 this.appId = appId;
64 this.configService = configService; 68 this.configService = configService;
65 this.packetService = packetService; 69 this.packetService = packetService;
70 + this.flowObjectiveService = flowObjectiveService;
66 71
67 BgpSpeaker bgpSpeaker = null; 72 BgpSpeaker bgpSpeaker = null;
68 for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) { 73 for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) {
...@@ -92,12 +97,27 @@ public class TunnellingConnectivityManager { ...@@ -92,12 +97,27 @@ public class TunnellingConnectivityManager {
92 .punt() 97 .punt()
93 .build(); 98 .build();
94 99
95 - FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); 100 + ForwardingObjective puntSrc = DefaultForwardingObjective.builder()
96 - builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(), 101 + .fromApp(appId)
97 - selectorSrc, treatment, 0, appId, 0, true)); 102 + .makePermanent()
98 - builder.add(new DefaultFlowRule(bgpSpeaker.connectPoint().deviceId(), 103 + .withSelector(selectorSrc)
99 - selectorDst, treatment, 0, appId, 0, true)); 104 + .withTreatment(treatment)
100 - flowService.apply(builder.build()); 105 + .withFlag(ForwardingObjective.Flag.VERSATILE)
106 + .add();
107 + flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(),
108 + puntSrc);
109 +
110 + ForwardingObjective puntDst = DefaultForwardingObjective.builder()
111 + .fromApp(appId)
112 + .makePermanent()
113 + .withSelector(selectorDst)
114 + .withTreatment(treatment)
115 + .withFlag(ForwardingObjective.Flag.VERSATILE)
116 + .add();
117 + flowObjectiveService.forward(bgpSpeaker.connectPoint().deviceId(),
118 + puntDst);
119 + log.info("Sent punt forwarding objective to {}", bgpSpeaker.connectPoint().deviceId());
120 +
101 } 121 }
102 122
103 public void start() { 123 public void start() {
......
...@@ -67,7 +67,7 @@ import static org.onlab.util.Tools.groupedThreads; ...@@ -67,7 +67,7 @@ import static org.onlab.util.Tools.groupedThreads;
67 @Service 67 @Service
68 public class FlowObjectiveManager implements FlowObjectiveService { 68 public class FlowObjectiveManager implements FlowObjectiveService {
69 69
70 - public static final int INSTALL_RETRY_ATTEMPTS = 5; 70 + public static final int INSTALL_RETRY_ATTEMPTS = 10;
71 public static final long INSTALL_RETRY_INTERVAL = 1000; // ms 71 public static final long INSTALL_RETRY_INTERVAL = 1000; // ms
72 72
73 private final Logger log = LoggerFactory.getLogger(getClass()); 73 private final Logger log = LoggerFactory.getLogger(getClass());
...@@ -167,7 +167,7 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -167,7 +167,7 @@ public class FlowObjectiveManager implements FlowObjectiveService {
167 pipeliner.filter((FilteringObjective) objective); 167 pipeliner.filter((FilteringObjective) objective);
168 } 168 }
169 } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) { 169 } else if (numAttempts < INSTALL_RETRY_ATTEMPTS) {
170 - Thread.currentThread().sleep(INSTALL_RETRY_INTERVAL); 170 + Thread.sleep(INSTALL_RETRY_INTERVAL);
171 executorService.submit(this); 171 executorService.submit(this);
172 } else { 172 } else {
173 // Otherwise we've tried a few times and failed, report an 173 // Otherwise we've tried a few times and failed, report an
...@@ -262,7 +262,9 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -262,7 +262,9 @@ public class FlowObjectiveManager implements FlowObjectiveService {
262 switch (event.type()) { 262 switch (event.type()) {
263 case MASTER_CHANGED: 263 case MASTER_CHANGED:
264 log.info("mastership changed on device {}", event.subject()); 264 log.info("mastership changed on device {}", event.subject());
265 - setupPipelineHandler(event.subject()); 265 + if (deviceService.isAvailable(event.subject())) {
266 + setupPipelineHandler(event.subject());
267 + }
266 break; 268 break;
267 case BACKUPS_CHANGED: 269 case BACKUPS_CHANGED:
268 break; 270 break;
...@@ -278,8 +280,6 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -278,8 +280,6 @@ public class FlowObjectiveManager implements FlowObjectiveService {
278 public void event(DeviceEvent event) { 280 public void event(DeviceEvent event) {
279 switch (event.type()) { 281 switch (event.type()) {
280 case DEVICE_ADDED: 282 case DEVICE_ADDED:
281 - setupPipelineHandler(event.subject().id());
282 - break;
283 case DEVICE_AVAILABILITY_CHANGED: 283 case DEVICE_AVAILABILITY_CHANGED:
284 log.info("Device either added or availability changed {}", 284 log.info("Device either added or availability changed {}",
285 event.subject().id()); 285 event.subject().id());
......
...@@ -194,7 +194,8 @@ public class PacketManager ...@@ -194,7 +194,8 @@ public class PacketManager
194 194
195 @Override 195 @Override
196 public void onError(Objective objective, ObjectiveError error) { 196 public void onError(Objective objective, ObjectiveError error) {
197 - log.warn("Failed to install packet request flow: {}", error); 197 + log.warn("Failed to install packet request {}: {}",
198 + request, error);
198 } 199 }
199 }); 200 });
200 201
......
...@@ -19,8 +19,10 @@ import com.google.common.cache.Cache; ...@@ -19,8 +19,10 @@ import com.google.common.cache.Cache;
19 import com.google.common.cache.CacheBuilder; 19 import com.google.common.cache.CacheBuilder;
20 import com.google.common.cache.RemovalCause; 20 import com.google.common.cache.RemovalCause;
21 import com.google.common.cache.RemovalNotification; 21 import com.google.common.cache.RemovalNotification;
22 +
22 import org.onlab.osgi.ServiceDirectory; 23 import org.onlab.osgi.ServiceDirectory;
23 import org.onlab.packet.Ethernet; 24 import org.onlab.packet.Ethernet;
25 +import org.onlab.packet.IPv4;
24 import org.onlab.packet.MacAddress; 26 import org.onlab.packet.MacAddress;
25 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
26 import org.onlab.util.KryoNamespace; 28 import org.onlab.util.KryoNamespace;
...@@ -240,12 +242,59 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli ...@@ -240,12 +242,59 @@ public class OVSCorsaPipeline extends AbstractHandlerBehaviour implements Pipeli
240 } 242 }
241 243
242 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { 244 private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
245 + log.debug("Processing versatile forwarding objective");
246 + TrafficSelector selector = fwd.selector();
247 +
248 + Criteria.EthTypeCriterion ethType =
249 + (Criteria.EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
250 + if (ethType == null) {
251 + log.error("Versatile forwarding objective must include ethType");
252 + fail(fwd, ObjectiveError.UNKNOWN);
253 + return Collections.emptySet();
254 + }
255 + if (ethType.ethType() == Ethernet.TYPE_ARP) {
256 + log.warn("Driver automatically handles ARP packets by punting to controller "
257 + + " from ETHER table");
258 + pass(fwd);
259 + return Collections.emptySet();
260 + } else if (ethType.ethType() == Ethernet.TYPE_LLDP ||
261 + ethType.ethType() == Ethernet.TYPE_BSN) {
262 + log.warn("Driver currently does not currently handle LLDP packets");
263 + fail(fwd, ObjectiveError.UNSUPPORTED);
264 + return Collections.emptySet();
265 + } else if (ethType.ethType() == Ethernet.TYPE_IPV4) {
266 + Criteria.IPCriterion ipSrc = (Criteria.IPCriterion) selector
267 + .getCriterion(Criterion.Type.IPV4_SRC);
268 + Criteria.IPCriterion ipDst = (Criteria.IPCriterion) selector
269 + .getCriterion(Criterion.Type.IPV4_DST);
270 + Criteria.IPProtocolCriterion ipProto = (Criteria.IPProtocolCriterion) selector
271 + .getCriterion(Criterion.Type.IP_PROTO);
272 + if (ipSrc != null) {
273 + log.warn("Driver currently does not currently handle matching Src IP");
274 + fail(fwd, ObjectiveError.UNSUPPORTED);
275 + return Collections.emptySet();
276 + }
277 + if (ipDst != null) {
278 + log.error("Driver handles Dst IP matching as specific forwarding "
279 + + "objective, not versatile");
280 + fail(fwd, ObjectiveError.UNSUPPORTED);
281 + return Collections.emptySet();
282 + }
283 + if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) {
284 + log.warn("Driver automatically punts all packets reaching the "
285 + + "LOCAL table to the controller");
286 + pass(fwd);
287 + return Collections.emptySet();
288 + }
289 + }
290 +
291 + log.warn("Driver does not support given versatile forwarding objective");
243 fail(fwd, ObjectiveError.UNSUPPORTED); 292 fail(fwd, ObjectiveError.UNSUPPORTED);
244 return Collections.emptySet(); 293 return Collections.emptySet();
245 } 294 }
246 295
247 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { 296 private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
248 - log.warn("Processing specific"); 297 + log.debug("Processing specific forwarding objective");
249 TrafficSelector selector = fwd.selector(); 298 TrafficSelector selector = fwd.selector();
250 Criteria.EthTypeCriterion ethType = 299 Criteria.EthTypeCriterion ethType =
251 (Criteria.EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 300 (Criteria.EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
......