alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 1 | package org.onlab.onos.of.drivers.impl; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 2 | |
| 3 | |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 4 | |
| 5 | import org.onlab.onos.of.controller.Dpid; |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 6 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver; |
| 7 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 8 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 9 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 10 | import org.slf4j.Logger; |
| 11 | import 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 17 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 18 | |
| 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 33 | @Override |
| 34 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 35 | 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); |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 55 | return null; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 56 | } |
| 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 | } |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 75 | |
| 76 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 77 | OFDescStatsReply desc, OFVersion ofv) { |
| 78 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 79 | } |
| 80 | |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 81 | } |