blob: dba63e22910cdb7d0d2c6f19d9e047ce4344f9b7 [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;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090022import org.onosproject.cluster.ClusterService;
23import org.onosproject.cluster.LeadershipService;
24import org.onosproject.cluster.NodeId;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.core.CoreService;
27import org.onosproject.incubator.net.virtual.NetworkId;
Hyunsun Moon53381e82017-03-28 19:58:28 +090028import org.onosproject.incubator.net.virtual.VirtualNetworkEvent;
29import org.onosproject.incubator.net.virtual.VirtualNetworkListener;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090030import org.onosproject.incubator.net.virtual.VirtualNetworkService;
Claudine Chiu785ef2d2017-07-04 13:13:28 -040031import org.onosproject.incubator.net.virtual.VirtualPort;
Claudine Chiu5c184e12017-08-08 21:21:38 -040032import org.onosproject.net.ConnectPoint;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090033import org.onosproject.net.Device;
34import org.onosproject.net.DeviceId;
Claudine Chiu5c184e12017-08-08 21:21:38 -040035import org.onosproject.net.Link;
Claudine Chiu785ef2d2017-07-04 13:13:28 -040036import org.onosproject.net.Port;
Claudine Chiu5c184e12017-08-08 21:21:38 -040037import org.onosproject.net.PortNumber;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090038import org.onosproject.net.device.DeviceEvent;
39import org.onosproject.net.device.DeviceListener;
40import org.onosproject.net.device.DeviceService;
Claudine Chiu2729ffd2017-07-31 21:38:27 -040041import org.onosproject.net.device.PortStatistics;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040042import org.onosproject.net.flow.FlowEntry;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090043import org.onosproject.net.flow.FlowRuleEvent;
44import org.onosproject.net.flow.FlowRuleListener;
45import org.onosproject.net.flow.FlowRuleService;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040046import org.onosproject.net.flow.TableStatisticsEntry;
47import org.onosproject.net.group.Group;
48import org.onosproject.net.group.GroupService;
Claudine Chiu5c184e12017-08-08 21:21:38 -040049import org.onosproject.net.link.LinkService;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090050import org.onosproject.net.packet.PacketContext;
51import org.onosproject.net.packet.PacketProcessor;
52import org.onosproject.net.packet.PacketService;
53import org.onosproject.ofagent.api.OFAgent;
54import org.onosproject.ofagent.api.OFAgentEvent;
55import org.onosproject.ofagent.api.OFAgentListener;
56import org.onosproject.ofagent.api.OFAgentService;
57import org.onosproject.ofagent.api.OFController;
58import org.onosproject.ofagent.api.OFSwitch;
59import org.onosproject.ofagent.api.OFSwitchCapabilities;
60import org.onosproject.ofagent.api.OFSwitchService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070061import org.osgi.service.component.annotations.Activate;
62import org.osgi.service.component.annotations.Component;
63import org.osgi.service.component.annotations.Deactivate;
64import org.osgi.service.component.annotations.Reference;
65import org.osgi.service.component.annotations.ReferenceCardinality;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090066import org.projectfloodlight.openflow.types.DatapathId;
67import org.slf4j.Logger;
68import org.slf4j.LoggerFactory;
69
70import java.net.InetSocketAddress;
71import java.net.SocketAddress;
Claudine Chiuce8ccc62017-08-16 10:06:20 -040072import java.util.ArrayList;
Claudine Chiu2729ffd2017-07-31 21:38:27 -040073import java.util.List;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090074import java.util.Objects;
75import java.util.Set;
76import java.util.concurrent.ConcurrentHashMap;
77import java.util.concurrent.ExecutorService;
78import java.util.stream.Collectors;
79
80import static com.google.common.base.Preconditions.checkArgument;
81import static org.onlab.util.BoundedThreadPool.newSingleThreadExecutor;
82import static org.onlab.util.Tools.groupedThreads;
Hyunsun Moon53381e82017-03-28 19:58:28 +090083import static org.onosproject.ofagent.api.OFAgent.State.STARTED;
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090084import static org.onosproject.ofagent.api.OFAgentService.APPLICATION_NAME;
85
86/**
87 * Manages OF switches.
88 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070089@Component(immediate = true, service = OFSwitchService.class)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090090public class OFSwitchManager implements OFSwitchService {
91
92 private final Logger log = LoggerFactory.getLogger(getClass());
93
Hyunsun Moon53381e82017-03-28 19:58:28 +090094 private static final OFSwitchCapabilities DEFAULT_CAPABILITIES =
95 DefaultOFSwitchCapabilities.builder()
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090096 .flowStats()
97 .tableStats()
98 .portStats()
99 .groupStats()
100 .queueStats()
101 .ipReasm()
102 .portBlocked()
103 .build();
104
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700105 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900106 protected CoreService coreService;
107
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700108 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900109 protected LeadershipService leadershipService;
110
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700111 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900112 protected ClusterService clusterService;
113
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700114 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900115 protected VirtualNetworkService virtualNetService;
116
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700117 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900118 protected OFAgentService ofAgentService;
119
120 private final ConcurrentHashMap<DeviceId, OFSwitch> ofSwitchMap = new ConcurrentHashMap<>();
121 private final ExecutorService eventExecutor = newSingleThreadExecutor(
122 groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
123 private final OFAgentListener ofAgentListener = new InternalOFAgentListener();
Hyunsun Moon53381e82017-03-28 19:58:28 +0900124 private final VirtualNetworkListener vNetworkListener = new InternalVirtualNetworkListener();
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900125 private final DeviceListener deviceListener = new InternalDeviceListener();
126 private final FlowRuleListener flowRuleListener = new InternalFlowRuleListener();
127 private final PacketProcessor packetProcessor = new InternalPacketProcessor();
128
129 private NioEventLoopGroup ioWorker;
130 private ApplicationId appId;
131 private NodeId localId;
132
133 @Activate
134 protected void activate() {
135 appId = coreService.registerApplication(APPLICATION_NAME);
136 localId = clusterService.getLocalNode().id();
137 ioWorker = new NioEventLoopGroup();
Hyunsun Moon53381e82017-03-28 19:58:28 +0900138
139 ofAgentService.agents().forEach(this::processOFAgentCreated);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900140 ofAgentService.addListener(ofAgentListener);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900141 virtualNetService.addListener(vNetworkListener);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900142
143 log.info("Started");
144 }
145
146 @Deactivate
147 protected void deactivate() {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900148 virtualNetService.removeListener(vNetworkListener);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900149 ofAgentService.removeListener(ofAgentListener);
150 ofAgentService.agents().forEach(this::processOFAgentStopped);
151
152 ioWorker.shutdownGracefully();
153 eventExecutor.shutdown();
154
155 log.info("Stopped");
156 }
157
158 @Override
159 public Set<OFSwitch> ofSwitches() {
160 return ImmutableSet.copyOf(ofSwitchMap.values());
161 }
162
163 @Override
164 public Set<OFSwitch> ofSwitches(NetworkId networkId) {
165 Set<OFSwitch> ofSwitches = devices(networkId).stream()
166 .map(ofSwitchMap::get)
167 .filter(Objects::nonNull)
168 .collect(Collectors.toSet());
169 return ImmutableSet.copyOf(ofSwitches);
170 }
171
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400172 @Override
Claudine Chiu2729ffd2017-07-31 21:38:27 -0400173 public OFSwitch ofSwitch(NetworkId networkId, DeviceId deviceId) {
174 return ofSwitchMap.get(deviceId);
175 }
176
177 @Override
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400178 public Set<Port> ports(NetworkId networkId, DeviceId deviceId) {
179 Set<Port> ports = virtualNetService.getVirtualPorts(networkId, deviceId)
180 .stream()
181 .collect(Collectors.toSet());
182 return ImmutableSet.copyOf(ports);
183 }
184
Claudine Chiu2729ffd2017-07-31 21:38:27 -0400185 @Override
186 public List<PortStatistics> getPortStatistics(NetworkId networkId, DeviceId deviceId) {
187 DeviceService deviceService = virtualNetService.get(networkId, DeviceService.class);
188 List<PortStatistics> portStatistics = deviceService.getPortStatistics(deviceId);
189 return portStatistics;
190 }
191
Claudine Chiu5c184e12017-08-08 21:21:38 -0400192 @Override
193 public ConnectPoint neighbour(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
194 ConnectPoint cp = new ConnectPoint(deviceId, portNumber);
195 LinkService linkService = virtualNetService.get(networkId, LinkService.class);
196 Set<Link> links = linkService.getEgressLinks(cp);
197 log.trace("neighbour cp {} egressLinks {}", cp, links);
198 if (links != null && links.size() > 0) {
199 Link link = links.iterator().next();
200 return link.src();
201 }
202 return null;
203 }
204
Claudine Chiuce8ccc62017-08-16 10:06:20 -0400205 @Override
Claudine Chiub211b872017-09-05 17:27:00 -0400206 public ApplicationId appId() {
207 return appId;
208 }
209
210 @Override
Claudine Chiuce8ccc62017-08-16 10:06:20 -0400211 public List<FlowEntry> getFlowEntries(NetworkId networkId, DeviceId deviceId) {
212 FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
213 Iterable<FlowEntry> entries = flowRuleService.getFlowEntries(deviceId);
214 return Lists.newArrayList(entries);
215 }
216
217 @Override
218 public List<TableStatisticsEntry> getFlowTableStatistics(NetworkId networkId, DeviceId deviceId) {
219 FlowRuleService flowRuleService = virtualNetService.get(networkId, FlowRuleService.class);
220 Iterable<TableStatisticsEntry> entries = flowRuleService.getFlowTableStatistics(deviceId);
221 if (entries == null) {
222 entries = new ArrayList<>();
223 }
224 return Lists.newArrayList(entries);
225 }
226
227 @Override
228 public List<Group> getGroups(NetworkId networkId, DeviceId deviceId) {
229 GroupService groupService = virtualNetService.get(networkId, GroupService.class);
230 Iterable<Group> entries = groupService.getGroups(deviceId);
231 return Lists.newArrayList(entries);
232 }
233
Hyunsun Moon53381e82017-03-28 19:58:28 +0900234 private void addOFSwitch(NetworkId networkId, DeviceId deviceId) {
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900235 OFSwitch ofSwitch = DefaultOFSwitch.of(
236 dpidWithDeviceId(deviceId),
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400237 DEFAULT_CAPABILITIES, networkId, deviceId,
238 virtualNetService.getServiceDirectory());
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900239 ofSwitchMap.put(deviceId, ofSwitch);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900240 log.info("Added virtual OF switch for {}", deviceId);
241
242 OFAgent ofAgent = ofAgentService.agent(networkId);
Eric Tangdf833c82017-06-04 22:55:49 +0800243 if (ofAgent == null) {
244 log.error("OFAgent for network {} does not exist", networkId);
245 return;
246 }
247
Hyunsun Moon53381e82017-03-28 19:58:28 +0900248 if (ofAgent.state() == STARTED) {
249 connectController(ofSwitch, ofAgent.controllers());
250 }
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900251 }
252
253 private void deleteOFSwitch(DeviceId deviceId) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900254 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
255 ofSwitch.controllerChannels().forEach(ChannelOutboundInvoker::disconnect);
256
257 ofSwitchMap.remove(deviceId);
258 log.info("Removed virtual OFSwitch for {}", deviceId);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900259 }
260
261 private void connectController(OFSwitch ofSwitch, Set<OFController> controllers) {
262 controllers.forEach(controller -> {
263 OFConnectionHandler connectionHandler = new OFConnectionHandler(
264 ofSwitch,
265 controller,
266 ioWorker);
267 connectionHandler.connect();
268 });
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900269 }
270
271 private void disconnectController(OFSwitch ofSwitch, Set<OFController> controllers) {
272 Set<SocketAddress> controllerAddrs = controllers.stream()
Hyunsun Moon53381e82017-03-28 19:58:28 +0900273 .map(ctrl -> new InetSocketAddress(
274 ctrl.ip().toInetAddress(), ctrl.port().toInt()))
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900275 .collect(Collectors.toSet());
276
277 ofSwitch.controllerChannels().stream()
278 .filter(channel -> controllerAddrs.contains(channel.remoteAddress()))
279 .forEach(ChannelOutboundInvoker::disconnect);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900280 }
281
282 private Set<DeviceId> devices(NetworkId networkId) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900283 Set<DeviceId> deviceIds = virtualNetService.getVirtualDevices(networkId)
284 .stream()
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900285 .map(Device::id)
286 .collect(Collectors.toSet());
287 return ImmutableSet.copyOf(deviceIds);
288 }
289
290 private DatapathId dpidWithDeviceId(DeviceId deviceId) {
291 String strDeviceId = deviceId.toString().split(":")[1];
292 checkArgument(strDeviceId.length() == 16, "Invalid device ID " + strDeviceId);
293
294 String resultedHexString = "";
295 for (int i = 0; i < 8; i++) {
296 resultedHexString = resultedHexString + strDeviceId.charAt(2 * i)
297 + strDeviceId.charAt(2 * i + 1);
298 if (i != 7) {
299 resultedHexString += ":";
300 }
301 }
302 return DatapathId.of(resultedHexString);
303 }
304
305 private void processOFAgentCreated(OFAgent ofAgent) {
Hyunsun Moon53381e82017-03-28 19:58:28 +0900306 devices(ofAgent.networkId()).forEach(deviceId -> {
307 addOFSwitch(ofAgent.networkId(), deviceId);
308 });
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900309 }
310
311 private void processOFAgentRemoved(OFAgent ofAgent) {
312 devices(ofAgent.networkId()).forEach(this::deleteOFSwitch);
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900313 }
314
315 private void processOFAgentStarted(OFAgent ofAgent) {
316 devices(ofAgent.networkId()).forEach(deviceId -> {
317 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
318 if (ofSwitch != null) {
319 connectController(ofSwitch, ofAgent.controllers());
320 }
321 });
322
Hyunsun Moon53381e82017-03-28 19:58:28 +0900323 DeviceService deviceService = virtualNetService.get(
324 ofAgent.networkId(),
325 DeviceService.class);
326 deviceService.addListener(deviceListener);
327
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900328 PacketService packetService = virtualNetService.get(
329 ofAgent.networkId(),
330 PacketService.class);
331 packetService.addProcessor(packetProcessor, PacketProcessor.director(0));
332
333 FlowRuleService flowRuleService = virtualNetService.get(
334 ofAgent.networkId(),
335 FlowRuleService.class);
336 flowRuleService.addListener(flowRuleListener);
337 }
338
339 private void processOFAgentStopped(OFAgent ofAgent) {
340 devices(ofAgent.networkId()).forEach(deviceId -> {
341 OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
342 if (ofSwitch != null) {
343 disconnectController(ofSwitch, ofAgent.controllers());
344 }
345 });
346
Hyunsun Moon53381e82017-03-28 19:58:28 +0900347 DeviceService deviceService = virtualNetService.get(
348 ofAgent.networkId(),
349 DeviceService.class);
350 deviceService.removeListener(deviceListener);
351
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900352 PacketService packetService = virtualNetService.get(
353 ofAgent.networkId(),
354 PacketService.class);
355 packetService.removeProcessor(packetProcessor);
356
357 FlowRuleService flowRuleService = virtualNetService.get(
358 ofAgent.networkId(),
359 FlowRuleService.class);
360 flowRuleService.removeListener(flowRuleListener);
361 }
362
Hyunsun Moon53381e82017-03-28 19:58:28 +0900363 private class InternalVirtualNetworkListener implements VirtualNetworkListener {
364
365 @Override
366 public void event(VirtualNetworkEvent event) {
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400367 log.trace("Vnet event {}", event);
Hyunsun Moon53381e82017-03-28 19:58:28 +0900368 switch (event.type()) {
369 case VIRTUAL_DEVICE_ADDED:
370 eventExecutor.execute(() -> {
371 log.debug("Virtual device {} added to network {}",
372 event.virtualDevice().id(),
373 event.subject());
374 addOFSwitch(event.subject(), event.virtualDevice().id());
375 });
376 break;
377 case VIRTUAL_DEVICE_UPDATED:
378 // TODO handle device availability updates
379 break;
380 case VIRTUAL_DEVICE_REMOVED:
381 eventExecutor.execute(() -> {
382 log.debug("Virtual device {} removed from network {}",
383 event.virtualDevice().id(),
384 event.subject());
385 deleteOFSwitch(event.virtualDevice().id());
386 });
387 break;
388 case NETWORK_UPDATED:
389 case NETWORK_REMOVED:
390 case NETWORK_ADDED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400391 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900392 case VIRTUAL_PORT_ADDED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400393 eventExecutor.execute(() -> {
394 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
395 if (ofSwitch != null) {
396 ofSwitch.processPortAdded(event.virtualPort());
397 log.debug("Virtual port {} added to network {}",
398 event.virtualPort(),
399 event.subject());
400 }
401 });
402 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900403 case VIRTUAL_PORT_UPDATED:
Claudine Chiue92efea2017-10-31 13:58:44 -0400404 eventExecutor.execute(() -> {
405 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
406 if (ofSwitch != null) {
407 if (event.virtualPort().isEnabled()) {
408 ofSwitch.processPortUp(event.virtualPort());
409 } else {
410 ofSwitch.processPortDown(event.virtualPort());
411 }
412 log.debug("Virtual port {} updated in network {}",
413 event.virtualPort(),
414 event.subject());
415 }
416 });
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400417 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900418 case VIRTUAL_PORT_REMOVED:
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400419 eventExecutor.execute(() -> {
420 OFSwitch ofSwitch = ofSwitch(event.virtualPort());
421 if (ofSwitch != null) {
422 ofSwitch.processPortRemoved(event.virtualPort());
423 log.debug("Virtual port {} removed from network {}",
424 event.virtualPort(),
425 event.subject());
426 }
427 });
428 break;
Hyunsun Moon53381e82017-03-28 19:58:28 +0900429 default:
430 // do nothing
431 break;
432 }
433 }
Claudine Chiu785ef2d2017-07-04 13:13:28 -0400434
435 private OFSwitch ofSwitch(VirtualPort virtualPort) {
436 OFSwitch ofSwitch = ofSwitchMap.get(virtualPort.element().id());
437 if (ofSwitch == null) {
438 log.warn("Switch does not exist for port {}", virtualPort);
439 } else {
440 log.trace("Switch exists for port {}", virtualPort);
441 }
442 return ofSwitch;
443 }
Hyunsun Moon53381e82017-03-28 19:58:28 +0900444 }
445
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900446 private class InternalOFAgentListener implements OFAgentListener {
447
448 @Override
449 public boolean isRelevant(OFAgentEvent event) {
450 return Objects.equals(localId, leadershipService.getLeader(appId.name()));
451 }
452
453 @Override
454 public void event(OFAgentEvent event) {
455 switch (event.type()) {
456 case OFAGENT_CREATED:
457 eventExecutor.execute(() -> {
458 OFAgent ofAgent = event.subject();
459 log.debug("Processing OFAgent created: {}", ofAgent);
460 processOFAgentCreated(ofAgent);
461 });
462 break;
463 case OFAGENT_REMOVED:
464 eventExecutor.execute(() -> {
465 OFAgent ofAgent = event.subject();
466 log.debug("Processing OFAgent removed: {}", ofAgent);
467 processOFAgentRemoved(ofAgent);
468 });
469 break;
470 case OFAGENT_CONTROLLER_ADDED:
471 // TODO handle additional controller
472 break;
473 case OFAGENT_CONTROLLER_REMOVED:
474 // TODO handle removed controller
475 break;
476 case OFAGENT_STARTED:
477 eventExecutor.execute(() -> {
478 OFAgent ofAgent = event.subject();
479 log.debug("Processing OFAgent started: {}", ofAgent);
480 processOFAgentStarted(ofAgent);
481 });
482 break;
483 case OFAGENT_STOPPED:
484 eventExecutor.execute(() -> {
485 OFAgent ofAgent = event.subject();
486 log.debug("Processing OFAgent stopped: {}", ofAgent);
487 processOFAgentStopped(ofAgent);
488 });
489 break;
490 default:
491 // do nothing
492 break;
493 }
494 }
495 }
496
497 private class InternalDeviceListener implements DeviceListener {
498
499 @Override
500 public void event(DeviceEvent event) {
501 switch (event.type()) {
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900502 case DEVICE_AVAILABILITY_CHANGED:
Hyunsun Moon53381e82017-03-28 19:58:28 +0900503 case DEVICE_ADDED:
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900504 case DEVICE_UPDATED:
Hyunsun Moon53381e82017-03-28 19:58:28 +0900505 case DEVICE_REMOVED:
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +0900506 case DEVICE_SUSPENDED:
507 case PORT_ADDED:
508 // TODO handle event
509 case PORT_REMOVED:
510 // TODO handle event
511 case PORT_STATS_UPDATED:
512 case PORT_UPDATED:
513 default:
514 break;
515 }
516 }
517 }
518
519 private class InternalPacketProcessor implements PacketProcessor {
520
521 @Override
522 public void process(PacketContext context) {
523 // TODO handle packet-in
524 }
525 }
526
527 private class InternalFlowRuleListener implements FlowRuleListener {
528
529 @Override
530 public void event(FlowRuleEvent event) {
531 // TODO handle flow rule event
532 }
533 }
534}