blob: 3005f736faa453d707fcd407ab26af606dfb249a [file] [log] [blame]
Hyunsun Moon90163ba2016-10-12 13:35:14 -07001/*
2 * Copyright 2017-present 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.ofagent.impl;
17
18import io.netty.channel.nio.NioEventLoopGroup;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Service;
23import org.onosproject.incubator.net.virtual.NetworkId;
24import org.onosproject.incubator.net.virtual.VirtualNetworkEvent;
25import org.onosproject.incubator.net.virtual.VirtualNetworkListener;
26import org.onosproject.ofagent.api.OFAgent;
27import org.onosproject.ofagent.api.OFAgentService;
28import org.onosproject.ofagent.api.OFController;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.Set;
33import java.util.concurrent.ConcurrentHashMap;
34import java.util.concurrent.ExecutorService;
35
36import static org.onlab.util.BoundedThreadPool.newFixedThreadPool;
37import static org.onlab.util.Tools.groupedThreads;
38
39/**
40 * Implementation of OpenFlow agent service.
41 */
42@Component(immediate = true)
43@Service
44public class OFAgentManager implements OFAgentService {
45
46 private final Logger log = LoggerFactory.getLogger(getClass());
47
48 // TODO make it to be configurable with component config
49 private static final int NUM_OF_THREADS = 1;
50 private final ExecutorService eventExecutor = newFixedThreadPool(
51 NUM_OF_THREADS,
52 groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
53
54 // TODO change it to ConsistentMap and support multi-instance mode
55 private ConcurrentHashMap<NetworkId, OFAgent> agentMap = new ConcurrentHashMap<>();
56 private NioEventLoopGroup ioWorker;
57
58 @Activate
59 protected void activate() {
60 // TODO listen to the virtual network event
61 ioWorker = new NioEventLoopGroup();
62 log.info("Started");
63 }
64
65 @Deactivate
66 protected void deactivate() {
67 ioWorker.shutdownGracefully();
68 eventExecutor.shutdown();
69 log.info("Stopped");
70 }
71
72 @Override
73 public Set<OFAgent> agents() {
74 // TODO return existing agents
75 return null;
76 }
77
78 @Override
79 public void createAgent(NetworkId networkId, OFController... controllers) {
80 // TODO create OFAgent instance with the given network ID, controllers
81 // TODO and device, flowRule, link, and packet service for the virtual network
82 // TODO start the OFAgent only if the virtual network state is active
83 }
84
85 @Override
86 public void removeAgent(NetworkId networkId) {
87 // TODO stop and remove the OFAgent for the network
88 }
89
90 @Override
91 public void startAgent(NetworkId networkId) {
92 // TODO starts the agent for the network
93 }
94
95 @Override
96 public void stopAgent(NetworkId networkId) {
97 // TODO stops the agent for the network
98 }
99
100 @Override
101 public boolean isActive(NetworkId networkId) {
102 // TODO manage the OF agent status
103 return false;
104 }
105
106 private class InternalVirtualNetworkListener implements VirtualNetworkListener {
107
108 @Override
109 public void event(VirtualNetworkEvent event) {
110 // TODO handle virtual network start and stop
111 }
112 }
113}