blob: 975beebbc51c0b06ae68583417584830352aebb7 [file] [log] [blame]
Jonathan Hartf5829202015-02-12 09:37:02 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.bgprouter;
17
alshabib910aff12015-04-09 16:55:57 -070018import com.google.common.collect.ConcurrentHashMultiset;
19import com.google.common.collect.HashMultimap;
20import com.google.common.collect.Maps;
21import com.google.common.collect.Multimap;
22import com.google.common.collect.Multiset;
Saurav Dasbd7f7422015-04-23 16:31:47 -070023
Jonathan Hartf5829202015-02-12 09:37:02 -080024import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Component;
26import org.apache.felix.scr.annotations.Deactivate;
27import org.apache.felix.scr.annotations.Reference;
28import org.apache.felix.scr.annotations.ReferenceCardinality;
29import org.onlab.packet.Ethernet;
Jonathan Hart7baba072015-02-23 14:27:59 -080030import org.onlab.packet.IpAddress;
31import org.onlab.packet.IpPrefix;
Jonathan Hart54b406b2015-03-06 16:24:14 -080032import org.onosproject.config.NetworkConfigService;
Jonathan Hartf5829202015-02-12 09:37:02 -080033import org.onosproject.core.ApplicationId;
34import org.onosproject.core.CoreService;
35import org.onosproject.net.DeviceId;
Saurav Dasbd7f7422015-04-23 16:31:47 -070036import org.onosproject.net.device.DeviceEvent;
37import org.onosproject.net.device.DeviceListener;
38import org.onosproject.net.device.DeviceService;
Jonathan Hartf5829202015-02-12 09:37:02 -080039import org.onosproject.net.flow.DefaultTrafficSelector;
40import org.onosproject.net.flow.DefaultTrafficTreatment;
Jonathan Hartf5829202015-02-12 09:37:02 -080041import org.onosproject.net.flow.TrafficSelector;
42import org.onosproject.net.flow.TrafficTreatment;
alshabib910aff12015-04-09 16:55:57 -070043import org.onosproject.net.flow.criteria.Criteria;
44import org.onosproject.net.flowobjective.DefaultFilteringObjective;
alshabib2a441c62015-04-13 18:39:38 -070045import org.onosproject.net.flowobjective.DefaultForwardingObjective;
46import org.onosproject.net.flowobjective.DefaultNextObjective;
alshabib910aff12015-04-09 16:55:57 -070047import org.onosproject.net.flowobjective.FilteringObjective;
48import org.onosproject.net.flowobjective.FlowObjectiveService;
alshabib2a441c62015-04-13 18:39:38 -070049import org.onosproject.net.flowobjective.ForwardingObjective;
50import org.onosproject.net.flowobjective.NextObjective;
Saurav Dasbd7f7422015-04-23 16:31:47 -070051import org.onosproject.net.flowobjective.Objective;
52import org.onosproject.net.flowobjective.ObjectiveContext;
53import org.onosproject.net.flowobjective.ObjectiveError;
Jonathan Hartf5829202015-02-12 09:37:02 -080054import org.onosproject.net.packet.PacketService;
Jonathan Hart7baba072015-02-23 14:27:59 -080055import org.onosproject.routing.FibEntry;
Jonathan Hart2da1e602015-02-18 19:09:24 -080056import org.onosproject.routing.FibListener;
57import org.onosproject.routing.FibUpdate;
58import org.onosproject.routing.RoutingService;
Saurav Dasfbe25c52015-03-04 11:12:00 -080059import org.onosproject.routing.config.BgpSpeaker;
Jonathan Hart2da1e602015-02-18 19:09:24 -080060import org.onosproject.routing.config.Interface;
61import org.onosproject.routing.config.RoutingConfigurationService;
Jonathan Hartf5829202015-02-12 09:37:02 -080062import org.slf4j.Logger;
63import org.slf4j.LoggerFactory;
64
alshabib910aff12015-04-09 16:55:57 -070065import java.util.Collection;
alshabib910aff12015-04-09 16:55:57 -070066import java.util.HashMap;
alshabib910aff12015-04-09 16:55:57 -070067import java.util.Map;
68import java.util.Set;
alshabib2a441c62015-04-13 18:39:38 -070069
Saurav Dasdfc639e2015-04-30 11:48:16 -070070/* For test only - will be removed before Cardinal release
71import org.onlab.packet.Ip4Address;
72import org.onlab.packet.Ip4Prefix;
73import org.onlab.packet.MacAddress;
74import java.util.Collections;
75import static org.onlab.util.Tools.delay;
76*/
77
Jonathan Hartf5829202015-02-12 09:37:02 -080078/**
79 * BgpRouter component.
80 */
81@Component(immediate = true)
82public class BgpRouter {
83
84 private static final Logger log = LoggerFactory.getLogger(BgpRouter.class);
85
86 private static final String BGP_ROUTER_APP = "org.onosproject.bgprouter";
87
Jonathan Hart12ef2052015-03-10 13:58:13 -070088 private static final int PRIORITY_OFFSET = 100;
89 private static final int PRIORITY_MULTIPLIER = 5;
Jonathan Hartf5829202015-02-12 09:37:02 -080090
91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 protected CoreService coreService;
93
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Jonathan Hartf5829202015-02-12 09:37:02 -080095 protected RoutingService routingService;
96
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 protected RoutingConfigurationService configService;
99
100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 protected PacketService packetService;
102
Saurav Dasbd7f7422015-04-23 16:31:47 -0700103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
104 protected FlowObjectiveService flowObjectiveService;
105
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected DeviceService deviceService;
108
Saurav Dasfbe25c52015-03-04 11:12:00 -0800109 //
110 // NOTE: Unused reference - needed to guarantee that the
111 // NetworkConfigReader component is activated and the network configuration
112 // is read.
113 //
114 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
115 protected NetworkConfigService networkConfigService;
116
Jonathan Hartf5829202015-02-12 09:37:02 -0800117 private ApplicationId appId;
118
Jonathan Hart7baba072015-02-23 14:27:59 -0800119 // Reference count for how many times a next hop is used by a route
120 private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create();
121
122 // Mapping from prefix to its current next hop
123 private final Map<IpPrefix, IpAddress> prefixToNextHop = Maps.newHashMap();
124
125 // Mapping from next hop IP to next hop object containing group info
alshabib2a441c62015-04-13 18:39:38 -0700126 private final Map<IpAddress, Integer> nextHops = Maps.newHashMap();
Jonathan Hart7baba072015-02-23 14:27:59 -0800127
128 // Stores FIB updates that are waiting for groups to be set up
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700129 private final Multimap<NextHopGroupKey, FibEntry> pendingUpdates = HashMultimap.create();
Jonathan Hartf5829202015-02-12 09:37:02 -0800130
Saurav Dasfbe25c52015-03-04 11:12:00 -0800131 // Device id of data-plane switch - should be learned from config
132 private DeviceId deviceId;
133
134 // Device id of control-plane switch (OVS) connected to BGP Speaker - should be
135 // learned from config
136 private DeviceId ctrlDeviceId;
Jonathan Hartf5829202015-02-12 09:37:02 -0800137
Saurav Dasbd7f7422015-04-23 16:31:47 -0700138 // Responsible for handling BGP traffic (encapsulated within OF messages)
139 // between the data-plane switch and the Quagga VM using a control plane OVS.
Jonathan Hartf5829202015-02-12 09:37:02 -0800140 private TunnellingConnectivityManager connectivityManager;
141
Saurav Dasbd7f7422015-04-23 16:31:47 -0700142 private DeviceListener deviceListener;
sangho5eaf0332015-03-09 15:08:12 -0700143 private IcmpHandler icmpHandler;
144
Jonathan Hartf5829202015-02-12 09:37:02 -0800145 @Activate
146 protected void activate() {
Jonathan Hartf5829202015-02-12 09:37:02 -0800147 appId = coreService.registerApplication(BGP_ROUTER_APP);
Saurav Dasfbe25c52015-03-04 11:12:00 -0800148 getDeviceConfiguration(configService.getBgpSpeakers());
Jonathan Hartf5829202015-02-12 09:37:02 -0800149
150 connectivityManager = new TunnellingConnectivityManager(appId,
151 configService,
Jonathan Hart936a7292015-03-06 18:02:57 -0800152 packetService,
Saurav Das3d038262015-04-23 12:36:58 -0700153 flowObjectiveService);
Jonathan Hartf5829202015-02-12 09:37:02 -0800154
sangho5eaf0332015-03-09 15:08:12 -0700155 icmpHandler = new IcmpHandler(configService, packetService);
Saurav Dasbd7f7422015-04-23 16:31:47 -0700156 deviceListener = new InnerDeviceListener();
Pingping Line28ae4c2015-03-13 11:37:03 -0700157 routingService.addFibListener(new InternalFibListener());
158 routingService.start();
Saurav Dasbd7f7422015-04-23 16:31:47 -0700159 deviceService.addListener(deviceListener);
Jonathan Hartf5829202015-02-12 09:37:02 -0800160 connectivityManager.start();
sangho5eaf0332015-03-09 15:08:12 -0700161 icmpHandler.start();
162
Jonathan Hartf5829202015-02-12 09:37:02 -0800163 log.info("BgpRouter started");
164 }
165
166 @Deactivate
167 protected void deactivate() {
168 routingService.stop();
169 connectivityManager.stop();
sangho5eaf0332015-03-09 15:08:12 -0700170 icmpHandler.stop();
Saurav Dasbd7f7422015-04-23 16:31:47 -0700171 deviceService.removeListener(deviceListener);
172 //processIntfFilters(false, configService.getInterfaces()); //TODO necessary?
Jonathan Hartf5829202015-02-12 09:37:02 -0800173 log.info("BgpRouter stopped");
174 }
175
Saurav Dasfbe25c52015-03-04 11:12:00 -0800176 private void getDeviceConfiguration(Map<String, BgpSpeaker> bgps) {
177 if (bgps == null || bgps.values().isEmpty()) {
178 log.error("BGP speakers configuration is missing");
179 return;
180 }
181 for (BgpSpeaker s : bgps.values()) {
182 ctrlDeviceId = s.connectPoint().deviceId();
183 if (s.interfaceAddresses() == null || s.interfaceAddresses().isEmpty()) {
184 log.error("BGP Router must have interfaces configured");
185 return;
186 }
187 deviceId = s.interfaceAddresses().get(0).connectPoint().deviceId();
188 break;
189 }
sangho5eaf0332015-03-09 15:08:12 -0700190
Saurav Dasfbe25c52015-03-04 11:12:00 -0800191 log.info("Router dpid: {}", deviceId);
192 log.info("Control Plane OVS dpid: {}", ctrlDeviceId);
193 }
194
Jonathan Hartf5829202015-02-12 09:37:02 -0800195 private void updateFibEntry(Collection<FibUpdate> updates) {
alshabib2a441c62015-04-13 18:39:38 -0700196 Map<FibEntry, Integer> toInstall = new HashMap<>(updates.size());
Jonathan Hart5b141422015-03-06 12:59:09 -0800197
Jonathan Hartf5829202015-02-12 09:37:02 -0800198 for (FibUpdate update : updates) {
Jonathan Hart7baba072015-02-23 14:27:59 -0800199 FibEntry entry = update.entry();
Jonathan Hartf5829202015-02-12 09:37:02 -0800200
Jonathan Hart7baba072015-02-23 14:27:59 -0800201 addNextHop(entry);
Jonathan Hartf5829202015-02-12 09:37:02 -0800202
alshabib2a441c62015-04-13 18:39:38 -0700203 Integer nextId;
Jonathan Hart7baba072015-02-23 14:27:59 -0800204 synchronized (pendingUpdates) {
alshabib2a441c62015-04-13 18:39:38 -0700205 nextId = nextHops.get(entry.nextHopIp());
Jonathan Hartf5829202015-02-12 09:37:02 -0800206 }
207
alshabib2a441c62015-04-13 18:39:38 -0700208 toInstall.put(update.entry(), nextId);
Jonathan Hartf5829202015-02-12 09:37:02 -0800209 }
Jonathan Hart5b141422015-03-06 12:59:09 -0800210
211 installFlows(toInstall);
Jonathan Hartf5829202015-02-12 09:37:02 -0800212 }
213
alshabib2a441c62015-04-13 18:39:38 -0700214 private void installFlows(Map<FibEntry, Integer> entriesToInstall) {
Jonathan Hart7baba072015-02-23 14:27:59 -0800215
alshabib2a441c62015-04-13 18:39:38 -0700216 for (Map.Entry<FibEntry, Integer> entry : entriesToInstall.entrySet()) {
Jonathan Hart5b141422015-03-06 12:59:09 -0800217 FibEntry fibEntry = entry.getKey();
alshabib2a441c62015-04-13 18:39:38 -0700218 Integer nextId = entry.getValue();
Jonathan Hart5b141422015-03-06 12:59:09 -0800219
alshabib2a441c62015-04-13 18:39:38 -0700220 flowObjectiveService.forward(deviceId,
Saurav Dasbd7f7422015-04-23 16:31:47 -0700221 generateRibForwardingObj(fibEntry.prefix(), nextId).add());
Saurav Das3d038262015-04-23 12:36:58 -0700222 log.trace("Sending forwarding objective {} -> nextId:{}", fibEntry, nextId);
Jonathan Hart5b141422015-03-06 12:59:09 -0800223 }
224
Jonathan Hart7baba072015-02-23 14:27:59 -0800225 }
226
227 private synchronized void deleteFibEntry(Collection<FibUpdate> withdraws) {
Jonathan Hart5b141422015-03-06 12:59:09 -0800228
Jonathan Hart7baba072015-02-23 14:27:59 -0800229 for (FibUpdate update : withdraws) {
230 FibEntry entry = update.entry();
sanghodde53d12015-04-30 10:34:41 -0700231 //Integer nextId = nextHops.get(entry.nextHopIp());
Jonathan Hart7baba072015-02-23 14:27:59 -0800232
Saurav Dasbd7f7422015-04-23 16:31:47 -0700233 /* Group group = deleteNextHop(entry.prefix());
Jonathan Hart37d659c2015-03-08 19:20:38 -0700234 if (group == null) {
235 log.warn("Group not found when deleting {}", entry);
236 return;
alshabib2a441c62015-04-13 18:39:38 -0700237 }*/
Jonathan Hartf5829202015-02-12 09:37:02 -0800238
alshabib2a441c62015-04-13 18:39:38 -0700239 flowObjectiveService.forward(deviceId,
sanghodde53d12015-04-30 10:34:41 -0700240 generateRibForwardingObj(entry.prefix(), null).remove());
Jonathan Hartf5829202015-02-12 09:37:02 -0800241
Jonathan Hartf5829202015-02-12 09:37:02 -0800242 }
Jonathan Hart5b141422015-03-06 12:59:09 -0800243
Jonathan Hartf5829202015-02-12 09:37:02 -0800244 }
245
Saurav Dasbd7f7422015-04-23 16:31:47 -0700246 private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix,
247 Integer nextId) {
Jonathan Hart37d659c2015-03-08 19:20:38 -0700248 TrafficSelector selector = DefaultTrafficSelector.builder()
249 .matchEthType(Ethernet.TYPE_IPV4)
250 .matchIPDst(prefix)
251 .build();
252
Jonathan Hart12ef2052015-03-10 13:58:13 -0700253 int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
254
alshabib2a441c62015-04-13 18:39:38 -0700255 ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
256 .fromApp(appId)
257 .makePermanent()
alshabib2a441c62015-04-13 18:39:38 -0700258 .withSelector(selector)
259 .withPriority(priority)
260 .withFlag(ForwardingObjective.Flag.SPECIFIC);
261
sanghodde53d12015-04-30 10:34:41 -0700262 if (nextId == null) {
263 fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
264 } else {
265 fwdBuilder.nextStep(nextId);
266 }
alshabib2a441c62015-04-13 18:39:38 -0700267 return fwdBuilder;
Jonathan Hart37d659c2015-03-08 19:20:38 -0700268 }
269
Jonathan Hart7baba072015-02-23 14:27:59 -0800270 private synchronized void addNextHop(FibEntry entry) {
271 prefixToNextHop.put(entry.prefix(), entry.nextHopIp());
272 if (nextHopsCount.count(entry.nextHopIp()) == 0) {
Jonathan Hartf5829202015-02-12 09:37:02 -0800273 // There was no next hop in the multiset
274
Jonathan Hart7baba072015-02-23 14:27:59 -0800275 Interface egressIntf = configService.getMatchingInterface(entry.nextHopIp());
Jonathan Hartf5829202015-02-12 09:37:02 -0800276 if (egressIntf == null) {
Jonathan Hart7baba072015-02-23 14:27:59 -0800277 log.warn("no egress interface found for {}", entry);
Jonathan Hartf5829202015-02-12 09:37:02 -0800278 return;
279 }
280
Jonathan Hart7baba072015-02-23 14:27:59 -0800281 NextHopGroupKey groupKey = new NextHopGroupKey(entry.nextHopIp());
282
283 NextHop nextHop = new NextHop(entry.nextHopIp(), entry.nextHopMac(), groupKey);
Jonathan Hartf5829202015-02-12 09:37:02 -0800284
285 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
286 .setEthSrc(egressIntf.mac())
287 .setEthDst(nextHop.mac())
Jonathan Hart54b406b2015-03-06 16:24:14 -0800288 .pushVlan()
Jonathan Hartf5829202015-02-12 09:37:02 -0800289 .setVlanId(egressIntf.vlan())
alshabibda1644e2015-03-13 14:01:35 -0700290 .setVlanPcp((byte) 0)
Jonathan Hartf5829202015-02-12 09:37:02 -0800291 .setOutput(egressIntf.connectPoint().port())
292 .build();
293
Saurav Das3ea46622015-04-22 14:01:34 -0700294 int nextId = flowObjectiveService.allocateNextId();
295
alshabib2a441c62015-04-13 18:39:38 -0700296 NextObjective nextObjective = DefaultNextObjective.builder()
Saurav Das3ea46622015-04-22 14:01:34 -0700297 .withId(nextId)
alshabib2a441c62015-04-13 18:39:38 -0700298 .addTreatment(treatment)
299 .withType(NextObjective.Type.SIMPLE)
300 .fromApp(appId)
Saurav Dasbd7f7422015-04-23 16:31:47 -0700301 .add(); // TODO add callbacks
alshabib2a441c62015-04-13 18:39:38 -0700302
303 flowObjectiveService.next(deviceId, nextObjective);
304
Saurav Das3ea46622015-04-22 14:01:34 -0700305 nextHops.put(nextHop.ip(), nextId);
Jonathan Hart7baba072015-02-23 14:27:59 -0800306
Jonathan Hartf5829202015-02-12 09:37:02 -0800307 }
Jonathan Hart7baba072015-02-23 14:27:59 -0800308
309 nextHopsCount.add(entry.nextHopIp());
Jonathan Hartf5829202015-02-12 09:37:02 -0800310 }
311
alshabib2a441c62015-04-13 18:39:38 -0700312 /*private synchronized Group deleteNextHop(IpPrefix prefix) {
Jonathan Hart7baba072015-02-23 14:27:59 -0800313 IpAddress nextHopIp = prefixToNextHop.remove(prefix);
314 NextHop nextHop = nextHops.get(nextHopIp);
315 if (nextHop == null) {
316 log.warn("No next hop found when removing prefix {}", prefix);
Jonathan Hart37d659c2015-03-08 19:20:38 -0700317 return null;
Jonathan Hart7baba072015-02-23 14:27:59 -0800318 }
319
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700320 Group group = groupService.getGroup(deviceId,
321 new DefaultGroupKey(appKryo.
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700322 serialize(nextHop.group())));
Jonathan Hart37d659c2015-03-08 19:20:38 -0700323
Jonathan Hartf9f2cbb2015-03-12 17:44:03 -0700324 // FIXME disabling group deletes for now until we verify the logic is OK
Saurav Dasbd7f7422015-04-23 16:31:47 -0700325 if (nextHopsCount.remove(nextHopIp, 1) <= 1) {
Jonathan Hartf5829202015-02-12 09:37:02 -0800326 // There was one or less next hops, so there are now none
327
Jonathan Hart7baba072015-02-23 14:27:59 -0800328 log.debug("removing group for next hop {}", nextHop);
Jonathan Hartf5829202015-02-12 09:37:02 -0800329
Jonathan Hart7baba072015-02-23 14:27:59 -0800330 nextHops.remove(nextHopIp);
331
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700332 groupService.removeGroup(deviceId,
333 new DefaultGroupKey(appKryo.build().serialize(nextHop.group())),
334 appId);
Saurav Dasbd7f7422015-04-23 16:31:47 -0700335 }
Jonathan Hart37d659c2015-03-08 19:20:38 -0700336
337 return group;
alshabib2a441c62015-04-13 18:39:38 -0700338 }*/
Jonathan Hartf5829202015-02-12 09:37:02 -0800339
340 private class InternalFibListener implements FibListener {
341
342 @Override
343 public void update(Collection<FibUpdate> updates,
344 Collection<FibUpdate> withdraws) {
345 BgpRouter.this.deleteFibEntry(withdraws);
346 BgpRouter.this.updateFibEntry(updates);
347 }
348 }
alshabib10580802015-02-18 18:30:33 -0800349
Saurav Dascfd63d22015-04-13 16:08:24 -0700350 private void processIntfFilters(boolean install, Set<Interface> intfs) {
351 log.info("Processing {} router interfaces", intfs.size());
352 for (Interface intf : intfs) {
353 FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
354 fob.withKey(Criteria.matchInPort(intf.connectPoint().port()))
355 .addCondition(Criteria.matchEthDst(intf.mac()))
356 .addCondition(Criteria.matchVlanId(intf.vlan()));
357 intf.ipAddresses().stream()
358 .forEach(ipaddr -> fob.addCondition(
359 Criteria.matchIPDst(ipaddr.subnetAddress())));
360 fob.permit().fromApp(appId);
Saurav Dasbd7f7422015-04-23 16:31:47 -0700361 flowObjectiveService.filter(
362 deviceId,
363 fob.add(new ObjectiveContext() {
364 @Override
365 public void onSuccess(Objective objective) {
366 log.info("Successfully installed interface based "
367 + "filtering objcetives");
368 }
369
370 @Override
371 public void onError(Objective objective,
372 ObjectiveError error) {
373 log.error("Failed to install interface filters {}: {}",
374 objective, error);
375 // TODO something more than just logging
376 }
377 }));
alshabib10580802015-02-18 18:30:33 -0800378 }
Jonathan Hart7baba072015-02-23 14:27:59 -0800379 }
alshabib10580802015-02-18 18:30:33 -0800380
Saurav Dasbd7f7422015-04-23 16:31:47 -0700381 // Triggers driver setup when a device is (re)detected.
382 private class InnerDeviceListener implements DeviceListener {
Jonathan Hart7baba072015-02-23 14:27:59 -0800383 @Override
Saurav Dasbd7f7422015-04-23 16:31:47 -0700384 public void event(DeviceEvent event) {
385 switch (event.type()) {
386 case DEVICE_ADDED:
387 case DEVICE_AVAILABILITY_CHANGED:
388 if (deviceService.isAvailable(event.subject().id())) {
389 log.info("Device connected {}", event.subject().id());
sanghof22fb402015-04-27 23:55:10 -0700390 if (event.subject().id().equals(deviceId)) {
391 processIntfFilters(true, configService.getInterfaces());
Jonathan Hart7baba072015-02-23 14:27:59 -0800392
sanghodde53d12015-04-30 10:34:41 -0700393 /* For test only - will be removed before Cardinal release
sanghof22fb402015-04-27 23:55:10 -0700394 delay(1000);
395 FibEntry fibEntry = new FibEntry(Ip4Prefix.valueOf("10.1.0.0/16"),
396 Ip4Address.valueOf("192.168.10.1"),
397 MacAddress.valueOf("DE:AD:BE:EF:FE:ED"));
398 FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry);
399 updateFibEntry(Collections.singletonList(fibUpdate));
sanghodde53d12015-04-30 10:34:41 -0700400 */
sanghof22fb402015-04-27 23:55:10 -0700401 }
402
403 if (event.subject().id().equals(ctrlDeviceId)) {
404 connectivityManager.notifySwitchAvailable();
405 }
Saurav Dasbd7f7422015-04-23 16:31:47 -0700406 }
407 break;
Jonathan Hart5b141422015-03-06 12:59:09 -0800408
Saurav Dasbd7f7422015-04-23 16:31:47 -0700409 // TODO other cases
410 case DEVICE_UPDATED:
411 break;
412 case DEVICE_REMOVED:
413 break;
414 case DEVICE_SUSPENDED:
415 break;
416 case PORT_ADDED:
417 break;
418 case PORT_UPDATED:
419 break;
420 case PORT_REMOVED:
421 break;
422 default:
423 break;
Jonathan Hart7baba072015-02-23 14:27:59 -0800424 }
425 }
Saurav Dasbd7f7422015-04-23 16:31:47 -0700426 }
Jonathan Hartf5829202015-02-12 09:37:02 -0800427}