Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 19 | package org.onlab.onos.openflow.drivers.impl; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 20 | |
| 21 | |
| 22 | |
| 23 | import java.util.Collections; |
| 24 | import java.util.List; |
| 25 | |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 26 | import org.onlab.onos.openflow.controller.Dpid; |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 27 | import org.onlab.onos.openflow.controller.RoleState; |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 28 | import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 29 | import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver; |
| 30 | import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriverFactory; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 31 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 32 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 33 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 34 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
| 38 | /** |
| 39 | * A simple implementation of a driver manager that differentiates between |
| 40 | * connected switches using the OF Description Statistics Reply message. |
| 41 | */ |
| 42 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
| 43 | |
| 44 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 45 | |
| 46 | // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style |
| 47 | // single table with packet-ins. |
| 48 | private static boolean cpqdUsePipeline13 = false; |
| 49 | |
| 50 | /** |
| 51 | * Return an IOFSwitch object based on switch's manufacturer description |
| 52 | * from OFDescStatsReply. |
| 53 | * |
| 54 | * @param desc DescriptionStatistics reply from the switch |
| 55 | * @return A IOFSwitch instance if the driver found an implementation for |
| 56 | * the given description. Otherwise it returns OFSwitchImplBase |
| 57 | */ |
| 58 | @Override |
| 59 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
| 60 | OFDescStatsReply desc, OFVersion ofv) { |
| 61 | String vendor = desc.getMfrDesc(); |
| 62 | String hw = desc.getHwDesc(); |
| 63 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 64 | && |
| 65 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
| 66 | return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13); |
| 67 | } |
| 68 | |
| 69 | if (vendor.startsWith("Nicira") && |
| 70 | hw.startsWith("Open vSwitch")) { |
| 71 | if (ofv == OFVersion.OF_10) { |
| 72 | return new OFSwitchImplOVS10(dpid, desc); |
| 73 | } else if (ofv == OFVersion.OF_13) { |
| 74 | return new OFSwitchImplOVS13(dpid, desc); |
| 75 | } |
| 76 | } |
| 77 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 78 | String sw = desc.getSwDesc(); |
| 79 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 80 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 81 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 82 | } |
| 83 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 84 | log.warn("DriverManager could not identify switch desc: {}. " |
| 85 | + "Assigning AbstractOpenFlowSwich", desc); |
| 86 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 87 | |
| 88 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 89 | public void setRole(RoleState state) { |
| 90 | this.role = RoleState.MASTER; |
| 91 | } |
| 92 | |
| 93 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 94 | public void write(List<OFMessage> msgs) { |
| 95 | channel.write(msgs); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void write(OFMessage msg) { |
| 100 | channel.write(Collections.singletonList(msg)); |
| 101 | |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Boolean supportNxRole() { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void startDriverHandshake() {} |
| 111 | |
| 112 | @Override |
| 113 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 114 | |
| 115 | @Override |
| 116 | public boolean isDriverHandshakeComplete() { |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public List<OFPortDesc> getPorts() { |
| 122 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 123 | return Collections.unmodifiableList(features.getPorts()); |
| 124 | } else { |
| 125 | return Collections.unmodifiableList(ports.getEntries()); |
| 126 | } |
| 127 | } |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Private constructor to avoid instantiation. |
| 133 | */ |
| 134 | private DriverManager() { |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Sets the configuration parameter which determines how the CPqD switch |
| 139 | * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on |
| 140 | * the switch. Otherwise, the switch will be set up in a 1.0 style with |
| 141 | * a single table where missed packets are sent to the controller. |
| 142 | * |
| 143 | * @param usePipeline13 whether to use a 1.3 pipeline or not |
| 144 | */ |
| 145 | public static void setConfigForCpqd(boolean usePipeline13) { |
| 146 | cpqdUsePipeline13 = usePipeline13; |
| 147 | } |
| 148 | |
| 149 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 150 | OFDescStatsReply desc, OFVersion ofv) { |
| 151 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 152 | } |
| 153 | |
| 154 | } |