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 | |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame^] | 5 | import java.util.Collections; |
| 6 | import java.util.List; |
| 7 | |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 8 | import org.onlab.onos.of.controller.Dpid; |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame^] | 9 | import org.onlab.onos.of.controller.driver.AbstractOpenFlowSwitch; |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 10 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriver; |
| 11 | import org.onlab.onos.of.controller.driver.OpenFlowSwitchDriverFactory; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 12 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame^] | 13 | import org.projectfloodlight.openflow.protocol.OFMessage; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 14 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 15 | import org.slf4j.Logger; |
| 16 | import 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 22 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 23 | |
| 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 38 | @Override |
| 39 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 40 | 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: {}. " |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame^] | 59 | + "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 | }; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 89 | } |
| 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 | } |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 108 | |
| 109 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 110 | OFDescStatsReply desc, OFVersion ofv) { |
| 111 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 112 | } |
| 113 | |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 114 | } |