Hyunsun Moon | 90163ba | 2016-10-12 13:35:14 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ofagent.impl; |
| 17 | |
| 18 | import io.netty.channel.nio.NioEventLoopGroup; |
| 19 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.device.DeviceEvent; |
| 22 | import org.onosproject.net.device.DeviceListener; |
| 23 | import org.onosproject.net.flow.FlowRuleEvent; |
| 24 | import org.onosproject.net.flow.FlowRuleListener; |
| 25 | import org.onosproject.net.packet.PacketContext; |
| 26 | import org.onosproject.net.packet.PacketProcessor; |
| 27 | import org.onosproject.ofagent.api.OFAgent; |
| 28 | import org.onosproject.ofagent.api.OFController; |
| 29 | import org.onosproject.ofagent.api.OFSwitch; |
| 30 | |
| 31 | import java.util.Map; |
| 32 | import java.util.Set; |
| 33 | import java.util.concurrent.ConcurrentHashMap; |
| 34 | import java.util.concurrent.ExecutorService; |
| 35 | |
| 36 | /** |
| 37 | * Implementation of OF agent. |
| 38 | */ |
| 39 | public 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 | } |