blob: c10c3a9b9ac66c241943bb1c2507d7ff9c178e5c [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 Hartbbd91d42015-02-27 11:18:04 -080062
63 if (dpid.equals(corsaDpid)) {
sanghoc0b3c342015-03-12 17:12:10 -070064 if (hw.startsWith("Open vSwitch")) {
65 return new OFOVSSwitchCorsaTTP(dpid, desc);
66 } else {
67 return new OFCorsaSwitchDriver(dpid, desc);
68 }
Jonathan Hartbbd91d42015-02-27 11:18:04 -080069 }
70
tom7ef8ff92014-09-17 13:08:06 -070071 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
72 &&
73 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
sanghob35a6192015-04-01 13:05:26 -070074 return new OFSwitchImplSpringOpenTTP(dpid, desc);
tom7ef8ff92014-09-17 13:08:06 -070075 }
76
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070077 //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 Hart081e7372015-01-08 14:17:28 -080085 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070086 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 Balakrishnane48aa682014-10-08 17:31:37 -070093 String sw = desc.getSwDesc();
94 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070095 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070096 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070097 }
98
alshabib2216bdb2015-03-04 16:59:22 -080099 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
tom7ef8ff92014-09-17 13:08:06 -0700105 log.warn("DriverManager could not identify switch desc: {}. "
Jonathan Hartbbd91d42015-02-27 11:18:04 -0800106 + "Assigning AbstractOpenFlowSwich", desc);
tom7ef8ff92014-09-17 13:08:06 -0700107 return new AbstractOpenFlowSwitch(dpid, desc) {
108
109 @Override
alshabib6eb438a2014-10-01 16:39:37 -0700110 public void setRole(RoleState state) {
111 this.role = RoleState.MASTER;
112 }
113
114 @Override
tom7ef8ff92014-09-17 13:08:06 -0700115 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 Hart2ffcd102015-01-16 16:47:50 -0800131 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 }
tom7ef8ff92014-09-17 13:08:06 -0700138
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 Vavilapallif5b234a2015-04-21 13:04:13 -0700152 return Collections.unmodifiableList(this.ports.stream()
153 .flatMap((portReply) -> (portReply.getEntries().stream()))
154 .collect(Collectors.toList()));
tom7ef8ff92014-09-17 13:08:06 -0700155 }
156 }
Saurav Dasfa2fa932015-03-03 11:29:48 -0800157
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 }
tom7ef8ff92014-09-17 13:08:06 -0700168 };
169 }
170
171 /**
172 * Private constructor to avoid instantiation.
173 */
174 private DriverManager() {
175 }
176
tom7ef8ff92014-09-17 13:08:06 -0700177 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
178 OFDescStatsReply desc, OFVersion ofv) {
179 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
180 }
181
Jonathan Hartbbd91d42015-02-27 11:18:04 -0800182 public static void setCorsaDpid(Dpid dpid) {
183 corsaDpid = dpid;
184 }
185
tom7ef8ff92014-09-17 13:08:06 -0700186}