blob: ce5751cca6fa4f318631f86aa9caad7a95b08a4a [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 */
alshabib452234e2014-11-25 00:03:49 -050016package org.onlab.onos.openflow.drivers;
tom7ef8ff92014-09-17 13:08:06 -070017
18
tom9c94c5b2014-09-17 13:14:42 -070019import org.onlab.onos.openflow.controller.Dpid;
alshabib6eb438a2014-10-01 16:39:37 -070020import org.onlab.onos.openflow.controller.RoleState;
tom9c94c5b2014-09-17 13:14:42 -070021import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
22import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver;
23import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriverFactory;
alshabib452234e2014-11-25 00:03:49 -050024
tom7ef8ff92014-09-17 13:08:06 -070025import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
26import org.projectfloodlight.openflow.protocol.OFMessage;
27import org.projectfloodlight.openflow.protocol.OFPortDesc;
28import org.projectfloodlight.openflow.protocol.OFVersion;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
alshabib452234e2014-11-25 00:03:49 -050032import java.util.Collections;
33import java.util.List;
34
tom7ef8ff92014-09-17 13:08:06 -070035/**
36 * A simple implementation of a driver manager that differentiates between
37 * connected switches using the OF Description Statistics Reply message.
38 */
39public final class DriverManager implements OpenFlowSwitchDriverFactory {
40
41 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
42
43 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
44 // single table with packet-ins.
45 private static boolean cpqdUsePipeline13 = false;
46
47 /**
48 * Return an IOFSwitch object based on switch's manufacturer description
49 * from OFDescStatsReply.
50 *
51 * @param desc DescriptionStatistics reply from the switch
52 * @return A IOFSwitch instance if the driver found an implementation for
53 * the given description. Otherwise it returns OFSwitchImplBase
54 */
55 @Override
56 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
57 OFDescStatsReply desc, OFVersion ofv) {
58 String vendor = desc.getMfrDesc();
59 String hw = desc.getHwDesc();
60 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
61 &&
62 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
63 return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13);
64 }
65
66 if (vendor.startsWith("Nicira") &&
67 hw.startsWith("Open vSwitch")) {
68 if (ofv == OFVersion.OF_10) {
69 return new OFSwitchImplOVS10(dpid, desc);
70 } else if (ofv == OFVersion.OF_13) {
71 return new OFSwitchImplOVS13(dpid, desc);
72 }
73 }
74
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070075 String sw = desc.getSwDesc();
76 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070077 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070078 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070079 }
80
tom7ef8ff92014-09-17 13:08:06 -070081 log.warn("DriverManager could not identify switch desc: {}. "
82 + "Assigning AbstractOpenFlowSwich", desc);
83 return new AbstractOpenFlowSwitch(dpid, desc) {
84
85 @Override
alshabib6eb438a2014-10-01 16:39:37 -070086 public void setRole(RoleState state) {
87 this.role = RoleState.MASTER;
88 }
89
90 @Override
tom7ef8ff92014-09-17 13:08:06 -070091 public void write(List<OFMessage> msgs) {
92 channel.write(msgs);
93 }
94
95 @Override
96 public void write(OFMessage msg) {
97 channel.write(Collections.singletonList(msg));
98
99 }
100
101 @Override
102 public Boolean supportNxRole() {
103 return false;
104 }
105
106 @Override
107 public void startDriverHandshake() {}
108
109 @Override
110 public void processDriverHandshakeMessage(OFMessage m) {}
111
112 @Override
113 public boolean isDriverHandshakeComplete() {
114 return true;
115 }
116
117 @Override
118 public List<OFPortDesc> getPorts() {
119 if (this.factory().getVersion() == OFVersion.OF_10) {
120 return Collections.unmodifiableList(features.getPorts());
121 } else {
122 return Collections.unmodifiableList(ports.getEntries());
123 }
124 }
125 };
126 }
127
128 /**
129 * Private constructor to avoid instantiation.
130 */
131 private DriverManager() {
132 }
133
134 /**
135 * Sets the configuration parameter which determines how the CPqD switch
136 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
137 * the switch. Otherwise, the switch will be set up in a 1.0 style with
138 * a single table where missed packets are sent to the controller.
139 *
140 * @param usePipeline13 whether to use a 1.3 pipeline or not
141 */
142 public static void setConfigForCpqd(boolean usePipeline13) {
143 cpqdUsePipeline13 = usePipeline13;
144 }
145
146 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
147 OFDescStatsReply desc, OFVersion ofv) {
148 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
149 }
150
151}