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 | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 62 | |
| 63 | if (dpid.equals(corsaDpid)) { |
sangho | c0b3c34 | 2015-03-12 17:12:10 -0700 | [diff] [blame] | 64 | if (hw.startsWith("Open vSwitch")) { |
| 65 | return new OFOVSSwitchCorsaTTP(dpid, desc); |
| 66 | } else { |
| 67 | return new OFCorsaSwitchDriver(dpid, desc); |
| 68 | } |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 69 | } |
| 70 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 71 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 72 | && |
| 73 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 74 | return new OFSwitchImplSpringOpenTTP(dpid, desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 77 | //TODO: Temporary work around until the configuration based |
| 78 | // driver manager framework is ready |
| 79 | if (vendor.contains("Dell") |
| 80 | && |
| 81 | hw.contains("OpenFlow switch HW ver. 1.0")) { |
| 82 | return new OFSwitchImplSpringOpenTTPDellOSR(dpid, desc); |
| 83 | } |
| 84 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 85 | if (hw.startsWith("Open vSwitch")) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 86 | if (ofv == OFVersion.OF_10) { |
| 87 | return new OFSwitchImplOVS10(dpid, desc); |
| 88 | } else if (ofv == OFVersion.OF_13) { |
| 89 | return new OFSwitchImplOVS13(dpid, desc); |
| 90 | } |
| 91 | } |
| 92 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 93 | String sw = desc.getSwDesc(); |
| 94 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 95 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 96 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 97 | } |
| 98 | |
alshabib | 2216bdb | 2015-03-04 16:59:22 -0800 | [diff] [blame] | 99 | if (vendor.startsWith("Corsa") && hw.startsWith("Corsa Element") |
| 100 | && sw.startsWith("2.3.1")) { |
| 101 | log.warn("Corsa Switch 2.3.1 found"); |
| 102 | return new OFCorsaSwitchDriver(dpid, desc); |
| 103 | } |
| 104 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 105 | log.warn("DriverManager could not identify switch desc: {}. " |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 106 | + "Assigning AbstractOpenFlowSwich", desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 107 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 108 | |
| 109 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 110 | public void setRole(RoleState state) { |
| 111 | this.role = RoleState.MASTER; |
| 112 | } |
| 113 | |
| 114 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 115 | public void write(List<OFMessage> msgs) { |
| 116 | channel.write(msgs); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void write(OFMessage msg) { |
| 121 | channel.write(Collections.singletonList(msg)); |
| 122 | |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public Boolean supportNxRole() { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | @Override |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 131 | public void startDriverHandshake() { |
| 132 | if (factory().getVersion() == OFVersion.OF_10) { |
| 133 | OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd(); |
| 134 | fmBuilder.setPriority(LOWEST_PRIORITY); |
| 135 | write(fmBuilder.build()); |
| 136 | } |
| 137 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 138 | |
| 139 | @Override |
| 140 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 141 | |
| 142 | @Override |
| 143 | public boolean isDriverHandshakeComplete() { |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public List<OFPortDesc> getPorts() { |
| 149 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 150 | return Collections.unmodifiableList(features.getPorts()); |
| 151 | } else { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame^] | 152 | return Collections.unmodifiableList(this.ports.stream() |
| 153 | .flatMap((portReply) -> (portReply.getEntries().stream())) |
| 154 | .collect(Collectors.toList())); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 155 | } |
| 156 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 157 | |
| 158 | @Override |
| 159 | public TableType getTableType(TableId tid) { |
| 160 | return TableType.NONE; |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void transformAndSendMsg(OFMessage msg, TableType tableType) { |
| 165 | // TODO Auto-generated method stub |
| 166 | |
| 167 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 168 | }; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Private constructor to avoid instantiation. |
| 173 | */ |
| 174 | private DriverManager() { |
| 175 | } |
| 176 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 177 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 178 | OFDescStatsReply desc, OFVersion ofv) { |
| 179 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 180 | } |
| 181 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 182 | public static void setCorsaDpid(Dpid dpid) { |
| 183 | corsaDpid = dpid; |
| 184 | } |
| 185 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 186 | } |