blob: 5c967ed65b5a6078a80511f45e5258679c560955 [file] [log] [blame]
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07001package net.onrc.onos.core.drivermanager;
2
3import net.floodlightcontroller.core.IOFSwitch;
4import net.floodlightcontroller.core.internal.OFSwitchImplBase;
5
6import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
7import org.projectfloodlight.openflow.protocol.OFVersion;
8import org.slf4j.Logger;
9import org.slf4j.LoggerFactory;
10
11/**
12 * A simple implementation of a driver manager that differentiates between
13 * connected switches using the OF Description Statistics Reply message.
14 */
15public final class DriverManager {
16
17 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
18
Jonathan Hartcb34f382014-08-12 21:11:03 -070019 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
20 // single table with packet-ins.
21 private static boolean cpqdUsePipeline13 = false;
22
Jonathan Hart2c44a642014-08-19 03:40:43 -070023 // This flag can be set to prevent the driver manager from classifying
24 // switches as OVS switches (and thereby the default switch implementation
25 // will be used).
26 private static boolean disableOvsClassification = false;
27
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070028 /**
29 * Return an IOFSwitch object based on switch's manufacturer description
30 * from OFDescStatsReply.
31 *
32 * @param desc DescriptionStatistics reply from the switch
33 * @return A IOFSwitch instance if the driver found an implementation for
34 * the given description. Otherwise it returns OFSwitchImplBase
35 */
36 public static IOFSwitch getOFSwitchImpl(OFDescStatsReply desc, OFVersion ofv) {
37 String vendor = desc.getMfrDesc();
38 String hw = desc.getHwDesc();
39 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
40 &&
41 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
Jonathan Hartcb34f382014-08-12 21:11:03 -070042 return new OFSwitchImplCPqD13(desc, cpqdUsePipeline13);
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070043 }
44
Jonathan Hart2c44a642014-08-19 03:40:43 -070045 if (!disableOvsClassification && vendor.startsWith("Nicira") &&
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070046 hw.startsWith("Open vSwitch")) {
47 if (ofv == OFVersion.OF_10) {
48 return new OFSwitchImplOVS10(desc);
49 } else if (ofv == OFVersion.OF_13) {
50 return new OFSwitchImplOVS13(desc);
51 }
52 }
53
54 log.warn("DriverManager could not identify switch desc: {}. "
55 + "Assigning OFSwitchImplBase", desc);
56 OFSwitchImplBase base = new OFSwitchImplBase();
57 base.setSwitchDescription(desc);
58 // XXX S must set counter here - unidentified switch
59 return base;
60 }
61
62 /**
63 * Private constructor to avoid instantiation.
64 */
65 private DriverManager() {
66 }
Jonathan Hartcb34f382014-08-12 21:11:03 -070067
68 /**
69 * Sets the configuration parameter which determines how the CPqD switch
70 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
71 * the switch. Otherwise, the switch will be set up in a 1.0 style with
72 * a single table where missed packets are sent to the controller.
73 *
74 * @param usePipeline13 whether to use a 1.3 pipeline or not
75 */
76 public static void setConfigForCpqd(boolean usePipeline13) {
77 cpqdUsePipeline13 = usePipeline13;
78 }
Jonathan Hart2c44a642014-08-19 03:40:43 -070079
80 /**
81 * Sets the configuration parameter which determines whether switches can
82 * be classified as OVS switches or as the default switch implementation.
83 *
84 * Our use case for this is when running OVS under the Flow Space Firewall
85 * (FSFW). The FSFW relays the switch desc reply (containing OVS
86 * description) from the switch to the controller. This causes us to
87 * classify the fake FSFW switch as OVS, however the FSFW switch doesn't
88 * support Nicira role requests and it breaks if we try to send them.
89 * Our workaround is to disable classifying switches as OVS.
90 *
91 * @param disableOvsClassificationFlag whether to use OVS switches or not
92 */
93 public static void setDisableOvsClassification(
94 boolean disableOvsClassificationFlag) {
95 disableOvsClassification = disableOvsClassificationFlag;
96 }
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070097}