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