blob: aa9900d8ae625195bc4ae7ac88745aa56420e569 [file] [log] [blame]
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +09003 *
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.ofagent.impl;
17
18import com.google.common.collect.ImmutableSet;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040019import com.google.common.collect.Lists;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090020import io.netty.channel.ChannelOutboundInvoker;
21import io.netty.channel.nio.NioEventLoopGroup;
22import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
27import org.apache.felix.scr.annotations.Service;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090028import org.onosproject.cluster.ClusterService;
29import org.onosproject.cluster.LeadershipService;
30import org.onosproject.cluster.NodeId;
31import org.onosproject.core.ApplicationId;
32import org.onosproject.core.CoreService;
33import org.onosproject.incubator.net.virtual.NetworkId;
Hyunsun Moon53381e82017-03-28 19:58:28 +090034import org.onosproject.incubator.net.virtual.VirtualNetworkEvent;
35import org.onosproject.incubator.net.virtual.VirtualNetworkListener;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090036import org.onosproject.incubator.net.virtual.VirtualNetworkService;
Claudine Chiu785ef2d2017-07-04 13:13:28 -040037import org.onosproject.incubator.net.virtual.VirtualPort;
Claudine Chiu5c184e12017-08-08 21:21:38 -040038import org.onosproject.net.ConnectPoint;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090039import org.onosproject.net.Device;
40import org.onosproject.net.DeviceId;
Claudine Chiu5c184e12017-08-08 21:21:38 -040041import org.onosproject.net.Link;
Claudine Chiu785ef2d2017-07-04 13:13:28 -040042import org.onosproject.net.Port;
Claudine Chiu5c184e12017-08-08 21:21:38 -040043import org.onosproject.net.PortNumber;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090044import org.onosproject.net.device.DeviceEvent;
45import org.onosproject.net.device.DeviceListener;
46import org.onosproject.net.device.DeviceService;
Claudine Chiu2729ffd2017-07-31 21:38:27 -040047import org.onosproject.net.device.PortStatistics;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040048import org.onosproject.net.flow.FlowEntry;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090049import org.onosproject.net.flow.FlowRuleEvent;
50import org.onosproject.net.flow.FlowRuleListener;
51import org.onosproject.net.flow.FlowRuleService;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040052import org.onosproject.net.flow.TableStatisticsEntry;
53import org.onosproject.net.group.Group;
54import org.onosproject.net.group.GroupService;
Claudine Chiu5c184e12017-08-08 21:21:38 -040055import org.onosproject.net.link.LinkService;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090056import org.onosproject.net.packet.PacketContext;
57import org.onosproject.net.packet.PacketProcessor;
58import org.onosproject.net.packet.PacketService;
59import org.onosproject.ofagent.api.OFAgent;
60import org.onosproject.ofagent.api.OFAgentEvent;
61import org.onosproject.ofagent.api.OFAgentListener;
62import org.onosproject.ofagent.api.OFAgentService;
63import org.onosproject.ofagent.api.OFController;
64import org.onosproject.ofagent.api.OFSwitch;
65import org.onosproject.ofagent.api.OFSwitchCapabilities;
66import org.onosproject.ofagent.api.OFSwitchService;
67import org.projectfloodlight.openflow.types.DatapathId;
68import org.slf4j.Logger;
69import org.slf4j.LoggerFactory;
70
71import java.net.InetSocketAddress;
72import java.net.SocketAddress;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040073import java.util.ArrayList;
Claudine Chiu2729ffd2017-07-31 21:38:27 -040074import java.util.List;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090075import java.util.Objects;
76import java.util.Set;
77import java.util.concurrent.ConcurrentHashMap;
78import java.util.concurrent.ExecutorService;
79import java.util.stream.Collectors;
80
81import static com.google.common.base.Preconditions.checkArgument;
82import static org.onlab.util.BoundedThreadPool.newSingleThreadExecutor;
83import static org.onlab.util.Tools.groupedThreads;
Hyunsun Moon53381e82017-03-28 19:58:28 +090084import static org.onosproject.ofagent.api.OFAgent.State.STARTED;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090085import static org.onosproject.ofagent.api.OFAgentService.APPLICATION_NAME;
86
87/**
88 * Manages OF switches.
89 */
90@Component(immediate = true)
91@Service
92public class OFSwitchManager implements OFSwitchService {
93
94 private final Logger log = LoggerFactory.getLogger(getClass());
95
Hyunsun Moon53381e82017-03-28 19:58:28 +090096 private static final OFSwitchCapabilities DEFAULT_CAPABILITIES =
97 DefaultOFSwitchCapabilities.builder()
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090098 .flowStats()
99 .tableStats()
100 .portStats()
101 .groupStats()
102 .queueStats()
103 .ipReasm()
104 .portBlocked()
105 .build();
106
107 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
108 protected CoreService coreService;
109
110 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
111 protected LeadershipService leadershipService;
112
113 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
114 protected ClusterService clusterService;
115
116 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
117 protected VirtualNetworkService virtualNetService;
118
119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
120 protected OFAgentService ofAgentService;
121
122 private final ConcurrentHashMap<DeviceId, OFSwitch> ofSwitchMap = new ConcurrentHashMap<>();
123 private final ExecutorService eventExecutor = newSingleThreadExecutor(
124 groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
125 private final OFAgentListener ofAgentListener = new InternalOFAgentListener();
Hyunsun Moon53381e82017-03-28 19:58:28 +0900126 private final VirtualNetworkListener vNetworkListener = new InternalVirtualNetworkListener();
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900127 private final DeviceListener deviceListener = new InternalDeviceListener();
128 private final FlowRuleListener flowRuleListener = new InternalFlowRuleListener();
129 private final PacketProcessor packetProcessor = new InternalPacketProcessor();
130
131 private NioEventLoopGroup ioWorker;
132 private ApplicationId appId;
133 private NodeId localId;
134
135 @Activate
136 protected void activate() {
137 appId = coreService.registerApplication(APPLICATION_NAME);
138 localId = clusterService.getLocalNode().id();
139 ioWorker = new NioEventLoopGroup();
Hyunsun Moon53381e82017-03-28 19:58:28 +0900140
141 ofAgentService.agents().forEach(this::processOFAgentCreated);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900142 ofAgentService.addListener(ofAgentListener);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900143 virtualNetService.addListener(vNetworkListener);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900144
145 log.info("Started");
146 }
147
148 @Deactivate
149 protected void deactivate() {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900150 virtualNetService.removeListener(vNetworkListener);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900151 ofAgentService.removeListener(ofAgentListener);
152 ofAgentService.agents().forEach(this::processOFAgentStopped);
153
154 ioWorker.shutdownGracefully();
155 eventExecutor.shutdown();
156
157 log.info("Stopped");
158 }
159
160 @Override
161 public Set<OFSwitch> ofSwitches() {
162 return ImmutableSet.copyOf(ofSwitchMap.values());
163 }
164
165 @Override
166 public Set<OFSwitch> ofSwitches(NetworkId networkId) {
167 Set<OFSwitch> ofSwitches = devices(networkId).stream()
168 .map(ofSwitchMap::get)
169 .filter(Objects::nonNull)
170 .collect(Collectors.toSet());
171 return ImmutableSet.copyOf(ofSwitches);
172 }
173
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400174 @Override
Claudine Chiu2729ffd2017-07-31 21:38:27 -0400175 public OFSwitch ofSwitch(NetworkId networkId, DeviceId deviceId) {
176 return ofSwitchMap.get(deviceId);
177 }
178
179 @Override
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400180 public Set<Port> ports(NetworkId networkId, DeviceId deviceId) {
181 Set<Port> ports = virtualNetService.getVirtualPorts(networkId, deviceId)
182 .stream()
183 .collect(Collectors.toSet());
184 return ImmutableSet.copyOf(ports);
185 }
186
Claudine Chiu2729ffd2017-07-31 21:38:27 -0400187 @Override
188 public List<PortStatistics> getPortStatistics(NetworkId networkId, DeviceId deviceId) {
189 DeviceService deviceService = virtualNetService.get(networkId, DeviceService.class);
190 List<PortStatistics> portStatistics = deviceService.getPortStatistics(deviceId);
191 return portStatistics;
192 }
193
Claudine Chiu5c184e12017-08-08 21:21:38 -0400194 @Override
195 public ConnectPoint neighbour(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
196 ConnectPoint cp = new ConnectPoint(deviceId, portNumber);
197 LinkService linkService = virtualNetService.get(networkId, LinkService.class);
198 Set<Link> links = linkService.getEgressLinks(cp);
199 log.trace("neighbour cp {} egressLinks {}", cp, links);
200 if (links != null && links.size() > 0) {
201 Link link = links.iterator().next();
202 return link.src();
203 }
204 return null;
205 }
206
Claudine Chiuce8ccc62017-08-16 10:06:20 -0400207 @Override
Claudine Chiub211b872017-09-05 17:27:00 -0400208 public ApplicationId appId() {
209 return appId;
210 }
211
212 @Override
Claudine Chiuce8ccc62017-08-16 10:06:20 -0400213 public List<FlowEntry> getFlowEntries(NetworkId networkId, DeviceId deviceId) {
214 FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
215 Iterable<FlowEntry> entries = flowRuleService.getFlowEntries(deviceId);
216 return Lists.newArrayList(entries);
217 }
218
219 @Override
220 public List<TableStatisticsEntry> getFlowTableStatistics(NetworkId networkId, DeviceId deviceId) {
221 FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
222 Iterable<TableStatisticsEntry> entries = flowRuleService.getFlowTableStatistics(deviceId);
223 if (entries == null) {
224 entries = new ArrayList<>();
225 }
226 return Lists.newArrayList(entries);
227 }
228
229 @Override
230 public List<Group> getGroups(NetworkId networkId, DeviceId deviceId) {
231 GroupService groupService = virtualNetService.get(networkId, GroupService.class);
232 Iterable<Group> entries = groupService.getGroups(deviceId);
233 return Lists.newArrayList(entries);
234 }
235
Hyunsun Moon53381e82017-03-28 19:58:28 +0900236 private void addOFSwitch(NetworkId networkId, DeviceId deviceId) {
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900237 OFSwitch ofSwitch = DefaultOFSwitch.of(
238 dpidWithDeviceId(deviceId),
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400239 DEFAULT_CAPABILITIES, networkId, deviceId,
240 virtualNetService.getServiceDirectory());
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900241 ofSwitchMap.put(deviceId, ofSwitch);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900242 log.info("Added virtual OF switch for {}", deviceId);
243
244 OFAgent ofAgent = ofAgentService.agent(networkId);
Eric Tangdf833c82017-06-04 22:55:49 +0800245 if (ofAgent == null) {
246 log.error("OFAgent for network {} does not exist", networkId);
247 return;
248 }
249
Hyunsun Moon53381e82017-03-28 19:58:28 +0900250 if (ofAgent.state() == STARTED) {
251 connectController(ofSwitch, ofAgent.controllers());
252 }
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900253 }
254
255 private void deleteOFSwitch(DeviceId deviceId) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900256 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
257 ofSwitch.controllerChannels().forEach(ChannelOutboundInvoker::disconnect);
258
259 ofSwitchMap.remove(deviceId);
260 log.info("Removed virtual OFSwitch for {}", deviceId);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900261 }
262
263 private void connectController(OFSwitch ofSwitch, Set<OFController> controllers) {
264 controllers.forEach(controller -> {
265 OFConnectionHandler connectionHandler = new OFConnectionHandler(
266 ofSwitch,
267 controller,
268 ioWorker);
269 connectionHandler.connect();
270 });
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900271 }
272
273 private void disconnectController(OFSwitch ofSwitch, Set<OFController> controllers) {
274 Set<SocketAddress> controllerAddrs = controllers.stream()
Hyunsun Moon53381e82017-03-28 19:58:28 +0900275 .map(ctrl -> new InetSocketAddress(
276 ctrl.ip().toInetAddress(), ctrl.port().toInt()))
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900277 .collect(Collectors.toSet());
278
279 ofSwitch.controllerChannels().stream()
280 .filter(channel -> controllerAddrs.contains(channel.remoteAddress()))
281 .forEach(ChannelOutboundInvoker::disconnect);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900282 }
283
284 private Set<DeviceId> devices(NetworkId networkId) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900285 Set<DeviceId> deviceIds = virtualNetService.getVirtualDevices(networkId)
286 .stream()
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900287 .map(Device::id)
288 .collect(Collectors.toSet());
289 return ImmutableSet.copyOf(deviceIds);
290 }
291
292 private DatapathId dpidWithDeviceId(DeviceId deviceId) {
293 String strDeviceId = deviceId.toString().split(":")[1];
294 checkArgument(strDeviceId.length() == 16, "Invalid device ID " + strDeviceId);
295
296 String resultedHexString = "";
297 for (int i = 0; i < 8; i++) {
298 resultedHexString = resultedHexString + strDeviceId.charAt(2 * i)
299 + strDeviceId.charAt(2 * i + 1);
300 if (i != 7) {
301 resultedHexString += ":";
302 }
303 }
304 return DatapathId.of(resultedHexString);
305 }
306
307 private void processOFAgentCreated(OFAgent ofAgent) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900308 devices(ofAgent.networkId()).forEach(deviceId -> {
309 addOFSwitch(ofAgent.networkId(), deviceId);
310 });
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900311 }
312
313 private void processOFAgentRemoved(OFAgent ofAgent) {
314 devices(ofAgent.networkId()).forEach(this::deleteOFSwitch);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900315 }
316
317 private void processOFAgentStarted(OFAgent ofAgent) {
318 devices(ofAgent.networkId()).forEach(deviceId -> {
319 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
320 if (ofSwitch != null) {
321 connectController(ofSwitch, ofAgent.controllers());
322 }
323 });
324
Hyunsun Moon53381e82017-03-28 19:58:28 +0900325 DeviceService deviceService = virtualNetService.get(
326 ofAgent.networkId(),
327 DeviceService.class);
328 deviceService.addListener(deviceListener);
329
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900330 PacketService packetService = virtualNetService.get(
331 ofAgent.networkId(),
332 PacketService.class);
333 packetService.addProcessor(packetProcessor, PacketProcessor.director(0));
334
335 FlowRuleService flowRuleService = virtualNetService.get(
336 ofAgent.networkId(),
337 FlowRuleService.class);
338 flowRuleService.addListener(flowRuleListener);
339 }
340
341 private void processOFAgentStopped(OFAgent ofAgent) {
342 devices(ofAgent.networkId()).forEach(deviceId -> {
343 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
344 if (ofSwitch != null) {
345 disconnectController(ofSwitch, ofAgent.controllers());
346 }
347 });
348
Hyunsun Moon53381e82017-03-28 19:58:28 +0900349 DeviceService deviceService = virtualNetService.get(
350 ofAgent.networkId(),
351 DeviceService.class);
352 deviceService.removeListener(deviceListener);
353
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900354 PacketService packetService = virtualNetService.get(
355 ofAgent.networkId(),
356 PacketService.class);
357 packetService.removeProcessor(packetProcessor);
358
359 FlowRuleService flowRuleService = virtualNetService.get(
360 ofAgent.networkId(),
361 FlowRuleService.class);
362 flowRuleService.removeListener(flowRuleListener);
363 }
364
Hyunsun Moon53381e82017-03-28 19:58:28 +0900365 private class InternalVirtualNetworkListener implements VirtualNetworkListener {
366
367 @Override
368 public void event(VirtualNetworkEvent event) {
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400369 log.trace("Vnet event {}", event);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900370 switch (event.type()) {
371 case VIRTUAL_DEVICE_ADDED:
372 eventExecutor.execute(() -> {
373 log.debug("Virtual device {} added to network {}",
374 event.virtualDevice().id(),
375 event.subject());
376 addOFSwitch(event.subject(), event.virtualDevice().id());
377 });
378 break;
379 case VIRTUAL_DEVICE_UPDATED:
380 // TODO handle device availability updates
381 break;
382 case VIRTUAL_DEVICE_REMOVED:
383 eventExecutor.execute(() -> {
384 log.debug("Virtual device {} removed from network {}",
385 event.virtualDevice().id(),
386 event.subject());
387 deleteOFSwitch(event.virtualDevice().id());
388 });
389 break;
390 case NETWORK_UPDATED:
391 case NETWORK_REMOVED:
392 case NETWORK_ADDED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400393 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900394 case VIRTUAL_PORT_ADDED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400395 eventExecutor.execute(() -> {
396 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
397 if (ofSwitch != null) {
398 ofSwitch.processPortAdded(event.virtualPort());
399 log.debug("Virtual port {} added to network {}",
400 event.virtualPort(),
401 event.subject());
402 }
403 });
404 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900405 case VIRTUAL_PORT_UPDATED:
Claudine Chiue92efea2017-10-31 13:58:44 -0400406 eventExecutor.execute(() -> {
407 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
408 if (ofSwitch != null) {
409 if (event.virtualPort().isEnabled()) {
410 ofSwitch.processPortUp(event.virtualPort());
411 } else {
412 ofSwitch.processPortDown(event.virtualPort());
413 }
414 log.debug("Virtual port {} updated in network {}",
415 event.virtualPort(),
416 event.subject());
417 }
418 });
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400419 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900420 case VIRTUAL_PORT_REMOVED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400421 eventExecutor.execute(() -> {
422 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
423 if (ofSwitch != null) {
424 ofSwitch.processPortRemoved(event.virtualPort());
425 log.debug("Virtual port {} removed from network {}",
426 event.virtualPort(),
427 event.subject());
428 }
429 });
430 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900431 default:
432 // do nothing
433 break;
434 }
435 }
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400436
437 private OFSwitch ofSwitch(VirtualPort virtualPort) {
438 OFSwitch ofSwitch = ofSwitchMap.get(virtualPort.element().id());
439 if (ofSwitch == null) {
440 log.warn("Switch does not exist for port {}", virtualPort);
441 } else {
442 log.trace("Switch exists for port {}", virtualPort);
443 }
444 return ofSwitch;
445 }
Hyunsun Moon53381e82017-03-28 19:58:28 +0900446 }
447
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900448 private class InternalOFAgentListener implements OFAgentListener {
449
450 @Override
451 public boolean isRelevant(OFAgentEvent event) {
452 return Objects.equals(localId, leadershipService.getLeader(appId.name()));
453 }
454
455 @Override
456 public void event(OFAgentEvent event) {
457 switch (event.type()) {
458 case OFAGENT_CREATED:
459 eventExecutor.execute(() -> {
460 OFAgent ofAgent = event.subject();
461 log.debug("Processing OFAgent created: {}", ofAgent);
462 processOFAgentCreated(ofAgent);
463 });
464 break;
465 case OFAGENT_REMOVED:
466 eventExecutor.execute(() -> {
467 OFAgent ofAgent = event.subject();
468 log.debug("Processing OFAgent removed: {}", ofAgent);
469 processOFAgentRemoved(ofAgent);
470 });
471 break;
472 case OFAGENT_CONTROLLER_ADDED:
473 // TODO handle additional controller
474 break;
475 case OFAGENT_CONTROLLER_REMOVED:
476 // TODO handle removed controller
477 break;
478 case OFAGENT_STARTED:
479 eventExecutor.execute(() -> {
480 OFAgent ofAgent = event.subject();
481 log.debug("Processing OFAgent started: {}", ofAgent);
482 processOFAgentStarted(ofAgent);
483 });
484 break;
485 case OFAGENT_STOPPED:
486 eventExecutor.execute(() -> {
487 OFAgent ofAgent = event.subject();
488 log.debug("Processing OFAgent stopped: {}", ofAgent);
489 processOFAgentStopped(ofAgent);
490 });
491 break;
492 default:
493 // do nothing
494 break;
495 }
496 }
497 }
498
499 private class InternalDeviceListener implements DeviceListener {
500
501 @Override
502 public void event(DeviceEvent event) {
503 switch (event.type()) {
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900504 case DEVICE_AVAILABILITY_CHANGED:
Hyunsun Moon53381e82017-03-28 19:58:28 +0900505 case DEVICE_ADDED:
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900506 case DEVICE_UPDATED:
Hyunsun Moon53381e82017-03-28 19:58:28 +0900507 case DEVICE_REMOVED:
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900508 case DEVICE_SUSPENDED:
509 case PORT_ADDED:
510 // TODO handle event
511 case PORT_REMOVED:
512 // TODO handle event
513 case PORT_STATS_UPDATED:
514 case PORT_UPDATED:
515 default:
516 break;
517 }
518 }
519 }
520
521 private class InternalPacketProcessor implements PacketProcessor {
522
523 @Override
524 public void process(PacketContext context) {
525 // TODO handle packet-in
526 }
527 }
528
529 private class InternalFlowRuleListener implements FlowRuleListener {
530
531 @Override
532 public void event(FlowRuleEvent event) {
533 // TODO handle flow rule event
534 }
535 }
536}