blob: fe86077b7b26e49b19af5adac89d4258a92e242f [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
19 /**
20 * Return an IOFSwitch object based on switch's manufacturer description
21 * from OFDescStatsReply.
22 *
23 * @param desc DescriptionStatistics reply from the switch
24 * @return A IOFSwitch instance if the driver found an implementation for
25 * the given description. Otherwise it returns OFSwitchImplBase
26 */
27 public static IOFSwitch getOFSwitchImpl(OFDescStatsReply desc, OFVersion ofv) {
28 String vendor = desc.getMfrDesc();
29 String hw = desc.getHwDesc();
30 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
31 &&
32 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
33 return new OFSwitchImplCPqD13(desc);
34 }
35
36 if (vendor.startsWith("Nicira") &&
37 hw.startsWith("Open vSwitch")) {
38 if (ofv == OFVersion.OF_10) {
39 return new OFSwitchImplOVS10(desc);
40 } else if (ofv == OFVersion.OF_13) {
41 return new OFSwitchImplOVS13(desc);
42 }
43 }
44
45 log.warn("DriverManager could not identify switch desc: {}. "
46 + "Assigning OFSwitchImplBase", desc);
47 OFSwitchImplBase base = new OFSwitchImplBase();
48 base.setSwitchDescription(desc);
49 // XXX S must set counter here - unidentified switch
50 return base;
51 }
52
53 /**
54 * Private constructor to avoid instantiation.
55 */
56 private DriverManager() {
57 }
58}