blob: 1e3064b5679a6e17a838462c2c1c9e2a0eb86857 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom9c94c5b2014-09-17 13:14:42 -070019package org.onlab.onos.openflow.drivers.impl;
tom7ef8ff92014-09-17 13:08:06 -070020
21
22
23import java.util.Collections;
24import java.util.List;
25
tom9c94c5b2014-09-17 13:14:42 -070026import org.onlab.onos.openflow.controller.Dpid;
alshabib6eb438a2014-10-01 16:39:37 -070027import org.onlab.onos.openflow.controller.RoleState;
tom9c94c5b2014-09-17 13:14:42 -070028import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
29import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver;
30import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriverFactory;
tom7ef8ff92014-09-17 13:08:06 -070031import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
32import org.projectfloodlight.openflow.protocol.OFMessage;
33import org.projectfloodlight.openflow.protocol.OFPortDesc;
34import org.projectfloodlight.openflow.protocol.OFVersion;
35import org.slf4j.Logger;
36import org.slf4j.LoggerFactory;
37
38/**
39 * A simple implementation of a driver manager that differentiates between
40 * connected switches using the OF Description Statistics Reply message.
41 */
42public final class DriverManager implements OpenFlowSwitchDriverFactory {
43
44 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
45
46 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
47 // single table with packet-ins.
48 private static boolean cpqdUsePipeline13 = false;
49
50 /**
51 * Return an IOFSwitch object based on switch's manufacturer description
52 * from OFDescStatsReply.
53 *
54 * @param desc DescriptionStatistics reply from the switch
55 * @return A IOFSwitch instance if the driver found an implementation for
56 * the given description. Otherwise it returns OFSwitchImplBase
57 */
58 @Override
59 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
60 OFDescStatsReply desc, OFVersion ofv) {
61 String vendor = desc.getMfrDesc();
62 String hw = desc.getHwDesc();
63 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
64 &&
65 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
66 return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13);
67 }
68
69 if (vendor.startsWith("Nicira") &&
70 hw.startsWith("Open vSwitch")) {
71 if (ofv == OFVersion.OF_10) {
72 return new OFSwitchImplOVS10(dpid, desc);
73 } else if (ofv == OFVersion.OF_13) {
74 return new OFSwitchImplOVS13(dpid, desc);
75 }
76 }
77
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070078 String sw = desc.getSwDesc();
79 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070080 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070081 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070082 }
83
tom7ef8ff92014-09-17 13:08:06 -070084 log.warn("DriverManager could not identify switch desc: {}. "
85 + "Assigning AbstractOpenFlowSwich", desc);
86 return new AbstractOpenFlowSwitch(dpid, desc) {
87
88 @Override
alshabib6eb438a2014-10-01 16:39:37 -070089 public void setRole(RoleState state) {
90 this.role = RoleState.MASTER;
91 }
92
93 @Override
tom7ef8ff92014-09-17 13:08:06 -070094 public void write(List<OFMessage> msgs) {
95 channel.write(msgs);
96 }
97
98 @Override
99 public void write(OFMessage msg) {
100 channel.write(Collections.singletonList(msg));
101
102 }
103
104 @Override
105 public Boolean supportNxRole() {
106 return false;
107 }
108
109 @Override
110 public void startDriverHandshake() {}
111
112 @Override
113 public void processDriverHandshakeMessage(OFMessage m) {}
114
115 @Override
116 public boolean isDriverHandshakeComplete() {
117 return true;
118 }
119
120 @Override
121 public List<OFPortDesc> getPorts() {
122 if (this.factory().getVersion() == OFVersion.OF_10) {
123 return Collections.unmodifiableList(features.getPorts());
124 } else {
125 return Collections.unmodifiableList(ports.getEntries());
126 }
127 }
128 };
129 }
130
131 /**
132 * Private constructor to avoid instantiation.
133 */
134 private DriverManager() {
135 }
136
137 /**
138 * Sets the configuration parameter which determines how the CPqD switch
139 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
140 * the switch. Otherwise, the switch will be set up in a 1.0 style with
141 * a single table where missed packets are sent to the controller.
142 *
143 * @param usePipeline13 whether to use a 1.3 pipeline or not
144 */
145 public static void setConfigForCpqd(boolean usePipeline13) {
146 cpqdUsePipeline13 = usePipeline13;
147 }
148
149 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
150 OFDescStatsReply desc, OFVersion ofv) {
151 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
152 }
153
154}