blob: f7c547cd7958788e29a84491a806dca40dce73a5 [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
Jonathan Hart081e7372015-01-08 14:17:28 -080019import java.util.Collections;
20import java.util.List;
21
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.openflow.controller.Dpid;
23import org.onosproject.openflow.controller.RoleState;
24import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
25import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
26import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory;
tom7ef8ff92014-09-17 13:08:06 -070027import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
28import org.projectfloodlight.openflow.protocol.OFMessage;
29import org.projectfloodlight.openflow.protocol.OFPortDesc;
30import org.projectfloodlight.openflow.protocol.OFVersion;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34/**
35 * A simple implementation of a driver manager that differentiates between
36 * connected switches using the OF Description Statistics Reply message.
37 */
38public final class DriverManager implements OpenFlowSwitchDriverFactory {
39
40 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
41
tom7ef8ff92014-09-17 13:08:06 -070042 /**
43 * Return an IOFSwitch object based on switch's manufacturer description
44 * from OFDescStatsReply.
45 *
46 * @param desc DescriptionStatistics reply from the switch
47 * @return A IOFSwitch instance if the driver found an implementation for
48 * the given description. Otherwise it returns OFSwitchImplBase
49 */
50 @Override
51 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
52 OFDescStatsReply desc, OFVersion ofv) {
53 String vendor = desc.getMfrDesc();
54 String hw = desc.getHwDesc();
55 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
56 &&
57 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
Jonathan Hart47f2dde2015-01-14 17:45:06 -080058 return new OFSwitchImplCPqD13(dpid, desc);
tom7ef8ff92014-09-17 13:08:06 -070059 }
60
Jonathan Hart081e7372015-01-08 14:17:28 -080061 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070062 if (ofv == OFVersion.OF_10) {
63 return new OFSwitchImplOVS10(dpid, desc);
64 } else if (ofv == OFVersion.OF_13) {
65 return new OFSwitchImplOVS13(dpid, desc);
66 }
67 }
68
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070069 String sw = desc.getSwDesc();
70 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070071 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070072 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070073 }
74
tom7ef8ff92014-09-17 13:08:06 -070075 log.warn("DriverManager could not identify switch desc: {}. "
76 + "Assigning AbstractOpenFlowSwich", desc);
77 return new AbstractOpenFlowSwitch(dpid, desc) {
78
79 @Override
alshabib6eb438a2014-10-01 16:39:37 -070080 public void setRole(RoleState state) {
81 this.role = RoleState.MASTER;
82 }
83
84 @Override
tom7ef8ff92014-09-17 13:08:06 -070085 public void write(List<OFMessage> msgs) {
86 channel.write(msgs);
87 }
88
89 @Override
90 public void write(OFMessage msg) {
91 channel.write(Collections.singletonList(msg));
92
93 }
94
95 @Override
96 public Boolean supportNxRole() {
97 return false;
98 }
99
100 @Override
101 public void startDriverHandshake() {}
102
103 @Override
104 public void processDriverHandshakeMessage(OFMessage m) {}
105
106 @Override
107 public boolean isDriverHandshakeComplete() {
108 return true;
109 }
110
111 @Override
112 public List<OFPortDesc> getPorts() {
113 if (this.factory().getVersion() == OFVersion.OF_10) {
114 return Collections.unmodifiableList(features.getPorts());
115 } else {
116 return Collections.unmodifiableList(ports.getEntries());
117 }
118 }
119 };
120 }
121
122 /**
123 * Private constructor to avoid instantiation.
124 */
125 private DriverManager() {
126 }
127
tom7ef8ff92014-09-17 13:08:06 -0700128 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
129 OFDescStatsReply desc, OFVersion ofv) {
130 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
131 }
132
133}