blob: 2c72c178e3c37f26b0d5ad09ca089f7d07ae94da [file] [log] [blame]
alshabibf1216ed2014-09-03 11:53:54 -07001package org.onlab.onos.of.drivers.impl;
alshabibd777b202014-08-28 17:52:55 -07002
3
alshabibd777b202014-08-28 17:52:55 -07004
5import org.onlab.onos.of.controller.Dpid;
alshabib6171f182014-09-02 19:00:32 -07006import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
7import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory;
alshabibd777b202014-08-28 17:52:55 -07008import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
alshabibd777b202014-08-28 17:52:55 -07009import org.projectfloodlight.openflow.protocol.OFVersion;
10import org.slf4j.Logger;
11import org.slf4j.LoggerFactory;
12
13/**
14 * A simple implementation of a driver manager that differentiates between
15 * connected switches using the OF Description Statistics Reply message.
16 */
alshabib6171f182014-09-02 19:00:32 -070017public final class DriverManager implements OpenFlowSwitchDriverFactory {
alshabibd777b202014-08-28 17:52:55 -070018
19 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
20
21 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
22 // single table with packet-ins.
23 private static boolean cpqdUsePipeline13 = false;
24
25 /**
26 * Return an IOFSwitch object based on switch's manufacturer description
27 * from OFDescStatsReply.
28 *
29 * @param desc DescriptionStatistics reply from the switch
30 * @return A IOFSwitch instance if the driver found an implementation for
31 * the given description. Otherwise it returns OFSwitchImplBase
32 */
alshabib6171f182014-09-02 19:00:32 -070033 @Override
34 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
alshabibd777b202014-08-28 17:52:55 -070035 OFDescStatsReply desc, OFVersion ofv) {
36 String vendor = desc.getMfrDesc();
37 String hw = desc.getHwDesc();
38 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
39 &&
40 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
41 return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13);
42 }
43
44 if (vendor.startsWith("Nicira") &&
45 hw.startsWith("Open vSwitch")) {
46 if (ofv == OFVersion.OF_10) {
47 return new OFSwitchImplOVS10(dpid, desc);
48 } else if (ofv == OFVersion.OF_13) {
49 return new OFSwitchImplOVS13(dpid, desc);
50 }
51 }
52
53 log.warn("DriverManager could not identify switch desc: {}. "
54 + "Assigning OFSwitchImplBase", desc);
alshabib6171f182014-09-02 19:00:32 -070055 return null;
alshabibd777b202014-08-28 17:52:55 -070056 }
57
58 /**
59 * Private constructor to avoid instantiation.
60 */
61 private DriverManager() {
62 }
63
64 /**
65 * Sets the configuration parameter which determines how the CPqD switch
66 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
67 * the switch. Otherwise, the switch will be set up in a 1.0 style with
68 * a single table where missed packets are sent to the controller.
69 *
70 * @param usePipeline13 whether to use a 1.3 pipeline or not
71 */
72 public static void setConfigForCpqd(boolean usePipeline13) {
73 cpqdUsePipeline13 = usePipeline13;
74 }
alshabib6171f182014-09-02 19:00:32 -070075
76 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
77 OFDescStatsReply desc, OFVersion ofv) {
78 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
79 }
80
alshabibd777b202014-08-28 17:52:55 -070081}