blob: 6a6ba065f31fc9d54fa3b249f155f4a4a84a3018 [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.onosproject.incubator.net.virtual.NetworkId;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.device.DeviceEvent;
22import org.onosproject.net.device.DeviceListener;
23import org.onosproject.net.flow.FlowRuleEvent;
24import org.onosproject.net.flow.FlowRuleListener;
25import org.onosproject.net.packet.PacketContext;
26import org.onosproject.net.packet.PacketProcessor;
27import org.onosproject.ofagent.api.OFAgent;
28import org.onosproject.ofagent.api.OFController;
29import org.onosproject.ofagent.api.OFSwitch;
30
31import java.util.Map;
32import java.util.Set;
33import java.util.concurrent.ConcurrentHashMap;
34import java.util.concurrent.ExecutorService;
35
36/**
37 * Implementation of OF agent.
38 */
39public final class DefaultOFAgent implements OFAgent {
40
41 private final NetworkId networkId;
42 private final Map<Class<?>, Object> services;
43 private final Set<OFController> controllers;
44 private final ExecutorService eventExecutor;
45 private final NioEventLoopGroup ioWorker;
46
47 private final ConcurrentHashMap<DeviceId, OFSwitch> switchMap = new ConcurrentHashMap<>();
48 private final DeviceListener deviceListener = new InternalDeviceListener();
49 private final FlowRuleListener flowRuleListener = new InternalFlowRuleListener();
50 private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
51
52 private DefaultOFAgent(NetworkId networkId,
53 Map<Class<?>, Object> services,
54 Set<OFController> controllers,
55 ExecutorService eventExecutor,
56 NioEventLoopGroup ioWorker) {
57 this.networkId = networkId;
58 this.services = services;
59 this.controllers = controllers;
60 this.eventExecutor = eventExecutor;
61 this.ioWorker = ioWorker;
62 }
63
64 @Override
65 public NetworkId networkId() {
66 return null;
67 }
68
69 @Override
70 public Set<OFController> controllers() {
71 return null;
72 }
73
74 @Override
75 public void start() {
76 // TODO add listeners to the services
77 // TODO connect all virtual devices in this network to the controllers
78 }
79
80 @Override
81 public void stop() {
82 // TODO remove listeners from the services
83 // TODO disconnect all active connections
84 }
85
86 private void connect(OFSwitch ofSwitch, OFController controller) {
87 // TODO connect the switch to the controller
88 }
89
90 private void disconnect(OFSwitch ofSwitch, OFController controller) {
91 // TODO disconnect the controller from the ofSwitch
92 }
93
94 private class InternalFlowRuleListener implements FlowRuleListener {
95
96 @Override
97 public void event(FlowRuleEvent event) {
98 // TODO handle flow rule event
99 }
100 }
101
102 private class InternalDeviceListener implements DeviceListener {
103
104 @Override
105 public void event(DeviceEvent event) {
106 // TODO handle device event
107 // device detected: connect the device to controllers
108 // device removed: disconnect and remove the switch from the map
109 // device state available: connect the switch to the controllers
110 // device state unavailable: disconnect the switch from the controllers
111 // port added: send out features reply
112 // port status change
113 }
114 }
115
116 private class InternalPacketProcessor implements PacketProcessor {
117
118 @Override
119 public void process(PacketContext context) {
120 // TODO handle packet-in
121 }
122 }
123
124 // TODO implement builder
125}