blob: f7a5f1a668fa3e79665dee291299b9fddbe3bbf1 [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
42 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
43 // single table with packet-ins.
44 private static boolean cpqdUsePipeline13 = false;
45
46 /**
47 * Return an IOFSwitch object based on switch's manufacturer description
48 * from OFDescStatsReply.
49 *
50 * @param desc DescriptionStatistics reply from the switch
51 * @return A IOFSwitch instance if the driver found an implementation for
52 * the given description. Otherwise it returns OFSwitchImplBase
53 */
54 @Override
55 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
56 OFDescStatsReply desc, OFVersion ofv) {
57 String vendor = desc.getMfrDesc();
58 String hw = desc.getHwDesc();
59 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
60 &&
61 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
62 return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13);
63 }
64
Jonathan Hart081e7372015-01-08 14:17:28 -080065 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070066 if (ofv == OFVersion.OF_10) {
67 return new OFSwitchImplOVS10(dpid, desc);
68 } else if (ofv == OFVersion.OF_13) {
69 return new OFSwitchImplOVS13(dpid, desc);
70 }
71 }
72
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070073 String sw = desc.getSwDesc();
74 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070075 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070076 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070077 }
78
tom7ef8ff92014-09-17 13:08:06 -070079 log.warn("DriverManager could not identify switch desc: {}. "
80 + "Assigning AbstractOpenFlowSwich", desc);
81 return new AbstractOpenFlowSwitch(dpid, desc) {
82
83 @Override
alshabib6eb438a2014-10-01 16:39:37 -070084 public void setRole(RoleState state) {
85 this.role = RoleState.MASTER;
86 }
87
88 @Override
tom7ef8ff92014-09-17 13:08:06 -070089 public void write(List<OFMessage> msgs) {
90 channel.write(msgs);
91 }
92
93 @Override
94 public void write(OFMessage msg) {
95 channel.write(Collections.singletonList(msg));
96
97 }
98
99 @Override
100 public Boolean supportNxRole() {
101 return false;
102 }
103
104 @Override
105 public void startDriverHandshake() {}
106
107 @Override
108 public void processDriverHandshakeMessage(OFMessage m) {}
109
110 @Override
111 public boolean isDriverHandshakeComplete() {
112 return true;
113 }
114
115 @Override
116 public List<OFPortDesc> getPorts() {
117 if (this.factory().getVersion() == OFVersion.OF_10) {
118 return Collections.unmodifiableList(features.getPorts());
119 } else {
120 return Collections.unmodifiableList(ports.getEntries());
121 }
122 }
123 };
124 }
125
126 /**
127 * Private constructor to avoid instantiation.
128 */
129 private DriverManager() {
130 }
131
132 /**
133 * Sets the configuration parameter which determines how the CPqD switch
134 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
135 * the switch. Otherwise, the switch will be set up in a 1.0 style with
136 * a single table where missed packets are sent to the controller.
137 *
138 * @param usePipeline13 whether to use a 1.3 pipeline or not
139 */
140 public static void setConfigForCpqd(boolean usePipeline13) {
141 cpqdUsePipeline13 = usePipeline13;
142 }
143
144 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
145 OFDescStatsReply desc, OFVersion ofv) {
146 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
147 }
148
149}