blob: bfd60d92166f4afe267829cc81f9fa42d58b3f20 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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;
35
tom7ef8ff92014-09-17 13:08:06 -070036/**
37 * A simple implementation of a driver manager that differentiates between
38 * connected switches using the OF Description Statistics Reply message.
39 */
40public final class DriverManager implements OpenFlowSwitchDriverFactory {
41
42 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
43
Jonathan Hart2ffcd102015-01-16 16:47:50 -080044 private static final int LOWEST_PRIORITY = 0;
45
Jonathan Hartbbd91d42015-02-27 11:18:04 -080046 private static Dpid corsaDpid = new Dpid();
47
tom7ef8ff92014-09-17 13:08:06 -070048 /**
49 * Return an IOFSwitch object based on switch's manufacturer description
50 * from OFDescStatsReply.
51 *
52 * @param desc DescriptionStatistics reply from the switch
53 * @return A IOFSwitch instance if the driver found an implementation for
54 * the given description. Otherwise it returns OFSwitchImplBase
55 */
56 @Override
57 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
58 OFDescStatsReply desc, OFVersion ofv) {
59 String vendor = desc.getMfrDesc();
60 String hw = desc.getHwDesc();
Jonathan Hartbbd91d42015-02-27 11:18:04 -080061
62 if (dpid.equals(corsaDpid)) {
sanghoc0b3c342015-03-12 17:12:10 -070063 if (hw.startsWith("Open vSwitch")) {
64 return new OFOVSSwitchCorsaTTP(dpid, desc);
65 } else {
66 return new OFCorsaSwitchDriver(dpid, desc);
67 }
Jonathan Hartbbd91d42015-02-27 11:18:04 -080068 }
69
tom7ef8ff92014-09-17 13:08:06 -070070 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
71 &&
72 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
Jonathan Hart47f2dde2015-01-14 17:45:06 -080073 return new OFSwitchImplCPqD13(dpid, desc);
tom7ef8ff92014-09-17 13:08:06 -070074 }
75
Jonathan Hart081e7372015-01-08 14:17:28 -080076 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070077 if (ofv == OFVersion.OF_10) {
78 return new OFSwitchImplOVS10(dpid, desc);
79 } else if (ofv == OFVersion.OF_13) {
80 return new OFSwitchImplOVS13(dpid, desc);
81 }
82 }
83
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070084 String sw = desc.getSwDesc();
85 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070086 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070087 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070088 }
89
alshabib2216bdb2015-03-04 16:59:22 -080090 if (vendor.startsWith("Corsa") && hw.startsWith("Corsa Element")
91 && sw.startsWith("2.3.1")) {
92 log.warn("Corsa Switch 2.3.1 found");
93 return new OFCorsaSwitchDriver(dpid, desc);
94 }
95
tom7ef8ff92014-09-17 13:08:06 -070096 log.warn("DriverManager could not identify switch desc: {}. "
Jonathan Hartbbd91d42015-02-27 11:18:04 -080097 + "Assigning AbstractOpenFlowSwich", desc);
tom7ef8ff92014-09-17 13:08:06 -070098 return new AbstractOpenFlowSwitch(dpid, desc) {
99
100 @Override
alshabib6eb438a2014-10-01 16:39:37 -0700101 public void setRole(RoleState state) {
102 this.role = RoleState.MASTER;
103 }
104
105 @Override
tom7ef8ff92014-09-17 13:08:06 -0700106 public void write(List<OFMessage> msgs) {
107 channel.write(msgs);
108 }
109
110 @Override
111 public void write(OFMessage msg) {
112 channel.write(Collections.singletonList(msg));
113
114 }
115
116 @Override
117 public Boolean supportNxRole() {
118 return false;
119 }
120
121 @Override
Jonathan Hart2ffcd102015-01-16 16:47:50 -0800122 public void startDriverHandshake() {
123 if (factory().getVersion() == OFVersion.OF_10) {
124 OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
125 fmBuilder.setPriority(LOWEST_PRIORITY);
126 write(fmBuilder.build());
127 }
128 }
tom7ef8ff92014-09-17 13:08:06 -0700129
130 @Override
131 public void processDriverHandshakeMessage(OFMessage m) {}
132
133 @Override
134 public boolean isDriverHandshakeComplete() {
135 return true;
136 }
137
138 @Override
139 public List<OFPortDesc> getPorts() {
140 if (this.factory().getVersion() == OFVersion.OF_10) {
141 return Collections.unmodifiableList(features.getPorts());
142 } else {
143 return Collections.unmodifiableList(ports.getEntries());
144 }
145 }
Saurav Dasfa2fa932015-03-03 11:29:48 -0800146
147 @Override
148 public TableType getTableType(TableId tid) {
149 return TableType.NONE;
150 }
151
152 @Override
153 public void transformAndSendMsg(OFMessage msg, TableType tableType) {
154 // TODO Auto-generated method stub
155
156 }
tom7ef8ff92014-09-17 13:08:06 -0700157 };
158 }
159
160 /**
161 * Private constructor to avoid instantiation.
162 */
163 private DriverManager() {
164 }
165
tom7ef8ff92014-09-17 13:08:06 -0700166 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
167 OFDescStatsReply desc, OFVersion ofv) {
168 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
169 }
170
Jonathan Hartbbd91d42015-02-27 11:18:04 -0800171 public static void setCorsaDpid(Dpid dpid) {
172 corsaDpid = dpid;
173 }
174
tom7ef8ff92014-09-17 13:08:06 -0700175}