blob: 1744a76ff69c8bc18165463b38bd8cb3dd76a901 [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
alshabib898033d2014-09-11 13:09:13 -07005import java.util.Collections;
6import java.util.List;
7
alshabibd777b202014-08-28 17:52:55 -07008import org.onlab.onos.of.controller.Dpid;
alshabib898033d2014-09-11 13:09:13 -07009import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch;
alshabib6171f182014-09-02 19:00:32 -070010import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver;
11import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory;
alshabibd777b202014-08-28 17:52:55 -070012import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
alshabib898033d2014-09-11 13:09:13 -070013import org.projectfloodlight.openflow.protocol.OFMessage;
alshabibd777b202014-08-28 17:52:55 -070014import org.projectfloodlight.openflow.protocol.OFVersion;
15import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
18/**
19 * A simple implementation of a driver manager that differentiates between
20 * connected switches using the OF Description Statistics Reply message.
21 */
alshabib6171f182014-09-02 19:00:32 -070022public final class DriverManager implements OpenFlowSwitchDriverFactory {
alshabibd777b202014-08-28 17:52:55 -070023
24 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
25
26 // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style
27 // single table with packet-ins.
28 private static boolean cpqdUsePipeline13 = false;
29
30 /**
31 * Return an IOFSwitch object based on switch's manufacturer description
32 * from OFDescStatsReply.
33 *
34 * @param desc DescriptionStatistics reply from the switch
35 * @return A IOFSwitch instance if the driver found an implementation for
36 * the given description. Otherwise it returns OFSwitchImplBase
37 */
alshabib6171f182014-09-02 19:00:32 -070038 @Override
39 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
alshabibd777b202014-08-28 17:52:55 -070040 OFDescStatsReply desc, OFVersion ofv) {
41 String vendor = desc.getMfrDesc();
42 String hw = desc.getHwDesc();
43 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
44 &&
45 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
46 return new OFSwitchImplCPqD13(dpid, desc, cpqdUsePipeline13);
47 }
48
49 if (vendor.startsWith("Nicira") &&
50 hw.startsWith("Open vSwitch")) {
51 if (ofv == OFVersion.OF_10) {
52 return new OFSwitchImplOVS10(dpid, desc);
53 } else if (ofv == OFVersion.OF_13) {
54 return new OFSwitchImplOVS13(dpid, desc);
55 }
56 }
57
58 log.warn("DriverManager could not identify switch desc: {}. "
alshabib898033d2014-09-11 13:09:13 -070059 + "Assigning AbstractOpenFlowSwich", desc);
60 return new AbstractOpenFlowSwitch(dpid) {
61
62 @Override
63 public void write(List<OFMessage> msgs) {
64 channel.write(msgs);
65 }
66
67 @Override
68 public void write(OFMessage msg) {
69 channel.write(Collections.singletonList(msg));
70
71 }
72
73 @Override
74 public Boolean supportNxRole() {
75 return false;
76 }
77
78 @Override
79 public void startDriverHandshake() {}
80
81 @Override
82 public void processDriverHandshakeMessage(OFMessage m) {}
83
84 @Override
85 public boolean isDriverHandshakeComplete() {
86 return true;
87 }
88 };
alshabibd777b202014-08-28 17:52:55 -070089 }
90
91 /**
92 * Private constructor to avoid instantiation.
93 */
94 private DriverManager() {
95 }
96
97 /**
98 * Sets the configuration parameter which determines how the CPqD switch
99 * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on
100 * the switch. Otherwise, the switch will be set up in a 1.0 style with
101 * a single table where missed packets are sent to the controller.
102 *
103 * @param usePipeline13 whether to use a 1.3 pipeline or not
104 */
105 public static void setConfigForCpqd(boolean usePipeline13) {
106 cpqdUsePipeline13 = usePipeline13;
107 }
alshabib6171f182014-09-02 19:00:32 -0700108
109 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
110 OFDescStatsReply desc, OFVersion ofv) {
111 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
112 }
113
alshabibd777b202014-08-28 17:52:55 -0700114}