Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.openflow.drivers; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 17 | |
| 18 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.openflow.controller.Dpid; |
| 20 | import org.onosproject.openflow.controller.RoleState; |
| 21 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 22 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; |
| 23 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 24 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 25 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 26 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 27 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 28 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.types.TableId; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 33 | import java.util.Collections; |
| 34 | import java.util.List; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 35 | import java.util.stream.Collectors; |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 36 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 37 | /** |
| 38 | * A simple implementation of a driver manager that differentiates between |
| 39 | * connected switches using the OF Description Statistics Reply message. |
| 40 | */ |
| 41 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
| 42 | |
| 43 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 44 | |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 45 | private static final int LOWEST_PRIORITY = 0; |
| 46 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 47 | private static Dpid corsaDpid = new Dpid(); |
| 48 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Return an IOFSwitch object based on switch's manufacturer description |
| 51 | * from OFDescStatsReply. |
| 52 | * |
| 53 | * @param desc DescriptionStatistics reply from the switch |
| 54 | * @return A IOFSwitch instance if the driver found an implementation for |
| 55 | * the given description. Otherwise it returns OFSwitchImplBase |
| 56 | */ |
| 57 | @Override |
| 58 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
| 59 | OFDescStatsReply desc, OFVersion ofv) { |
| 60 | String vendor = desc.getMfrDesc(); |
| 61 | String hw = desc.getHwDesc(); |
Jonathan Hart | 0165d19 | 2015-04-30 16:29:48 -0700 | [diff] [blame] | 62 | String sw = desc.getSwDesc(); |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 63 | |
| 64 | if (dpid.equals(corsaDpid)) { |
sangho | c0b3c34 | 2015-03-12 17:12:10 -0700 | [diff] [blame] | 65 | if (hw.startsWith("Open vSwitch")) { |
| 66 | return new OFOVSSwitchCorsaTTP(dpid, desc); |
| 67 | } else { |
| 68 | return new OFCorsaSwitchDriver(dpid, desc); |
| 69 | } |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 70 | } |
| 71 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 72 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 73 | && |
| 74 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 75 | return new OFSwitchImplSpringOpenTTP(dpid, desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 78 | //TODO: Temporary work around until the configuration based |
| 79 | // driver manager framework is ready |
| 80 | if (vendor.contains("Dell") |
| 81 | && |
| 82 | hw.contains("OpenFlow switch HW ver. 1.0")) { |
| 83 | return new OFSwitchImplSpringOpenTTPDellOSR(dpid, desc); |
| 84 | } |
| 85 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 86 | if (hw.startsWith("Open vSwitch")) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 87 | if (ofv == OFVersion.OF_10) { |
| 88 | return new OFSwitchImplOVS10(dpid, desc); |
| 89 | } else if (ofv == OFVersion.OF_13) { |
| 90 | return new OFSwitchImplOVS13(dpid, desc); |
| 91 | } |
| 92 | } |
| 93 | |
Jonathan Hart | 0165d19 | 2015-04-30 16:29:48 -0700 | [diff] [blame] | 94 | if (vendor.equals("Pica8, Inc.") && sw.startsWith("PicOS") && |
| 95 | ofv == OFVersion.OF_13) { |
| 96 | return new OFSwitchImplOVS13(dpid, desc); |
| 97 | } |
| 98 | |
| 99 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 100 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 101 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 102 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 103 | } |
| 104 | |
alshabib | 2216bdb | 2015-03-04 16:59:22 -0800 | [diff] [blame] | 105 | if (vendor.startsWith("Corsa") && hw.startsWith("Corsa Element") |
| 106 | && sw.startsWith("2.3.1")) { |
| 107 | log.warn("Corsa Switch 2.3.1 found"); |
| 108 | return new OFCorsaSwitchDriver(dpid, desc); |
| 109 | } |
| 110 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 111 | log.warn("DriverManager could not identify switch desc: {}. " |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 112 | + "Assigning AbstractOpenFlowSwich", desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 113 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 114 | |
| 115 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 116 | public void setRole(RoleState state) { |
| 117 | this.role = RoleState.MASTER; |
| 118 | } |
| 119 | |
| 120 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 121 | public void write(List<OFMessage> msgs) { |
| 122 | channel.write(msgs); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void write(OFMessage msg) { |
| 127 | channel.write(Collections.singletonList(msg)); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public Boolean supportNxRole() { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | @Override |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 137 | public void startDriverHandshake() { |
| 138 | if (factory().getVersion() == OFVersion.OF_10) { |
| 139 | OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd(); |
| 140 | fmBuilder.setPriority(LOWEST_PRIORITY); |
| 141 | write(fmBuilder.build()); |
| 142 | } |
| 143 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 144 | |
| 145 | @Override |
| 146 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 147 | |
| 148 | @Override |
| 149 | public boolean isDriverHandshakeComplete() { |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public List<OFPortDesc> getPorts() { |
| 155 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 156 | return Collections.unmodifiableList(features.getPorts()); |
| 157 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 158 | return Collections.unmodifiableList(this.ports.stream() |
| 159 | .flatMap((portReply) -> (portReply.getEntries().stream())) |
| 160 | .collect(Collectors.toList())); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 163 | |
| 164 | @Override |
| 165 | public TableType getTableType(TableId tid) { |
| 166 | return TableType.NONE; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void transformAndSendMsg(OFMessage msg, TableType tableType) { |
| 171 | // TODO Auto-generated method stub |
| 172 | |
| 173 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 174 | }; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Private constructor to avoid instantiation. |
| 179 | */ |
| 180 | private DriverManager() { |
| 181 | } |
| 182 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 183 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 184 | OFDescStatsReply desc, OFVersion ofv) { |
| 185 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 186 | } |
| 187 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 188 | public static void setCorsaDpid(Dpid dpid) { |
| 189 | corsaDpid = dpid; |
| 190 | } |
| 191 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 192 | } |