blob: 1560d4486e64ad19988d3941ed38d4f502d30431 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.openflow.drivers;
tom7ef8ff92014-09-17 13:08:06 -070017
18
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.openflow.controller.Dpid;
20import org.onosproject.openflow.controller.RoleState;
21import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
22import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
23import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory;
tom7ef8ff92014-09-17 13:08:06 -070024import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
Jonathan Hart2ffcd102015-01-16 16:47:50 -080025import org.projectfloodlight.openflow.protocol.OFFlowAdd;
tom7ef8ff92014-09-17 13:08:06 -070026import org.projectfloodlight.openflow.protocol.OFMessage;
27import org.projectfloodlight.openflow.protocol.OFPortDesc;
28import org.projectfloodlight.openflow.protocol.OFVersion;
Saurav Dasfa2fa932015-03-03 11:29:48 -080029import org.projectfloodlight.openflow.types.TableId;
tom7ef8ff92014-09-17 13:08:06 -070030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
Jonathan Hartbbd91d42015-02-27 11:18:04 -080033import java.util.Collections;
34import java.util.List;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070035import java.util.stream.Collectors;
Jonathan Hartbbd91d42015-02-27 11:18:04 -080036
tom7ef8ff92014-09-17 13:08:06 -070037/**
38 * A simple implementation of a driver manager that differentiates between
39 * connected switches using the OF Description Statistics Reply message.
40 */
41public final class DriverManager implements OpenFlowSwitchDriverFactory {
42
43 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
44
Jonathan Hart2ffcd102015-01-16 16:47:50 -080045 private static final int LOWEST_PRIORITY = 0;
46
Jonathan Hartbbd91d42015-02-27 11:18:04 -080047 private static Dpid corsaDpid = new Dpid();
48
tom7ef8ff92014-09-17 13:08:06 -070049 /**
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 Hart0165d192015-04-30 16:29:48 -070062 String sw = desc.getSwDesc();
Jonathan Hartbbd91d42015-02-27 11:18:04 -080063
64 if (dpid.equals(corsaDpid)) {
sanghoc0b3c342015-03-12 17:12:10 -070065 if (hw.startsWith("Open vSwitch")) {
66 return new OFOVSSwitchCorsaTTP(dpid, desc);
67 } else {
68 return new OFCorsaSwitchDriver(dpid, desc);
69 }
Jonathan Hartbbd91d42015-02-27 11:18:04 -080070 }
71
tom7ef8ff92014-09-17 13:08:06 -070072 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
73 &&
74 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
sanghob35a6192015-04-01 13:05:26 -070075 return new OFSwitchImplSpringOpenTTP(dpid, desc);
tom7ef8ff92014-09-17 13:08:06 -070076 }
77
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070078 //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 Hart081e7372015-01-08 14:17:28 -080086 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070087 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 Hart0165d192015-04-30 16:29:48 -070094 if (vendor.equals("Pica8, Inc.") && sw.startsWith("PicOS") &&
95 ofv == OFVersion.OF_13) {
96 return new OFSwitchImplOVS13(dpid, desc);
97 }
98
99
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700100 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -0700101 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -0700102 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -0700103 }
104
alshabib2216bdb2015-03-04 16:59:22 -0800105 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
tom7ef8ff92014-09-17 13:08:06 -0700111 log.warn("DriverManager could not identify switch desc: {}. "
Jonathan Hartbbd91d42015-02-27 11:18:04 -0800112 + "Assigning AbstractOpenFlowSwich", desc);
tom7ef8ff92014-09-17 13:08:06 -0700113 return new AbstractOpenFlowSwitch(dpid, desc) {
114
115 @Override
alshabib6eb438a2014-10-01 16:39:37 -0700116 public void setRole(RoleState state) {
117 this.role = RoleState.MASTER;
118 }
119
120 @Override
tom7ef8ff92014-09-17 13:08:06 -0700121 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 Hart2ffcd102015-01-16 16:47:50 -0800137 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 }
tom7ef8ff92014-09-17 13:08:06 -0700144
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 Vavilapallif5b234a2015-04-21 13:04:13 -0700158 return Collections.unmodifiableList(this.ports.stream()
159 .flatMap((portReply) -> (portReply.getEntries().stream()))
160 .collect(Collectors.toList()));
tom7ef8ff92014-09-17 13:08:06 -0700161 }
162 }
Saurav Dasfa2fa932015-03-03 11:29:48 -0800163
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 }
tom7ef8ff92014-09-17 13:08:06 -0700174 };
175 }
176
177 /**
178 * Private constructor to avoid instantiation.
179 */
180 private DriverManager() {
181 }
182
tom7ef8ff92014-09-17 13:08:06 -0700183 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
184 OFDescStatsReply desc, OFVersion ofv) {
185 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
186 }
187
Jonathan Hartbbd91d42015-02-27 11:18:04 -0800188 public static void setCorsaDpid(Dpid dpid) {
189 corsaDpid = dpid;
190 }
191
tom7ef8ff92014-09-17 13:08:06 -0700192}