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 | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame^] | 14 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 15 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 16 | import org.slf4j.Logger; |
| 17 | import 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 23 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 24 | |
| 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 | */ |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 41 | 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: {}. " |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame] | 60 | + "Assigning AbstractOpenFlowSwich", desc); |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame^] | 61 | return new AbstractOpenFlowSwitch(dpid, desc) { |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame] | 62 | |
| 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 | } |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame^] | 89 | |
| 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 | } |
alshabib | 898033d | 2014-09-11 13:09:13 -0700 | [diff] [blame] | 98 | }; |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 99 | } |
| 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 | } |
alshabib | 6171f18 | 2014-09-02 19:00:32 -0700 | [diff] [blame] | 118 | |
| 119 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 120 | OFDescStatsReply desc, OFVersion ofv) { |
| 121 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 122 | } |
| 123 | |
alshabib | d777b20 | 2014-08-28 17:52:55 -0700 | [diff] [blame] | 124 | } |