| /* |
| * Copyright 2017-present Open Networking Laboratory |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.onosproject.ofagent.impl; |
| |
| import io.netty.channel.Channel; |
| import org.onosproject.net.Device; |
| import org.onosproject.net.Port; |
| import org.onosproject.net.flow.FlowRule; |
| import org.onosproject.net.packet.InboundPacket; |
| import org.onosproject.ofagent.api.OFSwitch; |
| import org.onosproject.ofagent.api.OFSwitchCapabilities; |
| import org.projectfloodlight.openflow.protocol.OFControllerRole; |
| import org.projectfloodlight.openflow.protocol.OFMessage; |
| |
| import java.util.Set; |
| import java.util.concurrent.ConcurrentHashMap; |
| |
| import static com.google.common.base.Preconditions.checkArgument; |
| import static com.google.common.base.Preconditions.checkNotNull; |
| import static org.projectfloodlight.openflow.protocol.OFControllerRole.*; |
| |
| /** |
| * Implementation of OF switch. |
| */ |
| public final class DefaultOFSwitch implements OFSwitch { |
| |
| private static final String ERR_CH_DUPLICATE = "Channel already exists: "; |
| private static final String ERR_CH_NOT_FOUND = "Channel not found: "; |
| |
| private final Device device; |
| private final OFSwitchCapabilities capabilities; |
| |
| private final ConcurrentHashMap<Channel, OFControllerRole> controllerRoleMap |
| = new ConcurrentHashMap<>(); |
| |
| private DefaultOFSwitch(Device device, OFSwitchCapabilities capabilities) { |
| this.device = device; |
| this.capabilities = capabilities; |
| } |
| |
| // TODO add builder |
| |
| @Override |
| public Device device() { |
| return null; |
| } |
| |
| @Override |
| public OFSwitchCapabilities capabilities() { |
| return null; |
| } |
| |
| @Override |
| public boolean isConnected() { |
| return false; |
| } |
| |
| @Override |
| public void started() { |
| // TODO do some initial setups |
| } |
| |
| @Override |
| public void stopped() { |
| // TODO implement |
| } |
| |
| @Override |
| public void addControllerChannel(Channel channel) { |
| controllerRoleMap.compute(channel, (ch, existing) -> { |
| final String error = ERR_CH_DUPLICATE + channel.remoteAddress(); |
| checkArgument(existing == null, error); |
| return ROLE_EQUAL; |
| }); |
| } |
| |
| @Override |
| public void deleteControllerChannel(Channel channel) { |
| if (controllerRoleMap.remove(channel) == null) { |
| final String error = ERR_CH_NOT_FOUND + channel.remoteAddress(); |
| throw new IllegalStateException(error); |
| } |
| } |
| |
| @Override |
| public void setRole(Channel channel, OFControllerRole role) { |
| controllerRoleMap.compute(channel, (ch, existing) -> { |
| final String error = ERR_CH_NOT_FOUND + channel.remoteAddress(); |
| checkNotNull(existing, error); |
| return role; |
| }); |
| } |
| |
| @Override |
| public OFControllerRole role(Channel channel) { |
| OFControllerRole role = controllerRoleMap.get(channel); |
| if (role == null) { |
| final String error = ERR_CH_NOT_FOUND + channel.remoteAddress(); |
| throw new IllegalStateException(error); |
| } |
| return role; |
| } |
| |
| @Override |
| public Set<Channel> controllerChannels() { |
| return null; |
| } |
| |
| @Override |
| public void processPortAdded(Port port) { |
| // TODO generate FEATURES_REPLY message and send it to the controller |
| } |
| |
| @Override |
| public void processPortDown(Port port) { |
| // TODO generate PORT_STATUS message and send it to the controller |
| } |
| |
| @Override |
| public void processPortUp(Port port) { |
| // TODO generate PORT_STATUS message and send it to the controller |
| } |
| |
| @Override |
| public void processFlowRemoved(FlowRule flowRule) { |
| // TODO generate FLOW_REMOVED message and send it to the controller |
| } |
| |
| @Override |
| public void processPacketIn(InboundPacket packet) { |
| // TODO generate PACKET_IN message and send it to the controller |
| } |
| |
| @Override |
| public void processControllerCommand(Channel channel, OFMessage msg) { |
| // TODO process controller command |
| } |
| |
| @Override |
| public void processStatsRequest(Channel channel, OFMessage msg) { |
| // TODO process request and send reply |
| } |
| |
| @Override |
| public void processRoleRequest(Channel channel, OFMessage msg) { |
| // TODO process role request and send reply |
| } |
| |
| @Override |
| public void processFeaturesRequest(Channel channel, OFMessage msg) { |
| // TODO process features request and send reply |
| } |
| |
| @Override |
| public void processLldp(Channel channel, OFMessage msg) { |
| // TODO process lldp |
| } |
| } |