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